1 """Support for (EMEA/EU-based) Honeywell TCC systems."""
3 from __future__
import annotations
5 from datetime
import datetime, timedelta
6 from http
import HTTPStatus
11 import evohomeasync2
as evo
16 _LOGGER = logging.getLogger(__name__)
20 """Convert a local/naive datetime to TZ-aware."""
21 dt_aware = dt_util.now() + (dt_naive - datetime.now())
22 if dt_aware.microsecond >= 500000:
24 return dt_aware.replace(microsecond=0)
28 """Convert a TZ-aware datetime to naive/local."""
29 dt_naive = datetime.now() + (dt_aware - dt_util.now())
30 if dt_naive.microsecond >= 500000:
32 return dt_naive.replace(microsecond=0)
36 """Reformat a dt str from "%Y-%m-%dT%H:%M:%SZ" as local/aware/isoformat."""
37 if until_key
in status_dict
and (
38 dt_utc_naive := dt_util.parse_datetime(status_dict[until_key])
40 status_dict[until_key] = dt_util.as_local(dt_utc_naive).isoformat()
44 """Recursively convert a dict's keys to snake_case."""
46 def convert_key(key: str) -> str:
47 """Convert a string to snake_case."""
48 string = re.sub(
r"[\-\.\s]",
"_",
str(key))
53 lambda matched: f
"_{matched.group(0).lower()}",
59 (convert_key(k)
if isinstance(k, str)
else k): (
62 for k, v
in dictionary.items()
67 """Return False if the exception can't be ignored."""
72 except evo.AuthenticationFailed:
75 "Failed to authenticate with the vendor's server. Check your username"
76 " and password. NB: Some special password characters that work"
77 " correctly via the website will not work via the web API. Message"
83 except evo.RequestFailed:
84 if err.status
is None:
87 "Unable to connect with the vendor's server. "
88 "Check your network and the vendor's service status page. "
94 elif err.status == HTTPStatus.SERVICE_UNAVAILABLE:
96 "The vendor says their server is currently unavailable. "
97 "Check the vendor's service status page"
100 elif err.status == HTTPStatus.TOO_MANY_REQUESTS:
103 "The vendor's API rate limit has been exceeded. "
104 "If this message persists, consider increasing the %s"
None handle_evo_exception(evo.RequestFailed err)
datetime dt_local_to_aware(datetime dt_naive)
datetime dt_aware_to_naive(datetime dt_aware)
dict[str, Any] convert_dict(dict[str, Any] dictionary)
None convert_until(dict status_dict, str until_key)