1 """Implement a iotty Shutter Device."""
3 from __future__
import annotations
8 from iottycloud.device
import Device
9 from iottycloud.shutter
import Shutter, ShutterState
10 from iottycloud.verbs
import SH_DEVICE_TYPE_UID
21 from .
import IottyConfigEntry
22 from .api
import IottyProxy
23 from .coordinator
import IottyDataUpdateCoordinator
24 from .entity
import IottyEntity
26 _LOGGER = logging.getLogger(__name__)
31 config_entry: IottyConfigEntry,
32 async_add_entities: AddEntitiesCallback,
34 """Activate the iotty Shutter component."""
35 _LOGGER.debug(
"Setup COVER entry id is %s", config_entry.entry_id)
37 coordinator = config_entry.runtime_data.coordinator
40 coordinator=coordinator, iotty_cloud=coordinator.iotty, iotty_device=d
42 for d
in coordinator.data.devices
43 if d.device_type == SH_DEVICE_TYPE_UID
44 if (isinstance(d, Shutter))
46 _LOGGER.debug(
"Found %d Shutters", len(entities))
50 known_devices: set = config_entry.runtime_data.known_devices
51 for known_device
in coordinator.data.devices:
52 if known_device.device_type == SH_DEVICE_TYPE_UID:
53 known_devices.add(known_device)
56 def async_update_data() -> None:
57 """Handle updated data from the API endpoint."""
58 if not coordinator.last_update_success:
61 devices = coordinator.data.devices
63 known_devices: set = config_entry.runtime_data.known_devices
66 for device
in devices:
68 any(d.device_id == device.device_id
for d
in known_devices)
69 or device.device_type != SH_DEVICE_TYPE_UID
74 coordinator=coordinator,
75 iotty_cloud=coordinator.iotty,
84 entities.extend([iotty_entity])
85 known_devices.add(device)
90 coordinator.async_add_listener(async_update_data)
94 """Haas entity class for iotty Shutter."""
96 _attr_device_class = CoverDeviceClass.SHUTTER
97 _iotty_device: Shutter
99 CoverEntityFeature.OPEN
100 | CoverEntityFeature.CLOSE
101 | CoverEntityFeature.STOP
102 | CoverEntityFeature.SET_POSITION
107 coordinator: IottyDataUpdateCoordinator,
108 iotty_cloud: IottyProxy,
109 iotty_device: Shutter,
111 """Initialize the Shutter device."""
112 super().
__init__(coordinator, iotty_cloud, iotty_device)
116 """Return the current position of the shutter.
118 None is unknown, 0 is closed, 100 is fully open.
124 """Return true if the Shutter is closed."""
126 "Retrieve device status for %s ? %s : %s",
138 """Return true if the Shutter is opening."""
143 """Return true if the Shutter is closing."""
148 """Flag supported features."""
149 return self._attr_supported_features
152 """Open the cover."""
166 """Move the cover to a specific position."""
167 percentage = kwargs[ATTR_POSITION]
171 {
"open_percentage": percentage},
176 """Stop the cover."""
184 """Handle updated data from the coordinator."""
186 device: Device = next(
188 for device
in self.coordinator.data.devices
191 if isinstance(device, Shutter):
CoverEntityFeature supported_features(self)
None async_set_cover_position(self, **Any kwargs)
None async_open_cover(self, **Any kwargs)
None _handle_coordinator_update(self)
None async_stop_cover(self, **Any kwargs)
None __init__(self, IottyDataUpdateCoordinator coordinator, IottyProxy iotty_cloud, Shutter iotty_device)
None async_close_cover(self, **Any kwargs)
None async_write_ha_state(self)
None async_request_refresh(self)
None async_setup_entry(HomeAssistant hass, IottyConfigEntry config_entry, AddEntitiesCallback async_add_entities)