1 """The chacon_dio integration."""
3 from dataclasses
import dataclass
7 from dio_chacon_wifi_api
import DIOChaconAPIClient
13 EVENT_HOMEASSISTANT_STOP,
18 _LOGGER = logging.getLogger(__name__)
20 PLATFORMS: list[Platform] = [Platform.COVER, Platform.SWITCH]
25 """Chacon Dio data class."""
27 client: DIOChaconAPIClient
28 list_devices: list[dict[str, Any]]
31 type ChaconDioConfigEntry = ConfigEntry[ChaconDioData]
35 """Set up chacon_dio from a config entry."""
39 username = config[CONF_USERNAME]
40 password = config[CONF_PASSWORD]
41 dio_chacon_id = entry.unique_id
43 _LOGGER.debug(
"Initializing Chacon Dio client %s, %s", username, dio_chacon_id)
44 client = DIOChaconAPIClient(
50 found_devices = await client.search_all_devices(with_state=
True)
51 list_devices =
list(found_devices.values())
52 _LOGGER.debug(
"List of devices %s", list_devices)
56 list_devices=list_devices,
59 await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
62 async
def _async_disconnect_websocket(_: Event) ->
None:
63 await client.disconnect()
65 entry.async_on_unload(
66 hass.bus.async_listen_once(
67 EVENT_HOMEASSISTANT_STOP, _async_disconnect_websocket
75 """Unload a config entry."""
77 if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
78 await entry.runtime_data.client.disconnect()
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
bool async_setup_entry(HomeAssistant hass, ChaconDioConfigEntry entry)