Fix evohome coroutine not allowed to be passed to HassJob (#42730)

This commit is contained in:
David Bonnes 2020-11-05 09:17:48 +00:00 committed by GitHub
parent 623f2b6f9c
commit fd01636058
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -422,20 +422,20 @@ class EvoBroker:
await self._store.async_save(app_storage) await self._store.async_save(app_storage)
async def call_client_api(self, api_function, refresh=True) -> Any: async def call_client_api(self, api_function, update_state=True) -> Any:
"""Call a client API.""" """Call a client API and update the broker state if required."""
try: try:
result = await api_function result = await api_function
except (aiohttp.ClientError, evohomeasync2.AuthenticationError) as err: except (aiohttp.ClientError, evohomeasync2.AuthenticationError) as err:
if not _handle_exception(err): if not _handle_exception(err):
return return
if refresh: if update_state: # wait a moment for system to quiesce before updating state
self.hass.helpers.event.async_call_later(1, self.async_update) self.hass.helpers.event.async_call_later(1, self._update_v2_api_state)
return result return result
async def _update_v1(self, *args, **kwargs) -> None: async def _update_v1_api_temps(self, *args, **kwargs) -> None:
"""Get the latest high-precision temperatures of the default Location.""" """Get the latest high-precision temperatures of the default Location."""
def get_session_id(client_v1) -> Optional[str]: def get_session_id(client_v1) -> Optional[str]:
@ -476,7 +476,7 @@ class EvoBroker:
if session_id != get_session_id(self.client_v1): if session_id != get_session_id(self.client_v1):
await self.save_auth_tokens() await self.save_auth_tokens()
async def _update_v2(self, *args, **kwargs) -> None: async def _update_v2_api_state(self, *args, **kwargs) -> None:
"""Get the latest modes, temperatures, setpoints of a Location.""" """Get the latest modes, temperatures, setpoints of a Location."""
access_token = self.client.access_token access_token = self.client.access_token
@ -500,13 +500,10 @@ class EvoBroker:
operating mode of the Controller and the current temp of its children (e.g. operating mode of the Controller and the current temp of its children (e.g.
Zones, DHW controller). Zones, DHW controller).
""" """
await self._update_v2()
if self.client_v1: if self.client_v1:
await self._update_v1() await self._update_v1_api_temps()
# inform the evohome devices that state data has been updated await self._update_v2_api_state()
async_dispatcher_send(self.hass, DOMAIN)
class EvoDevice(Entity): class EvoDevice(Entity):
@ -690,7 +687,7 @@ class EvoChild(EvoDevice):
return # avoid unnecessary I/O - there's nothing to update return # avoid unnecessary I/O - there's nothing to update
self._schedule = await self._evo_broker.call_client_api( self._schedule = await self._evo_broker.call_client_api(
self._evo_device.schedule(), refresh=False self._evo_device.schedule(), update_state=False
) )
_LOGGER.debug("Schedule['%s'] = %s", self.name, self._schedule) _LOGGER.debug("Schedule['%s'] = %s", self.name, self._schedule)