From 4f53e2c6c6ec955d673ab1f66b7107e1f4651374 Mon Sep 17 00:00:00 2001 From: ColinRobbins Date: Sun, 2 Feb 2020 12:30:29 +0000 Subject: [PATCH] Add a shadow for covers that do not support postion --- homeassistant/components/somfy/__init__.py | 6 ++++++ homeassistant/components/somfy/cover.py | 19 ++++++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/somfy/__init__.py b/homeassistant/components/somfy/__init__.py index 365c6839300..89ad6400e5b 100644 --- a/homeassistant/components/somfy/__init__.py +++ b/homeassistant/components/somfy/__init__.py @@ -32,6 +32,7 @@ DOMAIN = "somfy" CONF_CLIENT_ID = "client_id" CONF_CLIENT_SECRET = "client_secret" +CONF_SHADOW = "shadow_cover" SOMFY_AUTH_CALLBACK_PATH = "/auth/somfy/callback" SOMFY_AUTH_START = "/auth/somfy" @@ -42,6 +43,7 @@ CONFIG_SCHEMA = vol.Schema( { vol.Required(CONF_CLIENT_ID): cv.string, vol.Required(CONF_CLIENT_SECRET): cv.string, + vol.Optional(CONF_SHADOW): cv.boolean, } ) }, @@ -58,6 +60,10 @@ async def async_setup(hass, config): if DOMAIN not in config: return True + hass.data[DOMAIN][CONF_SHADOW] = False + if CONF_SHADOW in config[DOMAIN].keys(): + hass.data[DOMAIN][CONF_SHADOW] = config[DOMAIN][CONF_SHADOW] + config_flow.SomfyFlowHandler.async_register_implementation( hass, config_entry_oauth2_flow.LocalOAuth2Implementation( diff --git a/homeassistant/components/somfy/cover.py b/homeassistant/components/somfy/cover.py index b48e326162d..0d1cc3f54b1 100644 --- a/homeassistant/components/somfy/cover.py +++ b/homeassistant/components/somfy/cover.py @@ -8,7 +8,7 @@ from homeassistant.components.cover import ( CoverDevice, ) -from . import API, DEVICES, DOMAIN, SomfyEntity +from . import API, CONF_SHADOW, DEVICES, DOMAIN, SomfyEntity async def async_setup_entry(hass, config_entry, async_add_entities): @@ -24,8 +24,13 @@ async def async_setup_entry(hass, config_entry, async_add_entities): devices = hass.data[DOMAIN][DEVICES] + if CONF_SHADOW in hass.data[DOMAIN].keys(): + shadow = hass.data[DOMAIN][CONF_SHADOW] + else: + shadow = False + return [ - SomfyCover(cover, hass.data[DOMAIN][API]) + SomfyCover(cover, hass.data[DOMAIN][API], shadow) for cover in devices if categories & set(cover.categories) ] @@ -36,10 +41,12 @@ async def async_setup_entry(hass, config_entry, async_add_entities): class SomfyCover(SomfyEntity, CoverDevice): """Representation of a Somfy cover device.""" - def __init__(self, device, api): + def __init__(self, device, api, shadow): """Initialize the Somfy device.""" super().__init__(device, api) self.cover = Blind(self.device, self.api) + self.shadow = shadow + self._closed = None async def async_update(self): """Update the device with the latest data.""" @@ -48,10 +55,14 @@ class SomfyCover(SomfyEntity, CoverDevice): def close_cover(self, **kwargs): """Close the cover.""" + if self.shadow: + self._closed = True self.cover.close() def open_cover(self, **kwargs): """Open the cover.""" + if self.shadow: + self._closed = False self.cover.open() def stop_cover(self, **kwargs): @@ -76,6 +87,8 @@ class SomfyCover(SomfyEntity, CoverDevice): is_closed = None if self.has_capability("position"): is_closed = self.cover.is_closed() + elif self.shadow: + is_closed = self._closed return is_closed @property