2019-02-13 20:21:14 +00:00
|
|
|
"""Support for Vera cover - curtains, rollershutters etc."""
|
2021-03-18 13:43:52 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2021-05-04 21:36:48 +00:00
|
|
|
from typing import Any
|
2020-09-16 21:23:50 +00:00
|
|
|
|
|
|
|
import pyvera as veraApi
|
2016-09-15 18:47:03 +00:00
|
|
|
|
2022-01-20 06:46:26 +00:00
|
|
|
from homeassistant.components.cover import ATTR_POSITION, ENTITY_ID_FORMAT, CoverEntity
|
2020-04-03 07:49:50 +00:00
|
|
|
from homeassistant.config_entries import ConfigEntry
|
2022-01-20 06:46:26 +00:00
|
|
|
from homeassistant.const import Platform
|
2020-04-03 07:49:50 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
2021-05-04 21:36:48 +00:00
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
2019-03-21 05:56:46 +00:00
|
|
|
|
2020-04-03 07:49:50 +00:00
|
|
|
from . import VeraDevice
|
2020-09-15 03:06:52 +00:00
|
|
|
from .common import ControllerData, get_controller_data
|
2016-09-15 18:47:03 +00:00
|
|
|
|
|
|
|
|
2020-04-03 07:49:50 +00:00
|
|
|
async def async_setup_entry(
|
|
|
|
hass: HomeAssistant,
|
|
|
|
entry: ConfigEntry,
|
2021-05-04 21:36:48 +00:00
|
|
|
async_add_entities: AddEntitiesCallback,
|
2020-04-03 07:49:50 +00:00
|
|
|
) -> None:
|
|
|
|
"""Set up the sensor config entry."""
|
2020-09-15 03:06:52 +00:00
|
|
|
controller_data = get_controller_data(hass, entry)
|
2020-04-03 07:49:50 +00:00
|
|
|
async_add_entities(
|
2019-07-31 19:25:30 +00:00
|
|
|
[
|
2020-09-15 03:06:52 +00:00
|
|
|
VeraCover(device, controller_data)
|
2022-01-20 06:46:26 +00:00
|
|
|
for device in controller_data.devices[Platform.COVER]
|
2021-02-05 12:20:15 +00:00
|
|
|
],
|
|
|
|
True,
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2016-09-15 18:47:03 +00:00
|
|
|
|
|
|
|
|
2020-09-16 21:23:50 +00:00
|
|
|
class VeraCover(VeraDevice[veraApi.VeraCurtain], CoverEntity):
|
2017-04-30 05:04:49 +00:00
|
|
|
"""Representation a Vera Cover."""
|
2016-09-15 18:47:03 +00:00
|
|
|
|
2020-09-16 21:23:50 +00:00
|
|
|
def __init__(
|
|
|
|
self, vera_device: veraApi.VeraCurtain, controller_data: ControllerData
|
2021-05-20 15:00:19 +00:00
|
|
|
) -> None:
|
2016-09-15 18:47:03 +00:00
|
|
|
"""Initialize the Vera device."""
|
2020-09-15 03:06:52 +00:00
|
|
|
VeraDevice.__init__(self, vera_device, controller_data)
|
2017-03-11 18:06:46 +00:00
|
|
|
self.entity_id = ENTITY_ID_FORMAT.format(self.vera_id)
|
2016-09-15 18:47:03 +00:00
|
|
|
|
|
|
|
@property
|
2020-09-16 21:23:50 +00:00
|
|
|
def current_cover_position(self) -> int:
|
2016-09-15 18:47:03 +00:00
|
|
|
"""
|
|
|
|
Return current position of cover.
|
|
|
|
|
|
|
|
0 is closed, 100 is fully open.
|
|
|
|
"""
|
|
|
|
position = self.vera_device.get_level()
|
|
|
|
if position <= 5:
|
|
|
|
return 0
|
|
|
|
if position >= 95:
|
|
|
|
return 100
|
|
|
|
return position
|
|
|
|
|
2020-09-16 21:23:50 +00:00
|
|
|
def set_cover_position(self, **kwargs) -> None:
|
2016-09-15 18:47:03 +00:00
|
|
|
"""Move the cover to a specific position."""
|
2018-02-11 17:20:28 +00:00
|
|
|
self.vera_device.set_level(kwargs.get(ATTR_POSITION))
|
2017-04-04 05:44:52 +00:00
|
|
|
self.schedule_update_ha_state()
|
2016-09-15 18:47:03 +00:00
|
|
|
|
|
|
|
@property
|
2020-09-16 21:23:50 +00:00
|
|
|
def is_closed(self) -> bool:
|
2016-09-15 18:47:03 +00:00
|
|
|
"""Return if the cover is closed."""
|
|
|
|
if self.current_cover_position is not None:
|
2017-07-06 06:30:01 +00:00
|
|
|
return self.current_cover_position == 0
|
2016-09-15 18:47:03 +00:00
|
|
|
|
2020-09-16 21:23:50 +00:00
|
|
|
def open_cover(self, **kwargs: Any) -> None:
|
2016-09-15 18:47:03 +00:00
|
|
|
"""Open the cover."""
|
|
|
|
self.vera_device.open()
|
2017-04-04 05:44:52 +00:00
|
|
|
self.schedule_update_ha_state()
|
2016-09-15 18:47:03 +00:00
|
|
|
|
2020-09-16 21:23:50 +00:00
|
|
|
def close_cover(self, **kwargs: Any) -> None:
|
2016-09-15 18:47:03 +00:00
|
|
|
"""Close the cover."""
|
|
|
|
self.vera_device.close()
|
2017-04-04 05:44:52 +00:00
|
|
|
self.schedule_update_ha_state()
|
2016-09-15 18:47:03 +00:00
|
|
|
|
2020-09-16 21:23:50 +00:00
|
|
|
def stop_cover(self, **kwargs: Any) -> None:
|
2016-09-15 18:47:03 +00:00
|
|
|
"""Stop the cover."""
|
|
|
|
self.vera_device.stop()
|
2017-04-04 05:44:52 +00:00
|
|
|
self.schedule_update_ha_state()
|