Add a shadow for covers that do not support postion
This commit is contained in:
parent
48402d49dc
commit
4f53e2c6c6
2 changed files with 22 additions and 3 deletions
|
@ -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(
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue