Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add retry before unavailable to Honeywell #101702

Merged
merged 5 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions homeassistant/components/honeywell/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
CONF_COOL_AWAY_TEMPERATURE,
CONF_HEAT_AWAY_TEMPERATURE,
DOMAIN,
RETRY,
)

ATTR_FAN_ACTION = "fan_action"
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
mkmer marked this conversation as resolved.
Show resolved Hide resolved

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
1 change: 1 addition & 0 deletions homeassistant/components/honeywell/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
CONF_DEV_ID = "thermostat"
CONF_LOC_ID = "location"
_LOGGER = logging.getLogger(__name__)
RETRY = 3
26 changes: 24 additions & 2 deletions tests/components/honeywell/test_climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -1083,6 +1083,17 @@ 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 attempts
for _ in range(RETRY):
async_fire_time_changed(
mkmer marked this conversation as resolved.
Show resolved Hide resolved
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,
Expand Down Expand Up @@ -1126,7 +1137,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(
Expand All @@ -1139,6 +1149,18 @@ async def test_async_update_errors(
assert state.state == "off"

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(
hass,
utcnow() + SCAN_INTERVAL,
Expand Down