Fix Honeywell unavailable state on connection lost (#86312)
* Fix for Issue 62957 * Cleanup exception test * rework connection error retry logic * Refactor HoneywellData class * move _atr_available to correct location * await create_task
This commit is contained in:
parent
402be4ebde
commit
5306883288
2 changed files with 17 additions and 34 deletions
|
@ -1,5 +1,6 @@
|
|||
"""Support for Honeywell (US) Total Connect Comfort climate systems."""
|
||||
import asyncio
|
||||
from dataclasses import dataclass
|
||||
|
||||
import AIOSomecomfort
|
||||
|
||||
|
@ -86,7 +87,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
|
|||
_LOGGER.debug("No devices found")
|
||||
return False
|
||||
|
||||
data = HoneywellData(hass, config_entry, client, username, password, devices)
|
||||
data = HoneywellData(config_entry.entry_id, client, devices)
|
||||
hass.data.setdefault(DOMAIN, {})
|
||||
hass.data[DOMAIN][config_entry.entry_id] = data
|
||||
await hass.config_entries.async_forward_entry_setups(config_entry, PLATFORMS)
|
||||
|
@ -111,33 +112,10 @@ async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) ->
|
|||
return unload_ok
|
||||
|
||||
|
||||
@dataclass
|
||||
class HoneywellData:
|
||||
"""Get the latest data and update."""
|
||||
"""Shared data for Honeywell."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
client: AIOSomecomfort.AIOSomeComfort,
|
||||
username: str,
|
||||
password: str,
|
||||
devices: dict[str, AIOSomecomfort.device.Device],
|
||||
) -> None:
|
||||
"""Initialize the data object."""
|
||||
self._hass = hass
|
||||
self._config = config_entry
|
||||
self._client = client
|
||||
self._username = username
|
||||
self._password = password
|
||||
self.devices = devices
|
||||
|
||||
async def retry_login(self) -> bool:
|
||||
"""Fire of a login retry."""
|
||||
|
||||
try:
|
||||
await self._client.login()
|
||||
except AIOSomecomfort.SomeComfortError:
|
||||
await asyncio.sleep(UPDATE_LOOP_SLEEP_TIME)
|
||||
return False
|
||||
|
||||
return True
|
||||
entry_id: str
|
||||
client: AIOSomecomfort.AIOSomeComfort
|
||||
devices: dict[str, AIOSomecomfort.device.Device]
|
||||
|
|
|
@ -84,7 +84,7 @@ async def async_setup_entry(
|
|||
cool_away_temp = entry.options.get(CONF_COOL_AWAY_TEMPERATURE)
|
||||
heat_away_temp = entry.options.get(CONF_HEAT_AWAY_TEMPERATURE)
|
||||
|
||||
data = hass.data[DOMAIN][entry.entry_id]
|
||||
data: HoneywellData = hass.data[DOMAIN][entry.entry_id]
|
||||
|
||||
async_add_entities(
|
||||
[
|
||||
|
@ -393,9 +393,14 @@ class HoneywellUSThermostat(ClimateEntity):
|
|||
try:
|
||||
await self._device.refresh()
|
||||
except (
|
||||
AIOSomecomfort.device.APIRateLimited,
|
||||
AIOSomecomfort.device.ConnectionError,
|
||||
AIOSomecomfort.device.ConnectionTimeout,
|
||||
AIOSomecomfort.device.SomeComfortError,
|
||||
OSError,
|
||||
):
|
||||
await self._data.retry_login()
|
||||
try:
|
||||
await self._data.client.login()
|
||||
|
||||
except AIOSomecomfort.device.SomeComfortError:
|
||||
self._attr_available = False
|
||||
await self.hass.async_create_task(
|
||||
self.hass.config_entries.async_reload(self._data.entry_id)
|
||||
)
|
||||
|
|
Loading…
Add table
Reference in a new issue