1 """Support for govee-ble binary sensors."""
3 from __future__
import annotations
5 from govee_ble
import (
6 BinarySensorDeviceClass
as GoveeBLEBinarySensorDeviceClass,
9 from govee_ble.parser
import ERROR
11 from homeassistant
import config_entries
13 BinarySensorDeviceClass,
15 BinarySensorEntityDescription,
18 PassiveBluetoothDataProcessor,
19 PassiveBluetoothDataUpdate,
20 PassiveBluetoothProcessorEntity,
26 from .coordinator
import GoveeBLEPassiveBluetoothDataProcessor
27 from .device
import device_key_to_bluetooth_entity_key
29 BINARY_SENSOR_DESCRIPTIONS = {
31 key=GoveeBLEBinarySensorDeviceClass.WINDOW,
32 device_class=BinarySensorDeviceClass.WINDOW,
35 key=GoveeBLEBinarySensorDeviceClass.MOTION,
36 device_class=BinarySensorDeviceClass.MOTION,
39 key=GoveeBLEBinarySensorDeviceClass.OCCUPANCY,
40 device_class=BinarySensorDeviceClass.OCCUPANCY,
46 sensor_update: SensorUpdate,
47 ) -> PassiveBluetoothDataUpdate[bool |
None]:
48 """Convert a sensor update to a bluetooth data update."""
52 for device_id, device_info
in sensor_update.devices.items()
56 description.device_class
58 for device_key, description
in sensor_update.binary_entity_descriptions.items()
59 if description.device_class
63 for device_key, sensor_values
in sensor_update.binary_entity_values.items()
67 for device_key, sensor_values
in sensor_update.binary_entity_values.items()
75 async_add_entities: AddEntitiesCallback,
77 """Set up the govee-ble BLE sensors."""
78 coordinator = entry.runtime_data
80 entry.async_on_unload(
81 processor.async_add_entities_listener(
82 GoveeBluetoothBinarySensorEntity, async_add_entities
85 entry.async_on_unload(
86 coordinator.async_register_processor(processor, BinarySensorEntityDescription)
91 PassiveBluetoothProcessorEntity[
92 PassiveBluetoothDataProcessor[bool |
None, SensorUpdate]
96 """Representation of a govee-ble binary sensor."""
98 processor: GoveeBLEPassiveBluetoothDataProcessor[bool |
None]
102 """Return False if sensor is in error."""
103 coordinator = self.processor.coordinator
104 return self.processor.entity_data.get(self.entity_key) != ERROR
and (
105 ((model_info := coordinator.model_info)
and model_info.sleepy)
111 """Return the native value."""
112 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, config_entries.ConfigEntry entry, AddEntitiesCallback async_add_entities)
PassiveBluetoothDataUpdate[bool|None] sensor_update_to_bluetooth_data_update(SensorUpdate sensor_update)
DeviceInfo sensor_device_info_to_hass_device_info(SensorDeviceInfo sensor_device_info)