1 """Support for OralB sensors."""
3 from __future__
import annotations
5 from oralb_ble
import OralBSensor, SensorUpdate
8 PassiveBluetoothDataProcessor,
9 PassiveBluetoothDataUpdate,
10 PassiveBluetoothProcessorEntity,
15 SensorEntityDescription,
20 SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
28 from .
import OralBConfigEntry
29 from .device
import device_key_to_bluetooth_entity_key
31 SENSOR_DESCRIPTIONS: dict[str, SensorEntityDescription] = {
34 device_class=SensorDeviceClass.DURATION,
35 state_class=SensorStateClass.TOTAL_INCREASING,
36 native_unit_of_measurement=UnitOfTime.SECONDS,
39 key=OralBSensor.SECTOR,
40 translation_key=
"sector",
41 entity_category=EntityCategory.DIAGNOSTIC,
44 key=OralBSensor.NUMBER_OF_SECTORS,
45 translation_key=
"number_of_sectors",
46 entity_category=EntityCategory.DIAGNOSTIC,
49 key=OralBSensor.SECTOR_TIMER,
50 translation_key=
"sector_timer",
51 entity_category=EntityCategory.DIAGNOSTIC,
52 entity_registry_enabled_default=
False,
55 key=OralBSensor.TOOTHBRUSH_STATE,
59 key=OralBSensor.PRESSURE,
60 translation_key=
"pressure",
64 translation_key=
"mode",
65 entity_category=EntityCategory.DIAGNOSTIC,
68 key=OralBSensor.SIGNAL_STRENGTH,
69 device_class=SensorDeviceClass.SIGNAL_STRENGTH,
70 native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
71 state_class=SensorStateClass.MEASUREMENT,
72 entity_category=EntityCategory.DIAGNOSTIC,
73 entity_registry_enabled_default=
False,
76 key=OralBSensor.BATTERY_PERCENT,
77 device_class=SensorDeviceClass.BATTERY,
78 native_unit_of_measurement=PERCENTAGE,
79 state_class=SensorStateClass.MEASUREMENT,
80 entity_category=EntityCategory.DIAGNOSTIC,
86 sensor_update: SensorUpdate,
87 ) -> PassiveBluetoothDataUpdate:
88 """Convert a sensor update to a bluetooth data update."""
92 for device_id, device_info
in sensor_update.devices.items()
98 for device_key
in sensor_update.entity_descriptions
102 for device_key, sensor_values
in sensor_update.entity_values.items()
110 entry: OralBConfigEntry,
111 async_add_entities: AddEntitiesCallback,
113 """Set up the OralB BLE sensors."""
114 coordinator = entry.runtime_data
116 entry.async_on_unload(
117 processor.async_add_entities_listener(
118 OralBBluetoothSensorEntity, async_add_entities
121 entry.async_on_unload(
122 coordinator.async_register_processor(processor, SensorEntityDescription)
127 PassiveBluetoothProcessorEntity[
128 PassiveBluetoothDataProcessor[str | int |
None, SensorUpdate]
132 """Representation of a OralB sensor."""
136 """Return the native value."""
137 return self.processor.entity_data.get(self.entity_key)
141 """Return True if entity is available.
143 The sensor is only created when the device is seen.
145 Since these are sleepy devices which stop broadcasting
146 when not in use, we can't rely on the last update time
147 so once we have seen the device we always return True.
153 """Return True if the device is no longer broadcasting."""
154 return not self.processor.available
str|int|None native_value(self)
PassiveBluetoothEntityKey device_key_to_bluetooth_entity_key(DeviceKey device_key)
None async_setup_entry(HomeAssistant hass, OralBConfigEntry 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)