1 """Base entity for Geniushub."""
3 from datetime
import datetime, timedelta
11 from .
import ATTR_DURATION, ATTR_ZONE_MODE, DOMAIN, SVC_SET_ZONE_OVERRIDE
14 GH_ZONE_ATTRS = [
"mode",
"temperature",
"type",
"occupied",
"override"]
16 "luminance":
"luminance",
17 "measuredTemperature":
"measured_temperature",
18 "occupancyTrigger":
"occupancy_trigger",
20 "setTemperature":
"set_temperature",
21 "wakeupInterval":
"wakeup_interval",
26 """Base for all Genius Hub entities."""
28 _attr_should_poll =
False
31 """Initialize the entity."""
32 self._unique_id: str |
None =
None
35 """Set up a listener when this entity is added to HA."""
38 async
def _refresh(self, payload: dict |
None =
None) ->
None:
39 """Process any signals."""
44 """Return a unique ID."""
45 return self._unique_id
49 """Base for all Genius Hub devices."""
52 """Initialize the Device."""
56 self.
_unique_id_unique_id = f
"{broker.hub_uid}_device_{device.id}"
62 """Return the device state attributes."""
64 attrs[
"assigned_zone"] = self.
_device_device.data[
"assignedZones"][0][
"name"]
66 attrs[
"last_comms"] = self.
_last_comms_last_comms.isoformat()
69 if "_state" in self.
_device_device.data:
70 state.update(self.
_device_device.data[
"_state"])
73 GH_DEVICE_ATTRS[k]: v
for k, v
in state.items()
if k
in GH_DEVICE_ATTRS
79 """Update an entity's state data."""
80 if "_state" in self.
_device_device.data:
82 self.
_device_device.data[
"_state"][
"lastComms"]
87 """Base for all Genius Hub zones."""
90 """Initialize the Zone."""
94 self.
_unique_id_unique_id = f
"{broker.hub_uid}_zone_{zone.id}"
96 async
def _refresh(self, payload: dict |
None =
None) ->
None:
97 """Process any signals."""
102 if payload[
"unique_id"] != self.
_unique_id_unique_id:
105 if payload[
"service"] == SVC_SET_ZONE_OVERRIDE:
106 temperature = round(payload[
"data"][ATTR_TEMPERATURE] * 10) / 10
107 duration = payload[
"data"].
get(ATTR_DURATION,
timedelta(hours=1))
109 await self.
_zone_zone.set_override(temperature,
int(duration.total_seconds()))
112 mode = payload[
"data"][ATTR_ZONE_MODE]
114 if mode ==
"footprint" and not self.
_zone_zone._has_pir:
116 f
"'{self.entity_id}' cannot support footprint mode (it has no PIR)"
119 await self.
_zone_zone.set_mode(mode)
123 """Return the name of the climate device."""
124 return self.
_zone_zone.name
128 """Return the device state attributes."""
129 status = {k: v
for k, v
in self.
_zone_zone.data.items()
if k
in GH_ZONE_ATTRS}
130 return {
"status": status}
134 """Base for Genius Heating Zones."""
141 """Return the current temperature."""
142 return self.
_zone_zone.data.get(
"temperature")
146 """Return the temperature we try to reach."""
147 return self.
_zone_zone.data[
"setpoint"]
151 """Return max valid temperature that can be set."""
152 return self._min_temp
156 """Return max valid temperature that can be set."""
157 return self._max_temp
161 """Return the unit of measurement."""
162 return UnitOfTemperature.CELSIUS
165 """Set a new target temperature for this zone."""
166 await self.
_zone_zone.set_override(
167 kwargs[ATTR_TEMPERATURE], kwargs.get(ATTR_DURATION, 3600)
dict[str, Any] extra_state_attributes(self)
None __init__(self, broker, device)
None _refresh(self, dict|None payload=None)
None async_added_to_hass(self)
str temperature_unit(self)
None async_set_temperature(self, **kwargs)
float|None current_temperature(self)
float target_temperature(self)
None _refresh(self, dict|None payload=None)
None __init__(self, broker, zone)
dict[str, Any] extra_state_attributes(self)
None async_schedule_update_ha_state(self, bool force_refresh=False)
None async_on_remove(self, CALLBACK_TYPE func)
web.Response get(self, web.Request request, str config_key)
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)