1 """Support for WiLight Cover."""
3 from __future__
import annotations
7 from pywilight.const
import (
23 from .const
import DOMAIN
24 from .entity
import WiLightDevice
25 from .parent_device
import WiLightParent
29 hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
31 """Set up WiLight covers from a config entry."""
32 parent: WiLightParent = hass.data[DOMAIN][entry.entry_id]
37 for item
in parent.api.items:
38 if item[
"type"] != ITEM_COVER:
41 item_name = item[
"name"]
42 if item[
"sub_type"] != COVER_V1:
44 entities.append(
WiLightCover(parent.api, index, item_name))
50 """Convert wilight position 1..255 to hass format 0..100."""
51 return min(100, round((value * 100) / 255))
55 """Convert hass position 0..100 to wilight 1..255 scale."""
56 return min(255, round((value * 255) / 100))
60 """Representation of a WiLights cover."""
66 """Return current position of cover.
68 None is unknown, 0 is closed, 100 is fully open.
70 if "position_current" in self.
_status_status:
76 """Return if the cover is opening or not."""
77 if "motor_state" not in self.
_status_status:
79 return self.
_status_status[
"motor_state"] == WL_OPENING
83 """Return if the cover is closing or not."""
84 if "motor_state" not in self.
_status_status:
86 return self.
_status_status[
"motor_state"] == WL_CLOSING
90 """Return if the cover is closed or not."""
91 if "motor_state" not in self.
_status_status
or "position_current" not in self.
_status_status:
94 self.
_status_status[
"motor_state"] == WL_STOPPED
100 await self.
_client_client.cover_command(self.
_index_index, WL_OPEN)
104 await self.
_client_client.cover_command(self.
_index_index, WL_CLOSE)
107 """Move the cover to a specific position."""
112 """Stop the cover."""
113 await self.
_client_client.cover_command(self.
_index_index, WL_STOP)
None set_cover_position(self, **Any kwargs)
None async_stop_cover(self, **Any kwargs)
bool|None is_closing(self)
bool|None is_closed(self)
None async_open_cover(self, **Any kwargs)
None async_close_cover(self, **Any kwargs)
None async_set_cover_position(self, **Any kwargs)
bool|None is_opening(self)
int hass_to_wilight_position(int value)
int wilight_to_hass_position(int value)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)