1 """Support for (EMEA/EU-based) Honeywell TCC systems."""
3 from __future__
import annotations
5 from collections.abc
import Awaitable
6 from datetime
import timedelta
8 from typing
import TYPE_CHECKING, Any
10 import evohomeasync
as ev1
11 from evohomeasync.schema
import SZ_ID, SZ_TEMP
12 import evohomeasync2
as evo
13 from evohomeasync2.schema.const
import (
23 from .const
import CONF_LOCATION_IDX, DOMAIN, GWS, TCS, UTC_OFFSET
24 from .helpers
import handle_evo_exception
27 from .
import EvoSession
29 _LOGGER = logging.getLogger(__name__.rpartition(
".")[0])
33 """Broker for evohome client broker."""
37 loc_utc_offset: timedelta
38 tcs: evo.ControlSystem
41 """Initialize the evohome broker and its data structure."""
46 assert sess.client_v2
is not None
51 self.
tempstemps: dict[str, float |
None] = {}
54 """Get the default TCS of the specified location."""
58 assert self.
clientclient.installation_info
is not None
61 loc_config = self.
clientclient.installation_info[loc_idx]
65 "Config error: '%s' = %s, but the valid range is 0-%s. "
66 "Unable to continue. Fix any configuration errors and restart HA"
70 len(self.
clientclient.installation_info) - 1,
76 self.
tcstcs = self.
locloc._gateways[0]._control_systems[0]
78 if _LOGGER.isEnabledFor(logging.DEBUG):
80 SZ_LOCATION_ID: loc_config[SZ_LOCATION_INFO][SZ_LOCATION_ID],
81 SZ_TIME_ZONE: loc_config[SZ_LOCATION_INFO][SZ_TIME_ZONE],
84 SZ_GATEWAY_ID: loc_config[GWS][0][SZ_GATEWAY_INFO][SZ_GATEWAY_ID],
85 TCS: loc_config[GWS][0][TCS],
88 SZ_LOCATION_INFO: loc_info,
89 GWS: [{SZ_GATEWAY_INFO: gwy_info}],
91 _LOGGER.debug(
"Config = %s", config)
97 client_api: Awaitable[dict[str, Any] |
None],
98 update_state: bool =
True,
99 ) -> dict[str, Any] |
None:
100 """Call a client API and update the broker state if required."""
103 result = await client_api
104 except evo.RequestFailed
as err:
109 await self.
hasshass.data[DOMAIN][
"coordinator"].async_request_refresh()
114 """Get the latest high-precision temperatures of the default Location."""
116 assert self.
client_v1client_v1
is not None
118 old_session_id = self.
_sess_sess.session_id
121 temps = await self.
client_v1client_v1.get_temperatures()
123 except ev1.InvalidSchema
as err:
126 "Unable to obtain high-precision temperatures. "
127 "It appears the JSON schema is not as expected, "
128 "so the high-precision feature will be disabled until next restart."
135 except ev1.RequestFailed
as err:
138 "Unable to obtain the latest high-precision temperatures. "
139 "Check your network and the vendor's service status page. "
140 "Proceeding without high-precision temperatures for now. "
154 "The v2 API's configured location doesn't match "
155 "the v1 API's default location (there is more than one location), "
156 "so the high-precision feature will be disabled until next restart"
160 self.
tempstemps = {
str(i[SZ_ID]): i[SZ_TEMP]
for i
in temps}
163 if self.
client_v1client_v1
and self.
client_v1client_v1.broker.session_id != old_session_id:
164 await self.
_sess_sess.save_auth_tokens()
166 _LOGGER.debug(
"Temperatures = %s", self.
tempstemps)
169 """Get the latest modes, temperatures, setpoints of a Location."""
171 access_token = self.
clientclient.access_token
174 status = await self.
locloc.refresh_status()
175 except evo.RequestFailed
as err:
179 _LOGGER.debug(
"Status = %s", status)
181 if access_token != self.
clientclient.access_token:
182 await self.
_sess_sess.save_auth_tokens()
185 """Get the latest state data of an entire Honeywell TCC Location.
187 This includes state data for a Controller and all its child devices, such as the
188 operating mode of the Controller and the current temp of its children (e.g.
189 Zones, DHW controller).
None async_update(self, *Any args)
dict[str, Any]|None call_client_api(self, Awaitable[dict[str, Any]|None] client_api, bool update_state=True)
None _update_v2_api_state(self, *Any args)
None __init__(self, EvoSession sess)
bool validate_location(self, int loc_idx)
None _update_v1_api_temps(self)
None handle_evo_exception(evo.RequestFailed err)
None async_dispatcher_send(HomeAssistant hass, str signal, *Any args)