Files

34 lines
1.1 KiB
Python

from __future__ import annotations
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryNotReady
from .bridge import BridgeManager
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
manager = BridgeManager(hass, entry)
try:
await manager.async_setup()
except ConfigEntryNotReady:
await manager.async_unload()
raise
entry.runtime_data = manager
entry.async_on_unload(entry.add_update_listener(_update_listener))
await hass.config_entries.async_forward_entry_setups(entry, ["switch"])
return True
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
manager: BridgeManager | None = getattr(entry, "runtime_data", None)
if manager is None:
return True
await manager.async_unload()
await hass.config_entries.async_unload_platforms(entry, ["switch"])
return True
async def _update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None:
await hass.config_entries.async_reload(entry.entry_id)