mirror of
https://github.com/home-assistant/core.git
synced 2025-07-26 06:37:52 +00:00
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
@ -1,5 +1,6 @@
|
|||||||
"""Support for Honeywell (US) Total Connect Comfort climate systems."""
|
"""Support for Honeywell (US) Total Connect Comfort climate systems."""
|
||||||
import asyncio
|
import asyncio
|
||||||
|
from dataclasses import dataclass
|
||||||
|
|
||||||
import AIOSomecomfort
|
import AIOSomecomfort
|
||||||
|
|
||||||
@ -86,7 +87,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
|
|||||||
_LOGGER.debug("No devices found")
|
_LOGGER.debug("No devices found")
|
||||||
return False
|
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.setdefault(DOMAIN, {})
|
||||||
hass.data[DOMAIN][config_entry.entry_id] = data
|
hass.data[DOMAIN][config_entry.entry_id] = data
|
||||||
await hass.config_entries.async_forward_entry_setups(config_entry, PLATFORMS)
|
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
|
return unload_ok
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
class HoneywellData:
|
class HoneywellData:
|
||||||
"""Get the latest data and update."""
|
"""Shared data for Honeywell."""
|
||||||
|
|
||||||
def __init__(
|
entry_id: str
|
||||||
self,
|
client: AIOSomecomfort.AIOSomeComfort
|
||||||
hass: HomeAssistant,
|
devices: dict[str, AIOSomecomfort.device.Device]
|
||||||
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
|
|
||||||
|
@ -84,7 +84,7 @@ async def async_setup_entry(
|
|||||||
cool_away_temp = entry.options.get(CONF_COOL_AWAY_TEMPERATURE)
|
cool_away_temp = entry.options.get(CONF_COOL_AWAY_TEMPERATURE)
|
||||||
heat_away_temp = entry.options.get(CONF_HEAT_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(
|
async_add_entities(
|
||||||
[
|
[
|
||||||
@ -393,9 +393,14 @@ class HoneywellUSThermostat(ClimateEntity):
|
|||||||
try:
|
try:
|
||||||
await self._device.refresh()
|
await self._device.refresh()
|
||||||
except (
|
except (
|
||||||
AIOSomecomfort.device.APIRateLimited,
|
AIOSomecomfort.device.SomeComfortError,
|
||||||
AIOSomecomfort.device.ConnectionError,
|
|
||||||
AIOSomecomfort.device.ConnectionTimeout,
|
|
||||||
OSError,
|
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…
x
Reference in New Issue
Block a user