Home Assistant Unofficial Reference 2024.12.1
cover.py
Go to the documentation of this file.
1 """Support for covers connected with WMS WebControl pro."""
2 
3 from __future__ import annotations
4 
5 from datetime import timedelta
6 from typing import Any
7 
8 from wmspro.const import (
9  WMS_WebControl_pro_API_actionDescription,
10  WMS_WebControl_pro_API_actionType,
11 )
12 
13 from homeassistant.components.cover import ATTR_POSITION, CoverDeviceClass, CoverEntity
14 from homeassistant.core import HomeAssistant
15 from homeassistant.helpers.entity_platform import AddEntitiesCallback
16 
17 from . import WebControlProConfigEntry
18 from .entity import WebControlProGenericEntity
19 
20 SCAN_INTERVAL = timedelta(seconds=5)
21 PARALLEL_UPDATES = 1
22 
23 
25  hass: HomeAssistant,
26  config_entry: WebControlProConfigEntry,
27  async_add_entities: AddEntitiesCallback,
28 ) -> None:
29  """Set up the WMS based covers from a config entry."""
30  hub = config_entry.runtime_data
31 
32  entities: list[WebControlProGenericEntity] = []
33  for dest in hub.dests.values():
34  if dest.action(WMS_WebControl_pro_API_actionDescription.AwningDrive):
35  entities.append(WebControlProAwning(config_entry.entry_id, dest)) # noqa: PERF401
36 
37  async_add_entities(entities)
38 
39 
41  """Representation of a WMS based awning."""
42 
43  _attr_device_class = CoverDeviceClass.AWNING
44 
45  @property
46  def current_cover_position(self) -> int | None:
47  """Return current position of cover."""
48  action = self._dest_dest.action(WMS_WebControl_pro_API_actionDescription.AwningDrive)
49  return 100 - action["percentage"]
50 
51  async def async_set_cover_position(self, **kwargs: Any) -> None:
52  """Move the cover to a specific position."""
53  action = self._dest_dest.action(WMS_WebControl_pro_API_actionDescription.AwningDrive)
54  await action(percentage=100 - kwargs[ATTR_POSITION])
55 
56  @property
57  def is_closed(self) -> bool | None:
58  """Return if the cover is closed."""
60 
61  async def async_open_cover(self, **kwargs: Any) -> None:
62  """Open the cover."""
63  action = self._dest_dest.action(WMS_WebControl_pro_API_actionDescription.AwningDrive)
64  await action(percentage=0)
65 
66  async def async_close_cover(self, **kwargs: Any) -> None:
67  """Close the cover."""
68  action = self._dest_dest.action(WMS_WebControl_pro_API_actionDescription.AwningDrive)
69  await action(percentage=100)
70 
71  async def async_stop_cover(self, **kwargs: Any) -> None:
72  """Stop the device if in motion."""
73  action = self._dest_dest.action(
74  WMS_WebControl_pro_API_actionDescription.ManualCommand,
75  WMS_WebControl_pro_API_actionType.Stop,
76  )
77  await action()
None async_setup_entry(HomeAssistant hass, WebControlProConfigEntry config_entry, AddEntitiesCallback async_add_entities)
Definition: cover.py:28