From 16780bf4c2e797bb2ff51621eb1f3984165ed65b Mon Sep 17 00:00:00 2001 From: starkillerOG Date: Wed, 24 May 2023 15:16:35 +0200 Subject: [PATCH] Prevent firmware update error when internet blocked for Reolink camera (#91738) * Prevent firmware update error when internet blocked * fix styling * switch back to async_config_entry_first_refresh * fix still raising when starting * missing return * Catch CancelledError --- homeassistant/components/reolink/__init__.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/reolink/__init__.py b/homeassistant/components/reolink/__init__.py index 76c0963e2c0..a5050d3c436 100644 --- a/homeassistant/components/reolink/__init__.py +++ b/homeassistant/components/reolink/__init__.py @@ -75,6 +75,8 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, host.stop) ) + starting = True + async def async_device_config_update() -> None: """Update the host state cache and renew the ONVIF-subscription.""" async with async_timeout.timeout(host.api.timeout): @@ -96,9 +98,19 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b async with async_timeout.timeout(host.api.timeout): try: return await host.api.check_new_firmware() - except ReolinkError as err: + except (ReolinkError, asyncio.exceptions.CancelledError) as err: + if starting: + _LOGGER.debug( + "Error checking Reolink firmware update at startup " + "from %s, possibly internet access is blocked", + host.api.nvr_name, + ) + return False + raise UpdateFailed( - f"Error checking Reolink firmware update {host.api.nvr_name}" + f"Error checking Reolink firmware update from {host.api.nvr_name}, " + "if the camera is blocked from accessing the internet, " + "disable the update entity" ) from err device_coordinator = DataUpdateCoordinator( @@ -120,7 +132,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b # If camera WAN blocked, firmware check fails, do not prevent setup await asyncio.gather( device_coordinator.async_config_entry_first_refresh(), - firmware_coordinator.async_refresh(), + firmware_coordinator.async_config_entry_first_refresh(), ) except ConfigEntryNotReady: await host.stop() @@ -138,6 +150,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b config_entry.add_update_listener(entry_update_listener) ) + starting = False return True