diff --git a/homeassistant/components/honeywell/__init__.py b/homeassistant/components/honeywell/__init__.py index 2ebec5c061a248..3316d2852e72e6 100644 --- a/homeassistant/components/honeywell/__init__.py +++ b/homeassistant/components/honeywell/__init__.py @@ -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.""" - - 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] diff --git a/homeassistant/components/honeywell/climate.py b/homeassistant/components/honeywell/climate.py index 60faedf5432d1d..6850607d7f7f38 100644 --- a/homeassistant/components/honeywell/climate.py +++ b/homeassistant/components/honeywell/climate.py @@ -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 @@ 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) + )