Bump aiosomecomfort to 0.0.17 (#98978)

* Clean up imports
Add refresh after login in update

* Bump somecomfort 0.0.17
Separate Somecomfort error to unauthorized

* Add tests

* Run Black format
This commit is contained in:
mkmer 2023-08-24 15:13:42 -04:00 committed by GitHub
parent 417fd0838a
commit f2c475cf1b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 43 additions and 17 deletions

View file

@ -6,7 +6,8 @@ import datetime
from typing import Any from typing import Any
from aiohttp import ClientConnectionError from aiohttp import ClientConnectionError
import aiosomecomfort from aiosomecomfort import SomeComfortError, UnauthorizedError, UnexpectedResponse
from aiosomecomfort.device import Device as SomeComfortDevice
from homeassistant.components.climate import ( from homeassistant.components.climate import (
ATTR_TARGET_TEMP_HIGH, ATTR_TARGET_TEMP_HIGH,
@ -106,7 +107,7 @@ class HoneywellUSThermostat(ClimateEntity):
def __init__( def __init__(
self, self,
data: HoneywellData, data: HoneywellData,
device: aiosomecomfort.device.Device, device: SomeComfortDevice,
cool_away_temp: int | None, cool_away_temp: int | None,
heat_away_temp: int | None, heat_away_temp: int | None,
) -> None: ) -> None:
@ -312,7 +313,7 @@ class HoneywellUSThermostat(ClimateEntity):
if mode == "heat": if mode == "heat":
await self._device.set_setpoint_heat(temperature) await self._device.set_setpoint_heat(temperature)
except aiosomecomfort.SomeComfortError as err: except SomeComfortError as err:
_LOGGER.error("Invalid temperature %.1f: %s", temperature, err) _LOGGER.error("Invalid temperature %.1f: %s", temperature, err)
async def async_set_temperature(self, **kwargs: Any) -> None: async def async_set_temperature(self, **kwargs: Any) -> None:
@ -325,7 +326,7 @@ class HoneywellUSThermostat(ClimateEntity):
if temperature := kwargs.get(ATTR_TARGET_TEMP_LOW): if temperature := kwargs.get(ATTR_TARGET_TEMP_LOW):
await self._device.set_setpoint_heat(temperature) await self._device.set_setpoint_heat(temperature)
except aiosomecomfort.SomeComfortError as err: except SomeComfortError as err:
_LOGGER.error("Invalid temperature %.1f: %s", temperature, err) _LOGGER.error("Invalid temperature %.1f: %s", temperature, err)
async def async_set_fan_mode(self, fan_mode: str) -> None: async def async_set_fan_mode(self, fan_mode: str) -> None:
@ -354,7 +355,7 @@ class HoneywellUSThermostat(ClimateEntity):
if mode in HEATING_MODES: if mode in HEATING_MODES:
await self._device.set_hold_heat(True, self._heat_away_temp) await self._device.set_hold_heat(True, self._heat_away_temp)
except aiosomecomfort.SomeComfortError: except SomeComfortError:
_LOGGER.error( _LOGGER.error(
"Temperature out of range. Mode: %s, Heat Temperature: %.1f, Cool Temperature: %.1f", "Temperature out of range. Mode: %s, Heat Temperature: %.1f, Cool Temperature: %.1f",
mode, mode,
@ -375,7 +376,7 @@ class HoneywellUSThermostat(ClimateEntity):
if mode in HEATING_MODES: if mode in HEATING_MODES:
await self._device.set_hold_heat(True) await self._device.set_hold_heat(True)
except aiosomecomfort.SomeComfortError: except SomeComfortError:
_LOGGER.error("Couldn't set permanent hold") _LOGGER.error("Couldn't set permanent hold")
else: else:
_LOGGER.error("Invalid system mode returned: %s", mode) _LOGGER.error("Invalid system mode returned: %s", mode)
@ -387,7 +388,7 @@ class HoneywellUSThermostat(ClimateEntity):
# Disabling all hold modes # Disabling all hold modes
await self._device.set_hold_cool(False) await self._device.set_hold_cool(False)
await self._device.set_hold_heat(False) await self._device.set_hold_heat(False)
except aiosomecomfort.SomeComfortError: except SomeComfortError:
_LOGGER.error("Can not stop hold mode") _LOGGER.error("Can not stop hold mode")
async def async_set_preset_mode(self, preset_mode: str) -> None: async def async_set_preset_mode(self, preset_mode: str) -> None:
@ -416,12 +417,14 @@ class HoneywellUSThermostat(ClimateEntity):
try: try:
await self._device.refresh() await self._device.refresh()
self._attr_available = True self._attr_available = True
except aiosomecomfort.SomeComfortError: except UnauthorizedError:
try: try:
await self._data.client.login() await self._data.client.login()
await self._device.refresh()
self._attr_available = True
except ( except (
aiosomecomfort.SomeComfortError, SomeComfortError,
ClientConnectionError, ClientConnectionError,
asyncio.TimeoutError, asyncio.TimeoutError,
): ):
@ -429,3 +432,6 @@ class HoneywellUSThermostat(ClimateEntity):
except (ClientConnectionError, asyncio.TimeoutError): except (ClientConnectionError, asyncio.TimeoutError):
self._attr_available = False self._attr_available = False
except UnexpectedResponse:
pass

View file

@ -6,5 +6,5 @@
"documentation": "https://www.home-assistant.io/integrations/honeywell", "documentation": "https://www.home-assistant.io/integrations/honeywell",
"iot_class": "cloud_polling", "iot_class": "cloud_polling",
"loggers": ["somecomfort"], "loggers": ["somecomfort"],
"requirements": ["AIOSomecomfort==0.0.16"] "requirements": ["AIOSomecomfort==0.0.17"]
} }

View file

@ -8,7 +8,7 @@ AEMET-OpenData==0.3.0
AIOAladdinConnect==0.1.57 AIOAladdinConnect==0.1.57
# homeassistant.components.honeywell # homeassistant.components.honeywell
AIOSomecomfort==0.0.16 AIOSomecomfort==0.0.17
# homeassistant.components.adax # homeassistant.components.adax
Adax-local==0.1.5 Adax-local==0.1.5

View file

@ -10,7 +10,7 @@ AEMET-OpenData==0.3.0
AIOAladdinConnect==0.1.57 AIOAladdinConnect==0.1.57
# homeassistant.components.honeywell # homeassistant.components.honeywell
AIOSomecomfort==0.0.16 AIOSomecomfort==0.0.17
# homeassistant.components.adax # homeassistant.components.adax
Adax-local==0.1.5 Adax-local==0.1.5

View file

@ -1010,8 +1010,8 @@ async def test_async_update_errors(
await init_integration(hass, config_entry) await init_integration(hass, config_entry)
device.refresh.side_effect = aiosomecomfort.SomeComfortError device.refresh.side_effect = aiosomecomfort.UnauthorizedError
client.login.side_effect = aiosomecomfort.SomeComfortError client.login.side_effect = aiosomecomfort.AuthError
entity_id = f"climate.{device.name}" entity_id = f"climate.{device.name}"
state = hass.states.get(entity_id) state = hass.states.get(entity_id)
assert state.state == "off" assert state.state == "off"
@ -1037,6 +1037,28 @@ async def test_async_update_errors(
state = hass.states.get(entity_id) state = hass.states.get(entity_id)
assert state.state == "off" assert state.state == "off"
device.refresh.side_effect = aiosomecomfort.UnexpectedResponse
client.login.side_effect = None
async_fire_time_changed(
hass,
utcnow() + SCAN_INTERVAL,
)
await hass.async_block_till_done()
state = hass.states.get(entity_id)
assert state.state == "off"
device.refresh.side_effect = [aiosomecomfort.UnauthorizedError, None]
client.login.side_effect = None
async_fire_time_changed(
hass,
utcnow() + SCAN_INTERVAL,
)
await hass.async_block_till_done()
state = hass.states.get(entity_id)
assert state.state == "off"
# "reload integration" test # "reload integration" test
device.refresh.side_effect = aiosomecomfort.SomeComfortError device.refresh.side_effect = aiosomecomfort.SomeComfortError
client.login.side_effect = aiosomecomfort.AuthError client.login.side_effect = aiosomecomfort.AuthError
@ -1046,9 +1068,8 @@ async def test_async_update_errors(
) )
await hass.async_block_till_done() await hass.async_block_till_done()
entity_id = f"climate.{device.name}"
state = hass.states.get(entity_id) state = hass.states.get(entity_id)
assert state.state == "unavailable" assert state.state == "off"
device.refresh.side_effect = ClientConnectionError device.refresh.side_effect = ClientConnectionError
async_fire_time_changed( async_fire_time_changed(
@ -1057,7 +1078,6 @@ async def test_async_update_errors(
) )
await hass.async_block_till_done() await hass.async_block_till_done()
entity_id = f"climate.{device.name}"
state = hass.states.get(entity_id) state = hass.states.get(entity_id)
assert state.state == "unavailable" assert state.state == "unavailable"