mirror of
https://github.com/home-assistant/core
synced 2024-09-03 08:14:07 +02:00
78 lines
2.3 KiB
Python
78 lines
2.3 KiB
Python
"""Support for Lutron shades."""
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
|
|
from homeassistant.components.cover import (
|
|
ATTR_POSITION,
|
|
CoverEntity,
|
|
CoverEntityFeature,
|
|
)
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
|
|
|
from . import LUTRON_CONTROLLER, LUTRON_DEVICES, LutronDevice
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
def setup_platform(
|
|
hass: HomeAssistant,
|
|
config: ConfigType,
|
|
add_entities: AddEntitiesCallback,
|
|
discovery_info: DiscoveryInfoType | None = None,
|
|
) -> None:
|
|
"""Set up the Lutron shades."""
|
|
devs = []
|
|
for (area_name, device) in hass.data[LUTRON_DEVICES]["cover"]:
|
|
dev = LutronCover(area_name, device, hass.data[LUTRON_CONTROLLER])
|
|
devs.append(dev)
|
|
|
|
add_entities(devs, True)
|
|
|
|
|
|
class LutronCover(LutronDevice, CoverEntity):
|
|
"""Representation of a Lutron shade."""
|
|
|
|
_attr_supported_features = (
|
|
CoverEntityFeature.OPEN
|
|
| CoverEntityFeature.CLOSE
|
|
| CoverEntityFeature.SET_POSITION
|
|
)
|
|
|
|
@property
|
|
def is_closed(self):
|
|
"""Return if the cover is closed."""
|
|
return self._lutron_device.last_level() < 1
|
|
|
|
@property
|
|
def current_cover_position(self):
|
|
"""Return the current position of cover."""
|
|
return self._lutron_device.last_level()
|
|
|
|
def close_cover(self, **kwargs):
|
|
"""Close the cover."""
|
|
self._lutron_device.level = 0
|
|
|
|
def open_cover(self, **kwargs):
|
|
"""Open the cover."""
|
|
self._lutron_device.level = 100
|
|
|
|
def set_cover_position(self, **kwargs):
|
|
"""Move the shade to a specific position."""
|
|
if ATTR_POSITION in kwargs:
|
|
position = kwargs[ATTR_POSITION]
|
|
self._lutron_device.level = position
|
|
|
|
def update(self):
|
|
"""Call when forcing a refresh of the device."""
|
|
# Reading the property (rather than last_level()) fetches value
|
|
level = self._lutron_device.level
|
|
_LOGGER.debug("Lutron ID: %d updated to %f", self._lutron_device.id, level)
|
|
|
|
@property
|
|
def extra_state_attributes(self):
|
|
"""Return the state attributes."""
|
|
return {"lutron_integration_id": self._lutron_device.id}
|