1 """Support for Soma Covers."""
3 from __future__
import annotations
19 from .const
import API, DEVICES, DOMAIN
20 from .entity
import SomaEntity
21 from .utils
import is_api_response_success
26 config_entry: ConfigEntry,
27 async_add_entities: AddEntitiesCallback,
29 """Set up the Soma cover platform."""
31 api = hass.data[DOMAIN][API]
32 devices = hass.data[DOMAIN][DEVICES]
33 entities: list[SomaTilt | SomaShade] = []
35 for device
in devices:
37 if "type" in device
and device[
"type"].lower() ==
"tilt":
38 entities.append(
SomaTilt(device, api))
46 """Representation of a Soma Tilt device."""
49 _attr_device_class = CoverDeviceClass.BLIND
50 _attr_supported_features = (
51 CoverEntityFeature.OPEN_TILT
52 | CoverEntityFeature.CLOSE_TILT
53 | CoverEntityFeature.STOP_TILT
54 | CoverEntityFeature.SET_TILT_POSITION
56 CLOSED_UP_THRESHOLD = 80
57 CLOSED_DOWN_THRESHOLD = 20
61 """Return the current cover tilt position."""
66 """Return if the cover tilt is closed."""
75 """Close the cover tilt."""
76 response = self.
apiapi.set_shade_position(self.
devicedevice[
"mac"], 100)
79 f
'Error while closing the cover ({self.name}): {response["msg"]}'
84 """Open the cover tilt."""
85 response = self.
apiapi.set_shade_position(self.
devicedevice[
"mac"], -100)
88 f
'Error while opening the cover ({self.name}): {response["msg"]}'
93 """Stop the cover tilt."""
94 response = self.
apiapi.stop_shade(self.
devicedevice[
"mac"])
97 f
'Error while stopping the cover ({self.name}): {response["msg"]}'
103 """Move the cover tilt to a specific position."""
107 target_api_position = 100 - ((kwargs[ATTR_TILT_POSITION] / 50) * 100)
108 response = self.
apiapi.set_shade_position(self.
devicedevice[
"mac"], target_api_position)
111 f
"Error while setting the cover position ({self.name}):"
112 f
' {response["msg"]}'
114 self.
set_positionset_position(kwargs[ATTR_TILT_POSITION])
117 """Update the entity with the latest data."""
120 api_position =
int(response[
"position"])
122 if "closed_upwards" in response:
129 """Representation of a Soma Shade device."""
132 _attr_device_class = CoverDeviceClass.SHADE
133 _attr_supported_features = (
134 CoverEntityFeature.OPEN
135 | CoverEntityFeature.CLOSE
136 | CoverEntityFeature.STOP
137 | CoverEntityFeature.SET_POSITION
142 """Return the current cover position."""
147 """Return if the cover is closed."""
151 """Close the cover."""
152 response = self.
apiapi.set_shade_position(self.
devicedevice[
"mac"], 100)
155 f
'Error while closing the cover ({self.name}): {response["msg"]}'
159 """Open the cover."""
160 response = self.
apiapi.set_shade_position(self.
devicedevice[
"mac"], 0)
163 f
'Error while opening the cover ({self.name}): {response["msg"]}'
167 """Stop the cover."""
168 response = self.
apiapi.stop_shade(self.
devicedevice[
"mac"])
171 f
'Error while stopping the cover ({self.name}): {response["msg"]}'
177 """Move the cover shutter to a specific position."""
179 response = self.
apiapi.set_shade_position(
180 self.
devicedevice[
"mac"], 100 - kwargs[ATTR_POSITION]
184 f
"Error while setting the cover position ({self.name}):"
185 f
' {response["msg"]}'
189 """Update the cover with the latest data."""
current_cover_tilt_position
None open_cover(self, **Any kwargs)
None close_cover(self, **Any kwargs)
None set_cover_position(self, **Any kwargs)
None stop_cover(self, **Any kwargs)
int CLOSED_DOWN_THRESHOLD
None stop_cover_tilt(self, **Any kwargs)
None close_cover_tilt(self, **Any kwargs)
None set_cover_tilt_position(self, **Any kwargs)
None open_cover_tilt(self, **Any kwargs)
None set_position(self, int position)
dict get_shade_state_from_api(self)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
bool is_api_response_success(dict api_response)