1 """Cover for Shelly."""
3 from __future__
import annotations
5 from typing
import Any, cast
7 from aioshelly.block_device
import Block
8 from aioshelly.const
import RPC_GENERATIONS
20 from .coordinator
import ShellyBlockCoordinator, ShellyConfigEntry, ShellyRpcCoordinator
21 from .entity
import ShellyBlockEntity, ShellyRpcEntity
22 from .utils
import get_device_entry_gen, get_rpc_key_ids
27 config_entry: ShellyConfigEntry,
28 async_add_entities: AddEntitiesCallback,
30 """Set up covers for device."""
40 config_entry: ShellyConfigEntry,
41 async_add_entities: AddEntitiesCallback,
43 """Set up cover for device."""
44 coordinator = config_entry.runtime_data.block
45 assert coordinator
and coordinator.device.blocks
46 blocks = [block
for block
in coordinator.device.blocks
if block.type ==
"roller"]
57 config_entry: ShellyConfigEntry,
58 async_add_entities: AddEntitiesCallback,
60 """Set up entities for RPC device."""
61 coordinator = config_entry.runtime_data.rpc
72 """Entity that controls a cover on block based Shelly devices."""
74 _attr_device_class = CoverDeviceClass.SHUTTER
75 _attr_supported_features: CoverEntityFeature = (
76 CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE | CoverEntityFeature.STOP
79 def __init__(self, coordinator: ShellyBlockCoordinator, block: Block) ->
None:
80 """Initialize block cover."""
83 if self.coordinator.device.settings[
"rollers"][0][
"positioning"]:
84 self._attr_supported_features |= CoverEntityFeature.SET_POSITION
88 """If cover is closed."""
90 return cast(bool, self.
control_resultcontrol_result[
"current_pos"] == 0)
92 return cast(int, self.
blockblock.rollerPos) == 0
96 """Position of the cover."""
100 return cast(int, self.
blockblock.rollerPos)
104 """Return if the cover is closing."""
106 return cast(bool, self.
control_resultcontrol_result[
"state"] ==
"close")
108 return self.
blockblock.roller ==
"close"
112 """Return if the cover is opening."""
114 return cast(bool, self.
control_resultcontrol_result[
"state"] ==
"open")
116 return self.
blockblock.roller ==
"open"
129 """Move the cover to a specific position."""
131 go=
"to_pos", roller_pos=kwargs[ATTR_POSITION]
136 """Stop the cover."""
142 """When device updates, clear control result that overrides state."""
148 """Entity that controls a cover on RPC based Shelly devices."""
150 _attr_device_class = CoverDeviceClass.SHUTTER
151 _attr_supported_features: CoverEntityFeature = (
152 CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE | CoverEntityFeature.STOP
155 def __init__(self, coordinator: ShellyRpcCoordinator, id_: int) ->
None:
156 """Initialize rpc cover."""
157 super().
__init__(coordinator, f
"cover:{id_}")
159 if self.
statusstatus[
"pos_control"]:
160 self._attr_supported_features |= CoverEntityFeature.SET_POSITION
161 if coordinator.device.config[f
"cover:{id_}"].
get(
"slat", {}).
get(
"enable"):
162 self._attr_supported_features |= (
163 CoverEntityFeature.OPEN_TILT
164 | CoverEntityFeature.CLOSE_TILT
165 | CoverEntityFeature.STOP_TILT
166 | CoverEntityFeature.SET_TILT_POSITION
171 """If cover is closed."""
172 return cast(bool, self.
statusstatus[
"state"] ==
"closed")
176 """Position of the cover."""
177 if not self.
statusstatus[
"pos_control"]:
180 return cast(int, self.
statusstatus[
"current_pos"])
184 """Return current position of cover tilt."""
185 if "slat_pos" not in self.
statusstatus:
188 return cast(int, self.
statusstatus[
"slat_pos"])
192 """Return if the cover is closing."""
193 return cast(bool, self.
statusstatus[
"state"] ==
"closing")
197 """Return if the cover is opening."""
198 return cast(bool, self.
statusstatus[
"state"] ==
"opening")
202 await self.
call_rpccall_rpc(
"Cover.Close", {
"id": self.
_id_id})
206 await self.
call_rpccall_rpc(
"Cover.Open", {
"id": self.
_id_id})
209 """Move the cover to a specific position."""
211 "Cover.GoToPosition", {
"id": self.
_id_id,
"pos": kwargs[ATTR_POSITION]}
215 """Stop the cover."""
216 await self.
call_rpccall_rpc(
"Cover.Stop", {
"id": self.
_id_id})
219 """Open the cover tilt."""
220 await self.
call_rpccall_rpc(
"Cover.GoToPosition", {
"id": self.
_id_id,
"slat_pos": 100})
223 """Close the cover tilt."""
224 await self.
call_rpccall_rpc(
"Cover.GoToPosition", {
"id": self.
_id_id,
"slat_pos": 0})
227 """Move the cover tilt to a specific position."""
229 "Cover.GoToPosition",
230 {
"id": self.
_id_id,
"slat_pos": kwargs[ATTR_TILT_POSITION]},
234 """Stop the cover."""
235 await self.
call_rpccall_rpc(
"Cover.Stop", {
"id": self.
_id_id})
current_cover_tilt_position
None _update_callback(self)
None async_set_cover_position(self, **Any kwargs)
None __init__(self, ShellyBlockCoordinator coordinator, Block block)
None async_open_cover(self, **Any kwargs)
None async_stop_cover(self, **Any _kwargs)
None async_close_cover(self, **Any kwargs)
None async_close_cover(self, **Any kwargs)
None async_set_cover_position(self, **Any kwargs)
None async_open_cover_tilt(self, **Any kwargs)
bool|None is_closed(self)
None __init__(self, ShellyRpcCoordinator coordinator, int id_)
None async_close_cover_tilt(self, **Any kwargs)
None async_stop_cover_tilt(self, **Any kwargs)
None async_open_cover(self, **Any kwargs)
None async_set_cover_tilt_position(self, **Any kwargs)
None async_stop_cover(self, **Any _kwargs)
Any set_state(self, **Any kwargs)
Any call_rpc(self, str method, Any params)
None async_write_ha_state(self)
web.Response get(self, web.Request request, str config_key)
None async_setup_entry(HomeAssistant hass, ShellyConfigEntry config_entry, AddEntitiesCallback async_add_entities)
None async_setup_rpc_entry(HomeAssistant hass, ShellyConfigEntry config_entry, AddEntitiesCallback async_add_entities)
None async_setup_block_entry(HomeAssistant hass, ShellyConfigEntry config_entry, AddEntitiesCallback async_add_entities)
list[int] get_rpc_key_ids(dict[str, Any] keys_dict, str key)
int get_device_entry_gen(ConfigEntry entry)