[ld2410] Find the gate from the number so all gate numbers share one class

This commit is contained in:
J. Nick Koston
2026-10-16 11:05:25 -10:00
parent 6aa647638c
commit e8e98ee3db
3 changed files with 16 additions and 9 deletions
+8 -1
View File
@@ -727,7 +727,14 @@ void LD2410Component::set_max_distances_timeout() {
this->set_config_mode_(false);
}
void LD2410Component::set_gate_threshold(uint8_t gate) {
void LD2410Component::set_gate_threshold(number::Number *n) {
// Found by pointer: up to 18 compares per write beat storing the gate in each number
uint8_t gate = 0;
while (gate < TOTAL_GATES && this->gate_move_threshold_numbers_[gate] != n &&
this->gate_still_threshold_numbers_[gate] != n)
gate++;
if (gate == TOTAL_GATES)
return;
number::Number *motionsens = this->gate_move_threshold_numbers_[gate];
number::Number *stillsens = this->gate_still_threshold_numbers_[gate];
+1 -1
View File
@@ -87,7 +87,7 @@ class LD2410Component final : public Component, public uart::UARTDevice {
void set_gate_still_threshold_number(uint8_t gate, number::Number *n);
void set_gate_move_threshold_number(uint8_t gate, number::Number *n);
void set_max_distances_timeout();
void set_gate_threshold(uint8_t gate);
void set_gate_threshold(number::Number *n);
#endif
#ifdef USE_SENSOR
void set_gate_move_sensor(uint8_t gate, sensor::Sensor *s);
+7 -7
View File
@@ -121,16 +121,16 @@ async def to_code(config: ConfigType) -> None:
apply="set_light_out_control()",
publish="before",
)
threshold = {
"min_value": 0,
"max_value": 100,
"step": 1,
"apply": "set_gate_threshold(entity)",
"publish": "before",
}
for x in range(9):
if gate_conf := config.get(f"g{x}"):
gate = number.sub_numbers(gate_conf, parent=hub)
threshold = {
"min_value": 0,
"max_value": 100,
"step": 1,
"apply": f"set_gate_threshold({x})",
"publish": "before",
}
await gate(
CONF_MOVE_THRESHOLD,
partial(hub.set_gate_move_threshold_number, x),