diff --git a/esphome/components/ld2450/switch/__init__.py b/esphome/components/ld2450/switch/__init__.py index bb920f6c76e..60c4aae73fe 100644 --- a/esphome/components/ld2450/switch/__init__.py +++ b/esphome/components/ld2450/switch/__init__.py @@ -11,10 +11,7 @@ from esphome.const import ( ) from esphome.types import ConfigType -from .. import CONF_LD2450_ID, LD2450Component, ld2450_ns - -BluetoothSwitch = ld2450_ns.class_("BluetoothSwitch", switch.Switch) -MultiTargetSwitch = ld2450_ns.class_("MultiTargetSwitch", switch.Switch) +from .. import CONF_LD2450_ID, LD2450Component CONF_MULTI_TARGET = "multi_target" @@ -22,13 +19,13 @@ CONFIG_SCHEMA = { cv.GenerateID(CONF_ID): cv.declare_id(cg.EntityBase), cv.GenerateID(CONF_LD2450_ID): cv.use_id(LD2450Component), cv.Optional(CONF_BLUETOOTH): switch.switch_schema( - BluetoothSwitch, + switch.ApplySwitch, device_class=DEVICE_CLASS_SWITCH, entity_category=ENTITY_CATEGORY_CONFIG, icon=ICON_BLUETOOTH, ), cv.Optional(CONF_MULTI_TARGET): switch.switch_schema( - MultiTargetSwitch, + switch.ApplySwitch, device_class=DEVICE_CLASS_SWITCH, entity_category=ENTITY_CATEGORY_CONFIG, icon=ICON_PULSE, @@ -39,5 +36,15 @@ CONFIG_SCHEMA = { async def to_code(config: ConfigType) -> None: hub = await cg.get_variable(config[CONF_LD2450_ID]) switches = switch.sub_switches(config, parent=hub) - await switches(CONF_BLUETOOTH, hub.set_bluetooth_switch) - await switches(CONF_MULTI_TARGET, hub.set_multi_target_switch) + await switches( + CONF_BLUETOOTH, + hub.set_bluetooth_switch, + apply="set_bluetooth(state)", + publish="before", + ) + await switches( + CONF_MULTI_TARGET, + hub.set_multi_target_switch, + apply="set_multi_target(state)", + publish="before", + ) diff --git a/esphome/components/ld2450/switch/bluetooth_switch.cpp b/esphome/components/ld2450/switch/bluetooth_switch.cpp deleted file mode 100644 index 0e19a3e6c66..00000000000 --- a/esphome/components/ld2450/switch/bluetooth_switch.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include "bluetooth_switch.h" - -namespace esphome::ld2450 { - -void BluetoothSwitch::write_state(bool state) { - this->publish_state(state); - this->parent_->set_bluetooth(state); -} - -} // namespace esphome::ld2450 diff --git a/esphome/components/ld2450/switch/bluetooth_switch.h b/esphome/components/ld2450/switch/bluetooth_switch.h deleted file mode 100644 index 8b118a7b8c1..00000000000 --- a/esphome/components/ld2450/switch/bluetooth_switch.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#include "esphome/components/switch/switch.h" -#include "../ld2450.h" - -namespace esphome::ld2450 { - -class BluetoothSwitch : public switch_::Switch, public Parented { - public: - // User provided, not "= default": `new(p) BluetoothSwitch()` would zero-fill .bss that is already zero. - BluetoothSwitch() {} - - protected: - void write_state(bool state) override; -}; - -} // namespace esphome::ld2450 diff --git a/esphome/components/ld2450/switch/multi_target_switch.cpp b/esphome/components/ld2450/switch/multi_target_switch.cpp deleted file mode 100644 index 0b1cb04a685..00000000000 --- a/esphome/components/ld2450/switch/multi_target_switch.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include "multi_target_switch.h" - -namespace esphome::ld2450 { - -void MultiTargetSwitch::write_state(bool state) { - this->publish_state(state); - this->parent_->set_multi_target(state); -} - -} // namespace esphome::ld2450 diff --git a/esphome/components/ld2450/switch/multi_target_switch.h b/esphome/components/ld2450/switch/multi_target_switch.h deleted file mode 100644 index d711a2d2d29..00000000000 --- a/esphome/components/ld2450/switch/multi_target_switch.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#include "esphome/components/switch/switch.h" -#include "../ld2450.h" - -namespace esphome::ld2450 { - -class MultiTargetSwitch : public switch_::Switch, public Parented { - public: - // User provided, not "= default": `new(p) MultiTargetSwitch()` would zero-fill .bss that is already zero. - MultiTargetSwitch() {} - - protected: - void write_state(bool state) override; -}; - -} // namespace esphome::ld2450