1 """Support for Kegtron sensors."""
3 from __future__
import annotations
5 from kegtron_ble
import (
6 SensorDeviceClass
as KegtronSensorDeviceClass,
11 from homeassistant
import config_entries
13 PassiveBluetoothDataProcessor,
14 PassiveBluetoothDataUpdate,
15 PassiveBluetoothProcessorCoordinator,
16 PassiveBluetoothProcessorEntity,
21 SensorEntityDescription,
25 SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
33 from .const
import DOMAIN
34 from .device
import device_key_to_bluetooth_entity_key
36 SENSOR_DESCRIPTIONS = {
38 key=KegtronSensorDeviceClass.PORT_COUNT,
39 icon=
"mdi:water-pump",
42 key=KegtronSensorDeviceClass.KEG_SIZE,
44 native_unit_of_measurement=UnitOfVolume.LITERS,
45 device_class=SensorDeviceClass.VOLUME,
48 key=KegtronSensorDeviceClass.KEG_TYPE,
52 key=KegtronSensorDeviceClass.VOLUME_START,
54 native_unit_of_measurement=UnitOfVolume.LITERS,
55 device_class=SensorDeviceClass.VOLUME,
58 key=KegtronSensorDeviceClass.VOLUME_DISPENSED,
60 native_unit_of_measurement=UnitOfVolume.LITERS,
61 device_class=SensorDeviceClass.VOLUME,
62 state_class=SensorStateClass.TOTAL,
65 key=KegtronSensorDeviceClass.PORT_STATE,
66 icon=
"mdi:water-pump",
69 key=KegtronSensorDeviceClass.PORT_NAME,
70 icon=
"mdi:water-pump",
73 key=f
"{KegtronSensorDeviceClass.SIGNAL_STRENGTH}_{Units.SIGNAL_STRENGTH_DECIBELS_MILLIWATT}",
74 device_class=SensorDeviceClass.SIGNAL_STRENGTH,
75 native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
76 state_class=SensorStateClass.MEASUREMENT,
77 entity_category=EntityCategory.DIAGNOSTIC,
78 entity_registry_enabled_default=
False,
84 sensor_update: SensorUpdate,
85 ) -> PassiveBluetoothDataUpdate:
86 """Convert a sensor update to a bluetooth data update."""
90 for device_id, device_info
in sensor_update.devices.items()
94 description.device_class
96 for device_key, description
in sensor_update.entity_descriptions.items()
97 if description.device_class
101 for device_key, sensor_values
in sensor_update.entity_values.items()
105 for device_key, sensor_values
in sensor_update.entity_values.items()
113 async_add_entities: AddEntitiesCallback,
115 """Set up the Kegtron BLE sensors."""
116 coordinator: PassiveBluetoothProcessorCoordinator = hass.data[DOMAIN][
120 entry.async_on_unload(
121 processor.async_add_entities_listener(
122 KegtronBluetoothSensorEntity, async_add_entities
125 entry.async_on_unload(coordinator.async_register_processor(processor))
129 PassiveBluetoothProcessorEntity[
130 PassiveBluetoothDataProcessor[float | int |
None, SensorUpdate]
134 """Representation of a Kegtron sensor."""
138 """Return the native value."""
139 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)