diff --git a/esphome/components/seeed_mr24hpc1/switch/__init__.py b/esphome/components/seeed_mr24hpc1/switch/__init__.py index 76e8a2089bc..9fdbf4a6d8a 100644 --- a/esphome/components/seeed_mr24hpc1/switch/__init__.py +++ b/esphome/components/seeed_mr24hpc1/switch/__init__.py @@ -4,18 +4,14 @@ import esphome.config_validation as cv from esphome.const import DEVICE_CLASS_SWITCH, ENTITY_CATEGORY_CONFIG from esphome.types import ConfigType -from .. import CONF_MR24HPC1_ID, MR24HPC1Component, mr24hpc1_ns - -UnderlyingOpenFuncSwitch = mr24hpc1_ns.class_( - "UnderlyOpenFunctionSwitch", switch.Switch -) +from .. import CONF_MR24HPC1_ID, MR24HPC1Component CONF_UNDERLYING_OPEN_FUNCTION = "underlying_open_function" CONFIG_SCHEMA = { cv.GenerateID(CONF_MR24HPC1_ID): cv.use_id(MR24HPC1Component), cv.Optional(CONF_UNDERLYING_OPEN_FUNCTION): switch.switch_schema( - UnderlyingOpenFuncSwitch, + switch.ApplySwitch, device_class=DEVICE_CLASS_SWITCH, entity_category=ENTITY_CATEGORY_CONFIG, icon="mdi:electric-switch", @@ -27,5 +23,8 @@ async def to_code(config: ConfigType) -> None: hub = await cg.get_variable(config[CONF_MR24HPC1_ID]) switches = switch.sub_switches(config, parent=hub) await switches( - CONF_UNDERLYING_OPEN_FUNCTION, hub.set_underlying_open_function_switch + CONF_UNDERLYING_OPEN_FUNCTION, + hub.set_underlying_open_function_switch, + apply="set_underlying_open_function(state)", + publish="before", ) diff --git a/esphome/components/seeed_mr24hpc1/switch/underlyFuc_switch.cpp b/esphome/components/seeed_mr24hpc1/switch/underlyFuc_switch.cpp deleted file mode 100644 index d4691102915..00000000000 --- a/esphome/components/seeed_mr24hpc1/switch/underlyFuc_switch.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include "underlyFuc_switch.h" - -namespace esphome::seeed_mr24hpc1 { - -void UnderlyOpenFunctionSwitch::write_state(bool state) { - this->publish_state(state); - this->parent_->set_underlying_open_function(state); -} - -} // namespace esphome::seeed_mr24hpc1 diff --git a/esphome/components/seeed_mr24hpc1/switch/underlyFuc_switch.h b/esphome/components/seeed_mr24hpc1/switch/underlyFuc_switch.h deleted file mode 100644 index 8b8dbdf5de5..00000000000 --- a/esphome/components/seeed_mr24hpc1/switch/underlyFuc_switch.h +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -#include "esphome/components/switch/switch.h" -#include "../seeed_mr24hpc1.h" - -namespace esphome::seeed_mr24hpc1 { - -class UnderlyOpenFunctionSwitch final : public switch_::Switch, public Parented { - public: - UnderlyOpenFunctionSwitch() = default; - - protected: - void write_state(bool state) override; -}; - -} // namespace esphome::seeed_mr24hpc1