mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Add retry before unavailable to Honeywell (#101702)
Co-authored-by: Robert Resch <robert@resch.dev>
This commit is contained in:
parent
4ed3676a56
commit
92ec525de1
@ -38,6 +38,7 @@ from .const import (
|
|||||||
CONF_COOL_AWAY_TEMPERATURE,
|
CONF_COOL_AWAY_TEMPERATURE,
|
||||||
CONF_HEAT_AWAY_TEMPERATURE,
|
CONF_HEAT_AWAY_TEMPERATURE,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
|
RETRY,
|
||||||
)
|
)
|
||||||
|
|
||||||
ATTR_FAN_ACTION = "fan_action"
|
ATTR_FAN_ACTION = "fan_action"
|
||||||
@ -155,6 +156,7 @@ class HoneywellUSThermostat(ClimateEntity):
|
|||||||
self._cool_away_temp = cool_away_temp
|
self._cool_away_temp = cool_away_temp
|
||||||
self._heat_away_temp = heat_away_temp
|
self._heat_away_temp = heat_away_temp
|
||||||
self._away = False
|
self._away = False
|
||||||
|
self._retry = 0
|
||||||
|
|
||||||
self._attr_unique_id = device.deviceid
|
self._attr_unique_id = device.deviceid
|
||||||
|
|
||||||
@ -483,21 +485,28 @@ class HoneywellUSThermostat(ClimateEntity):
|
|||||||
try:
|
try:
|
||||||
await self._device.refresh()
|
await self._device.refresh()
|
||||||
self._attr_available = True
|
self._attr_available = True
|
||||||
|
self._retry = 0
|
||||||
|
|
||||||
except UnauthorizedError:
|
except UnauthorizedError:
|
||||||
try:
|
try:
|
||||||
await self._data.client.login()
|
await self._data.client.login()
|
||||||
await self._device.refresh()
|
await self._device.refresh()
|
||||||
self._attr_available = True
|
self._attr_available = True
|
||||||
|
self._retry = 0
|
||||||
|
|
||||||
except (
|
except (
|
||||||
SomeComfortError,
|
SomeComfortError,
|
||||||
ClientConnectionError,
|
ClientConnectionError,
|
||||||
asyncio.TimeoutError,
|
asyncio.TimeoutError,
|
||||||
):
|
):
|
||||||
self._attr_available = False
|
self._retry += 1
|
||||||
|
if self._retry > RETRY:
|
||||||
|
self._attr_available = False
|
||||||
|
|
||||||
except (ClientConnectionError, asyncio.TimeoutError):
|
except (ClientConnectionError, asyncio.TimeoutError):
|
||||||
self._attr_available = False
|
self._retry += 1
|
||||||
|
if self._retry > RETRY:
|
||||||
|
self._attr_available = False
|
||||||
|
|
||||||
except UnexpectedResponse:
|
except UnexpectedResponse:
|
||||||
pass
|
pass
|
||||||
|
@ -10,3 +10,4 @@ DEFAULT_HEAT_AWAY_TEMPERATURE = 61
|
|||||||
CONF_DEV_ID = "thermostat"
|
CONF_DEV_ID = "thermostat"
|
||||||
CONF_LOC_ID = "location"
|
CONF_LOC_ID = "location"
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
RETRY = 3
|
||||||
|
@ -28,7 +28,7 @@ from homeassistant.components.climate import (
|
|||||||
SERVICE_SET_TEMPERATURE,
|
SERVICE_SET_TEMPERATURE,
|
||||||
HVACMode,
|
HVACMode,
|
||||||
)
|
)
|
||||||
from homeassistant.components.honeywell.climate import SCAN_INTERVAL
|
from homeassistant.components.honeywell.climate import RETRY, SCAN_INTERVAL
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_ENTITY_ID,
|
ATTR_ENTITY_ID,
|
||||||
ATTR_TEMPERATURE,
|
ATTR_TEMPERATURE,
|
||||||
@ -1083,6 +1083,17 @@ 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"
|
||||||
|
|
||||||
|
# Due to server instability, only mark entity unavailable after RETRY update attempts
|
||||||
|
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(
|
async_fire_time_changed(
|
||||||
hass,
|
hass,
|
||||||
utcnow() + SCAN_INTERVAL,
|
utcnow() + SCAN_INTERVAL,
|
||||||
@ -1126,7 +1137,6 @@ 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"
|
||||||
|
|
||||||
# "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
|
||||||
async_fire_time_changed(
|
async_fire_time_changed(
|
||||||
@ -1139,6 +1149,18 @@ async def test_async_update_errors(
|
|||||||
assert state.state == "off"
|
assert state.state == "off"
|
||||||
|
|
||||||
device.refresh.side_effect = ClientConnectionError
|
device.refresh.side_effect = ClientConnectionError
|
||||||
|
|
||||||
|
# Due to server instability, only mark entity unavailable after RETRY update attempts
|
||||||
|
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(
|
async_fire_time_changed(
|
||||||
hass,
|
hass,
|
||||||
utcnow() + SCAN_INTERVAL,
|
utcnow() + SCAN_INTERVAL,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user