1 """Support for covers."""
3 from __future__
import annotations
7 from aiocomelit
import ComelitSerialBridgeObject
8 from aiocomelit.const
import COVER, STATE_COVER, STATE_OFF, STATE_ON
17 from .const
import DOMAIN
18 from .coordinator
import ComelitSerialBridge
23 config_entry: ConfigEntry,
24 async_add_entities: AddEntitiesCallback,
26 """Set up Comelit covers."""
28 coordinator: ComelitSerialBridge = hass.data[DOMAIN][config_entry.entry_id]
32 for device
in coordinator.data[COVER].values()
37 CoordinatorEntity[ComelitSerialBridge], RestoreEntity, CoverEntity
41 _attr_device_class = CoverDeviceClass.SHUTTER
42 _attr_has_entity_name =
True
47 coordinator: ComelitSerialBridge,
48 device: ComelitSerialBridgeObject,
49 config_entry_entry_id: str,
51 """Init cover entity."""
52 self.
_api_api = coordinator.api
58 self.
_attr_device_info_attr_device_info = coordinator.platform_device_info(device, device.type)
64 """Return the current cover action."""
72 """Return current device status."""
73 return self.coordinator.data[COVER][self.
_device_device_device.index].status
77 """Return if the cover is closed."""
79 if self.
_last_state_last_state
in [
None,
"unknown"]:
86 return self.
_last_action_last_action == STATE_COVER.index(
"closing")
92 """Return if the cover is closing."""
97 """Return if the cover is opening."""
102 await self.
_api_api.set_device_status(COVER, self.
_device_device_device.index, STATE_OFF)
106 await self.
_api_api.set_device_status(COVER, self.
_device_device_device.index, STATE_ON)
109 """Stop the cover."""
114 await self.
_api_api.set_device_status(COVER, self.
_device_device_device.index, action)
118 """Handle device update."""
123 """Handle entity which will be added."""
None async_added_to_hass(self)
None async_open_cover(self, **Any kwargs)
bool _current_action(self, str action)
bool|None is_closed(self)
None __init__(self, ComelitSerialBridge coordinator, ComelitSerialBridgeObject device, str config_entry_entry_id)
None async_stop_cover(self, **Any _kwargs)
None async_close_cover(self, **Any kwargs)
None _handle_coordinator_update(self)
bool|None is_opening(self)
bool|None is_closing(self)
None async_write_ha_state(self)
State|None async_get_last_state(self)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)