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