Home Assistant Unofficial Reference 2024.12.1
cover.py
Go to the documentation of this file.
1 """Support for Lutron shades."""
2 
3 from __future__ import annotations
4 
5 from collections.abc import Mapping
6 import logging
7 from typing import Any
8 
9 from pylutron import Output
10 
12  ATTR_POSITION,
13  CoverEntity,
14  CoverEntityFeature,
15 )
16 from homeassistant.config_entries import ConfigEntry
17 from homeassistant.core import HomeAssistant
18 from homeassistant.helpers.entity_platform import AddEntitiesCallback
19 
20 from . import DOMAIN, LutronData
21 from .entity import LutronDevice
22 
23 _LOGGER = logging.getLogger(__name__)
24 
25 
27  hass: HomeAssistant,
28  config_entry: ConfigEntry,
29  async_add_entities: AddEntitiesCallback,
30 ) -> None:
31  """Set up the Lutron cover platform.
32 
33  Adds shades from the Main Repeater associated with the config_entry as
34  cover entities.
35  """
36  entry_data: LutronData = hass.data[DOMAIN][config_entry.entry_id]
38  [
39  LutronCover(area_name, device, entry_data.client)
40  for area_name, device in entry_data.covers
41  ],
42  True,
43  )
44 
45 
47  """Representation of a Lutron shade."""
48 
49  _attr_supported_features = (
50  CoverEntityFeature.OPEN
51  | CoverEntityFeature.CLOSE
52  | CoverEntityFeature.SET_POSITION
53  )
54  _lutron_device: Output
55  _attr_name = None
56 
57  def close_cover(self, **kwargs: Any) -> None:
58  """Close the cover."""
59  self._lutron_device_lutron_device.level = 0
60 
61  def open_cover(self, **kwargs: Any) -> None:
62  """Open the cover."""
63  self._lutron_device_lutron_device.level = 100
64 
65  def set_cover_position(self, **kwargs: Any) -> None:
66  """Move the shade to a specific position."""
67  if ATTR_POSITION in kwargs:
68  position = kwargs[ATTR_POSITION]
69  self._lutron_device_lutron_device.level = position
70 
71  def _request_state(self) -> None:
72  """Request the state from the device."""
73  _ = self._lutron_device_lutron_device.level
74 
75  def _update_attrs(self) -> None:
76  """Update the state attributes."""
77  level = self._lutron_device_lutron_device.last_level()
78  self._attr_is_closed_attr_is_closed = level < 1
79  self._attr_current_cover_position_attr_current_cover_position = level
80  _LOGGER.debug("Lutron ID: %d updated to %f", self._lutron_device_lutron_device.id, level)
81 
82  @property
83  def extra_state_attributes(self) -> Mapping[str, Any] | None:
84  """Return the state attributes."""
85  return {"lutron_integration_id": self._lutron_device_lutron_device.id}
Mapping[str, Any]|None extra_state_attributes(self)
Definition: cover.py:83
None set_cover_position(self, **Any kwargs)
Definition: cover.py:65
None close_cover(self, **Any kwargs)
Definition: cover.py:57
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
Definition: cover.py:30