import logging from homeassistant.config_entries import ConfigEntry from homeassistant.const import Platform from homeassistant.core import HomeAssistant from .coordinator import OneControlCoordinator from .const import DOMAIN _LOGGER = logging.getLogger(__name__) PLATFORMS = [Platform.SWITCH, Platform.SENSOR, Platform.COVER] async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: address = entry.data["address"] coordinator = OneControlCoordinator(hass, address) try: await coordinator.async_connect() except Exception as e: _LOGGER.error("Failed to connect to OneControl at %s: %s", address, e) return False hass.data.setdefault(DOMAIN, {})[entry.entry_id] = coordinator await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) return True async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS) if unload_ok: coordinator: OneControlCoordinator = hass.data[DOMAIN].pop(entry.entry_id) await coordinator.async_disconnect() return unload_ok