1 """Support for ZHA covers."""
3 from __future__
import annotations
5 from collections.abc
import Mapping
10 from zha.application.platforms.cover
import Shade
as ZhaShade
11 from zha.application.platforms.cover.const
import (
12 CoverEntityFeature
as ZHACoverEntityFeature,
28 from .entity
import ZHAEntity
29 from .helpers
import (
32 async_add_entities
as zha_async_add_entities,
33 convert_zha_error_to_ha_error,
37 _LOGGER = logging.getLogger(__name__)
42 config_entry: ConfigEntry,
43 async_add_entities: AddEntitiesCallback,
45 """Set up the Zigbee Home Automation cover from config entry."""
47 entities_to_create = zha_data.platforms[Platform.COVER]
53 zha_async_add_entities, async_add_entities, ZhaCover, entities_to_create
56 config_entry.async_on_unload(unsub)
60 """Representation of a ZHA cover."""
62 def __init__(self, entity_data: EntityData) ->
None:
63 """Initialize the ZHA cover."""
66 if self.entity_data.entity.info_object.device_class
is not None:
68 self.entity_data.entity.info_object.device_class
72 zha_features: ZHACoverEntityFeature = self.entity_data.entity.supported_features
74 if ZHACoverEntityFeature.OPEN
in zha_features:
75 features |= CoverEntityFeature.OPEN
76 if ZHACoverEntityFeature.CLOSE
in zha_features:
77 features |= CoverEntityFeature.CLOSE
78 if ZHACoverEntityFeature.SET_POSITION
in zha_features:
79 features |= CoverEntityFeature.SET_POSITION
80 if ZHACoverEntityFeature.STOP
in zha_features:
81 features |= CoverEntityFeature.STOP
82 if ZHACoverEntityFeature.OPEN_TILT
in zha_features:
83 features |= CoverEntityFeature.OPEN_TILT
84 if ZHACoverEntityFeature.CLOSE_TILT
in zha_features:
85 features |= CoverEntityFeature.CLOSE_TILT
86 if ZHACoverEntityFeature.STOP_TILT
in zha_features:
87 features |= CoverEntityFeature.STOP_TILT
88 if ZHACoverEntityFeature.SET_TILT_POSITION
in zha_features:
89 features |= CoverEntityFeature.SET_TILT_POSITION
95 """Return entity specific state attributes."""
96 state = self.entity_data.entity.state
98 "target_lift_position": state.get(
"target_lift_position"),
99 "target_tilt_position": state.get(
"target_tilt_position"),
104 """Return True if the cover is closed."""
105 return self.entity_data.entity.is_closed
109 """Return if the cover is opening or not."""
110 return self.entity_data.entity.is_opening
114 """Return if the cover is closing or not."""
115 return self.entity_data.entity.is_closing
119 """Return the current position of ZHA cover."""
120 return self.entity_data.entity.current_cover_position
124 """Return the current tilt position of the cover."""
125 return self.entity_data.entity.current_cover_tilt_position
127 @convert_zha_error_to_ha_error
129 """Open the cover."""
130 await self.entity_data.entity.async_open_cover()
133 @convert_zha_error_to_ha_error
135 """Open the cover tilt."""
136 await self.entity_data.entity.async_open_cover_tilt()
139 @convert_zha_error_to_ha_error
141 """Close the cover."""
142 await self.entity_data.entity.async_close_cover()
145 @convert_zha_error_to_ha_error
147 """Close the cover tilt."""
148 await self.entity_data.entity.async_close_cover_tilt()
151 @convert_zha_error_to_ha_error
153 """Move the cover to a specific position."""
154 await self.entity_data.entity.async_set_cover_position(
155 position=kwargs.get(ATTR_POSITION)
159 @convert_zha_error_to_ha_error
161 """Move the cover tilt to a specific position."""
162 await self.entity_data.entity.async_set_cover_tilt_position(
163 tilt_position=kwargs.get(ATTR_TILT_POSITION)
167 @convert_zha_error_to_ha_error
169 """Stop the cover."""
170 await self.entity_data.entity.async_stop_cover()
173 @convert_zha_error_to_ha_error
175 """Stop the cover tilt."""
176 await self.entity_data.entity.async_stop_cover_tilt()
181 """Restore entity state."""
184 if isinstance(self.entity_data.entity, ZhaShade):
188 self.entity_data.entity.restore_external_state_attributes(
190 target_lift_position=state.attributes.get(
"target_lift_position"),
191 target_tilt_position=state.attributes.get(
"target_tilt_position"),
current_cover_tilt_position
None async_set_cover_position(self, **Any kwargs)
None async_set_cover_tilt_position(self, **Any kwargs)
None async_open_cover(self, **Any kwargs)
None __init__(self, EntityData entity_data)
None async_stop_cover(self, **Any kwargs)
None async_stop_cover_tilt(self, **Any kwargs)
bool|None is_closed(self)
None async_close_cover_tilt(self, **Any kwargs)
None async_close_cover(self, **Any kwargs)
Mapping[str, Any]|None extra_state_attributes(self)
None restore_external_state_attributes(self, State state)
None async_open_cover_tilt(self, **Any kwargs)
None async_write_ha_state(self)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
HAZHAData get_zha_data(HomeAssistant hass)
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)