Handle missing Somfy devices during update (#44425)

* Handle missing devices during update

* Raise error only if there was devices previously

* Not final dot

Co-authored-by: Franck Nijhof <frenck@frenck.nl>

Co-authored-by: Franck Nijhof <frenck@frenck.nl>
This commit is contained in:
Thibaut 2020-12-25 22:29:23 +01:00 committed by GitHub
parent fa69daf5b3
commit dc79d71f39
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -21,6 +21,7 @@ from homeassistant.helpers.typing import HomeAssistantType
from homeassistant.helpers.update_coordinator import (
CoordinatorEntity,
DataUpdateCoordinator,
UpdateFailed,
)
from . import api
@ -92,6 +93,10 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry):
async def _update_all_devices():
"""Update all the devices."""
devices = await hass.async_add_executor_job(data[API].get_devices)
previous_devices = data[COORDINATOR].data
# Sometimes Somfy returns an empty list.
if not devices and previous_devices:
raise UpdateFailed("No devices returned")
return {dev.id: dev for dev in devices}
coordinator = DataUpdateCoordinator(