From bb7f91140d322815492234a949ac167d4c292b38 Mon Sep 17 00:00:00 2001 From: mkmer Date: Mon, 9 Oct 2023 12:59:30 +0000 Subject: [PATCH 1/5] Add retry before unavailable --- homeassistant/components/honeywell/climate.py | 13 ++++- homeassistant/components/honeywell/const.py | 1 + tests/components/honeywell/test_climate.py | 52 +++++++++++++++++++ 3 files changed, 64 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/honeywell/climate.py b/homeassistant/components/honeywell/climate.py index 63d05135d5df9c..ab23c878c15703 100644 --- a/homeassistant/components/honeywell/climate.py +++ b/homeassistant/components/honeywell/climate.py @@ -38,6 +38,7 @@ CONF_COOL_AWAY_TEMPERATURE, CONF_HEAT_AWAY_TEMPERATURE, DOMAIN, + RETRY, ) ATTR_FAN_ACTION = "fan_action" @@ -155,6 +156,7 @@ def __init__( self._cool_away_temp = cool_away_temp self._heat_away_temp = heat_away_temp self._away = False + self._retry = 0 self._attr_unique_id = device.deviceid @@ -483,21 +485,28 @@ async def async_update(self) -> None: try: await self._device.refresh() self._attr_available = True + self._retry = 0 + except UnauthorizedError: try: await self._data.client.login() await self._device.refresh() self._attr_available = True + self._retry = 0 except ( SomeComfortError, ClientConnectionError, asyncio.TimeoutError, ): - self._attr_available = False + self._retry += 1 + if self._retry > RETRY: + self._attr_available = False except (ClientConnectionError, asyncio.TimeoutError): - self._attr_available = False + self._retry += 1 + if self._retry > RETRY: + self._attr_available = False except UnexpectedResponse: pass diff --git a/homeassistant/components/honeywell/const.py b/homeassistant/components/honeywell/const.py index d5153a69f65a10..32846563c4475f 100644 --- a/homeassistant/components/honeywell/const.py +++ b/homeassistant/components/honeywell/const.py @@ -10,3 +10,4 @@ CONF_DEV_ID = "thermostat" CONF_LOC_ID = "location" _LOGGER = logging.getLogger(__name__) +RETRY = 3 diff --git a/tests/components/honeywell/test_climate.py b/tests/components/honeywell/test_climate.py index 7bd76cb8522f94..c7e5c031d1703c 100644 --- a/tests/components/honeywell/test_climate.py +++ b/tests/components/honeywell/test_climate.py @@ -1089,6 +1089,31 @@ async def test_async_update_errors( ) await hass.async_block_till_done() + state = hass.states.get(entity_id) + assert state.state == "off" + + async_fire_time_changed( + hass, + utcnow() + SCAN_INTERVAL, + ) + await hass.async_block_till_done() + + state = hass.states.get(entity_id) + assert state.state == "off" + async_fire_time_changed( + hass, + utcnow() + SCAN_INTERVAL, + ) + await hass.async_block_till_done() + state = hass.states.get(entity_id) + assert state.state == "off" + + async_fire_time_changed( + hass, + utcnow() + SCAN_INTERVAL, + ) + await hass.async_block_till_done() + state = hass.states.get(entity_id) assert state.state == "unavailable" @@ -1145,6 +1170,33 @@ async def test_async_update_errors( ) await hass.async_block_till_done() + state = hass.states.get(entity_id) + assert state.state == "off" + + async_fire_time_changed( + hass, + utcnow() + SCAN_INTERVAL, + ) + await hass.async_block_till_done() + + state = hass.states.get(entity_id) + assert state.state == "off" + + async_fire_time_changed( + hass, + utcnow() + SCAN_INTERVAL, + ) + await hass.async_block_till_done() + + state = hass.states.get(entity_id) + assert state.state == "off" + + async_fire_time_changed( + hass, + utcnow() + SCAN_INTERVAL, + ) + await hass.async_block_till_done() + state = hass.states.get(entity_id) assert state.state == "unavailable" From 09aa10b2741270ac6fa961c6ea11a1e51c03c2aa Mon Sep 17 00:00:00 2001 From: mkmer Date: Fri, 27 Oct 2023 17:22:56 +0000 Subject: [PATCH 2/5] loop tied to RETRY --- tests/components/honeywell/test_climate.py | 35 ++++++---------------- 1 file changed, 9 insertions(+), 26 deletions(-) diff --git a/tests/components/honeywell/test_climate.py b/tests/components/honeywell/test_climate.py index c7e5c031d1703c..c9d10ed0f87649 100644 --- a/tests/components/honeywell/test_climate.py +++ b/tests/components/honeywell/test_climate.py @@ -28,7 +28,7 @@ SERVICE_SET_TEMPERATURE, HVACMode, ) -from homeassistant.components.honeywell.climate import SCAN_INTERVAL +from homeassistant.components.honeywell.climate import RETRY, SCAN_INTERVAL from homeassistant.const import ( ATTR_ENTITY_ID, ATTR_TEMPERATURE, @@ -1151,7 +1151,6 @@ async def test_async_update_errors( state = hass.states.get(entity_id) assert state.state == "off" - # "reload integration" test device.refresh.side_effect = aiosomecomfort.SomeComfortError client.login.side_effect = aiosomecomfort.AuthError async_fire_time_changed( @@ -1164,32 +1163,16 @@ async def test_async_update_errors( assert state.state == "off" device.refresh.side_effect = ClientConnectionError - async_fire_time_changed( - hass, - utcnow() + SCAN_INTERVAL, - ) - await hass.async_block_till_done() - state = hass.states.get(entity_id) - assert state.state == "off" - - async_fire_time_changed( - hass, - utcnow() + SCAN_INTERVAL, - ) - await hass.async_block_till_done() - - state = hass.states.get(entity_id) - assert state.state == "off" - - async_fire_time_changed( - hass, - utcnow() + SCAN_INTERVAL, - ) - await hass.async_block_till_done() + for _ in range(RETRY): + async_fire_time_changed( + hass, + utcnow() + SCAN_INTERVAL, + ) + await hass.async_block_till_done() - state = hass.states.get(entity_id) - assert state.state == "off" + state = hass.states.get(entity_id) + assert state.state == "off" async_fire_time_changed( hass, From 7463a584755958246916f477f4f7b00761a13a11 Mon Sep 17 00:00:00 2001 From: mkmer Date: Fri, 27 Oct 2023 17:38:10 +0000 Subject: [PATCH 3/5] Fix the other loop too --- tests/components/honeywell/test_climate.py | 31 ++++++---------------- 1 file changed, 8 insertions(+), 23 deletions(-) diff --git a/tests/components/honeywell/test_climate.py b/tests/components/honeywell/test_climate.py index c9d10ed0f87649..cdb2e194701582 100644 --- a/tests/components/honeywell/test_climate.py +++ b/tests/components/honeywell/test_climate.py @@ -1083,30 +1083,15 @@ async def test_async_update_errors( state = hass.states.get(entity_id) assert state.state == "off" - async_fire_time_changed( - hass, - utcnow() + SCAN_INTERVAL, - ) - await hass.async_block_till_done() - - state = hass.states.get(entity_id) - assert state.state == "off" - - async_fire_time_changed( - hass, - utcnow() + SCAN_INTERVAL, - ) - await hass.async_block_till_done() + for _ in range(RETRY): + async_fire_time_changed( + hass, + utcnow() + SCAN_INTERVAL, + ) + await hass.async_block_till_done() - state = hass.states.get(entity_id) - assert state.state == "off" - async_fire_time_changed( - hass, - utcnow() + SCAN_INTERVAL, - ) - await hass.async_block_till_done() - state = hass.states.get(entity_id) - assert state.state == "off" + state = hass.states.get(entity_id) + assert state.state == "off" async_fire_time_changed( hass, From 2288c9e77bd2eba0bf078510b7d98d1605c65b63 Mon Sep 17 00:00:00 2001 From: mkmer Date: Mon, 30 Oct 2023 10:58:53 +0000 Subject: [PATCH 4/5] Add comment --- tests/components/honeywell/test_climate.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/components/honeywell/test_climate.py b/tests/components/honeywell/test_climate.py index cdb2e194701582..385c7610eba51f 100644 --- a/tests/components/honeywell/test_climate.py +++ b/tests/components/honeywell/test_climate.py @@ -1083,6 +1083,7 @@ async def test_async_update_errors( state = hass.states.get(entity_id) assert state.state == "off" + # Due to server instability, only mark entity unavailable after RETRY update attmpts for _ in range(RETRY): async_fire_time_changed( hass, @@ -1149,6 +1150,7 @@ async def test_async_update_errors( device.refresh.side_effect = ClientConnectionError + # Due to server instability, only mark entity unavailable after RETRY update attmpts for _ in range(RETRY): async_fire_time_changed( hass, From 31565c325eb3b69417d7abe55ace5edaaf2813d6 Mon Sep 17 00:00:00 2001 From: Robert Resch Date: Mon, 30 Oct 2023 14:50:37 +0100 Subject: [PATCH 5/5] typo --- tests/components/honeywell/test_climate.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/components/honeywell/test_climate.py b/tests/components/honeywell/test_climate.py index 385c7610eba51f..53cb70475c98bb 100644 --- a/tests/components/honeywell/test_climate.py +++ b/tests/components/honeywell/test_climate.py @@ -1083,7 +1083,7 @@ async def test_async_update_errors( state = hass.states.get(entity_id) assert state.state == "off" - # Due to server instability, only mark entity unavailable after RETRY update attmpts + # Due to server instability, only mark entity unavailable after RETRY update attempts for _ in range(RETRY): async_fire_time_changed( hass, @@ -1150,7 +1150,7 @@ async def test_async_update_errors( device.refresh.side_effect = ClientConnectionError - # Due to server instability, only mark entity unavailable after RETRY update attmpts + # Due to server instability, only mark entity unavailable after RETRY update attempts for _ in range(RETRY): async_fire_time_changed( hass,