From 30154763f86e953e305eebde8ba0b9838fe8b7f6 Mon Sep 17 00:00:00 2001 From: Kevin Hellemun <17928966+OGKevin@users.noreply.github.com> Date: Mon, 11 Oct 2021 13:11:45 +0200 Subject: [PATCH] Add xiaomi vacuum -9999 fix back (#57473) --- homeassistant/components/xiaomi_miio/__init__.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/xiaomi_miio/__init__.py b/homeassistant/components/xiaomi_miio/__init__.py index 840212d3dd6..5382adb8d96 100644 --- a/homeassistant/components/xiaomi_miio/__init__.py +++ b/homeassistant/components/xiaomi_miio/__init__.py @@ -235,12 +235,23 @@ def _async_update_data_vacuum(hass, device: Vacuum): async def update_async(): """Fetch data from the device using async_add_executor_job.""" - try: + + async def execute_update(): async with async_timeout.timeout(10): state = await hass.async_add_executor_job(update) _LOGGER.debug("Got new vacuum state: %s", state) return state + try: + return await execute_update() + 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 execute_update() except DeviceException as ex: raise UpdateFailed(ex) from ex