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
This commit is contained in:
starkillerOG 2023-05-24 15:16:35 +02:00 committed by GitHub
parent e97b331942
commit 16780bf4c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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