1 """Support for BlueMaestro sensors."""
3 from __future__
import annotations
5 from bluemaestro_ble
import (
6 SensorDeviceClass
as BlueMaestroSensorDeviceClass,
12 PassiveBluetoothDataProcessor,
13 PassiveBluetoothDataUpdate,
14 PassiveBluetoothProcessorEntity,
19 SensorEntityDescription,
24 SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
33 from .
import BlueMaestroConfigEntry
34 from .device
import device_key_to_bluetooth_entity_key
36 SENSOR_DESCRIPTIONS = {
38 key=f
"{BlueMaestroSensorDeviceClass.BATTERY}_{Units.PERCENTAGE}",
39 device_class=SensorDeviceClass.BATTERY,
40 native_unit_of_measurement=PERCENTAGE,
41 state_class=SensorStateClass.MEASUREMENT,
42 entity_category=EntityCategory.DIAGNOSTIC,
45 key=f
"{BlueMaestroSensorDeviceClass.HUMIDITY}_{Units.PERCENTAGE}",
46 device_class=SensorDeviceClass.HUMIDITY,
47 native_unit_of_measurement=PERCENTAGE,
48 state_class=SensorStateClass.MEASUREMENT,
51 BlueMaestroSensorDeviceClass.SIGNAL_STRENGTH,
52 Units.SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
54 key=f
"{BlueMaestroSensorDeviceClass.SIGNAL_STRENGTH}_{Units.SIGNAL_STRENGTH_DECIBELS_MILLIWATT}",
55 device_class=SensorDeviceClass.SIGNAL_STRENGTH,
56 native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
57 state_class=SensorStateClass.MEASUREMENT,
58 entity_category=EntityCategory.DIAGNOSTIC,
59 entity_registry_enabled_default=
False,
62 BlueMaestroSensorDeviceClass.TEMPERATURE,
65 key=f
"{BlueMaestroSensorDeviceClass.TEMPERATURE}_{Units.TEMP_CELSIUS}",
66 device_class=SensorDeviceClass.TEMPERATURE,
67 native_unit_of_measurement=UnitOfTemperature.CELSIUS,
68 state_class=SensorStateClass.MEASUREMENT,
71 BlueMaestroSensorDeviceClass.DEW_POINT,
74 key=f
"{BlueMaestroSensorDeviceClass.DEW_POINT}_{Units.TEMP_CELSIUS}",
75 device_class=SensorDeviceClass.TEMPERATURE,
76 translation_key=
"dew_point",
77 native_unit_of_measurement=UnitOfTemperature.CELSIUS,
78 state_class=SensorStateClass.MEASUREMENT,
81 BlueMaestroSensorDeviceClass.PRESSURE,
84 key=f
"{BlueMaestroSensorDeviceClass.PRESSURE}_{Units.PRESSURE_MBAR}",
85 device_class=SensorDeviceClass.PRESSURE,
86 native_unit_of_measurement=UnitOfPressure.MBAR,
87 state_class=SensorStateClass.MEASUREMENT,
93 sensor_update: SensorUpdate,
94 ) -> PassiveBluetoothDataUpdate:
95 """Convert a sensor update to a bluetooth data update."""
99 for device_id, device_info
in sensor_update.devices.items()
101 entity_descriptions={
103 (description.device_class, description.native_unit_of_measurement)
105 for device_key, description
in sensor_update.entity_descriptions.items()
106 if description.device_class
and description.native_unit_of_measurement
110 for device_key, sensor_values
in sensor_update.entity_values.items()
118 entry: BlueMaestroConfigEntry,
119 async_add_entities: AddEntitiesCallback,
121 """Set up the BlueMaestro BLE sensors."""
122 coordinator = entry.runtime_data
124 entry.async_on_unload(
125 processor.async_add_entities_listener(
126 BlueMaestroBluetoothSensorEntity, async_add_entities
129 entry.async_on_unload(coordinator.async_register_processor(processor))
133 PassiveBluetoothProcessorEntity[
134 PassiveBluetoothDataProcessor[float | int |
None, SensorUpdate]
138 """Representation of a BlueMaestro sensor."""
142 """Return the native value."""
143 return self.processor.entity_data.get(self.entity_key)
int|float|None native_value(self)
PassiveBluetoothEntityKey device_key_to_bluetooth_entity_key(DeviceKey device_key)
PassiveBluetoothDataUpdate sensor_update_to_bluetooth_data_update(SensorUpdate sensor_update)
None async_setup_entry(HomeAssistant hass, BlueMaestroConfigEntry entry, AddEntitiesCallback async_add_entities)
DeviceInfo sensor_device_info_to_hass_device_info(SensorDeviceInfo sensor_device_info)