1 """LD2410 BLE integration sensor platform."""
6 SensorEntityDescription,
17 from .
import LD2410BLE, LD2410BLECoordinator
18 from .const
import DOMAIN
19 from .models
import LD2410BLEData
22 key=
"moving_target_distance",
23 translation_key=
"moving_target_distance",
24 device_class=SensorDeviceClass.DISTANCE,
25 entity_registry_enabled_default=
False,
26 entity_registry_visible_default=
True,
27 native_unit_of_measurement=UnitOfLength.CENTIMETERS,
28 state_class=SensorStateClass.MEASUREMENT,
32 key=
"static_target_distance",
33 translation_key=
"static_target_distance",
34 device_class=SensorDeviceClass.DISTANCE,
35 entity_registry_enabled_default=
False,
36 entity_registry_visible_default=
True,
37 native_unit_of_measurement=UnitOfLength.CENTIMETERS,
38 state_class=SensorStateClass.MEASUREMENT,
42 key=
"detection_distance",
43 translation_key=
"detection_distance",
44 device_class=SensorDeviceClass.DISTANCE,
45 entity_registry_enabled_default=
False,
46 entity_registry_visible_default=
True,
47 native_unit_of_measurement=UnitOfLength.CENTIMETERS,
48 state_class=SensorStateClass.MEASUREMENT,
52 key=
"moving_target_energy",
53 translation_key=
"moving_target_energy",
55 entity_registry_enabled_default=
False,
56 entity_registry_visible_default=
True,
57 native_unit_of_measurement=
"Target Energy",
58 state_class=SensorStateClass.MEASUREMENT,
62 key=
"static_target_energy",
63 translation_key=
"static_target_energy",
65 entity_registry_enabled_default=
False,
66 entity_registry_visible_default=
True,
67 native_unit_of_measurement=
"Target Energy",
68 state_class=SensorStateClass.MEASUREMENT,
72 key=
"max_motion_gates",
73 translation_key=
"max_motion_gates",
74 entity_category=EntityCategory.DIAGNOSTIC,
75 entity_registry_enabled_default=
False,
76 native_unit_of_measurement=
"Gates",
80 key=
"max_static_gates",
81 translation_key=
"max_static_gates",
82 entity_category=EntityCategory.DIAGNOSTIC,
83 entity_registry_enabled_default=
False,
84 native_unit_of_measurement=
"Gates",
87 MOTION_ENERGY_GATES = [
89 key=f
"motion_energy_gate_{i}",
90 translation_key=f
"motion_energy_gate_{i}",
91 entity_category=EntityCategory.DIAGNOSTIC,
92 entity_registry_enabled_default=
False,
93 native_unit_of_measurement=
"Target Energy",
98 STATIC_ENERGY_GATES = [
100 key=f
"static_energy_gate_{i}",
101 translation_key=f
"static_energy_gate_{i}",
102 entity_category=EntityCategory.DIAGNOSTIC,
103 entity_registry_enabled_default=
False,
104 native_unit_of_measurement=
"Target Energy",
109 SENSOR_DESCRIPTIONS = [
110 MOVING_TARGET_DISTANCE_DESCRIPTION,
111 STATIC_TARGET_DISTANCE_DESCRIPTION,
112 MOVING_TARGET_ENERGY_DESCRIPTION,
113 STATIC_TARGET_ENERGY_DESCRIPTION,
114 DETECTION_DISTANCE_DESCRIPTION,
115 MAX_MOTION_GATES_DESCRIPTION,
116 MAX_STATIC_GATES_DESCRIPTION,
117 *MOTION_ENERGY_GATES,
118 *STATIC_ENERGY_GATES,
125 async_add_entities: AddEntitiesCallback,
127 """Set up the platform for LD2410BLE."""
128 data: LD2410BLEData = hass.data[DOMAIN][entry.entry_id]
136 for description
in SENSOR_DESCRIPTIONS
141 """Generic sensor for LD2410BLE."""
143 _attr_has_entity_name =
True
147 coordinator: LD2410BLECoordinator,
150 description: SensorEntityDescription,
152 """Initialize the sensor."""
156 self.
_key_key = description.key
161 connections={(dr.CONNECTION_BLUETOOTH, device.address)},
167 """Handle updated data from the coordinator."""
173 """Unavailable if coordinator isn't connected."""
174 return self.
_coordinator_coordinator.connected
and super().available
None __init__(self, LD2410BLECoordinator coordinator, LD2410BLE device, str name, SensorEntityDescription description)
None _handle_coordinator_update(self)
None async_write_ha_state(self)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)