1 """Support for Sensirion sensors."""
3 from __future__
import annotations
5 from sensor_state_data
import (
8 SensorDeviceClass
as SSDSensorDeviceClass,
13 from homeassistant
import config_entries
15 PassiveBluetoothDataProcessor,
16 PassiveBluetoothDataUpdate,
17 PassiveBluetoothEntityKey,
18 PassiveBluetoothProcessorCoordinator,
19 PassiveBluetoothProcessorEntity,
24 SensorEntityDescription,
28 CONCENTRATION_PARTS_PER_MILLION,
36 from .const
import DOMAIN
38 SENSOR_DESCRIPTIONS: dict[
39 tuple[SSDSensorDeviceClass, Units |
None], SensorEntityDescription
42 SSDSensorDeviceClass.CO2,
43 Units.CONCENTRATION_PARTS_PER_MILLION,
45 key=f
"{SSDSensorDeviceClass.CO2}_{Units.CONCENTRATION_PARTS_PER_MILLION}",
46 device_class=SensorDeviceClass.CO2,
47 native_unit_of_measurement=CONCENTRATION_PARTS_PER_MILLION,
48 state_class=SensorStateClass.MEASUREMENT,
51 key=f
"{SSDSensorDeviceClass.HUMIDITY}_{Units.PERCENTAGE}",
52 device_class=SensorDeviceClass.HUMIDITY,
53 native_unit_of_measurement=PERCENTAGE,
54 state_class=SensorStateClass.MEASUREMENT,
57 key=f
"{SSDSensorDeviceClass.TEMPERATURE}_{Units.TEMP_CELSIUS}",
58 device_class=SensorDeviceClass.TEMPERATURE,
59 native_unit_of_measurement=UnitOfTemperature.CELSIUS,
60 state_class=SensorStateClass.MEASUREMENT,
66 device_key: DeviceKey,
67 ) -> PassiveBluetoothEntityKey:
68 """Convert a device key to an entity key."""
73 description: SensorDescription,
74 ) -> tuple[SSDSensorDeviceClass, Units |
None]:
75 assert description.device_class
is not None
76 return (description.device_class, description.native_unit_of_measurement)
80 sensor_update: SensorUpdate,
81 ) -> PassiveBluetoothDataUpdate:
82 """Convert a sensor update to a bluetooth data update."""
86 for device_id, device_info
in sensor_update.devices.items()
92 for device_key, description
in sensor_update.entity_descriptions.items()
97 for device_key, sensor_values
in sensor_update.entity_values.items()
101 for device_key, sensor_values
in sensor_update.entity_values.items()
109 async_add_entities: AddEntitiesCallback,
111 """Set up the Sensirion BLE sensors."""
112 coordinator: PassiveBluetoothProcessorCoordinator = hass.data[DOMAIN][
116 entry.async_on_unload(
117 processor.async_add_entities_listener(
118 SensirionBluetoothSensorEntity, async_add_entities
121 entry.async_on_unload(coordinator.async_register_processor(processor))
125 PassiveBluetoothProcessorEntity[
126 PassiveBluetoothDataProcessor[float | int |
None, SensorUpdate]
130 """Representation of a Sensirion BLE sensor."""
134 """Return the native value."""
135 return self.processor.entity_data.get(self.entity_key)
int|float|None native_value(self)
None async_setup_entry(HomeAssistant hass, config_entries.ConfigEntry entry, AddEntitiesCallback async_add_entities)
PassiveBluetoothEntityKey _device_key_to_bluetooth_entity_key(DeviceKey device_key)
tuple[SSDSensorDeviceClass, Units|None] _to_sensor_key(SensorDescription description)
PassiveBluetoothDataUpdate sensor_update_to_bluetooth_data_update(SensorUpdate sensor_update)
DeviceInfo sensor_device_info_to_hass_device_info(SensorDeviceInfo sensor_device_info)