1 """Support for SensorPro sensors."""
3 from __future__
import annotations
5 from sensorpro_ble
import (
6 SensorDeviceClass
as SensorProSensorDeviceClass,
11 from homeassistant
import config_entries
13 PassiveBluetoothDataProcessor,
14 PassiveBluetoothDataUpdate,
15 PassiveBluetoothProcessorCoordinator,
16 PassiveBluetoothProcessorEntity,
21 SensorEntityDescription,
26 SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
28 UnitOfElectricPotential,
35 from .const
import DOMAIN
36 from .device
import device_key_to_bluetooth_entity_key
38 SENSOR_DESCRIPTIONS = {
40 key=f
"{SensorProSensorDeviceClass.BATTERY}_{Units.PERCENTAGE}",
41 device_class=SensorDeviceClass.BATTERY,
42 native_unit_of_measurement=PERCENTAGE,
43 state_class=SensorStateClass.MEASUREMENT,
44 entity_category=EntityCategory.DIAGNOSTIC,
47 key=f
"{SensorProSensorDeviceClass.HUMIDITY}_{Units.PERCENTAGE}",
48 device_class=SensorDeviceClass.HUMIDITY,
49 native_unit_of_measurement=PERCENTAGE,
50 state_class=SensorStateClass.MEASUREMENT,
53 SensorProSensorDeviceClass.SIGNAL_STRENGTH,
54 Units.SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
56 key=f
"{SensorProSensorDeviceClass.SIGNAL_STRENGTH}_{Units.SIGNAL_STRENGTH_DECIBELS_MILLIWATT}",
57 device_class=SensorDeviceClass.SIGNAL_STRENGTH,
58 native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
59 state_class=SensorStateClass.MEASUREMENT,
60 entity_category=EntityCategory.DIAGNOSTIC,
61 entity_registry_enabled_default=
False,
64 SensorProSensorDeviceClass.TEMPERATURE,
67 key=f
"{SensorProSensorDeviceClass.TEMPERATURE}_{Units.TEMP_CELSIUS}",
68 device_class=SensorDeviceClass.TEMPERATURE,
69 native_unit_of_measurement=UnitOfTemperature.CELSIUS,
70 state_class=SensorStateClass.MEASUREMENT,
73 SensorProSensorDeviceClass.VOLTAGE,
74 Units.ELECTRIC_POTENTIAL_VOLT,
76 key=f
"{SensorProSensorDeviceClass.VOLTAGE}_{Units.ELECTRIC_POTENTIAL_VOLT}",
77 device_class=SensorDeviceClass.VOLTAGE,
78 native_unit_of_measurement=UnitOfElectricPotential.VOLT,
79 state_class=SensorStateClass.MEASUREMENT,
85 sensor_update: SensorUpdate,
86 ) -> PassiveBluetoothDataUpdate:
87 """Convert a sensor update to a bluetooth data update."""
91 for device_id, device_info
in sensor_update.devices.items()
95 (description.device_class, description.native_unit_of_measurement)
97 for device_key, description
in sensor_update.entity_descriptions.items()
98 if description.device_class
and description.native_unit_of_measurement
102 for device_key, sensor_values
in sensor_update.entity_values.items()
106 for device_key, sensor_values
in sensor_update.entity_values.items()
114 async_add_entities: AddEntitiesCallback,
116 """Set up the SensorPro BLE sensors."""
117 coordinator: PassiveBluetoothProcessorCoordinator = hass.data[DOMAIN][
121 entry.async_on_unload(
122 processor.async_add_entities_listener(
123 SensorProBluetoothSensorEntity, async_add_entities
126 entry.async_on_unload(coordinator.async_register_processor(processor))
130 PassiveBluetoothProcessorEntity[
131 PassiveBluetoothDataProcessor[float | int |
None, SensorUpdate]
135 """Representation of a SensorPro sensor."""
139 """Return the native value."""
140 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)
None async_setup_entry(HomeAssistant hass, config_entries.ConfigEntry entry, AddEntitiesCallback async_add_entities)
PassiveBluetoothDataUpdate sensor_update_to_bluetooth_data_update(SensorUpdate sensor_update)
DeviceInfo sensor_device_info_to_hass_device_info(SensorDeviceInfo sensor_device_info)