1 """Support for ESPHome covers."""
3 from __future__
import annotations
5 from functools
import partial
8 from aioesphomeapi
import APIVersion, CoverInfo, CoverOperation, CoverState, EntityInfo
22 convert_api_error_ha_error,
23 esphome_state_property,
24 platform_async_setup_entry,
29 """A cover implementation for ESPHome."""
33 """Set attrs from static info."""
36 flags = CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE
37 if self.
_api_version_api_version < APIVersion(1, 8)
or static_info.supports_stop:
38 flags |= CoverEntityFeature.STOP
39 if static_info.supports_position:
40 flags |= CoverEntityFeature.SET_POSITION
41 if static_info.supports_tilt:
43 CoverEntityFeature.OPEN_TILT
44 | CoverEntityFeature.CLOSE_TILT
45 | CoverEntityFeature.SET_TILT_POSITION
49 CoverDeviceClass, static_info.device_class
54 @esphome_state_property
56 """Return if the cover is closed or not."""
61 @esphome_state_property
63 """Return if the cover is opening or not."""
64 return self.
_state_state.current_operation
is CoverOperation.IS_OPENING
67 @esphome_state_property
69 """Return if the cover is closing or not."""
70 return self.
_state_state.current_operation
is CoverOperation.IS_CLOSING
73 @esphome_state_property
75 """Return current position of cover. 0 is closed, 100 is open."""
78 return round(self.
_state_state.position * 100.0)
81 @esphome_state_property
83 """Return current position of cover tilt. 0 is closed, 100 is open."""
86 return round(self.
_state_state.tilt * 100.0)
88 @convert_api_error_ha_error
91 self.
_client_client.cover_command(key=self.
_key_key, position=1.0)
93 @convert_api_error_ha_error
96 self.
_client_client.cover_command(key=self.
_key_key, position=0.0)
98 @convert_api_error_ha_error
100 """Stop the cover."""
101 self.
_client_client.cover_command(key=self.
_key_key, stop=
True)
103 @convert_api_error_ha_error
105 """Move the cover to a specific position."""
106 self.
_client_client.cover_command(key=self.
_key_key, position=kwargs[ATTR_POSITION] / 100)
108 @convert_api_error_ha_error
110 """Open the cover tilt."""
111 self.
_client_client.cover_command(key=self.
_key_key, tilt=1.0)
113 @convert_api_error_ha_error
115 """Close the cover tilt."""
116 self.
_client_client.cover_command(key=self.
_key_key, tilt=0.0)
118 @convert_api_error_ha_error
120 """Move the cover tilt to a specific position."""
121 tilt_position: int = kwargs[ATTR_TILT_POSITION]
122 self.
_client_client.cover_command(key=self.
_key_key, tilt=tilt_position / 100)
125 async_setup_entry = partial(
126 platform_async_setup_entry,
128 entity_type=EsphomeCover,
129 state_type=CoverState,
current_cover_tilt_position
None async_close_cover_tilt(self, **Any kwargs)
None async_open_cover(self, **Any kwargs)
None async_set_cover_position(self, **Any kwargs)
None async_open_cover_tilt(self, **Any kwargs)
None _on_static_info_update(self, EntityInfo static_info)
None async_close_cover(self, **Any kwargs)
None async_stop_cover(self, **Any kwargs)
bool|None is_closed(self)
None async_set_cover_tilt_position(self, **Any kwargs)