Home Assistant Unofficial Reference 2024.12.1
cover.py
Go to the documentation of this file.
1 """Platform for cover integration."""
2 
3 from typing import Any
4 
5 from boschshcpy import SHCSession, SHCShutterControl
6 
8  ATTR_POSITION,
9  CoverDeviceClass,
10  CoverEntity,
11  CoverEntityFeature,
12 )
13 from homeassistant.config_entries import ConfigEntry
14 from homeassistant.core import HomeAssistant
15 from homeassistant.helpers.entity_platform import AddEntitiesCallback
16 
17 from .const import DATA_SESSION, DOMAIN
18 from .entity import SHCEntity
19 
20 
22  hass: HomeAssistant,
23  config_entry: ConfigEntry,
24  async_add_entities: AddEntitiesCallback,
25 ) -> None:
26  """Set up the SHC cover platform."""
27 
28  session: SHCSession = hass.data[DOMAIN][config_entry.entry_id][DATA_SESSION]
29 
32  device=cover,
33  parent_id=session.information.unique_id,
34  entry_id=config_entry.entry_id,
35  )
36  for cover in session.device_helper.shutter_controls
37  )
38 
39 
41  """Representation of a SHC shutter control device."""
42 
43  _attr_name = None
44  _attr_device_class = CoverDeviceClass.SHUTTER
45  _attr_supported_features = (
46  CoverEntityFeature.OPEN
47  | CoverEntityFeature.CLOSE
48  | CoverEntityFeature.STOP
49  | CoverEntityFeature.SET_POSITION
50  )
51 
52  @property
53  def current_cover_position(self) -> int:
54  """Return the current cover position."""
55  return round(self._device_device.level * 100.0)
56 
57  def stop_cover(self, **kwargs: Any) -> None:
58  """Stop the cover."""
59  self._device_device.stop()
60 
61  @property
62  def is_closed(self) -> bool:
63  """Return if the cover is closed or not."""
65 
66  @property
67  def is_opening(self) -> bool:
68  """Return if the cover is opening or not."""
69  return (
70  self._device_device.operation_state
71  == SHCShutterControl.ShutterControlService.State.OPENING
72  )
73 
74  @property
75  def is_closing(self) -> bool:
76  """Return if the cover is closing or not."""
77  return (
78  self._device_device.operation_state
79  == SHCShutterControl.ShutterControlService.State.CLOSING
80  )
81 
82  def open_cover(self, **kwargs: Any) -> None:
83  """Open the cover."""
84  self._device_device.level = 1.0
85 
86  def close_cover(self, **kwargs: Any) -> None:
87  """Close cover."""
88  self._device_device.level = 0.0
89 
90  def set_cover_position(self, **kwargs: Any) -> None:
91  """Move the cover to a specific position."""
92  position = kwargs[ATTR_POSITION]
93  self._device_device.level = position / 100.0
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
Definition: cover.py:25