1 """Support for Genius Hub sensor devices."""
3 from __future__
import annotations
5 from datetime
import timedelta
14 from .
import GeniusHubConfigEntry
15 from .entity
import GeniusDevice, GeniusEntity
17 GH_STATE_ATTR =
"batteryLevel"
21 "warning":
"Warnings",
22 "information":
"Information",
28 entry: GeniusHubConfigEntry,
29 async_add_entities: AddEntitiesCallback,
31 """Set up the Genius Hub sensor entities."""
33 broker = entry.runtime_data
35 entities: list[GeniusBattery | GeniusIssue] = [
37 for d
in broker.client.device_objs
38 if GH_STATE_ATTR
in d.data[
"state"]
40 entities.extend([
GeniusIssue(broker, i)
for i
in list(GH_LEVEL_MAPPING)])
46 """Representation of a Genius Hub sensor."""
48 _attr_device_class = SensorDeviceClass.BATTERY
49 _attr_native_unit_of_measurement = PERCENTAGE
51 def __init__(self, broker, device, state_attr) -> None:
52 """Initialize the sensor."""
61 """Return the icon of the sensor."""
62 if "_state" in self.
_device_device.data:
64 seconds=self.
_device_device.data[
"_state"].
get(
"wakeupInterval", 30 * 60)
68 or self.
_last_comms_last_comms < dt_util.utcnow() - interval * 3
70 return "mdi:battery-unknown"
73 if battery_level == 255:
74 return "mdi:battery-unknown"
75 if battery_level < 40:
76 return "mdi:battery-alert"
79 if battery_level <= 95:
80 icon += f
"-{int(round(battery_level / 10 - 0.01)) * 10}"
86 """Return the state of the sensor."""
88 return level
if level != 255
else 0
92 """Representation of a Genius Hub sensor."""
95 """Initialize the sensor."""
98 self.
_hub_hub = broker.client
99 self.
_unique_id_unique_id = f
"{broker.hub_uid}_{GH_LEVEL_MAPPING[level]}"
101 self.
_attr_name_attr_name = f
"GeniusHub {GH_LEVEL_MAPPING[level]}"
107 """Return the number of issues."""
108 return len(self.
_issues_issues)
112 """Return the device state attributes."""
113 return {f
"{self._level}_list": self.
_issues_issues}
116 """Process the sensor's state data."""
118 i[
"description"]
for i
in self.
_hub_hub.issues
if i[
"level"] == self.
_level_level
None __init__(self, broker, device, state_attr)
dict[str, Any] extra_state_attributes(self)
None __init__(self, broker, level)
web.Response get(self, web.Request request, str config_key)
None async_setup_entry(HomeAssistant hass, GeniusHubConfigEntry entry, AddEntitiesCallback async_add_entities)