From 5fd7c33916ca216df8cda497bd5ad85f402cab22 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 16 Oct 2026 10:39:25 -1000 Subject: [PATCH] [ld2410] Use Apply entities for the forwarding buttons, switches, numbers and selects --- esphome/components/ld2410/button/__init__.py | 22 +++---- .../ld2410/button/factory_reset_button.cpp | 7 --- .../ld2410/button/factory_reset_button.h | 16 ----- .../components/ld2410/button/query_button.cpp | 7 --- .../components/ld2410/button/query_button.h | 16 ----- .../ld2410/button/restart_button.cpp | 7 --- .../components/ld2410/button/restart_button.h | 16 ----- esphome/components/ld2410/number/__init__.py | 61 +++++++++++-------- .../ld2410/number/gate_threshold_number.cpp | 12 ---- .../ld2410/number/gate_threshold_number.h | 17 ------ .../ld2410/number/light_threshold_number.cpp | 10 --- .../ld2410/number/light_threshold_number.h | 16 ----- .../number/max_distance_timeout_number.cpp | 10 --- .../number/max_distance_timeout_number.h | 16 ----- esphome/components/ld2410/select/__init__.py | 25 +++++--- .../ld2410/select/baud_rate_select.cpp | 10 --- .../ld2410/select/baud_rate_select.h | 16 ----- .../select/distance_resolution_select.cpp | 10 --- .../select/distance_resolution_select.h | 16 ----- .../select/light_out_control_select.cpp | 10 --- .../ld2410/select/light_out_control_select.h | 16 ----- esphome/components/ld2410/switch/__init__.py | 23 ++++--- .../ld2410/switch/bluetooth_switch.cpp | 10 --- .../ld2410/switch/bluetooth_switch.h | 16 ----- .../ld2410/switch/engineering_mode_switch.cpp | 10 --- .../ld2410/switch/engineering_mode_switch.h | 16 ----- 26 files changed, 77 insertions(+), 334 deletions(-) delete mode 100644 esphome/components/ld2410/button/factory_reset_button.cpp delete mode 100644 esphome/components/ld2410/button/factory_reset_button.h delete mode 100644 esphome/components/ld2410/button/query_button.cpp delete mode 100644 esphome/components/ld2410/button/query_button.h delete mode 100644 esphome/components/ld2410/button/restart_button.cpp delete mode 100644 esphome/components/ld2410/button/restart_button.h delete mode 100644 esphome/components/ld2410/number/gate_threshold_number.cpp delete mode 100644 esphome/components/ld2410/number/gate_threshold_number.h delete mode 100644 esphome/components/ld2410/number/light_threshold_number.cpp delete mode 100644 esphome/components/ld2410/number/light_threshold_number.h delete mode 100644 esphome/components/ld2410/number/max_distance_timeout_number.cpp delete mode 100644 esphome/components/ld2410/number/max_distance_timeout_number.h delete mode 100644 esphome/components/ld2410/select/baud_rate_select.cpp delete mode 100644 esphome/components/ld2410/select/baud_rate_select.h delete mode 100644 esphome/components/ld2410/select/distance_resolution_select.cpp delete mode 100644 esphome/components/ld2410/select/distance_resolution_select.h delete mode 100644 esphome/components/ld2410/select/light_out_control_select.cpp delete mode 100644 esphome/components/ld2410/select/light_out_control_select.h delete mode 100644 esphome/components/ld2410/switch/bluetooth_switch.cpp delete mode 100644 esphome/components/ld2410/switch/bluetooth_switch.h delete mode 100644 esphome/components/ld2410/switch/engineering_mode_switch.cpp delete mode 100644 esphome/components/ld2410/switch/engineering_mode_switch.h diff --git a/esphome/components/ld2410/button/__init__.py b/esphome/components/ld2410/button/__init__.py index 21618babe79..97167ea81ba 100644 --- a/esphome/components/ld2410/button/__init__.py +++ b/esphome/components/ld2410/button/__init__.py @@ -15,29 +15,25 @@ from esphome.const import ( ) from esphome.types import ConfigType -from .. import CONF_LD2410_ID, LD2410Component, ld2410_ns - -FactoryResetButton = ld2410_ns.class_("FactoryResetButton", button.Button) -QueryButton = ld2410_ns.class_("QueryButton", button.Button) -RestartButton = ld2410_ns.class_("RestartButton", button.Button) +from .. import CONF_LD2410_ID, LD2410Component CONFIG_SCHEMA = { cv.GenerateID(CONF_ID): cv.declare_id(cg.EntityBase), cv.GenerateID(CONF_LD2410_ID): cv.use_id(LD2410Component), cv.Optional(CONF_FACTORY_RESET): button.button_schema( - FactoryResetButton, + button.ApplyButton, device_class=DEVICE_CLASS_RESTART, entity_category=ENTITY_CATEGORY_CONFIG, icon=ICON_RESTART_ALERT, ), cv.Optional(CONF_RESTART): button.button_schema( - RestartButton, + button.ApplyButton, device_class=DEVICE_CLASS_RESTART, entity_category=ENTITY_CATEGORY_DIAGNOSTIC, icon=ICON_RESTART, ), cv.Optional(CONF_QUERY_PARAMS): button.button_schema( - QueryButton, + button.ApplyButton, entity_category=ENTITY_CATEGORY_DIAGNOSTIC, icon=ICON_DATABASE, ), @@ -47,6 +43,10 @@ CONFIG_SCHEMA = { async def to_code(config: ConfigType) -> None: hub = await cg.get_variable(config[CONF_LD2410_ID]) buttons = button.sub_buttons(config, parent=hub) - await buttons(CONF_FACTORY_RESET, hub.set_factory_reset_button) - await buttons(CONF_RESTART, hub.set_restart_button) - await buttons(CONF_QUERY_PARAMS, hub.set_query_button) + await buttons( + CONF_FACTORY_RESET, hub.set_factory_reset_button, apply="factory_reset()" + ) + await buttons( + CONF_RESTART, hub.set_restart_button, apply="restart_and_read_all_info()" + ) + await buttons(CONF_QUERY_PARAMS, hub.set_query_button, apply="read_all_info()") diff --git a/esphome/components/ld2410/button/factory_reset_button.cpp b/esphome/components/ld2410/button/factory_reset_button.cpp deleted file mode 100644 index 0223df70868..00000000000 --- a/esphome/components/ld2410/button/factory_reset_button.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include "factory_reset_button.h" - -namespace esphome::ld2410 { - -void FactoryResetButton::press_action() { this->parent_->factory_reset(); } - -} // namespace esphome::ld2410 diff --git a/esphome/components/ld2410/button/factory_reset_button.h b/esphome/components/ld2410/button/factory_reset_button.h deleted file mode 100644 index 1da7c813375..00000000000 --- a/esphome/components/ld2410/button/factory_reset_button.h +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -#include "esphome/components/button/button.h" -#include "../ld2410.h" - -namespace esphome::ld2410 { - -class FactoryResetButton final : public button::Button, public Parented { - public: - FactoryResetButton() = default; - - protected: - void press_action() override; -}; - -} // namespace esphome::ld2410 diff --git a/esphome/components/ld2410/button/query_button.cpp b/esphome/components/ld2410/button/query_button.cpp deleted file mode 100644 index 4085dc3d11e..00000000000 --- a/esphome/components/ld2410/button/query_button.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include "query_button.h" - -namespace esphome::ld2410 { - -void QueryButton::press_action() { this->parent_->read_all_info(); } - -} // namespace esphome::ld2410 diff --git a/esphome/components/ld2410/button/query_button.h b/esphome/components/ld2410/button/query_button.h deleted file mode 100644 index 4f3f147e673..00000000000 --- a/esphome/components/ld2410/button/query_button.h +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -#include "esphome/components/button/button.h" -#include "../ld2410.h" - -namespace esphome::ld2410 { - -class QueryButton final : public button::Button, public Parented { - public: - QueryButton() = default; - - protected: - void press_action() override; -}; - -} // namespace esphome::ld2410 diff --git a/esphome/components/ld2410/button/restart_button.cpp b/esphome/components/ld2410/button/restart_button.cpp deleted file mode 100644 index 0d5002d3c63..00000000000 --- a/esphome/components/ld2410/button/restart_button.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include "restart_button.h" - -namespace esphome::ld2410 { - -void RestartButton::press_action() { this->parent_->restart_and_read_all_info(); } - -} // namespace esphome::ld2410 diff --git a/esphome/components/ld2410/button/restart_button.h b/esphome/components/ld2410/button/restart_button.h deleted file mode 100644 index 70e0a74c9a5..00000000000 --- a/esphome/components/ld2410/button/restart_button.h +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -#include "esphome/components/button/button.h" -#include "../ld2410.h" - -namespace esphome::ld2410 { - -class RestartButton final : public button::Button, public Parented { - public: - RestartButton() = default; - - protected: - void press_action() override; -}; - -} // namespace esphome::ld2410 diff --git a/esphome/components/ld2410/number/__init__.py b/esphome/components/ld2410/number/__init__.py index b1891a5935a..5c80922ba6e 100644 --- a/esphome/components/ld2410/number/__init__.py +++ b/esphome/components/ld2410/number/__init__.py @@ -1,3 +1,5 @@ +from functools import partial + import esphome.codegen as cg from esphome.components import number import esphome.config_validation as cv @@ -18,11 +20,7 @@ from esphome.const import ( ) from esphome.types import ConfigType -from .. import CONF_LD2410_ID, LD2410Component, ld2410_ns - -GateThresholdNumber = ld2410_ns.class_("GateThresholdNumber", number.Number) -LightThresholdNumber = ld2410_ns.class_("LightThresholdNumber", number.Number) -MaxDistanceTimeoutNumber = ld2410_ns.class_("MaxDistanceTimeoutNumber", number.Number) +from .. import CONF_LD2410_ID, LD2410Component CONF_MAX_MOVE_DISTANCE_GATE = "max_move_distance_gate" CONF_MAX_STILL_DISTANCE_GATE = "max_still_distance_gate" @@ -35,25 +33,25 @@ CONFIG_SCHEMA = cv.Schema( cv.GenerateID(CONF_ID): cv.declare_id(cg.EntityBase), cv.GenerateID(CONF_LD2410_ID): cv.use_id(LD2410Component), cv.Inclusive(CONF_TIMEOUT, TIMEOUT_GROUP): number.number_schema( - MaxDistanceTimeoutNumber, + number.ApplyNumber, unit_of_measurement=UNIT_SECOND, entity_category=ENTITY_CATEGORY_CONFIG, icon=ICON_TIMELAPSE, ), cv.Inclusive(CONF_MAX_MOVE_DISTANCE_GATE, TIMEOUT_GROUP): number.number_schema( - MaxDistanceTimeoutNumber, + number.ApplyNumber, device_class=DEVICE_CLASS_DISTANCE, entity_category=ENTITY_CATEGORY_CONFIG, icon=ICON_MOTION_SENSOR, ), cv.Inclusive(CONF_MAX_STILL_DISTANCE_GATE, TIMEOUT_GROUP): number.number_schema( - MaxDistanceTimeoutNumber, + number.ApplyNumber, device_class=DEVICE_CLASS_DISTANCE, entity_category=ENTITY_CATEGORY_CONFIG, icon=ICON_MOTION_SENSOR, ), cv.Optional(CONF_LIGHT_THRESHOLD): number.number_schema( - LightThresholdNumber, + number.ApplyNumber, device_class=DEVICE_CLASS_ILLUMINANCE, entity_category=ENTITY_CATEGORY_CONFIG, icon=ICON_LIGHTBULB, @@ -66,14 +64,14 @@ CONFIG_SCHEMA = CONFIG_SCHEMA.extend( cv.Optional(f"g{x}"): cv.Schema( { cv.Required(CONF_MOVE_THRESHOLD): number.number_schema( - GateThresholdNumber, + number.ApplyNumber, device_class=DEVICE_CLASS_SIGNAL_STRENGTH, unit_of_measurement=UNIT_PERCENT, entity_category=ENTITY_CATEGORY_CONFIG, icon=ICON_MOTION_SENSOR, ), cv.Required(CONF_STILL_THRESHOLD): number.number_schema( - GateThresholdNumber, + number.ApplyNumber, device_class=DEVICE_CLASS_SIGNAL_STRENGTH, unit_of_measurement=UNIT_PERCENT, entity_category=ENTITY_CATEGORY_CONFIG, @@ -89,8 +87,14 @@ CONFIG_SCHEMA = CONFIG_SCHEMA.extend( async def to_code(config: ConfigType) -> None: hub = await cg.get_variable(config[CONF_LD2410_ID]) numbers = number.sub_numbers(config, parent=hub) + timeouts = {"apply": "set_max_distances_timeout()", "publish": "before"} await numbers( - CONF_TIMEOUT, hub.set_timeout_number, min_value=0, max_value=65535, step=1 + CONF_TIMEOUT, + hub.set_timeout_number, + min_value=0, + max_value=65535, + step=1, + **timeouts, ) await numbers( CONF_MAX_MOVE_DISTANCE_GATE, @@ -98,6 +102,7 @@ async def to_code(config: ConfigType) -> None: min_value=2, max_value=8, step=1, + **timeouts, ) await numbers( CONF_MAX_STILL_DISTANCE_GATE, @@ -105,6 +110,7 @@ async def to_code(config: ConfigType) -> None: min_value=2, max_value=8, step=1, + **timeouts, ) await numbers( CONF_LIGHT_THRESHOLD, @@ -112,21 +118,26 @@ async def to_code(config: ConfigType) -> None: min_value=0, max_value=255, step=1, + apply="set_light_out_control()", + publish="before", ) for x in range(9): if gate_conf := config.get(f"g{x}"): - move_config = gate_conf[CONF_MOVE_THRESHOLD] - n = cg.new_Pvariable(move_config[CONF_ID], x) - await number.register_number( - n, move_config, min_value=0, max_value=100, step=1 + 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), + **threshold, ) - await cg.register_parented(n, hub) - cg.add(hub.set_gate_move_threshold_number(x, n)) - - still_config = gate_conf[CONF_STILL_THRESHOLD] - n = cg.new_Pvariable(still_config[CONF_ID], x) - await number.register_number( - n, still_config, min_value=0, max_value=100, step=1 + await gate( + CONF_STILL_THRESHOLD, + partial(hub.set_gate_still_threshold_number, x), + **threshold, ) - await cg.register_parented(n, hub) - cg.add(hub.set_gate_still_threshold_number(x, n)) diff --git a/esphome/components/ld2410/number/gate_threshold_number.cpp b/esphome/components/ld2410/number/gate_threshold_number.cpp deleted file mode 100644 index 65e864a4d7d..00000000000 --- a/esphome/components/ld2410/number/gate_threshold_number.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "gate_threshold_number.h" - -namespace esphome::ld2410 { - -GateThresholdNumber::GateThresholdNumber(uint8_t gate) : gate_(gate) {} - -void GateThresholdNumber::control(float value) { - this->publish_state(value); - this->parent_->set_gate_threshold(this->gate_); -} - -} // namespace esphome::ld2410 diff --git a/esphome/components/ld2410/number/gate_threshold_number.h b/esphome/components/ld2410/number/gate_threshold_number.h deleted file mode 100644 index 68359a10d4f..00000000000 --- a/esphome/components/ld2410/number/gate_threshold_number.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#include "esphome/components/number/number.h" -#include "../ld2410.h" - -namespace esphome::ld2410 { - -class GateThresholdNumber final : public number::Number, public Parented { - public: - GateThresholdNumber(uint8_t gate); - - protected: - uint8_t gate_; - void control(float value) override; -}; - -} // namespace esphome::ld2410 diff --git a/esphome/components/ld2410/number/light_threshold_number.cpp b/esphome/components/ld2410/number/light_threshold_number.cpp deleted file mode 100644 index 55f69ff1fc9..00000000000 --- a/esphome/components/ld2410/number/light_threshold_number.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include "light_threshold_number.h" - -namespace esphome::ld2410 { - -void LightThresholdNumber::control(float value) { - this->publish_state(value); - this->parent_->set_light_out_control(); -} - -} // namespace esphome::ld2410 diff --git a/esphome/components/ld2410/number/light_threshold_number.h b/esphome/components/ld2410/number/light_threshold_number.h deleted file mode 100644 index 6e1a5ca4a4b..00000000000 --- a/esphome/components/ld2410/number/light_threshold_number.h +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -#include "esphome/components/number/number.h" -#include "../ld2410.h" - -namespace esphome::ld2410 { - -class LightThresholdNumber final : public number::Number, public Parented { - public: - LightThresholdNumber() = default; - - protected: - void control(float value) override; -}; - -} // namespace esphome::ld2410 diff --git a/esphome/components/ld2410/number/max_distance_timeout_number.cpp b/esphome/components/ld2410/number/max_distance_timeout_number.cpp deleted file mode 100644 index b8667f5dbc1..00000000000 --- a/esphome/components/ld2410/number/max_distance_timeout_number.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include "max_distance_timeout_number.h" - -namespace esphome::ld2410 { - -void MaxDistanceTimeoutNumber::control(float value) { - this->publish_state(value); - this->parent_->set_max_distances_timeout(); -} - -} // namespace esphome::ld2410 diff --git a/esphome/components/ld2410/number/max_distance_timeout_number.h b/esphome/components/ld2410/number/max_distance_timeout_number.h deleted file mode 100644 index 29b19c2022b..00000000000 --- a/esphome/components/ld2410/number/max_distance_timeout_number.h +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -#include "esphome/components/number/number.h" -#include "../ld2410.h" - -namespace esphome::ld2410 { - -class MaxDistanceTimeoutNumber final : public number::Number, public Parented { - public: - MaxDistanceTimeoutNumber() = default; - - protected: - void control(float value) override; -}; - -} // namespace esphome::ld2410 diff --git a/esphome/components/ld2410/select/__init__.py b/esphome/components/ld2410/select/__init__.py index e1129ac9524..0e70497e1b8 100644 --- a/esphome/components/ld2410/select/__init__.py +++ b/esphome/components/ld2410/select/__init__.py @@ -13,11 +13,7 @@ from esphome.const import ( ) from esphome.types import ConfigType -from .. import CONF_LD2410_ID, LD2410Component, ld2410_ns - -BaudRateSelect = ld2410_ns.class_("BaudRateSelect", select.Select) -DistanceResolutionSelect = ld2410_ns.class_("DistanceResolutionSelect", select.Select) -LightOutControlSelect = ld2410_ns.class_("LightOutControlSelect", select.Select) +from .. import CONF_LD2410_ID, LD2410Component CONF_DISTANCE_RESOLUTION = "distance_resolution" CONF_LIGHT_FUNCTION = "light_function" @@ -27,22 +23,22 @@ CONFIG_SCHEMA = { cv.GenerateID(CONF_ID): cv.declare_id(cg.EntityBase), cv.GenerateID(CONF_LD2410_ID): cv.use_id(LD2410Component), cv.Optional(CONF_DISTANCE_RESOLUTION): select.select_schema( - DistanceResolutionSelect, + select.ApplySelect, entity_category=ENTITY_CATEGORY_CONFIG, icon=ICON_RULER, ), cv.Optional(CONF_LIGHT_FUNCTION): select.select_schema( - LightOutControlSelect, + select.ApplySelect, entity_category=ENTITY_CATEGORY_CONFIG, icon=ICON_LIGHTBULB, ), cv.Optional(CONF_OUT_PIN_LEVEL): select.select_schema( - LightOutControlSelect, + select.ApplySelect, entity_category=ENTITY_CATEGORY_CONFIG, icon=ICON_SCALE, ), cv.Optional(CONF_BAUD_RATE): select.select_schema( - BaudRateSelect, + select.ApplySelect, entity_category=ENTITY_CATEGORY_CONFIG, icon=ICON_THERMOMETER, ), @@ -56,18 +52,27 @@ async def to_code(config: ConfigType) -> None: CONF_DISTANCE_RESOLUTION, hub.set_distance_resolution_select, options=["0.2m", "0.75m"], + apply="set_distance_resolution(entity->option_at(index))", + publish="before", ) + light = {"apply": "set_light_out_control()", "publish": "before"} await selects( - CONF_OUT_PIN_LEVEL, hub.set_out_pin_level_select, options=["low", "high"] + CONF_OUT_PIN_LEVEL, + hub.set_out_pin_level_select, + options=["low", "high"], + **light, ) await selects( CONF_LIGHT_FUNCTION, hub.set_light_function_select, options=["off", "below", "above"], + **light, ) await selects( CONF_BAUD_RATE, hub.set_baud_rate_select, + apply="set_baud_rate(entity->option_at(index))", + publish="before", options=[ "9600", "19200", diff --git a/esphome/components/ld2410/select/baud_rate_select.cpp b/esphome/components/ld2410/select/baud_rate_select.cpp deleted file mode 100644 index a533a2e2d69..00000000000 --- a/esphome/components/ld2410/select/baud_rate_select.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include "baud_rate_select.h" - -namespace esphome::ld2410 { - -void BaudRateSelect::control(size_t index) { - this->publish_state(index); - this->parent_->set_baud_rate(this->option_at(index)); -} - -} // namespace esphome::ld2410 diff --git a/esphome/components/ld2410/select/baud_rate_select.h b/esphome/components/ld2410/select/baud_rate_select.h deleted file mode 100644 index b06ce139ad3..00000000000 --- a/esphome/components/ld2410/select/baud_rate_select.h +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -#include "esphome/components/select/select.h" -#include "../ld2410.h" - -namespace esphome::ld2410 { - -class BaudRateSelect final : public select::Select, public Parented { - public: - BaudRateSelect() = default; - - protected: - void control(size_t index) override; -}; - -} // namespace esphome::ld2410 diff --git a/esphome/components/ld2410/select/distance_resolution_select.cpp b/esphome/components/ld2410/select/distance_resolution_select.cpp deleted file mode 100644 index 635bf206d3f..00000000000 --- a/esphome/components/ld2410/select/distance_resolution_select.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include "distance_resolution_select.h" - -namespace esphome::ld2410 { - -void DistanceResolutionSelect::control(size_t index) { - this->publish_state(index); - this->parent_->set_distance_resolution(this->option_at(index)); -} - -} // namespace esphome::ld2410 diff --git a/esphome/components/ld2410/select/distance_resolution_select.h b/esphome/components/ld2410/select/distance_resolution_select.h deleted file mode 100644 index 0c5409b7b17..00000000000 --- a/esphome/components/ld2410/select/distance_resolution_select.h +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -#include "esphome/components/select/select.h" -#include "../ld2410.h" - -namespace esphome::ld2410 { - -class DistanceResolutionSelect final : public select::Select, public Parented { - public: - DistanceResolutionSelect() = default; - - protected: - void control(size_t index) override; -}; - -} // namespace esphome::ld2410 diff --git a/esphome/components/ld2410/select/light_out_control_select.cpp b/esphome/components/ld2410/select/light_out_control_select.cpp deleted file mode 100644 index 1c55721d52b..00000000000 --- a/esphome/components/ld2410/select/light_out_control_select.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include "light_out_control_select.h" - -namespace esphome::ld2410 { - -void LightOutControlSelect::control(size_t index) { - this->publish_state(index); - this->parent_->set_light_out_control(); -} - -} // namespace esphome::ld2410 diff --git a/esphome/components/ld2410/select/light_out_control_select.h b/esphome/components/ld2410/select/light_out_control_select.h deleted file mode 100644 index a8a16598b18..00000000000 --- a/esphome/components/ld2410/select/light_out_control_select.h +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -#include "esphome/components/select/select.h" -#include "../ld2410.h" - -namespace esphome::ld2410 { - -class LightOutControlSelect final : public select::Select, public Parented { - public: - LightOutControlSelect() = default; - - protected: - void control(size_t index) override; -}; - -} // namespace esphome::ld2410 diff --git a/esphome/components/ld2410/switch/__init__.py b/esphome/components/ld2410/switch/__init__.py index 646890d43f5..2c42cbc193e 100644 --- a/esphome/components/ld2410/switch/__init__.py +++ b/esphome/components/ld2410/switch/__init__.py @@ -11,10 +11,7 @@ from esphome.const import ( ) from esphome.types import ConfigType -from .. import CONF_LD2410_ID, LD2410Component, ld2410_ns - -BluetoothSwitch = ld2410_ns.class_("BluetoothSwitch", switch.Switch) -EngineeringModeSwitch = ld2410_ns.class_("EngineeringModeSwitch", switch.Switch) +from .. import CONF_LD2410_ID, LD2410Component CONF_ENGINEERING_MODE = "engineering_mode" @@ -22,13 +19,13 @@ CONFIG_SCHEMA = { cv.GenerateID(CONF_ID): cv.declare_id(cg.EntityBase), cv.GenerateID(CONF_LD2410_ID): cv.use_id(LD2410Component), cv.Optional(CONF_ENGINEERING_MODE): switch.switch_schema( - EngineeringModeSwitch, + switch.ApplySwitch, device_class=DEVICE_CLASS_SWITCH, entity_category=ENTITY_CATEGORY_CONFIG, icon=ICON_PULSE, ), cv.Optional(CONF_BLUETOOTH): switch.switch_schema( - BluetoothSwitch, + switch.ApplySwitch, device_class=DEVICE_CLASS_SWITCH, entity_category=ENTITY_CATEGORY_CONFIG, icon=ICON_BLUETOOTH, @@ -39,5 +36,15 @@ CONFIG_SCHEMA = { async def to_code(config: ConfigType) -> None: hub = await cg.get_variable(config[CONF_LD2410_ID]) switches = switch.sub_switches(config, parent=hub) - await switches(CONF_ENGINEERING_MODE, hub.set_engineering_mode_switch) - await switches(CONF_BLUETOOTH, hub.set_bluetooth_switch) + await switches( + CONF_ENGINEERING_MODE, + hub.set_engineering_mode_switch, + apply="set_engineering_mode(state)", + publish="before", + ) + await switches( + CONF_BLUETOOTH, + hub.set_bluetooth_switch, + apply="set_bluetooth(state)", + publish="before", + ) diff --git a/esphome/components/ld2410/switch/bluetooth_switch.cpp b/esphome/components/ld2410/switch/bluetooth_switch.cpp deleted file mode 100644 index c85dd70ec9e..00000000000 --- a/esphome/components/ld2410/switch/bluetooth_switch.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include "bluetooth_switch.h" - -namespace esphome::ld2410 { - -void BluetoothSwitch::write_state(bool state) { - this->publish_state(state); - this->parent_->set_bluetooth(state); -} - -} // namespace esphome::ld2410 diff --git a/esphome/components/ld2410/switch/bluetooth_switch.h b/esphome/components/ld2410/switch/bluetooth_switch.h deleted file mode 100644 index cc56b2cda03..00000000000 --- a/esphome/components/ld2410/switch/bluetooth_switch.h +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -#include "esphome/components/switch/switch.h" -#include "../ld2410.h" - -namespace esphome::ld2410 { - -class BluetoothSwitch final : public switch_::Switch, public Parented { - public: - BluetoothSwitch() = default; - - protected: - void write_state(bool state) override; -}; - -} // namespace esphome::ld2410 diff --git a/esphome/components/ld2410/switch/engineering_mode_switch.cpp b/esphome/components/ld2410/switch/engineering_mode_switch.cpp deleted file mode 100644 index 4f2f08b03ed..00000000000 --- a/esphome/components/ld2410/switch/engineering_mode_switch.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include "engineering_mode_switch.h" - -namespace esphome::ld2410 { - -void EngineeringModeSwitch::write_state(bool state) { - this->publish_state(state); - this->parent_->set_engineering_mode(state); -} - -} // namespace esphome::ld2410 diff --git a/esphome/components/ld2410/switch/engineering_mode_switch.h b/esphome/components/ld2410/switch/engineering_mode_switch.h deleted file mode 100644 index 49243a73adc..00000000000 --- a/esphome/components/ld2410/switch/engineering_mode_switch.h +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -#include "esphome/components/switch/switch.h" -#include "../ld2410.h" - -namespace esphome::ld2410 { - -class EngineeringModeSwitch final : public switch_::Switch, public Parented { - public: - EngineeringModeSwitch() = default; - - protected: - void write_state(bool state) override; -}; - -} // namespace esphome::ld2410