From dc79d71f39e66ab309ce708a0e01e690a925a00b Mon Sep 17 00:00:00 2001
From: Thibaut <thibaut@etienne.pw>
Date: Fri, 25 Dec 2020 22:29:23 +0100
Subject: [PATCH] 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>
---
 homeassistant/components/somfy/__init__.py | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/homeassistant/components/somfy/__init__.py b/homeassistant/components/somfy/__init__.py
index 78429dd1fe0..2fc83ea71de 100644
--- a/homeassistant/components/somfy/__init__.py
+++ b/homeassistant/components/somfy/__init__.py
@@ -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(
-- 
GitLab