1 """Support for inkbird ble sensors."""
3 from __future__
import annotations
5 from inkbird_ble
import DeviceClass, DeviceKey, SensorUpdate, Units
7 from homeassistant
import config_entries
9 PassiveBluetoothDataProcessor,
10 PassiveBluetoothDataUpdate,
11 PassiveBluetoothEntityKey,
12 PassiveBluetoothProcessorCoordinator,
13 PassiveBluetoothProcessorEntity,
18 SensorEntityDescription,
23 SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
30 from .const
import DOMAIN
32 SENSOR_DESCRIPTIONS = {
34 key=f
"{DeviceClass.TEMPERATURE}_{Units.TEMP_CELSIUS}",
35 device_class=SensorDeviceClass.TEMPERATURE,
36 native_unit_of_measurement=UnitOfTemperature.CELSIUS,
37 state_class=SensorStateClass.MEASUREMENT,
40 key=f
"{DeviceClass.HUMIDITY}_{Units.PERCENTAGE}",
41 device_class=SensorDeviceClass.HUMIDITY,
42 native_unit_of_measurement=PERCENTAGE,
43 state_class=SensorStateClass.MEASUREMENT,
46 key=f
"{DeviceClass.BATTERY}_{Units.PERCENTAGE}",
47 device_class=SensorDeviceClass.BATTERY,
48 native_unit_of_measurement=PERCENTAGE,
49 state_class=SensorStateClass.MEASUREMENT,
52 DeviceClass.SIGNAL_STRENGTH,
53 Units.SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
55 key=f
"{DeviceClass.SIGNAL_STRENGTH}_{Units.SIGNAL_STRENGTH_DECIBELS_MILLIWATT}",
56 device_class=SensorDeviceClass.SIGNAL_STRENGTH,
57 native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
58 state_class=SensorStateClass.MEASUREMENT,
59 entity_registry_enabled_default=
False,
65 device_key: DeviceKey,
66 ) -> PassiveBluetoothEntityKey:
67 """Convert a device key to an entity key."""
72 sensor_update: SensorUpdate,
73 ) -> PassiveBluetoothDataUpdate:
74 """Convert a sensor update to a bluetooth data update."""
78 for device_id, device_info
in sensor_update.devices.items()
82 (description.device_class, description.native_unit_of_measurement)
84 for device_key, description
in sensor_update.entity_descriptions.items()
85 if description.device_class
and description.native_unit_of_measurement
89 for device_key, sensor_values
in sensor_update.entity_values.items()
93 for device_key, sensor_values
in sensor_update.entity_values.items()
101 async_add_entities: AddEntitiesCallback,
103 """Set up the INKBIRD BLE sensors."""
104 coordinator: PassiveBluetoothProcessorCoordinator = hass.data[DOMAIN][
108 entry.async_on_unload(
109 processor.async_add_entities_listener(
110 INKBIRDBluetoothSensorEntity, async_add_entities
113 entry.async_on_unload(coordinator.async_register_processor(processor))
117 PassiveBluetoothProcessorEntity[
118 PassiveBluetoothDataProcessor[float | int |
None, SensorUpdate]
122 """Representation of a inkbird ble sensor."""
126 """Return the native value."""
127 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)