Home Assistant Unofficial Reference 2024.12.1
cover.py
Go to the documentation of this file.
1 """Cover platform for Advantage Air integration."""
2 
3 from typing import Any
4 
6  ATTR_POSITION,
7  CoverDeviceClass,
8  CoverEntity,
9  CoverEntityFeature,
10 )
11 from homeassistant.core import HomeAssistant
12 from homeassistant.helpers.entity_platform import AddEntitiesCallback
13 
14 from . import AdvantageAirDataConfigEntry
15 from .const import ADVANTAGE_AIR_STATE_CLOSE, ADVANTAGE_AIR_STATE_OPEN
16 from .entity import AdvantageAirThingEntity, AdvantageAirZoneEntity
17 from .models import AdvantageAirData
18 
19 PARALLEL_UPDATES = 0
20 
21 
23  hass: HomeAssistant,
24  config_entry: AdvantageAirDataConfigEntry,
25  async_add_entities: AddEntitiesCallback,
26 ) -> None:
27  """Set up AdvantageAir cover platform."""
28 
29  instance = config_entry.runtime_data
30 
31  entities: list[CoverEntity] = []
32  if aircons := instance.coordinator.data.get("aircons"):
33  for ac_key, ac_device in aircons.items():
34  for zone_key, zone in ac_device["zones"].items():
35  # Only add zone vent controls when zone in vent control mode.
36  if zone["type"] == 0:
37  entities.append(AdvantageAirZoneVent(instance, ac_key, zone_key))
38  if things := instance.coordinator.data.get("myThings"):
39  for thing in things["things"].values():
40  if thing["channelDipState"] in [1, 2]: # 1 = "Blind", 2 = "Blind 2"
41  entities.append(
42  AdvantageAirThingCover(instance, thing, CoverDeviceClass.BLIND)
43  )
44  elif thing["channelDipState"] == 3: # 3 = "Garage door"
45  entities.append(
46  AdvantageAirThingCover(instance, thing, CoverDeviceClass.GARAGE)
47  )
48  async_add_entities(entities)
49 
50 
52  """Advantage Air Zone Vent."""
53 
54  _attr_device_class = CoverDeviceClass.DAMPER
55  _attr_supported_features = (
56  CoverEntityFeature.OPEN
57  | CoverEntityFeature.CLOSE
58  | CoverEntityFeature.SET_POSITION
59  )
60 
61  def __init__(self, instance: AdvantageAirData, ac_key: str, zone_key: str) -> None:
62  """Initialize an Advantage Air Zone Vent."""
63  super().__init__(instance, ac_key, zone_key)
64  self._attr_name_attr_name = self._zone_zone["name"]
65 
66  @property
67  def is_closed(self) -> bool:
68  """Return if vent is fully closed."""
69  return self._zone_zone["state"] == ADVANTAGE_AIR_STATE_CLOSE
70 
71  @property
72  def current_cover_position(self) -> int:
73  """Return vents current position as a percentage."""
74  if self._zone_zone["state"] == ADVANTAGE_AIR_STATE_OPEN:
75  return self._zone_zone["value"]
76  return 0
77 
78  async def async_open_cover(self, **kwargs: Any) -> None:
79  """Fully open zone vent."""
80  await self.async_update_zoneasync_update_zone(
81  {"state": ADVANTAGE_AIR_STATE_OPEN, "value": 100},
82  )
83 
84  async def async_close_cover(self, **kwargs: Any) -> None:
85  """Fully close zone vent."""
86  await self.async_update_zoneasync_update_zone({"state": ADVANTAGE_AIR_STATE_CLOSE})
87 
88  async def async_set_cover_position(self, **kwargs: Any) -> None:
89  """Change vent position."""
90  position = round(kwargs[ATTR_POSITION] / 5) * 5
91  if position == 0:
92  await self.async_update_zoneasync_update_zone({"state": ADVANTAGE_AIR_STATE_CLOSE})
93  else:
94  await self.async_update_zoneasync_update_zone(
95  {
96  "state": ADVANTAGE_AIR_STATE_OPEN,
97  "value": position,
98  }
99  )
100 
101 
103  """Representation of Advantage Air Cover controlled by MyPlace."""
104 
105  _attr_supported_features = CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE
106 
107  def __init__(
108  self,
109  instance: AdvantageAirData,
110  thing: dict[str, Any],
111  device_class: CoverDeviceClass,
112  ) -> None:
113  """Initialize an Advantage Air Things Cover."""
114  super().__init__(instance, thing)
115  self._attr_device_class_attr_device_class = device_class
116 
117  @property
118  def is_closed(self) -> bool:
119  """Return if cover is fully closed."""
120  return self._data_data["value"] == 0
121 
122  async def async_open_cover(self, **kwargs: Any) -> None:
123  """Fully open zone vent."""
124  return await self.async_turn_onasync_turn_on()
125 
126  async def async_close_cover(self, **kwargs: Any) -> None:
127  """Fully close zone vent."""
128  return await self.async_turn_offasync_turn_off()
None __init__(self, AdvantageAirData instance, dict[str, Any] thing, CoverDeviceClass device_class)
Definition: cover.py:112
None __init__(self, AdvantageAirData instance, str ac_key, str zone_key)
Definition: cover.py:61
None async_setup_entry(HomeAssistant hass, AdvantageAirDataConfigEntry config_entry, AddEntitiesCallback async_add_entities)
Definition: cover.py:26