Tweak evohome code quality (#107596)

* initial commit

* lint

* initial commit
This commit is contained in:
David Bonnes 2024-01-21 21:22:04 +00:00 committed by GitHub
parent fbe1f238d4
commit 0566ceca0f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -160,6 +160,7 @@ def convert_dict(dictionary: dict[str, Any]) -> dict[str, Any]:
def _handle_exception(err: evo.RequestFailed) -> None: def _handle_exception(err: evo.RequestFailed) -> None:
"""Return False if the exception can't be ignored.""" """Return False if the exception can't be ignored."""
try: try:
raise err raise err
@ -471,12 +472,13 @@ class EvoBroker:
async def call_client_api( async def call_client_api(
self, self,
api_function: Awaitable[dict[str, Any] | None], client_api: Awaitable[dict[str, Any] | None],
update_state: bool = True, update_state: bool = True,
) -> dict[str, Any] | None: ) -> dict[str, Any] | None:
"""Call a client API and update the broker state if required.""" """Call a client API and update the broker state if required."""
try: try:
result = await api_function result = await client_api
except evo.RequestFailed as err: except evo.RequestFailed as err:
_handle_exception(err) _handle_exception(err)
return None return None
@ -556,7 +558,6 @@ class EvoBroker:
_handle_exception(err) _handle_exception(err)
else: else:
async_dispatcher_send(self.hass, DOMAIN) async_dispatcher_send(self.hass, DOMAIN)
_LOGGER.debug("Status = %s", status) _LOGGER.debug("Status = %s", status)
finally: finally:
if access_token != self.client.access_token: if access_token != self.client.access_token:
@ -657,9 +658,9 @@ class EvoChild(EvoDevice):
assert isinstance(self._evo_device, evo.HotWater | evo.Zone) # mypy check assert isinstance(self._evo_device, evo.HotWater | evo.Zone) # mypy check
if self._evo_broker.temps.get(self._evo_id) is not None: if (temp := self._evo_broker.temps.get(self._evo_id)) is not None:
# use high-precision temps if available # use high-precision temps if available
return self._evo_broker.temps[self._evo_id] return temp
return self._evo_device.temperature return self._evo_device.temperature
@property @property