Home Assistant Unofficial Reference 2024.12.1
cover.py
Go to the documentation of this file.
1 """Support for Lutron Caseta shades."""
2 
3 from typing import Any
4 
6  ATTR_POSITION,
7  ATTR_TILT_POSITION,
8  DOMAIN as COVER_DOMAIN,
9  CoverDeviceClass,
10  CoverEntity,
11  CoverEntityFeature,
12 )
13 from homeassistant.core import HomeAssistant
14 from homeassistant.helpers.entity_platform import AddEntitiesCallback
15 
16 from .entity import LutronCasetaUpdatableEntity
17 from .models import LutronCasetaConfigEntry
18 
19 
21  """Representation of a Lutron shade with open/close functionality."""
22 
23  _attr_supported_features = (
24  CoverEntityFeature.OPEN
25  | CoverEntityFeature.CLOSE
26  | CoverEntityFeature.STOP
27  | CoverEntityFeature.SET_POSITION
28  )
29  _attr_device_class = CoverDeviceClass.SHADE
30 
31  @property
32  def is_closed(self) -> bool:
33  """Return if the cover is closed."""
34  return self._device_device_device["current_state"] < 1
35 
36  @property
37  def current_cover_position(self) -> int:
38  """Return the current position of cover."""
39  return self._device_device_device["current_state"]
40 
41  async def async_close_cover(self, **kwargs: Any) -> None:
42  """Close the cover."""
43  await self._smartbridge_smartbridge.lower_cover(self.device_iddevice_id)
44  await self.async_updateasync_update()
45  self.async_write_ha_stateasync_write_ha_state()
46 
47  async def async_stop_cover(self, **kwargs: Any) -> None:
48  """Stop the cover."""
49  await self._smartbridge_smartbridge.stop_cover(self.device_iddevice_id)
50 
51  async def async_open_cover(self, **kwargs: Any) -> None:
52  """Open the cover."""
53  await self._smartbridge_smartbridge.raise_cover(self.device_iddevice_id)
54  await self.async_updateasync_update()
55  self.async_write_ha_stateasync_write_ha_state()
56 
57  async def async_set_cover_position(self, **kwargs: Any) -> None:
58  """Move the shade to a specific position."""
59  await self._smartbridge_smartbridge.set_value(self.device_iddevice_id, kwargs[ATTR_POSITION])
60 
61 
63  """Representation of a Lutron tilt only blind."""
64 
65  _attr_supported_features = (
66  CoverEntityFeature.OPEN_TILT
67  | CoverEntityFeature.CLOSE_TILT
68  | CoverEntityFeature.SET_TILT_POSITION
69  | CoverEntityFeature.OPEN_TILT
70  )
71  _attr_device_class = CoverDeviceClass.BLIND
72 
73  @property
74  def is_closed(self) -> bool:
75  """Return if the blind is closed, either at position 0 or 100."""
76  return self._device_device_device["tilt"] == 0 or self._device_device_device["tilt"] == 100
77 
78  @property
79  def current_cover_tilt_position(self) -> int:
80  """Return the current tilt position of blind."""
81  return self._device_device_device["tilt"]
82 
83  async def async_close_cover_tilt(self, **kwargs: Any) -> None:
84  """Close the blind."""
85  await self._smartbridge_smartbridge.set_tilt(self.device_iddevice_id, 0)
86  await self.async_updateasync_update()
87  self.async_write_ha_stateasync_write_ha_state()
88 
89  async def async_open_cover_tilt(self, **kwargs: Any) -> None:
90  """Open the blind."""
91  await self._smartbridge_smartbridge.set_tilt(self.device_iddevice_id, 50)
92  await self.async_updateasync_update()
93  self.async_write_ha_stateasync_write_ha_state()
94 
95  async def async_set_cover_tilt_position(self, **kwargs: Any) -> None:
96  """Move the blind to a specific tilt."""
97  await self._smartbridge_smartbridge.set_tilt(self.device_iddevice_id, kwargs[ATTR_TILT_POSITION])
98 
99 
100 PYLUTRON_TYPE_TO_CLASSES = {
101  "SerenaTiltOnlyWoodBlind": LutronCasetaTiltOnlyBlind,
102  "SerenaHoneycombShade": LutronCasetaShade,
103  "SerenaRollerShade": LutronCasetaShade,
104  "TriathlonHoneycombShade": LutronCasetaShade,
105  "TriathlonRollerShade": LutronCasetaShade,
106  "QsWirelessShade": LutronCasetaShade,
107  "QsWirelessHorizontalSheerBlind": LutronCasetaShade,
108  "Shade": LutronCasetaShade,
109  "PalladiomWireFreeShade": LutronCasetaShade,
110 }
111 
112 
114  hass: HomeAssistant,
115  config_entry: LutronCasetaConfigEntry,
116  async_add_entities: AddEntitiesCallback,
117 ) -> None:
118  """Set up the Lutron Caseta cover platform.
119 
120  Adds shades from the Caseta bridge associated with the config_entry as
121  cover entities.
122  """
123  data = config_entry.runtime_data
124  bridge = data.bridge
125  cover_devices = bridge.get_devices_by_domain(COVER_DOMAIN)
127  # default to standard LutronCasetaCover type if the pylutron type is not yet mapped
128  PYLUTRON_TYPE_TO_CLASSES.get(cover_device["type"], LutronCasetaShade)(
129  cover_device, data
130  )
131  for cover_device in cover_devices
132  )
None stop_cover(self, **Any kwargs)
Definition: __init__.py:435
None async_setup_entry(HomeAssistant hass, LutronCasetaConfigEntry config_entry, AddEntitiesCallback async_add_entities)
Definition: cover.py:117