Refactor async_update in Honeywell (#103069)
* Refactor async_update * remove ignore-import * Restore somecomforterror rather than autherror * Update climate.py Limit exceptions in async_update() * Update climate.py Ruff it * Update climate.py Ruff * Refactor to login routine * Add back avialable change * Address extra logic in try * Address expected returns with logic move
This commit is contained in:
parent
3622944dda
commit
0eb8daee23
1 changed files with 26 additions and 14 deletions
|
@ -6,7 +6,12 @@ import datetime
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from aiohttp import ClientConnectionError
|
from aiohttp import ClientConnectionError
|
||||||
from aiosomecomfort import SomeComfortError, UnauthorizedError, UnexpectedResponse
|
from aiosomecomfort import (
|
||||||
|
AuthError,
|
||||||
|
SomeComfortError,
|
||||||
|
UnauthorizedError,
|
||||||
|
UnexpectedResponse,
|
||||||
|
)
|
||||||
from aiosomecomfort.device import Device as SomeComfortDevice
|
from aiosomecomfort.device import Device as SomeComfortDevice
|
||||||
|
|
||||||
from homeassistant.components.climate import (
|
from homeassistant.components.climate import (
|
||||||
|
@ -492,31 +497,38 @@ class HoneywellUSThermostat(ClimateEntity):
|
||||||
|
|
||||||
async def async_update(self) -> None:
|
async def async_update(self) -> None:
|
||||||
"""Get the latest state from the service."""
|
"""Get the latest state from the service."""
|
||||||
try:
|
|
||||||
await self._device.refresh()
|
|
||||||
self._attr_available = True
|
|
||||||
self._retry = 0
|
|
||||||
|
|
||||||
except UnauthorizedError:
|
async def _login() -> None:
|
||||||
try:
|
try:
|
||||||
await self._data.client.login()
|
await self._data.client.login()
|
||||||
await self._device.refresh()
|
await self._device.refresh()
|
||||||
self._attr_available = True
|
|
||||||
self._retry = 0
|
|
||||||
|
|
||||||
except (
|
except (
|
||||||
SomeComfortError,
|
AuthError,
|
||||||
ClientConnectionError,
|
ClientConnectionError,
|
||||||
asyncio.TimeoutError,
|
asyncio.TimeoutError,
|
||||||
):
|
):
|
||||||
self._retry += 1
|
self._retry += 1
|
||||||
if self._retry > RETRY:
|
self._attr_available = self._retry <= RETRY
|
||||||
self._attr_available = False
|
return
|
||||||
|
|
||||||
|
self._attr_available = True
|
||||||
|
self._retry = 0
|
||||||
|
|
||||||
|
try:
|
||||||
|
await self._device.refresh()
|
||||||
|
|
||||||
|
except UnauthorizedError:
|
||||||
|
await _login()
|
||||||
|
return
|
||||||
|
|
||||||
except (ClientConnectionError, asyncio.TimeoutError):
|
except (ClientConnectionError, asyncio.TimeoutError):
|
||||||
self._retry += 1
|
self._retry += 1
|
||||||
if self._retry > RETRY:
|
self._attr_available = self._retry <= RETRY
|
||||||
self._attr_available = False
|
return
|
||||||
|
|
||||||
except UnexpectedResponse:
|
except UnexpectedResponse:
|
||||||
pass
|
return
|
||||||
|
|
||||||
|
self._attr_available = True
|
||||||
|
self._retry = 0
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue