2019-11-28 09:42:17 +00:00
|
|
|
"""Support for Somfy Camera Shutter."""
|
|
|
|
from pymfy.api.devices.camera_protect import CameraProtect
|
|
|
|
from pymfy.api.devices.category import Category
|
|
|
|
|
2020-04-26 16:50:37 +00:00
|
|
|
from homeassistant.components.switch import SwitchEntity
|
2019-12-09 11:07:10 +00:00
|
|
|
|
2021-07-06 16:48:48 +00:00
|
|
|
from .const import COORDINATOR, DOMAIN
|
|
|
|
from .entity import SomfyEntity
|
2019-11-28 09:42:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def async_setup_entry(hass, config_entry, async_add_entities):
|
|
|
|
"""Set up the Somfy switch platform."""
|
2020-12-24 19:42:56 +00:00
|
|
|
domain_data = hass.data[DOMAIN]
|
|
|
|
coordinator = domain_data[COORDINATOR]
|
|
|
|
|
|
|
|
switches = [
|
2021-07-06 16:48:48 +00:00
|
|
|
SomfyCameraShutter(coordinator, device_id)
|
2020-12-24 19:42:56 +00:00
|
|
|
for device_id, device in coordinator.data.items()
|
|
|
|
if Category.CAMERA.value in device.categories
|
|
|
|
]
|
|
|
|
|
|
|
|
async_add_entities(switches)
|
2019-11-28 09:42:17 +00:00
|
|
|
|
|
|
|
|
2020-04-26 16:50:37 +00:00
|
|
|
class SomfyCameraShutter(SomfyEntity, SwitchEntity):
|
2019-11-28 09:42:17 +00:00
|
|
|
"""Representation of a Somfy Camera Shutter device."""
|
|
|
|
|
2021-07-06 16:48:48 +00:00
|
|
|
def __init__(self, coordinator, device_id):
|
2019-11-28 09:42:17 +00:00
|
|
|
"""Initialize the Somfy device."""
|
2021-07-06 16:48:48 +00:00
|
|
|
super().__init__(coordinator, device_id)
|
2020-10-28 00:57:22 +00:00
|
|
|
self._create_device()
|
2019-11-28 09:42:17 +00:00
|
|
|
|
2020-10-28 00:57:22 +00:00
|
|
|
def _create_device(self):
|
2019-11-28 09:42:17 +00:00
|
|
|
"""Update the device with the latest data."""
|
2021-07-06 16:48:48 +00:00
|
|
|
self.shutter = CameraProtect(self.device, self.coordinator.client)
|
2019-11-28 09:42:17 +00:00
|
|
|
|
|
|
|
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"
|