diff --git a/esphome/components/ld2410/ld2410.cpp b/esphome/components/ld2410/ld2410.cpp index 22bd20d1e5a..71a9c4b8761 100644 --- a/esphome/components/ld2410/ld2410.cpp +++ b/esphome/components/ld2410/ld2410.cpp @@ -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]; diff --git a/esphome/components/ld2410/ld2410.h b/esphome/components/ld2410/ld2410.h index 6c7601df3d2..bd1da42c293 100644 --- a/esphome/components/ld2410/ld2410.h +++ b/esphome/components/ld2410/ld2410.h @@ -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); diff --git a/esphome/components/ld2410/number/__init__.py b/esphome/components/ld2410/number/__init__.py index 5c80922ba6e..49c047f5457 100644 --- a/esphome/components/ld2410/number/__init__.py +++ b/esphome/components/ld2410/number/__init__.py @@ -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),