From 456e13adee56822a85096ede7d343dee62e3f92b Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 25 Sep 2026 20:20:44 +0100 Subject: [PATCH] [ld2410] Use register_apply_action for bluetooth_password.set (#19667) --- esphome/components/ld2410/__init__.py | 24 ++----------------- esphome/components/ld2410/automation.h | 20 ---------------- esphome/components/ld2410/ld2410.h | 1 - tests/components/ld2410/common-actions.yaml | 10 ++++++++ .../ld2410/test-actions.esp8266-ard.yaml | 8 +++++++ 5 files changed, 20 insertions(+), 43 deletions(-) delete mode 100644 esphome/components/ld2410/automation.h create mode 100644 tests/components/ld2410/common-actions.yaml create mode 100644 tests/components/ld2410/test-actions.esp8266-ard.yaml diff --git a/esphome/components/ld2410/__init__.py b/esphome/components/ld2410/__init__.py index 19786f38d3..f157cb50fd 100644 --- a/esphome/components/ld2410/__init__.py +++ b/esphome/components/ld2410/__init__.py @@ -4,8 +4,6 @@ import esphome.codegen as cg from esphome.components import uart import esphome.config_validation as cv from esphome.const import CONF_ID, CONF_PASSWORD, CONF_THROTTLE, CONF_TIMEOUT -from esphome.core import ID -from esphome.cpp_generator import MockObj, TemplateArgsType from esphome.types import ConfigType AUTO_LOAD = ["ld24xx"] @@ -86,11 +84,6 @@ CALIBRATION_ACTION_SCHEMA = maybe_simple_id( # Actions -BluetoothPasswordSetAction = ld2410_ns.class_( - "BluetoothPasswordSetAction", automation.Action -) - - BLUETOOTH_PASSWORD_SET_SCHEMA = cv.Schema( { cv.Required(CONF_ID): cv.use_id(LD2410Component), @@ -98,21 +91,8 @@ BLUETOOTH_PASSWORD_SET_SCHEMA = cv.Schema( } ) - -@automation.register_action( +automation.register_apply_action( "bluetooth_password.set", - BluetoothPasswordSetAction, BLUETOOTH_PASSWORD_SET_SCHEMA, - synchronous=True, + automation.ApplyField(CONF_PASSWORD, "set_bluetooth_password", cg.std_string), ) -async def bluetooth_password_set_to_code( - config: ConfigType, - action_id: ID, - template_arg: cg.TemplateArguments, - args: TemplateArgsType, -) -> MockObj: - paren = await cg.get_variable(config[CONF_ID]) - var = cg.new_Pvariable(action_id, template_arg, paren) - template_ = await cg.templatable(config[CONF_PASSWORD], args, cg.std_string) - cg.add(var.set_password(template_)) - return var diff --git a/esphome/components/ld2410/automation.h b/esphome/components/ld2410/automation.h deleted file mode 100644 index b0b9591d37..0000000000 --- a/esphome/components/ld2410/automation.h +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once - -#include "esphome/core/automation.h" -#include "esphome/core/component.h" -#include "ld2410.h" - -namespace esphome::ld2410 { - -template class BluetoothPasswordSetAction final : public Action { - public: - explicit BluetoothPasswordSetAction(LD2410Component *ld2410_comp) : ld2410_comp_(ld2410_comp) {} - TEMPLATABLE_VALUE(std::string, password) - - void play(const Ts &...x) override { this->ld2410_comp_->set_bluetooth_password(this->password_.value(x...)); } - - protected: - LD2410Component *ld2410_comp_; -}; - -} // namespace esphome::ld2410 diff --git a/esphome/components/ld2410/ld2410.h b/esphome/components/ld2410/ld2410.h index 061846f1f1..6c7601df3d 100644 --- a/esphome/components/ld2410/ld2410.h +++ b/esphome/components/ld2410/ld2410.h @@ -24,7 +24,6 @@ #endif #include "esphome/components/ld24xx/ld24xx.h" #include "esphome/components/uart/uart.h" -#include "esphome/core/automation.h" #include "esphome/core/helpers.h" #include diff --git a/tests/components/ld2410/common-actions.yaml b/tests/components/ld2410/common-actions.yaml new file mode 100644 index 0000000000..7cd4d6abbc --- /dev/null +++ b/tests/components/ld2410/common-actions.yaml @@ -0,0 +1,10 @@ +button: + - platform: template + name: LD2410 Actions + on_press: + - bluetooth_password.set: + id: my_ld2410 + password: HiLink + - bluetooth_password.set: + id: my_ld2410 + password: !lambda return "HiLink"; diff --git a/tests/components/ld2410/test-actions.esp8266-ard.yaml b/tests/components/ld2410/test-actions.esp8266-ard.yaml new file mode 100644 index 0000000000..188d8cb87f --- /dev/null +++ b/tests/components/ld2410/test-actions.esp8266-ard.yaml @@ -0,0 +1,8 @@ +substitutions: + tx_pin: GPIO0 + rx_pin: GPIO2 + +packages: + uart: !include ../../test_build_components/common/uart/esp8266-ard.yaml + ld2410: !include common.yaml + actions: !include common-actions.yaml