Fetch the data a second time when -9999 error occurs in Xiaomi Miio integration (#56288)

This commit is contained in:
Maciej Bieniek 2021-09-16 18:19:41 +02:00 committed by GitHub
parent 8418d4ade2
commit 41bf1eb610
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -175,12 +175,23 @@ async def async_create_miio_device_and_coordinator(
async def async_update_data():
"""Fetch data from the device using async_add_executor_job."""
try:
async def _async_fetch_data():
"""Fetch data from the device."""
async with async_timeout.timeout(10):
state = await hass.async_add_executor_job(device.status)
_LOGGER.debug("Got new state: %s", state)
return state
try:
return await _async_fetch_data()
except DeviceException as ex:
if getattr(ex, "code", None) != -9999:
raise UpdateFailed(ex) from ex
_LOGGER.info("Got exception while fetching the state, trying again: %s", ex)
# Try to fetch the data a second time after error code -9999
try:
return await _async_fetch_data()
except DeviceException as ex:
raise UpdateFailed(ex) from ex