1 """Support for Brunt Blind Engine covers."""
3 from __future__
import annotations
7 from aiohttp.client_exceptions
import ClientResponseError
8 from brunt
import Thing
23 ATTR_REQUEST_POSITION,
31 from .coordinator
import BruntConfigEntry, BruntCoordinator
36 entry: BruntConfigEntry,
37 async_add_entities: AddEntitiesCallback,
39 """Set up the brunt platform."""
40 coordinator = entry.runtime_data
43 BruntDevice(coordinator, serial, thing, entry.entry_id)
44 for serial, thing
in coordinator.data.items()
49 """Representation of a Brunt cover device.
51 Contains the common logic for all Brunt devices.
54 _attr_has_entity_name =
True
56 _attr_device_class = CoverDeviceClass.BLIND
57 _attr_attribution = ATTRIBUTION
58 _attr_supported_features = (
59 CoverEntityFeature.OPEN
60 | CoverEntityFeature.CLOSE
61 | CoverEntityFeature.SET_POSITION
66 coordinator: BruntCoordinator,
71 """Init the Brunt device."""
81 name=self.
_thing_thing.name,
82 via_device=(DOMAIN, self.
_entry_id_entry_id),
84 sw_version=self.
_thing_thing.fw_version,
85 model=self.
_thing_thing.model,
89 """When entity is added to hass."""
97 """Return current position of cover.
99 None is unknown, 0 is closed, 100 is fully open.
101 return self.coordinator.data[self.
unique_idunique_id].current_position
105 """Return request position of cover.
107 The request position is the position of the last request
108 to Brunt, at times there is a diff of 1 to current
109 None is unknown, 0 is closed, 100 is fully open.
111 return self.coordinator.data[self.
unique_idunique_id].request_position
115 """Return current moving state of cover.
117 None is unknown, 0 when stopped, 1 when opening, 2 when closing
119 return self.coordinator.data[self.
unique_idunique_id].move_state
123 """Return if the cover is opening or not."""
128 """Return if the cover is closing or not."""
133 """Return the detailed device state attributes."""
140 """Return true if cover is closed, else False."""
144 """Set the cover to the open position."""
148 """Set the cover to the closed position."""
152 """Set the cover to a specific position."""
156 """Set the cover to the new position and wait for the update to be reflected."""
158 await self.coordinator.bapi.async_change_request_position(
159 position, thing_uri=self.
_thing_thing.thing_uri
161 except ClientResponseError
as exc:
163 f
"Unable to reposition {self._thing.name}"
165 self.coordinator.update_interval = FAST_INTERVAL
170 """Update the update interval after each refresh."""
173 == self.coordinator.bapi.last_requested_positions[self.
_thing_thing.thing_uri]
176 self.coordinator.update_interval = REGULAR_INTERVAL
178 self.coordinator.update_interval = FAST_INTERVAL
None async_added_to_hass(self)
int|None request_cover_position(self)
dict[str, Any] extra_state_attributes(self)
None async_set_cover_position(self, **Any kwargs)
None __init__(self, BruntCoordinator coordinator, str|None serial, Thing thing, str entry_id)
None async_open_cover(self, **Any kwargs)
int|None current_cover_position(self)
int|None move_state(self)
None _brunt_update_listener(self)
None async_close_cover(self, **Any kwargs)
None _async_update_cover(self, int position)
int|None current_cover_position(self)
None async_on_remove(self, CALLBACK_TYPE func)
Callable[[], None] async_add_listener(self, CALLBACK_TYPE update_callback, Any context=None)
None async_request_refresh(self)
None async_setup_entry(HomeAssistant hass, BruntConfigEntry entry, AddEntitiesCallback async_add_entities)