1 """Coordinator for the elmax-cloud integration."""
3 from __future__
import annotations
5 from asyncio
import timeout
6 from datetime
import timedelta
7 from logging
import Logger
9 from elmax_api.exceptions
import (
16 from elmax_api.http
import Elmax, GenericElmax
17 from elmax_api.model.actuator
import Actuator
18 from elmax_api.model.area
import Area
19 from elmax_api.model.cover
import Cover
20 from elmax_api.model.endpoint
import DeviceEndpoint
21 from elmax_api.model.panel
import PanelEntry, PanelStatus
22 from elmax_api.push.push
import PushNotificationHandler
23 from httpx
import ConnectError, ConnectTimeout
29 from .const
import DEFAULT_TIMEOUT
33 """Coordinator helper to handle Elmax API polling."""
35 _state_by_endpoint: dict[str, Actuator | Area | Cover | DeviceEndpoint]
41 elmax_api_client: GenericElmax,
44 update_interval: timedelta,
46 """Instantiate the object."""
52 hass=hass, logger=logger, name=name, update_interval=update_interval
57 """Return the panel entry."""
61 """Return state of a specific actuator."""
67 """Return state of a specific zone."""
73 """Return state of a specific area."""
79 """Return state of a specific cover."""
86 """Return the current http client being used by this instance."""
91 """Set the client library instance for Elmax API."""
96 async
with timeout(DEFAULT_TIMEOUT):
99 status = await self.
_client_client.get_current_panel_status()
101 except ElmaxBadPinError
as err:
103 except ElmaxBadLoginError
as err:
105 except ElmaxApiError
as err:
106 raise UpdateFailed(f
"Error communicating with ELMAX API: {err}")
from err
107 except ElmaxPanelBusyError
as err:
109 "Communication with the panel failed, as it is currently busy"
111 except (ConnectError, ConnectTimeout, ElmaxNetworkError)
as err:
112 if isinstance(self.
_client_client, Elmax):
114 "A communication error has occurred. "
115 "Make sure HA can reach the internet and that "
116 "your firewall allows communication with the Meross Cloud."
120 "A communication error has occurred. "
121 "Make sure the panel is online and that "
122 "your firewall allows communication with it."
126 self.
_state_by_endpoint_state_by_endpoint = {k.endpoint_id: k
for k
in status.all_endpoints}
137 self.
_state_by_endpoint_state_by_endpoint = {k.endpoint_id: k
for k
in status.all_endpoints}
142 f
"{'wss' if self.http_client.base_url.scheme == 'https' else 'ws'}"
143 f
"://{self.http_client.base_url.host}"
144 f
":{self.http_client.base_url.port}"
145 f
"{self.http_client.base_url.path}/push"
161 """Cancel any scheduled call, and ignore new runs."""
Area get_area_state(self, str area_id)
def _async_update_data(self)
def http_client(self, GenericElmax client)
None _push_handler(self, PanelStatus status)
None __init__(self, HomeAssistant hass, Logger logger, GenericElmax elmax_api_client, PanelEntry panel, str name, timedelta update_interval)
def _register_push_notification_handler(self)
Cover get_cover_state(self, str cover_id)
def _fire_data_update(self, PanelStatus status)
PanelEntry panel_entry(self)
_push_notification_handler
None async_shutdown(self)
Actuator get_actuator_state(self, str actuator_id)
Actuator get_zone_state(self, str zone_id)
None async_set_updated_data(self, _DataT data)