Skip to content

Commit

Permalink
Bump evohome-async to 0.4.4 (#103084)
Browse files Browse the repository at this point in the history
* initial commit

* use correct attr

* fix hass-logger-period

* initial commit

* reduce footprint

* reduce footprint 2

* reduce footprint 3

* reduce footprint 4

* reduce footprint 6

* reduce footprint 7

* reduce footprint 8

* reduce footprint 9

* bump client to 0.4.1

* missing commit - changed method name

* bump client to 0.4.3

* bump client to 0.4.4
  • Loading branch information
zxdavb committed Nov 6, 2023
1 parent aa8b36c commit 3cfb2d5
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 54 deletions.
82 changes: 49 additions & 33 deletions homeassistant/components/evohome/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import re
from typing import Any

import aiohttp.client_exceptions
import evohomeasync
import evohomeasync2
import voluptuous as vol
Expand Down Expand Up @@ -144,7 +143,7 @@ def _handle_exception(err) -> None:
try:
raise err

except evohomeasync2.AuthenticationError:
except evohomeasync2.AuthenticationFailed:
_LOGGER.error(
(
"Failed to authenticate with the vendor's server. Check your username"
Expand All @@ -155,19 +154,18 @@ def _handle_exception(err) -> None:
err,
)

except aiohttp.ClientConnectionError:
# this appears to be a common occurrence with the vendor's servers
_LOGGER.warning(
(
"Unable to connect with the vendor's server. "
"Check your network and the vendor's service status page. "
"Message is: %s"
),
err,
)
except evohomeasync2.RequestFailed:
if err.status is None:
_LOGGER.warning(
(
"Unable to connect with the vendor's server. "
"Check your network and the vendor's service status page. "
"Message is: %s"
),
err,
)

except aiohttp.ClientResponseError:
if err.status == HTTPStatus.SERVICE_UNAVAILABLE:
elif err.status == HTTPStatus.SERVICE_UNAVAILABLE:
_LOGGER.warning(
"The vendor says their server is currently unavailable. "
"Check the vendor's service status page"
Expand Down Expand Up @@ -219,7 +217,7 @@ async def load_auth_tokens(store) -> tuple[dict, dict | None]:

try:
await client_v2.login()
except (aiohttp.ClientError, evohomeasync2.AuthenticationError) as err:
except evohomeasync2.AuthenticationFailed as err:
_handle_exception(err)
return False
finally:
Expand Down Expand Up @@ -452,7 +450,7 @@ async def call_client_api(self, api_function, update_state=True) -> Any:
"""Call a client API and update the broker state if required."""
try:
result = await api_function
except (aiohttp.ClientError, evohomeasync2.AuthenticationError) as err:
except evohomeasync2.EvohomeError as err:
_handle_exception(err)
return

Expand All @@ -475,15 +473,27 @@ def get_session_id(client_v1) -> str | None:
try:
temps = list(await self.client_v1.temperatures(force_refresh=True))

except aiohttp.ClientError as err:
except evohomeasync.InvalidSchema as exc:
_LOGGER.warning(
(
"Unable to obtain high-precision temperatures. "
"It appears the JSON schema is not as expected, "
"so the high-precision feature will be disabled until next restart."
"Message is: %s"
),
exc,
)
self.temps = self.client_v1 = None

except evohomeasync.EvohomeError as exc:
_LOGGER.warning(
(
"Unable to obtain the latest high-precision temperatures. "
"Check your network and the vendor's service status page. "
"Proceeding with low-precision temperatures. "
"Proceeding without high-precision temperatures for now. "
"Message is: %s"
),
err,
exc,
)
self.temps = None # these are now stale, will fall back to v2 temps

Expand Down Expand Up @@ -513,19 +523,20 @@ def get_session_id(client_v1) -> str | None:
else:
self.temps = {str(i["id"]): i["temp"] for i in temps}

_LOGGER.debug("Temperatures = %s", self.temps)
finally:
if session_id != get_session_id(self.client_v1):
await self.save_auth_tokens()

if session_id != get_session_id(self.client_v1):
await self.save_auth_tokens()
_LOGGER.debug("Temperatures = %s", self.temps)

async def _update_v2_api_state(self, *args, **kwargs) -> None:
"""Get the latest modes, temperatures, setpoints of a Location."""
access_token = self.client.access_token

loc_idx = self.params[CONF_LOCATION_IDX]
try:
status = await self.client.locations[loc_idx].status()
except (aiohttp.ClientError, evohomeasync2.AuthenticationError) as err:
status = await self.client.locations[loc_idx].refresh_status()
except evohomeasync2.EvohomeError as err:
_handle_exception(err)
else:
async_dispatcher_send(self.hass, DOMAIN)
Expand All @@ -542,11 +553,14 @@ async def async_update(self, *args, **kwargs) -> None:
operating mode of the Controller and the current temp of its children (e.g.
Zones, DHW controller).
"""
if self.client_v1:
await self._update_v1_api_temps()

await self._update_v2_api_state()

if self.client_v1:
try:
await self._update_v1_api_temps()
except evohomeasync.EvohomeError:
self.temps = None # these are now stale, will fall back to v2 temps


class EvoDevice(Entity):
"""Base for any evohome device.
Expand Down Expand Up @@ -618,11 +632,13 @@ def __init__(self, evo_broker, evo_device) -> None:
@property
def current_temperature(self) -> float | None:
"""Return the current temperature of a Zone."""
if (
self._evo_broker.temps
and self._evo_broker.temps[self._evo_device.zoneId] != 128
):
return self._evo_broker.temps[self._evo_device.zoneId]
if self._evo_device.TYPE == "domesticHotWater":
dev_id = self._evo_device.dhwId
else:
dev_id = self._evo_device.zoneId

if self._evo_broker.temps and self._evo_broker.temps[dev_id] is not None:
return self._evo_broker.temps[dev_id]

if self._evo_device.temperatureStatus["isAvailable"]:
return self._evo_device.temperatureStatus["temperature"]
Expand Down Expand Up @@ -695,7 +711,7 @@ def _dt_evo_to_aware(dt_naive: dt, utc_offset: timedelta) -> dt:
async def _update_schedule(self) -> None:
"""Get the latest schedule, if any."""
self._schedule = await self._evo_broker.call_client_api(
self._evo_device.schedule(), update_state=False
self._evo_device.get_schedule(), update_state=False
)

_LOGGER.debug("Schedule['%s'] = %s", self.name, self._schedule)
Expand Down
14 changes: 4 additions & 10 deletions homeassistant/components/evohome/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,7 @@ def __init__(self, evo_broker, evo_device) -> None:
async def async_zone_svc_request(self, service: str, data: dict[str, Any]) -> None:
"""Process a service request (setpoint override) for a zone."""
if service == SVC_RESET_ZONE_OVERRIDE:
await self._evo_broker.call_client_api(
self._evo_device.cancel_temp_override()
)
await self._evo_broker.call_client_api(self._evo_device.reset_mode())
return

# otherwise it is SVC_SET_ZONE_OVERRIDE
Expand Down Expand Up @@ -264,18 +262,14 @@ async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
self._evo_device.set_temperature(self.min_temp, until=None)
)
else: # HVACMode.HEAT
await self._evo_broker.call_client_api(
self._evo_device.cancel_temp_override()
)
await self._evo_broker.call_client_api(self._evo_device.reset_mode())

async def async_set_preset_mode(self, preset_mode: str) -> None:
"""Set the preset mode; if None, then revert to following the schedule."""
evo_preset_mode = HA_PRESET_TO_EVO.get(preset_mode, EVO_FOLLOW)

if evo_preset_mode == EVO_FOLLOW:
await self._evo_broker.call_client_api(
self._evo_device.cancel_temp_override()
)
await self._evo_broker.call_client_api(self._evo_device.reset_mode())
return

temperature = self._evo_device.setpointStatus["targetHeatTemperature"]
Expand Down Expand Up @@ -352,7 +346,7 @@ async def _set_tcs_mode(self, mode: str, until: dt | None = None) -> None:
"""Set a Controller to any of its native EVO_* operating modes."""
until = dt_util.as_utc(until) if until else None
await self._evo_broker.call_client_api(
self._evo_tcs.set_status(mode, until=until)
self._evo_tcs.set_mode(mode, until=until)
)

@property
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/evohome/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
"documentation": "https://www.home-assistant.io/integrations/evohome",
"iot_class": "cloud_polling",
"loggers": ["evohomeasync", "evohomeasync2"],
"requirements": ["evohome-async==0.3.15"]
"requirements": ["evohome-async==0.4.4"]
}
19 changes: 10 additions & 9 deletions homeassistant/components/evohome/water_heater.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ async def async_setup_platform(

_LOGGER.debug(
"Adding: DhwController (%s), id=%s",
broker.tcs.hotwater.zone_type,
broker.tcs.hotwater.zoneId,
broker.tcs.hotwater.TYPE,
broker.tcs.hotwater.dhwId,
)

new_entity = EvoDHW(broker, broker.tcs.hotwater)

async_add_entities([new_entity], update_before_add=True)
Expand Down Expand Up @@ -95,36 +96,36 @@ async def async_set_operation_mode(self, operation_mode: str) -> None:
Except for Auto, the mode is only until the next SetPoint.
"""
if operation_mode == STATE_AUTO:
await self._evo_broker.call_client_api(self._evo_device.set_dhw_auto())
await self._evo_broker.call_client_api(self._evo_device.reset_mode())
else:
await self._update_schedule()
until = dt_util.parse_datetime(self.setpoints.get("next_sp_from", ""))
until = dt_util.as_utc(until) if until else None

if operation_mode == STATE_ON:
await self._evo_broker.call_client_api(
self._evo_device.set_dhw_on(until=until)
self._evo_device.set_on(until=until)
)
else: # STATE_OFF
await self._evo_broker.call_client_api(
self._evo_device.set_dhw_off(until=until)
self._evo_device.set_off(until=until)
)

async def async_turn_away_mode_on(self) -> None:
"""Turn away mode on."""
await self._evo_broker.call_client_api(self._evo_device.set_dhw_off())
await self._evo_broker.call_client_api(self._evo_device.set_off())

async def async_turn_away_mode_off(self) -> None:
"""Turn away mode off."""
await self._evo_broker.call_client_api(self._evo_device.set_dhw_auto())
await self._evo_broker.call_client_api(self._evo_device.reset_mode())

async def async_turn_on(self):
"""Turn on."""
await self._evo_broker.call_client_api(self._evo_device.set_dhw_on())
await self._evo_broker.call_client_api(self._evo_device.set_on())

async def async_turn_off(self):
"""Turn off."""
await self._evo_broker.call_client_api(self._evo_device.set_dhw_off())
await self._evo_broker.call_client_api(self._evo_device.set_off())

async def async_update(self) -> None:
"""Get the latest state data for a DHW controller."""
Expand Down
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ eufylife-ble-client==0.1.8
# evdev==1.6.1

# homeassistant.components.evohome
evohome-async==0.3.15
evohome-async==0.4.4

# homeassistant.components.faa_delays
faadelays==2023.9.1
Expand Down

0 comments on commit 3cfb2d5

Please sign in to comment.