上面的代码还有些问题,没有处理系统本就已经启动完毕的情况
刚才后台掉线关灯失败,怎么重载都连不上才发现..
还得改造一下下
from homeassistant.const import EVENT_HOMEASSISTANT_STARTED
async def async_setup_entry(hass: HomeAssistant, entry: WsMCPServerConfigEntry) -> bool:
"""Set up Model Context Protocol Server from a config entry."""
async def _system_started(event):
entry.runtime_data = SessionManager()
await websocket_transport.async_setup_entry(hass,entry)
if hass.is_running:
await _system_started(None)
else:
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STARTED, _system_started)
return True
|