1 """Platform for the opengarage.io cover component."""
3 from __future__
import annotations
6 from typing
import Any, cast
18 from .const
import DOMAIN
19 from .coordinator
import OpenGarageDataUpdateCoordinator
20 from .entity
import OpenGarageEntity
22 _LOGGER = logging.getLogger(__name__)
24 STATES_MAP = {0: CoverState.CLOSED, 1: CoverState.OPEN}
28 hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
30 """Set up the OpenGarage covers."""
32 [
OpenGarageCover(hass.data[DOMAIN][entry.entry_id], cast(str, entry.unique_id))]
37 """Representation of a OpenGarage cover."""
39 _attr_device_class = CoverDeviceClass.GARAGE
40 _attr_supported_features = CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE
44 self, coordinator: OpenGarageDataUpdateCoordinator, device_id: str
46 """Initialize the cover."""
47 self.
_state_state: str |
None =
None
50 super().
__init__(coordinator, device_id)
54 """Return if the cover is closed."""
55 if self.
_state_state
is None:
57 return self.
_state_state == CoverState.CLOSED
61 """Return if the cover is closing."""
62 if self.
_state_state
is None:
64 return self.
_state_state == CoverState.CLOSING
68 """Return if the cover is opening."""
69 if self.
_state_state
is None:
71 return self.
_state_state == CoverState.OPENING
74 """Close the cover."""
75 if self.
_state_state
in [CoverState.CLOSED, CoverState.CLOSING]:
78 self.
_state_state = CoverState.CLOSING
83 if self.
_state_state
in [CoverState.OPEN, CoverState.OPENING]:
86 self.
_state_state = CoverState.OPENING
91 """Update the state and attributes."""
92 status = self.coordinator.data
94 state = STATES_MAP.get(status.get(
"door"))
103 """Send commands to API."""
104 result = await self.coordinator.open_garage_connection.push_button()
106 _LOGGER.error(
"Unable to connect to OpenGarage device")
111 _LOGGER.error(
"Unable to control %s: Device key is incorrect", self.
namenamename)
113 _LOGGER.error(
"Unable to control %s: Error code %s", self.
namenamename, result)
bool|None is_opening(self)
None async_open_cover(self, **Any kwargs)
None __init__(self, OpenGarageDataUpdateCoordinator coordinator, str device_id)
None async_close_cover(self, **Any kwargs)
bool|None is_closed(self)
bool|None is_closing(self)
str|UndefinedType|None name(self)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)