diff --git a/esphome/components/at581x/switch/__init__.py b/esphome/components/at581x/switch/__init__.py index 7e45ed89ec0..b5f3b100cac 100644 --- a/esphome/components/at581x/switch/__init__.py +++ b/esphome/components/at581x/switch/__init__.py @@ -4,14 +4,13 @@ import esphome.config_validation as cv from esphome.const import DEVICE_CLASS_SWITCH, ICON_WIFI from esphome.types import ConfigType -from .. import CONF_AT581X_ID, AT581XComponent, at581x_ns +from .. import CONF_AT581X_ID, AT581XComponent DEPENDENCIES = ["at581x"] -RFSwitch = at581x_ns.class_("RFSwitch", switch.Switch) CONFIG_SCHEMA = switch.switch_schema( - RFSwitch, + switch.ApplySwitch, device_class=DEVICE_CLASS_SWITCH, icon=ICON_WIFI, ).extend( @@ -24,7 +23,7 @@ CONFIG_SCHEMA = switch.switch_schema( async def to_code(config: ConfigType) -> None: - at581x_component = await cg.get_variable(config[CONF_AT581X_ID]) - s = await switch.new_switch(config) - await cg.register_parented(s, config[CONF_AT581X_ID]) - cg.add(at581x_component.set_rf_power_switch(s)) + hub = await cg.get_variable(config[CONF_AT581X_ID]) + await switch.sub_switches(config, parent=hub).create( + config, hub.set_rf_power_switch, apply="set_rf_mode(state)", publish="before" + ) diff --git a/esphome/components/at581x/switch/rf_switch.cpp b/esphome/components/at581x/switch/rf_switch.cpp deleted file mode 100644 index 7432233863e..00000000000 --- a/esphome/components/at581x/switch/rf_switch.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include "rf_switch.h" - -namespace esphome::at581x { - -void RFSwitch::write_state(bool state) { - this->publish_state(state); - this->parent_->set_rf_mode(state); -} - -} // namespace esphome::at581x diff --git a/esphome/components/at581x/switch/rf_switch.h b/esphome/components/at581x/switch/rf_switch.h deleted file mode 100644 index 0e251b8baaf..00000000000 --- a/esphome/components/at581x/switch/rf_switch.h +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once - -#include "esphome/components/switch/switch.h" -#include "../at581x.h" - -namespace esphome::at581x { - -class RFSwitch final : public switch_::Switch, public Parented { - protected: - void write_state(bool state) override; -}; - -} // namespace esphome::at581x