Add support for Somfy Camera Shutter (#29057)

This commit is contained in:
tetienne 2019-11-28 10:42:17 +01:00 committed by Franck Nijhof
parent 9c9e9bc92a
commit 4e107a2bcf
6 changed files with 54 additions and 19 deletions

View file

@ -48,7 +48,7 @@ CONFIG_SCHEMA = vol.Schema(
extra=vol.ALLOW_EXTRA,
)
SOMFY_COMPONENTS = ["cover"]
SOMFY_COMPONENTS = ["cover", "switch"]
async def async_setup(hass, config):

View file

@ -1,9 +1,4 @@
"""
Support for Somfy Covers.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/cover.somfy/
"""
"""Support for Somfy Covers."""
from pymfy.api.devices.category import Category
from pymfy.api.devices.blind import Blind
@ -37,15 +32,6 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
async_add_entities(await hass.async_add_executor_job(get_covers), True)
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Old way of setting up platform.
Can only be called when a user accidentally mentions the platform in their
config. But even in that case it would have been ignored.
"""
pass
class SomfyCover(SomfyEntity, CoverDevice):
"""Representation of a Somfy cover device."""

View file

@ -5,5 +5,5 @@
"documentation": "https://www.home-assistant.io/integrations/somfy",
"dependencies": ["http"],
"codeowners": ["@tetienne"],
"requirements": ["pymfy==0.6.1"]
"requirements": ["pymfy==0.7.1"]
}

View file

@ -0,0 +1,49 @@
"""Support for Somfy Camera Shutter."""
from pymfy.api.devices.camera_protect import CameraProtect
from pymfy.api.devices.category import Category
from homeassistant.components.somfy import DOMAIN, SomfyEntity, DEVICES, API
from homeassistant.helpers.entity import ToggleEntity
async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up the Somfy switch platform."""
def get_shutters():
"""Retrieve switches."""
devices = hass.data[DOMAIN][DEVICES]
return [
SomfyCameraShutter(device, hass.data[DOMAIN][API])
for device in devices
if Category.CAMERA.value in device.categories
]
async_add_entities(await hass.async_add_executor_job(get_shutters), True)
class SomfyCameraShutter(SomfyEntity, ToggleEntity):
"""Representation of a Somfy Camera Shutter device."""
def __init__(self, device, api):
"""Initialize the Somfy device."""
super().__init__(device, api)
self.shutter = CameraProtect(self.device, self.api)
async def async_update(self):
"""Update the device with the latest data."""
await super().async_update()
self.shutter = CameraProtect(self.device, self.api)
def turn_on(self, **kwargs) -> None:
"""Turn the entity on."""
self.shutter.open_shutter()
def turn_off(self, **kwargs):
"""Turn the entity off."""
self.shutter.close_shutter()
@property
def is_on(self) -> bool:
"""Return True if entity is on."""
return self.shutter.get_shutter_position() == "opened"

View file

@ -1335,7 +1335,7 @@ pymailgunner==1.4
pymediaroom==0.6.4
# homeassistant.components.somfy
pymfy==0.6.1
pymfy==0.7.1
# homeassistant.components.xiaomi_tv
pymitv==1.4.3

View file

@ -449,7 +449,7 @@ pylitejet==0.1
pymailgunner==1.4
# homeassistant.components.somfy
pymfy==0.6.1
pymfy==0.7.1
# homeassistant.components.mochad
pymochad==0.2.0