Home Assistant Unofficial Reference 2024.12.1
cover.py
Go to the documentation of this file.
1 """Support for Insteon covers via PowerLinc Modem."""
2 
3 import math
4 from typing import Any
5 
7  ATTR_POSITION,
8  CoverEntity,
9  CoverEntityFeature,
10 )
11 from homeassistant.config_entries import ConfigEntry
12 from homeassistant.const import Platform
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 SIGNAL_ADD_ENTITIES
18 from .entity import InsteonEntity
19 from .utils import async_add_insteon_devices, async_add_insteon_entities
20 
21 
23  hass: HomeAssistant,
24  config_entry: ConfigEntry,
25  async_add_entities: AddEntitiesCallback,
26 ) -> None:
27  """Set up the Insteon covers from a config entry."""
28 
29  @callback
30  def async_add_insteon_cover_entities(discovery_info=None):
31  """Add the Insteon entities for the platform."""
33  hass, Platform.COVER, InsteonCoverEntity, async_add_entities, discovery_info
34  )
35 
36  signal = f"{SIGNAL_ADD_ENTITIES}_{Platform.COVER}"
37  async_dispatcher_connect(hass, signal, async_add_insteon_cover_entities)
39  hass,
40  Platform.COVER,
41  InsteonCoverEntity,
42  async_add_entities,
43  )
44 
45 
47  """A Class for an Insteon cover entity."""
48 
49  _attr_supported_features = (
50  CoverEntityFeature.OPEN
51  | CoverEntityFeature.CLOSE
52  | CoverEntityFeature.SET_POSITION
53  )
54 
55  @property
56  def current_cover_position(self) -> int:
57  """Return the current cover position."""
58  if self._insteon_device_group_insteon_device_group.value is not None:
59  pos = self._insteon_device_group_insteon_device_group.value
60  else:
61  pos = 0
62  return int(math.ceil(pos * 100 / 255))
63 
64  @property
65  def is_closed(self) -> bool:
66  """Return the boolean response if the node is on."""
68 
69  async def async_open_cover(self, **kwargs: Any) -> None:
70  """Open cover."""
71  await self._insteon_device_insteon_device.async_open()
72 
73  async def async_close_cover(self, **kwargs: Any) -> None:
74  """Close cover."""
75  await self._insteon_device_insteon_device.async_close()
76 
77  async def async_set_cover_position(self, **kwargs: Any) -> None:
78  """Set the cover position."""
79  position = int(kwargs[ATTR_POSITION] * 255 / 100)
80  if position == 0:
81  await self._insteon_device_insteon_device.async_close()
82  else:
83  await self._insteon_device_insteon_device.async_open(
84  open_level=position, group=self._insteon_device_group_insteon_device_group.group
85  )
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
Definition: cover.py:26
None async_add_insteon_devices(HomeAssistant hass, Platform platform, type[InsteonEntity] entity_type, AddEntitiesCallback async_add_entities)
Definition: utils.py:436
None async_add_insteon_entities(HomeAssistant hass, Platform platform, type[InsteonEntity] entity_type, AddEntitiesCallback async_add_entities, dict[str, Any] discovery_info)
Definition: utils.py:420
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)
Definition: dispatcher.py:103