diff --git a/homeassistant/components/somfy/__init__.py b/homeassistant/components/somfy/__init__.py index aa288e13ac7..1b2722882e6 100644 --- a/homeassistant/components/somfy/__init__.py +++ b/homeassistant/components/somfy/__init__.py @@ -27,6 +27,7 @@ DOMAIN = "somfy" CONF_CLIENT_ID = "client_id" CONF_CLIENT_SECRET = "client_secret" +CONF_OPTIMISTIC = "optimisitic" SOMFY_AUTH_CALLBACK_PATH = "/auth/somfy/callback" SOMFY_AUTH_START = "/auth/somfy" @@ -37,6 +38,7 @@ CONFIG_SCHEMA = vol.Schema( { vol.Required(CONF_CLIENT_ID): cv.string, vol.Required(CONF_CLIENT_SECRET): cv.string, + vol.Optional(CONF_OPTIMISTIC, default=False): cv.boolean, } ) }, @@ -53,6 +55,8 @@ async def async_setup(hass, config): if DOMAIN not in config: return True + hass.data[DOMAIN][CONF_OPTIMISTIC] = config[DOMAIN][CONF_OPTIMISTIC] + 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..d0e555ed55c 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_OPTIMISTIC, DEVICES, DOMAIN, SomfyEntity async def async_setup_entry(hass, config_entry, async_add_entities): @@ -25,7 +25,9 @@ async def async_setup_entry(hass, config_entry, async_add_entities): devices = hass.data[DOMAIN][DEVICES] return [ - SomfyCover(cover, hass.data[DOMAIN][API]) + SomfyCover( + cover, hass.data[DOMAIN][API], hass.data[DOMAIN][CONF_OPTIMISTIC] + ) for cover in devices if categories & set(cover.categories) ] @@ -36,10 +38,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, optimistic): """Initialize the Somfy device.""" super().__init__(device, api) self.cover = Blind(self.device, self.api) + self.optimistic = optimistic + self._closed = None async def async_update(self): """Update the device with the latest data.""" @@ -48,10 +52,14 @@ class SomfyCover(SomfyEntity, CoverDevice): def close_cover(self, **kwargs): """Close the cover.""" + if self.optimistic: + self._closed = True self.cover.close() def open_cover(self, **kwargs): """Open the cover.""" + if self.optimistic: + self._closed = False self.cover.open() def stop_cover(self, **kwargs): @@ -76,6 +84,8 @@ class SomfyCover(SomfyEntity, CoverDevice): is_closed = None if self.has_capability("position"): is_closed = self.cover.is_closed() + elif self.optimistic: + is_closed = self._closed return is_closed @property