Skip to content

Commit

Permalink
Fix Honeywell unavailable state on connection lost (home-assistant#86312
Browse files Browse the repository at this point in the history
)

* Fix for Issue 62957

* Cleanup exception test

* rework connection error retry logic

* Refactor HoneywellData class

* move _atr_available to correct location

* await create_task
  • Loading branch information
mkmer authored Jan 21, 2023
1 parent 402be4e commit 5306883
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 35 deletions.
38 changes: 8 additions & 30 deletions homeassistant/components/honeywell/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Support for Honeywell (US) Total Connect Comfort climate systems."""
import asyncio
from dataclasses import dataclass

import AIOSomecomfort

Expand Down Expand Up @@ -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)
Expand All @@ -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."""

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
"""Shared data for Honeywell."""

entry_id: str
client: AIOSomecomfort.AIOSomeComfort
devices: dict[str, AIOSomecomfort.device.Device]
15 changes: 10 additions & 5 deletions homeassistant/components/honeywell/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
[
Expand Down Expand Up @@ -393,9 +393,14 @@ async def async_update(self) -> None:
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)
)

0 comments on commit 5306883

Please sign in to comment.