1 """Support for sensorpush ble sensors."""
3 from __future__
import annotations
5 from sensorpush_ble
import DeviceClass, DeviceKey, SensorUpdate, Units
8 PassiveBluetoothDataProcessor,
9 PassiveBluetoothDataUpdate,
10 PassiveBluetoothEntityKey,
11 PassiveBluetoothProcessorEntity,
16 SensorEntityDescription,
21 SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
29 from .
import SensorPushConfigEntry
31 SENSOR_DESCRIPTIONS = {
33 key=f
"{DeviceClass.TEMPERATURE}_{Units.TEMP_CELSIUS}",
34 device_class=SensorDeviceClass.TEMPERATURE,
35 native_unit_of_measurement=UnitOfTemperature.CELSIUS,
36 state_class=SensorStateClass.MEASUREMENT,
39 key=f
"{DeviceClass.HUMIDITY}_{Units.PERCENTAGE}",
40 device_class=SensorDeviceClass.HUMIDITY,
41 native_unit_of_measurement=PERCENTAGE,
42 state_class=SensorStateClass.MEASUREMENT,
45 key=f
"{DeviceClass.PRESSURE}_{Units.PRESSURE_MBAR}",
46 device_class=SensorDeviceClass.PRESSURE,
47 native_unit_of_measurement=UnitOfPressure.MBAR,
48 state_class=SensorStateClass.MEASUREMENT,
51 DeviceClass.SIGNAL_STRENGTH,
52 Units.SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
54 key=f
"{DeviceClass.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_registry_enabled_default=
False,
64 device_key: DeviceKey,
65 ) -> PassiveBluetoothEntityKey:
66 """Convert a device key to an entity key."""
71 sensor_update: SensorUpdate,
72 ) -> PassiveBluetoothDataUpdate:
73 """Convert a sensor update to a bluetooth data update."""
77 for device_id, device_info
in sensor_update.devices.items()
81 (description.device_class, description.native_unit_of_measurement)
83 for device_key, description
in sensor_update.entity_descriptions.items()
84 if description.device_class
and description.native_unit_of_measurement
88 for device_key, sensor_values
in sensor_update.entity_values.items()
92 for device_key, sensor_values
in sensor_update.entity_values.items()
99 entry: SensorPushConfigEntry,
100 async_add_entities: AddEntitiesCallback,
102 """Set up the SensorPush BLE sensors."""
103 coordinator = entry.runtime_data
105 entry.async_on_unload(
106 processor.async_add_entities_listener(
107 SensorPushBluetoothSensorEntity, async_add_entities
110 entry.async_on_unload(
111 coordinator.async_register_processor(processor, SensorEntityDescription)
116 PassiveBluetoothProcessorEntity[
117 PassiveBluetoothDataProcessor[float | int |
None, SensorUpdate]
121 """Representation of a sensorpush ble sensor."""
125 """Return the native value."""
126 return self.processor.entity_data.get(self.entity_key)
int|float|None native_value(self)
PassiveBluetoothDataUpdate sensor_update_to_bluetooth_data_update(SensorUpdate sensor_update)
None async_setup_entry(HomeAssistant hass, SensorPushConfigEntry entry, AddEntitiesCallback async_add_entities)
PassiveBluetoothEntityKey _device_key_to_bluetooth_entity_key(DeviceKey device_key)
DeviceInfo sensor_device_info_to_hass_device_info(SensorDeviceInfo sensor_device_info)