1 """Support for Hue sensors."""
3 from __future__
import annotations
5 from functools
import partial
8 from aiohue.v2
import HueBridgeV2
9 from aiohue.v2.controllers.events
import EventType
10 from aiohue.v2.controllers.sensors
import (
11 DevicePowerController,
14 TemperatureController,
15 ZigbeeConnectivityController,
17 from aiohue.v2.models.device_power
import DevicePower
18 from aiohue.v2.models.light_level
import LightLevel
19 from aiohue.v2.models.temperature
import Temperature
20 from aiohue.v2.models.zigbee_connectivity
import ZigbeeConnectivity
25 SensorEntityDescription,
33 from ..bridge
import HueBridge
34 from ..const
import DOMAIN
35 from .entity
import HueBaseEntity
37 type SensorType = DevicePower | LightLevel | Temperature | ZigbeeConnectivity
38 type ControllerType = (
40 | LightLevelController
41 | TemperatureController
42 | ZigbeeConnectivityController
48 config_entry: ConfigEntry,
49 async_add_entities: AddEntitiesCallback,
51 """Set up Hue Sensors from Config Entry."""
52 bridge: HueBridge = hass.data[DOMAIN][config_entry.entry_id]
53 api: HueBridgeV2 = bridge.api
54 ctrl_base: SensorsController = api.sensors
57 def register_items(controller: ControllerType, sensor_class: SensorType):
58 make_sensor_entity = partial(sensor_class, bridge, controller)
61 def async_add_sensor(event_type: EventType, resource: SensorType) ->
None:
69 config_entry.async_on_unload(
71 async_add_sensor, event_filter=EventType.RESOURCE_ADDED
76 register_items(ctrl_base.temperature, HueTemperatureSensor)
77 register_items(ctrl_base.light_level, HueLightLevelSensor)
78 register_items(ctrl_base.device_power, HueBatterySensor)
79 register_items(ctrl_base.zigbee_connectivity, HueZigbeeConnectivitySensor)
84 """Representation of a Hue sensor."""
89 controller: ControllerType,
92 """Initialize the light."""
93 super().
__init__(bridge, controller, resource)
100 """Representation of a Hue Temperature sensor."""
103 key=
"temperature_sensor",
104 device_class=SensorDeviceClass.TEMPERATURE,
105 native_unit_of_measurement=UnitOfTemperature.CELSIUS,
106 has_entity_name=
True,
107 state_class=SensorStateClass.MEASUREMENT,
112 """Return the value reported by the sensor."""
118 """Representation of a Hue LightLevel (illuminance) sensor."""
121 key=
"lightlevel_sensor",
122 device_class=SensorDeviceClass.ILLUMINANCE,
123 native_unit_of_measurement=LIGHT_LUX,
124 has_entity_name=
True,
125 state_class=SensorStateClass.MEASUREMENT,
130 """Return the value reported by the sensor."""
139 """Return the optional state attributes."""
147 """Representation of a Hue Battery sensor."""
150 key=
"battery_sensor",
151 device_class=SensorDeviceClass.BATTERY,
152 native_unit_of_measurement=PERCENTAGE,
153 has_entity_name=
True,
154 state_class=SensorStateClass.MEASUREMENT,
155 entity_category=EntityCategory.DIAGNOSTIC,
160 """Return the value reported by the sensor."""
165 """Return the optional state attributes."""
168 return {
"battery_state": self.
resourceresourceresource.power_state.battery_state.value}
173 """Representation of a Hue ZigbeeConnectivity sensor."""
176 key=
"zigbee_connectivity_sensor",
177 device_class=SensorDeviceClass.ENUM,
178 has_entity_name=
True,
179 entity_category=EntityCategory.DIAGNOSTIC,
180 translation_key=
"zigbee_connectivity",
184 "connectivity_issue",
185 "unidirectional_incoming",
187 entity_registry_enabled_default=
False,
192 """Return the value reported by the sensor."""
197 """Return the optional state attributes."""
dict[str, Any] extra_state_attributes(self)
dict[str, Any] extra_state_attributes(self)
None __init__(self, HueBridge bridge, ControllerType controller, SensorType resource)
dict[str, Any] extra_state_attributes(self)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)