1 """The devolo_home_control integration."""
3 from __future__
import annotations
6 from functools
import partial
7 from types
import MappingProxyType
10 from devolo_home_control_api.exceptions.gateway
import GatewayOfflineError
11 from devolo_home_control_api.homecontrol
import HomeControl
12 from devolo_home_control_api.mydevolo
import Mydevolo
21 from .const
import CONF_MYDEVOLO, DEFAULT_MYDEVOLO, GATEWAY_SERIAL_PATTERN, PLATFORMS
23 type DevoloHomeControlConfigEntry = ConfigEntry[list[HomeControl]]
27 hass: HomeAssistant, entry: DevoloHomeControlConfigEntry
29 """Set up the devolo account from a config entry."""
32 credentials_valid = await hass.async_add_executor_job(mydevolo.credentials_valid)
34 if not credentials_valid:
35 raise ConfigEntryAuthFailed
37 if await hass.async_add_executor_job(mydevolo.maintenance):
38 raise ConfigEntryNotReady
40 gateway_ids = await hass.async_add_executor_job(mydevolo.get_gateway_ids)
42 if entry.unique_id
and GATEWAY_SERIAL_PATTERN.match(entry.unique_id):
43 uuid = await hass.async_add_executor_job(mydevolo.uuid)
44 hass.config_entries.async_update_entry(entry, unique_id=uuid)
47 for gateway
in entry.runtime_data:
48 gateway.websocket_disconnect(
49 f
"websocket disconnect requested by {EVENT_HOMEASSISTANT_STOP}"
53 entry.async_on_unload(
54 hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, shutdown)
58 zeroconf_instance = await zeroconf.async_get_instance(hass)
59 entry.runtime_data = []
60 for gateway_id
in gateway_ids:
61 entry.runtime_data.append(
62 await hass.async_add_executor_job(
65 gateway_id=
str(gateway_id),
66 mydevolo_instance=mydevolo,
67 zeroconf_instance=zeroconf_instance,
71 except GatewayOfflineError
as err:
72 raise ConfigEntryNotReady
from err
74 await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
80 hass: HomeAssistant, entry: DevoloHomeControlConfigEntry
82 """Unload a config entry."""
83 unload = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
86 hass.async_add_executor_job(gateway.websocket_disconnect)
87 for gateway
in entry.runtime_data
94 hass: HomeAssistant, config_entry: ConfigEntry, device_entry: DeviceEntry
96 """Remove a config entry from a device."""
101 """Configure mydevolo."""
102 mydevolo = Mydevolo()
103 mydevolo.user = conf[CONF_USERNAME]
104 mydevolo.password = conf[CONF_PASSWORD]
105 mydevolo.url = conf.get(CONF_MYDEVOLO, DEFAULT_MYDEVOLO)
bool async_unload_entry(HomeAssistant hass, DevoloHomeControlConfigEntry entry)
bool async_remove_config_entry_device(HomeAssistant hass, ConfigEntry config_entry, DeviceEntry device_entry)
bool async_setup_entry(HomeAssistant hass, DevoloHomeControlConfigEntry entry)
Mydevolo configure_mydevolo(dict[str, Any]|MappingProxyType[str, Any] conf)