1 """Support for Qingping binary sensors."""
3 from __future__
import annotations
5 from qingping_ble
import (
6 BinarySensorDeviceClass
as QingpingBinarySensorDeviceClass,
11 BinarySensorDeviceClass,
13 BinarySensorEntityDescription,
16 PassiveBluetoothDataProcessor,
17 PassiveBluetoothDataUpdate,
18 PassiveBluetoothProcessorEntity,
24 from .
import QingpingConfigEntry
25 from .device
import device_key_to_bluetooth_entity_key
27 BINARY_SENSOR_DESCRIPTIONS = {
29 key=QingpingBinarySensorDeviceClass.MOTION,
30 device_class=BinarySensorDeviceClass.MOTION,
33 key=QingpingBinarySensorDeviceClass.LIGHT,
34 device_class=BinarySensorDeviceClass.LIGHT,
37 key=QingpingBinarySensorDeviceClass.DOOR,
38 device_class=BinarySensorDeviceClass.DOOR,
41 key=QingpingBinarySensorDeviceClass.PROBLEM,
42 device_class=BinarySensorDeviceClass.PROBLEM,
48 sensor_update: SensorUpdate,
49 ) -> PassiveBluetoothDataUpdate:
50 """Convert a sensor update to a bluetooth data update."""
54 for device_id, device_info
in sensor_update.devices.items()
58 description.device_class
60 for device_key, description
in sensor_update.binary_entity_descriptions.items()
61 if description.device_class
65 for device_key, sensor_values
in sensor_update.binary_entity_values.items()
69 for device_key, sensor_values
in sensor_update.binary_entity_values.items()
76 entry: QingpingConfigEntry,
77 async_add_entities: AddEntitiesCallback,
79 """Set up the Qingping BLE sensors."""
80 coordinator = entry.runtime_data
82 entry.async_on_unload(
83 processor.async_add_entities_listener(
84 QingpingBluetoothSensorEntity, async_add_entities
87 entry.async_on_unload(
88 coordinator.async_register_processor(processor, BinarySensorEntityDescription)
93 PassiveBluetoothProcessorEntity[
94 PassiveBluetoothDataProcessor[bool |
None, SensorUpdate]
98 """Representation of a Qingping binary sensor."""
102 """Return the native value."""
103 return self.processor.entity_data.get(self.entity_key)
PassiveBluetoothEntityKey device_key_to_bluetooth_entity_key(DeviceKey device_key)
None async_setup_entry(HomeAssistant hass, QingpingConfigEntry 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)