1 """Controller module."""
3 from __future__
import annotations
5 from collections.abc
import Mapping
6 from functools
import partial
11 from deebot_client.api_client
import ApiClient
12 from deebot_client.authentication
import Authenticator, create_rest_config
13 from deebot_client.const
import UNDEFINED, UndefinedType
14 from deebot_client.device
import Device
15 from deebot_client.exceptions
import DeebotError, InvalidAuthenticationError
16 from deebot_client.mqtt_client
import MqttClient, create_mqtt_config
17 from deebot_client.util
import md5
18 from deebot_client.util.continents
import get_continent
19 from sucks
import EcoVacsAPI, VacBot
28 CONF_OVERRIDE_MQTT_URL,
29 CONF_OVERRIDE_REST_URL,
30 CONF_VERIFY_MQTT_CERTIFICATE,
32 from .util
import get_client_device_id
34 _LOGGER = logging.getLogger(__name__)
38 """Ecovacs controller."""
40 def __init__(self, hass: HomeAssistant, config: Mapping[str, Any]) ->
None:
41 """Initialize controller."""
43 self._devices: list[Device] = []
44 self._legacy_devices: list[VacBot] = []
45 rest_url = config.get(CONF_OVERRIDE_REST_URL)
47 country = config[CONF_COUNTRY]
52 aiohttp_client.async_get_clientsession(self.
_hass_hass),
54 alpha_2_country=country,
55 override_rest_url=rest_url,
57 config[CONF_USERNAME],
58 md5(config[CONF_PASSWORD]),
62 mqtt_url = config.get(CONF_OVERRIDE_MQTT_URL)
63 ssl_context: UndefinedType | ssl.SSLContext = UNDEFINED
64 if not config.get(CONF_VERIFY_MQTT_CERTIFICATE,
True)
and mqtt_url:
71 override_mqtt_url=mqtt_url,
72 ssl_context=ssl_context,
76 self._added_legacy_entities: set[str] = set()
79 """Init controller."""
81 devices = await self.
_api_client_api_client.get_devices()
83 for device_info
in devices.mqtt:
86 await device.initialize(mqtt)
87 self._devices.append(device)
88 for device_config
in devices.xmpp:
98 self._legacy_devices.append(bot)
99 for device_config
in devices.not_supported:
102 'Device "%s" not supported. More information at '
103 "https://github.com/DeebotUniverse/client.py/issues/612: %s"
105 device_config[
"deviceName"],
109 except InvalidAuthenticationError
as ex:
111 except DeebotError
as ex:
114 _LOGGER.debug(
"Controller initialize complete")
117 """Disconnect controller."""
118 for device
in self._devices:
119 await device.teardown()
120 for legacy_device
in self._legacy_devices:
121 await self.
_hass_hass.async_add_executor_job(legacy_device.disconnect)
127 """Add legacy entity."""
128 self._added_legacy_entities.
add(f
"{device.vacuum['did']}_{component}")
131 """Check if legacy entity is added."""
132 return f
"{device.vacuum['did']}_{component}" in self._added_legacy_entities
135 """Return validated MQTT client."""
139 await mqtt.verify_config()
146 """Return devices."""
151 """Return legacy devices."""
152 return self._legacy_devices
MqttClient _get_mqtt_client(self)
None add_legacy_entity(self, VacBot device, str component)
list[Device] devices(self)
list[VacBot] legacy_devices(self)
None __init__(self, HomeAssistant hass, Mapping[str, Any] config)
bool legacy_entity_is_added(self, VacBot device, str component)
bool add(self, _T matcher)
str get_client_device_id(HomeAssistant hass, bool self_hosted)
def authenticate(HomeAssistant hass, host, port, servers)
ssl.SSLContext get_default_no_verify_context()