Home Assistant Unofficial Reference 2024.12.1
awning.py
Go to the documentation of this file.
1 """Support for Overkiz awnings."""
2 
3 from __future__ import annotations
4 
5 from typing import Any, cast
6 
7 from pyoverkiz.enums import OverkizCommand, OverkizState
8 
10  ATTR_POSITION,
11  CoverDeviceClass,
12  CoverEntityFeature,
13 )
14 
15 from .generic_cover import (
16  COMMANDS_CLOSE,
17  COMMANDS_OPEN,
18  COMMANDS_STOP,
19  OverkizGenericCover,
20 )
21 
22 
24  """Representation of an Overkiz awning."""
25 
26  _attr_device_class = CoverDeviceClass.AWNING
27 
28  @property
29  def supported_features(self) -> CoverEntityFeature:
30  """Flag supported features."""
31  supported_features = super().supported_features
32 
33  if self.executorexecutor.has_command(OverkizCommand.SET_DEPLOYMENT):
34  supported_features |= CoverEntityFeature.SET_POSITION
35 
36  if self.executorexecutor.has_command(OverkizCommand.DEPLOY):
37  supported_features |= CoverEntityFeature.OPEN
38 
39  if self.executorexecutor.has_command(*COMMANDS_STOP):
40  supported_features |= CoverEntityFeature.STOP
41 
42  if self.executorexecutor.has_command(OverkizCommand.UNDEPLOY):
43  supported_features |= CoverEntityFeature.CLOSE
44 
45  return supported_features
46 
47  @property
48  def current_cover_position(self) -> int | None:
49  """Return current position of cover.
50 
51  None is unknown, 0 is closed, 100 is fully open.
52  """
53  current_position = self.executorexecutor.select_state(OverkizState.CORE_DEPLOYMENT)
54  if current_position is not None:
55  return cast(int, current_position)
56 
57  return None
58 
59  async def async_set_cover_position(self, **kwargs: Any) -> None:
60  """Move the cover to a specific position."""
61  await self.executorexecutor.async_execute_command(
62  OverkizCommand.SET_DEPLOYMENT, kwargs[ATTR_POSITION]
63  )
64 
65  async def async_open_cover(self, **kwargs: Any) -> None:
66  """Open the cover."""
67  await self.executorexecutor.async_execute_command(OverkizCommand.DEPLOY)
68 
69  async def async_close_cover(self, **kwargs: Any) -> None:
70  """Close the cover."""
71  await self.executorexecutor.async_execute_command(OverkizCommand.UNDEPLOY)
72 
73  @property
74  def is_opening(self) -> bool | None:
75  """Return if the cover is opening or not."""
76  if self.is_runningis_running(COMMANDS_OPEN):
77  return True
78 
79  # Check if cover is moving based on current state
80  is_moving = self.devicedevice.states.get(OverkizState.CORE_MOVING)
81  current_closure = self.devicedevice.states.get(OverkizState.CORE_DEPLOYMENT)
82  target_closure = self.devicedevice.states.get(OverkizState.CORE_TARGET_CLOSURE)
83 
84  if not is_moving or not current_closure or not target_closure:
85  return None
86 
87  return cast(int, current_closure.value) < cast(int, target_closure.value)
88 
89  @property
90  def is_closing(self) -> bool | None:
91  """Return if the cover is closing or not."""
92  if self.is_runningis_running(COMMANDS_CLOSE):
93  return True
94 
95  # Check if cover is moving based on current state
96  is_moving = self.devicedevice.states.get(OverkizState.CORE_MOVING)
97  current_closure = self.devicedevice.states.get(OverkizState.CORE_DEPLOYMENT)
98  target_closure = self.devicedevice.states.get(OverkizState.CORE_TARGET_CLOSURE)
99 
100  if not is_moving or not current_closure or not target_closure:
101  return None
102 
103  return cast(int, current_closure.value) > cast(int, target_closure.value)
None async_set_cover_position(self, **Any kwargs)
Definition: awning.py:59