From 8f79467d5fbf1535e1a200e7bbcb05f44cae6c4f Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 16 Oct 2026 10:51:36 -1000 Subject: [PATCH] [at581x] Use an Apply entity for the RF switch --- esphome/components/at581x/switch/__init__.py | 13 +++++----- .../components/at581x/switch/rf_switch.cpp | 10 -------- esphome/components/at581x/switch/rf_switch.h | 13 ---------- esphome/components/bq25186/bq25186_button.h | 25 ------------------- .../es8388/select/adc_input_mic_select.cpp | 10 -------- .../es8388/select/adc_input_mic_select.h | 13 ---------- .../es8388/select/dac_output_select.cpp | 10 -------- .../es8388/select/dac_output_select.h | 13 ---------- .../espectre/button/espectre_button.h | 19 -------------- .../espectre/select/espectre_select.cpp | 11 -------- .../espectre/select/espectre_select.h | 19 -------------- 11 files changed, 6 insertions(+), 150 deletions(-) delete mode 100644 esphome/components/at581x/switch/rf_switch.cpp delete mode 100644 esphome/components/at581x/switch/rf_switch.h delete mode 100644 esphome/components/bq25186/bq25186_button.h delete mode 100644 esphome/components/es8388/select/adc_input_mic_select.cpp delete mode 100644 esphome/components/es8388/select/adc_input_mic_select.h delete mode 100644 esphome/components/es8388/select/dac_output_select.cpp delete mode 100644 esphome/components/es8388/select/dac_output_select.h delete mode 100644 esphome/components/espectre/button/espectre_button.h delete mode 100644 esphome/components/espectre/select/espectre_select.cpp delete mode 100644 esphome/components/espectre/select/espectre_select.h 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 diff --git a/esphome/components/bq25186/bq25186_button.h b/esphome/components/bq25186/bq25186_button.h deleted file mode 100644 index e088166ac6c..00000000000 --- a/esphome/components/bq25186/bq25186_button.h +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -#include "esphome/core/defines.h" -#ifdef USE_BUTTON - -#include "bq25186.h" -#include "esphome/components/button/button.h" - -namespace esphome::bq25186 { - -/// Writes one SHIP_RST field when pressed -class BQ25186Button final : public button::Button, public Parented { - public: - BQ25186Button(uint8_t mask, uint8_t value) : mask_(mask), value_(value) {} - - protected: - void press_action() override { this->parent_->write_ship_rst(this->mask_, this->value_); } - - const uint8_t mask_; - const uint8_t value_; -}; - -} // namespace esphome::bq25186 - -#endif // USE_BUTTON diff --git a/esphome/components/es8388/select/adc_input_mic_select.cpp b/esphome/components/es8388/select/adc_input_mic_select.cpp deleted file mode 100644 index a91ccf4d5b4..00000000000 --- a/esphome/components/es8388/select/adc_input_mic_select.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include "adc_input_mic_select.h" - -namespace esphome::es8388 { - -void ADCInputMicSelect::control(size_t index) { - this->publish_state(index); - this->parent_->set_adc_input_mic(static_cast(index)); -} - -} // namespace esphome::es8388 diff --git a/esphome/components/es8388/select/adc_input_mic_select.h b/esphome/components/es8388/select/adc_input_mic_select.h deleted file mode 100644 index 2d4e8d72db1..00000000000 --- a/esphome/components/es8388/select/adc_input_mic_select.h +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once - -#include "esphome/components/es8388/es8388.h" -#include "esphome/components/select/select.h" - -namespace esphome::es8388 { - -class ADCInputMicSelect final : public select::Select, public Parented { - protected: - void control(size_t index) override; -}; - -} // namespace esphome::es8388 diff --git a/esphome/components/es8388/select/dac_output_select.cpp b/esphome/components/es8388/select/dac_output_select.cpp deleted file mode 100644 index cfe0fe1472f..00000000000 --- a/esphome/components/es8388/select/dac_output_select.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include "dac_output_select.h" - -namespace esphome::es8388 { - -void DacOutputSelect::control(size_t index) { - this->publish_state(index); - this->parent_->set_dac_output(static_cast(index)); -} - -} // namespace esphome::es8388 diff --git a/esphome/components/es8388/select/dac_output_select.h b/esphome/components/es8388/select/dac_output_select.h deleted file mode 100644 index f63ee8d1ba4..00000000000 --- a/esphome/components/es8388/select/dac_output_select.h +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once - -#include "esphome/components/es8388/es8388.h" -#include "esphome/components/select/select.h" - -namespace esphome::es8388 { - -class DacOutputSelect final : public select::Select, public Parented { - protected: - void control(size_t index) override; -}; - -} // namespace esphome::es8388 diff --git a/esphome/components/espectre/button/espectre_button.h b/esphome/components/espectre/button/espectre_button.h deleted file mode 100644 index f89c42f8fe9..00000000000 --- a/esphome/components/espectre/button/espectre_button.h +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once - -#include "esphome/core/defines.h" - -#ifdef USE_ESPECTRE - -#include "esphome/components/button/button.h" -#include "../espectre.h" - -namespace esphome::espectre { - -class RecalibrateButton final : public button::Button, public Parented { - protected: - void press_action() override { this->parent_->recalibrate(); } -}; - -} // namespace esphome::espectre - -#endif // USE_ESPECTRE diff --git a/esphome/components/espectre/select/espectre_select.cpp b/esphome/components/espectre/select/espectre_select.cpp deleted file mode 100644 index 9569b2955b5..00000000000 --- a/esphome/components/espectre/select/espectre_select.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include "espectre_select.h" - -#ifdef USE_ESPECTRE - -namespace esphome::espectre { - -void TrafficModeSelect::control(size_t index) { this->parent_->request_traffic_generator_mode(this->option_at(index)); } - -} // namespace esphome::espectre - -#endif // USE_ESPECTRE diff --git a/esphome/components/espectre/select/espectre_select.h b/esphome/components/espectre/select/espectre_select.h deleted file mode 100644 index 3d27cfabf9e..00000000000 --- a/esphome/components/espectre/select/espectre_select.h +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once - -#include "esphome/core/defines.h" - -#ifdef USE_ESPECTRE - -#include "esphome/components/select/select.h" -#include "../espectre.h" - -namespace esphome::espectre { - -class TrafficModeSelect final : public select::Select, public Parented { - protected: - void control(size_t index) override; -}; - -} // namespace esphome::espectre - -#endif // USE_ESPECTRE