"""The Smart Home integration.""" from __future__ import annotations import logging from homeassistant.config_entries import ConfigEntry from homeassistant.const import Platform, CONF_HOST, CONF_PORT, CONF_NAME from homeassistant.core import HomeAssistant, callback from .const import ( DOMAIN, DATA_COORDINATOR, DATA_CONFIG, DEFAULT_PORT ) from .coordinator import SmartHomeDataUpdateCoordinator from .services import async_setup_services, async_unload_services _LOGGER = logging.getLogger(__name__) PLATFORMS: list[Platform] = [ Platform.SWITCH, Platform.LIGHT, Platform.BUTTON, Platform.COVER, Platform.SENSOR, Platform.BINARY_SENSOR, ] async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Set up Smart Home from a config entry.""" hass.data.setdefault(DOMAIN, {}) coordinator = SmartHomeDataUpdateCoordinator( hass, config=entry.data, entry_id=entry.entry_id, ) await coordinator.async_config_entry_first_refresh() hass.data[DOMAIN][entry.entry_id] = { DATA_COORDINATOR: coordinator, DATA_CONFIG: entry.data, } await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) # Register services await async_setup_services(hass) return True async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Unload a config entry.""" unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS) if unload_ok: coordinator: SmartHomeDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id][DATA_COORDINATOR] await coordinator.async_shutdown() hass.data[DOMAIN].pop(entry.entry_id) await async_unload_services(hass) return unload_ok