1 """Support for covers through the SmartThings cloud API."""
3 from __future__
import annotations
5 from collections.abc
import Sequence
8 from pysmartthings
import Attribute, Capability
12 DOMAIN
as COVER_DOMAIN,
23 from .const
import DATA_BROKERS, DOMAIN
24 from .entity
import SmartThingsEntity
27 "closed": CoverState.CLOSED,
28 "closing": CoverState.CLOSING,
29 "open": CoverState.OPEN,
30 "opening": CoverState.OPENING,
31 "partially open": CoverState.OPEN,
38 config_entry: ConfigEntry,
39 async_add_entities: AddEntitiesCallback,
41 """Add covers for a config entry."""
42 broker = hass.data[DOMAIN][DATA_BROKERS][config_entry.entry_id]
46 for device
in broker.devices.values()
47 if broker.any_assigned(device.device_id, COVER_DOMAIN)
54 """Return all capabilities supported if minimum required are present."""
56 Capability.door_control,
57 Capability.garage_door_control,
58 Capability.window_shade,
61 if any(capability
in capabilities
for capability
in min_required):
66 Capability.switch_level,
67 Capability.window_shade_level,
74 """Define a SmartThings cover."""
77 """Initialize the cover class."""
82 CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE
85 Capability.switch_level
in device.capabilities
86 or Capability.window_shade_level
in device.capabilities
90 if Capability.door_control
in device.capabilities:
92 elif Capability.window_shade
in device.capabilities:
94 elif Capability.garage_door_control
in device.capabilities:
100 await self.
_device_device.close(set_status=
True)
106 """Open the cover."""
114 """Move the cover to a specific position."""
118 if Capability.window_shade_level
in self.
_device_device.capabilities:
119 await self.
_device_device.set_window_shade_level(
120 kwargs[ATTR_POSITION], set_status=
False
123 await self.
_device_device.set_level(kwargs[ATTR_POSITION], set_status=
False)
126 """Update the attrs of the cover."""
127 if Capability.door_control
in self.
_device_device.capabilities:
128 self.
_state_state = VALUE_TO_STATE.get(self.
_device_device.status.door)
129 elif Capability.window_shade
in self.
_device_device.capabilities:
130 self.
_state_state = VALUE_TO_STATE.get(self.
_device_device.status.window_shade)
131 elif Capability.garage_door_control
in self.
_device_device.capabilities:
132 self.
_state_state = VALUE_TO_STATE.get(self.
_device_device.status.door)
134 if Capability.window_shade_level
in self.
_device_device.capabilities:
136 elif Capability.switch_level
in self.
_device_device.capabilities:
140 battery = self.
_device_device.status.attributes[Attribute.battery].value
141 if battery
is not None:
146 """Return if the cover is opening or not."""
147 return self.
_state_state == CoverState.OPENING
151 """Return if the cover is closing or not."""
152 return self.
_state_state == CoverState.CLOSING
156 """Return if the cover is closed or not."""
157 if self.
_state_state == CoverState.CLOSED:
159 return None if self.
_state_state
is None else False
CoverEntityFeature supported_features(self)
None async_set_cover_position(self, **Any kwargs)
None async_open_cover(self, **Any kwargs)
bool|None is_closed(self)
def __init__(self, device)
_attr_extra_state_attributes
None async_close_cover(self, **Any kwargs)
_attr_current_cover_position
None async_schedule_update_ha_state(self, bool force_refresh=False)
int|None supported_features(self)
None open(self, **Any kwargs)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
Sequence[str]|None get_capabilities(Sequence[str] capabilities)