Home Assistant Unofficial Reference 2024.12.1
cover.py
Go to the documentation of this file.
1 """Representation of a cover."""
2 
3 from __future__ import annotations
4 
5 from typing import Any
6 
8  ATTR_POSITION,
9  CoverEntity,
10  CoverEntityFeature,
11 )
12 from homeassistant.config_entries import ConfigEntry
13 from homeassistant.core import HomeAssistant, callback
14 from homeassistant.helpers.dispatcher import async_dispatcher_connect
15 from homeassistant.helpers.entity_platform import AddEntitiesCallback
16 
17 from .const import DOMAIN, ZWaveMePlatform
18 from .entity import ZWaveMeEntity
19 
20 DEVICE_NAME = ZWaveMePlatform.COVER
21 
22 
24  hass: HomeAssistant,
25  config_entry: ConfigEntry,
26  async_add_entities: AddEntitiesCallback,
27 ) -> None:
28  """Set up the cover platform."""
29 
30  @callback
31  def add_new_device(new_device):
32  controller = hass.data[DOMAIN][config_entry.entry_id]
33  cover = ZWaveMeCover(controller, new_device)
34 
36  [
37  cover,
38  ]
39  )
40 
41  config_entry.async_on_unload(
43  hass, f"ZWAVE_ME_NEW_{DEVICE_NAME.upper()}", add_new_device
44  )
45  )
46 
47 
49  """Representation of a ZWaveMe Multilevel Cover."""
50 
51  _attr_supported_features = (
52  CoverEntityFeature.OPEN
53  | CoverEntityFeature.CLOSE
54  | CoverEntityFeature.SET_POSITION
55  | CoverEntityFeature.STOP
56  )
57 
58  def close_cover(self, **kwargs: Any) -> None:
59  """Close cover."""
60  self.controllercontroller.zwave_api.send_command(self.devicedevice.id, "exact?level=0")
61 
62  def open_cover(self, **kwargs: Any) -> None:
63  """Open cover."""
64  self.controllercontroller.zwave_api.send_command(self.devicedevice.id, "exact?level=99")
65 
66  def set_cover_position(self, **kwargs: Any) -> None:
67  """Update the current value."""
68  value = kwargs[ATTR_POSITION]
69  self.controllercontroller.zwave_api.send_command(
70  self.devicedevice.id, f"exact?level={min(value, 99)!s}"
71  )
72 
73  def stop_cover(self, **kwargs: Any) -> None:
74  """Stop cover."""
75  self.controllercontroller.zwave_api.send_command(self.devicedevice.id, "stop")
76 
77  @property
78  def current_cover_position(self) -> int | None:
79  """Return current position of cover.
80 
81  None is unknown, 0 is closed, 100 is fully open.
82 
83  Allow small calibration errors (some devices after a long time
84  become not well calibrated).
85  """
86  if self.devicedevice.level > 95:
87  return 100
88 
89  return self.devicedevice.level
90 
91  @property
92  def is_closed(self) -> bool | None:
93  """Return true if cover is closed.
94 
95  None is unknown.
96 
97  Allow small calibration errors (some devices after a long time
98  become not well calibrated).
99  """
100  if self.devicedevice.level is None:
101  return None
102 
103  return self.devicedevice.level < 5
None set_cover_position(self, **Any kwargs)
Definition: cover.py:66
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
Definition: cover.py:27
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)
Definition: dispatcher.py:103