2021-11-18 13:00:01 +00:00
|
|
|
"""Platform for cover integration."""
|
2022-06-24 04:40:26 +00:00
|
|
|
from typing import Any
|
|
|
|
|
2021-11-18 13:00:01 +00:00
|
|
|
from boschshcpy import SHCSession, SHCShutterControl
|
|
|
|
|
|
|
|
from homeassistant.components.cover import (
|
|
|
|
ATTR_POSITION,
|
2021-12-09 08:16:14 +00:00
|
|
|
CoverDeviceClass,
|
2021-11-18 13:00:01 +00:00
|
|
|
CoverEntity,
|
2022-04-05 21:53:45 +00:00
|
|
|
CoverEntityFeature,
|
2021-11-18 13:00:01 +00:00
|
|
|
)
|
2022-01-03 14:13:18 +00:00
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
2021-11-18 13:00:01 +00:00
|
|
|
|
|
|
|
from .const import DATA_SESSION, DOMAIN
|
|
|
|
from .entity import SHCEntity
|
|
|
|
|
|
|
|
|
2022-01-03 14:13:18 +00:00
|
|
|
async def async_setup_entry(
|
|
|
|
hass: HomeAssistant,
|
|
|
|
config_entry: ConfigEntry,
|
|
|
|
async_add_entities: AddEntitiesCallback,
|
|
|
|
) -> None:
|
2021-11-18 13:00:01 +00:00
|
|
|
"""Set up the SHC cover platform."""
|
|
|
|
|
|
|
|
entities = []
|
|
|
|
session: SHCSession = hass.data[DOMAIN][config_entry.entry_id][DATA_SESSION]
|
|
|
|
|
|
|
|
for cover in session.device_helper.shutter_controls:
|
|
|
|
entities.append(
|
|
|
|
ShutterControlCover(
|
|
|
|
device=cover,
|
|
|
|
parent_id=session.information.unique_id,
|
|
|
|
entry_id=config_entry.entry_id,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
if entities:
|
|
|
|
async_add_entities(entities)
|
|
|
|
|
|
|
|
|
|
|
|
class ShutterControlCover(SHCEntity, CoverEntity):
|
|
|
|
"""Representation of a SHC shutter control device."""
|
|
|
|
|
2021-12-09 08:16:14 +00:00
|
|
|
_attr_device_class = CoverDeviceClass.SHUTTER
|
2021-11-18 13:00:01 +00:00
|
|
|
_attr_supported_features = (
|
2022-04-05 21:53:45 +00:00
|
|
|
CoverEntityFeature.OPEN
|
|
|
|
| CoverEntityFeature.CLOSE
|
|
|
|
| CoverEntityFeature.STOP
|
|
|
|
| CoverEntityFeature.SET_POSITION
|
2021-11-18 13:00:01 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
@property
|
2022-06-25 09:59:56 +00:00
|
|
|
def current_cover_position(self) -> int:
|
2021-11-18 13:00:01 +00:00
|
|
|
"""Return the current cover position."""
|
|
|
|
return round(self._device.level * 100.0)
|
|
|
|
|
2022-06-24 04:40:26 +00:00
|
|
|
def stop_cover(self, **kwargs: Any) -> None:
|
2021-11-18 13:00:01 +00:00
|
|
|
"""Stop the cover."""
|
|
|
|
self._device.stop()
|
|
|
|
|
|
|
|
@property
|
2022-06-25 09:59:56 +00:00
|
|
|
def is_closed(self) -> bool:
|
2021-11-18 13:00:01 +00:00
|
|
|
"""Return if the cover is closed or not."""
|
|
|
|
return self.current_cover_position == 0
|
|
|
|
|
|
|
|
@property
|
2022-06-25 09:59:56 +00:00
|
|
|
def is_opening(self) -> bool:
|
2021-11-18 13:00:01 +00:00
|
|
|
"""Return if the cover is opening or not."""
|
|
|
|
return (
|
|
|
|
self._device.operation_state
|
|
|
|
== SHCShutterControl.ShutterControlService.State.OPENING
|
|
|
|
)
|
|
|
|
|
|
|
|
@property
|
2022-06-25 09:59:56 +00:00
|
|
|
def is_closing(self) -> bool:
|
2021-11-18 13:00:01 +00:00
|
|
|
"""Return if the cover is closing or not."""
|
|
|
|
return (
|
|
|
|
self._device.operation_state
|
|
|
|
== SHCShutterControl.ShutterControlService.State.CLOSING
|
|
|
|
)
|
|
|
|
|
2022-06-24 04:40:26 +00:00
|
|
|
def open_cover(self, **kwargs: Any) -> None:
|
2021-11-18 13:00:01 +00:00
|
|
|
"""Open the cover."""
|
|
|
|
self._device.level = 1.0
|
|
|
|
|
2022-06-24 04:40:26 +00:00
|
|
|
def close_cover(self, **kwargs: Any) -> None:
|
2021-11-18 13:00:01 +00:00
|
|
|
"""Close cover."""
|
|
|
|
self._device.level = 0.0
|
|
|
|
|
2022-06-24 04:40:26 +00:00
|
|
|
def set_cover_position(self, **kwargs: Any) -> None:
|
2021-11-18 13:00:01 +00:00
|
|
|
"""Move the cover to a specific position."""
|
|
|
|
position = kwargs[ATTR_POSITION]
|
|
|
|
self._device.level = position / 100.0
|