1 """Support for SwitchBee cover."""
3 from __future__
import annotations
7 from switchbee.api.central_unit
import SwitchBeeError, SwitchBeeTokenError
8 from switchbee.const
import SomfyCommand
9 from switchbee.device
import SwitchBeeShutter, SwitchBeeSomfy
22 from .const
import DOMAIN
23 from .coordinator
import SwitchBeeCoordinator
24 from .entity
import SwitchBeeDeviceEntity
28 hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
30 """Set up SwitchBee switch."""
31 coordinator: SwitchBeeCoordinator = hass.data[DOMAIN][entry.entry_id]
32 entities: list[CoverEntity] = []
34 for device
in coordinator.data.values():
35 if isinstance(device, SwitchBeeShutter):
37 elif isinstance(device, SwitchBeeSomfy):
44 """Representation of a SwitchBee Somfy cover."""
46 _attr_device_class = CoverDeviceClass.SHUTTER
47 _attr_supported_features = (
48 CoverEntityFeature.CLOSE | CoverEntityFeature.OPEN | CoverEntityFeature.STOP
50 _attr_is_closed =
None
53 """Async function to fire Somfy device command."""
55 await self.coordinator.api.set_state(self._device.id, command)
56 except (SwitchBeeError, SwitchBeeTokenError)
as exp:
58 f
"Failed to fire {command} for {self.name}, {exp!s}"
66 """Close the cover."""
70 """Stop a moving cover."""
75 """Representation of a SwitchBee cover."""
77 _attr_device_class = CoverDeviceClass.SHUTTER
78 _attr_supported_features = (
79 CoverEntityFeature.CLOSE
80 | CoverEntityFeature.OPEN
81 | CoverEntityFeature.SET_POSITION
82 | CoverEntityFeature.STOP
84 _attr_is_closed: bool |
None =
None
88 """Handle updated data from the coordinator."""
93 """Update the entity attributes from the coordinator data."""
95 coordinator_device = self._get_coordinator_device()
97 if coordinator_device.position == -1:
98 self._check_if_became_offline()
102 self._check_if_became_online()
113 """Open the cover."""
120 """Close the cover."""
127 """Stop a moving cover."""
134 await self.coordinator.async_request_refresh()
137 """Async function to set position to cover."""
140 and "force" not in kwargs
144 await self.coordinator.api.set_state(self._device.id, kwargs[ATTR_POSITION])
145 except (SwitchBeeError, SwitchBeeTokenError)
as exp:
147 f
"Failed to set {self.name} position to {kwargs[ATTR_POSITION]}, error:"
151 self._get_coordinator_device().position = kwargs[ATTR_POSITION]
152 self.coordinator.async_set_updated_data(self.coordinator.data)
None async_set_cover_position(self, **Any kwargs)
int|None current_cover_position(self)
None async_close_cover(self, **Any kwargs)
None _handle_coordinator_update(self)
None _update_from_coordinator(self)
None async_set_cover_position(self, **Any kwargs)
_attr_current_cover_position
None async_stop_cover(self, **Any kwargs)
None async_open_cover(self, **Any kwargs)
None async_close_cover(self, **Any kwargs)
None async_stop_cover(self, **Any kwargs)
None _fire_somfy_command(self, str command)
None async_open_cover(self, **Any kwargs)
None async_write_ha_state(self)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)