1 """Support for Fibaro sensors."""
3 from __future__
import annotations
5 from contextlib
import suppress
7 from pyfibaro.fibaro_device
import DeviceModel
13 SensorEntityDescription,
18 CONCENTRATION_PARTS_PER_MILLION,
30 from .
import FibaroController
31 from .const
import DOMAIN
32 from .entity
import FibaroEntity
35 MAIN_SENSOR_TYPES: dict[str, SensorEntityDescription] = {
37 key=
"com.fibaro.temperatureSensor",
39 device_class=SensorDeviceClass.TEMPERATURE,
40 state_class=SensorStateClass.MEASUREMENT,
43 key=
"com.fibaro.smokeSensor",
45 native_unit_of_measurement=CONCENTRATION_PARTS_PER_MILLION,
51 native_unit_of_measurement=CONCENTRATION_PARTS_PER_MILLION,
52 device_class=SensorDeviceClass.CO2,
53 state_class=SensorStateClass.MEASUREMENT,
56 key=
"com.fibaro.humiditySensor",
58 native_unit_of_measurement=PERCENTAGE,
59 device_class=SensorDeviceClass.HUMIDITY,
60 state_class=SensorStateClass.MEASUREMENT,
63 key=
"com.fibaro.lightSensor",
65 native_unit_of_measurement=LIGHT_LUX,
66 device_class=SensorDeviceClass.ILLUMINANCE,
67 state_class=SensorStateClass.MEASUREMENT,
70 key=
"com.fibaro.energyMeter",
72 native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
73 device_class=SensorDeviceClass.ENERGY,
74 state_class=SensorStateClass.TOTAL_INCREASING,
80 ADDITIONAL_SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
84 native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
85 device_class=SensorDeviceClass.ENERGY,
86 state_class=SensorStateClass.TOTAL_INCREASING,
91 native_unit_of_measurement=UnitOfPower.WATT,
92 device_class=SensorDeviceClass.POWER,
93 state_class=SensorStateClass.MEASUREMENT,
97 FIBARO_TO_HASS_UNIT: dict[str, str] = {
99 "C": UnitOfTemperature.CELSIUS,
100 "F": UnitOfTemperature.FAHRENHEIT,
107 async_add_entities: AddEntitiesCallback,
109 """Set up the Fibaro controller devices."""
111 controller: FibaroController = hass.data[DOMAIN][entry.entry_id]
112 entities: list[SensorEntity] = [
113 FibaroSensor(device, MAIN_SENSOR_TYPES.get(device.type))
114 for device
in controller.fibaro_devices[Platform.SENSOR]
119 if device.value.has_value
125 Platform.BINARY_SENSOR,
133 for device
in controller.fibaro_devices[platform]
134 for entity_description
in ADDITIONAL_SENSOR_TYPES
135 if entity_description.key
in device.properties
142 """Representation of a Fibaro Sensor."""
146 fibaro_device: DeviceModel,
147 entity_description: SensorEntityDescription |
None,
149 """Initialize the sensor."""
151 if entity_description
is not None:
157 with suppress(KeyError, ValueError):
160 fibaro_device.unit, fibaro_device.unit
164 """Update the state."""
166 with suppress(TypeError):
171 """Representation of a Fibaro Additional Sensor."""
174 self, fibaro_device: DeviceModel, entity_description: SensorEntityDescription
176 """Initialize the sensor."""
183 f
"{self.ha_id}_{entity_description.key}"
189 """Update the state."""
191 with suppress(KeyError, ValueError):
None __init__(self, DeviceModel fibaro_device, SensorEntityDescription entity_description)
None __init__(self, DeviceModel fibaro_device, SensorEntityDescription|None entity_description)
_attr_native_unit_of_measurement
str|None native_unit_of_measurement(self)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)