diff --git a/esphome/components/kt0803/__init__.py b/esphome/components/kt0803/__init__.py index c99f6f58f3..ee1b629e76 100644 --- a/esphome/components/kt0803/__init__.py +++ b/esphome/components/kt0803/__init__.py @@ -13,18 +13,13 @@ from esphome.const import ( DEVICE_CLASS_POWER, DEVICE_CLASS_EMPTY, ) +import logging + +_LOGGER = logging.getLogger(__name__) CODEOWNERS = ["@gabest11"] DEPENDENCIES = ["i2c"] -AUTO_LOAD = [ - "sensor", - "text_sensor", - "binary_sensor", - "number", - "switch", - "select", - "text", -] +AUTO_LOAD = ["binary_sensor", "number", "switch", "select", "text"] MULTI_CONF = True UNIT_MEGA_HERTZ = "MHz" @@ -72,10 +67,10 @@ CONF_SWITCH_MODE = "switch_mode" CONF_AU_ENHANCE = "au_enhance" # ref_clk CONF_ENABLE = "enable" -CONF_REF_CLK = "ref_clk" +CONF_SEL = "sel" # xtal # CONF_ENABLE = "enable" -CONF_SEL = "sel" +# CONF_SEL = "sel" # alc # CONF_ENABLE = "enable" # CONF_GAIN = "gain" @@ -95,10 +90,6 @@ CONF_LOW_COUNTER = "low_counter" CONF_PW_OK = "pw_ok" CONF_SLNCID = "slncid" -SetFrequencyAction = kt0803_ns.class_( - "SetFrequencyAction", automation.Action, cg.Parented.template(KT0803Component) -) - ChipId = kt0803_ns.enum("ChipId", True) CHIP_ID = { "KT0803": ChipId.KT0803, @@ -371,11 +362,11 @@ CONFIG_SCHEMA = ( cv.Required(CONF_CHIP_ID): cv.enum(CHIP_ID), cv.Optional(CONF_FREQUENCY, default=87.50): cv.float_range(70, 108), cv.Optional(CONF_DEVIATION, default="75kHz"): cv.enum(FREQUENCY_DEVIATION), - cv.Optional(CONF_PGA, default=0): cv.float_range(-15, 12), - cv.Optional(CONF_RFGAIN, default=108): cv.float_range(95.5, 108), cv.Optional(CONF_MUTE, default=False): cv.boolean, cv.Optional(CONF_MONO, default=False): cv.boolean, cv.Optional(CONF_PRE_EMPHASIS, default="75us"): cv.enum(PRE_EMPHASIS), + cv.Optional(CONF_PGA, default=0): cv.float_range(-15, 12), + cv.Optional(CONF_RFGAIN, default=108): cv.float_range(95.5, 108), cv.Optional(CONF_PILOT_TONE_AMPLITUDE, default="Low"): cv.enum( PILOT_TONE_AMPLITUDE ), @@ -402,6 +393,92 @@ CONFIG_SCHEMA = ( .extend(i2c.i2c_device_schema(0x3E)) ) +VARIABLES = { + None: [ + [CONF_CHIP_ID], + [CONF_FREQUENCY], + [CONF_DEVIATION], + [CONF_MUTE], + [CONF_MONO], + [CONF_PRE_EMPHASIS], + [CONF_PGA], + [CONF_RFGAIN], + [CONF_PILOT_TONE_AMPLITUDE], + [CONF_BASS_BOOST_CONTROL], + [CONF_AUTO_PA_DOWN], + [CONF_PA_DOWN], + [CONF_STANDBY_ENABLE], + [CONF_PA_BIAS], + [CONF_AUDIO_LIMITER_LEVEL], + [CONF_SWITCH_MODE], + [CONF_AU_ENHANCE], + ], + CONF_REF_CLK: [ + [CONF_ENABLE], + [CONF_SEL], + ], + CONF_XTAL: [ + [CONF_ENABLE], + [CONF_SEL], + ], + CONF_ALC: [ + [CONF_ENABLE], + [CONF_GAIN], + [CONF_ATTACK_TIME], + [CONF_DECAY_TIME], + [CONF_HOLD_TIME], + [CONF_HIGH], + [CONF_LOW], + ], + CONF_SILENCE: [ + [CONF_DETECTION], + [CONF_DURATION], + [CONF_HIGH], + [CONF_LOW], + [CONF_HIGH_COUNTER], + [CONF_LOW_COUNTER], + ], +} + +SENSORS = { + CONF_SENSOR: [ + [CONF_PW_OK, "binary_sensor"], + [CONF_SLNCID, "binary_sensor"], + ] +} + + +async def for_each_conf(config, vars, callback): + for section in vars: + c = config[section] if section in config else config + for args in vars[section]: + setter = "set_" + if section is not None and section != CONF_SENSOR: + setter += section + "_" + setter += args[0] + if cc := c.get(args[0]): + await callback(cc, args, setter) + + +async def to_code(config): + var = cg.new_Pvariable(config[CONF_ID]) + await cg.register_component(var, config) + await i2c.register_i2c_device(var, config) + + async def set_var(c, a, s): + cg.add(getattr(var, s)(c)) + + await for_each_conf(config, VARIABLES, set_var) + + async def new_sensor(c, args, setter): + s = None + match args[1]: + case "binary_sensor": + s = await binary_sensor.new_binary_sensor(c) + cg.add(getattr(var, setter + "_" + args[1])(s)) + + await for_each_conf(config, SENSORS, new_sensor) + FREQUENCY_SCHEMA = automation.maybe_simple_id( { @@ -410,6 +487,10 @@ FREQUENCY_SCHEMA = automation.maybe_simple_id( } ) +SetFrequencyAction = kt0803_ns.class_( + "SetFrequencyAction", automation.Action, cg.Parented.template(KT0803Component) +) + @automation.register_action( "kt0803.set_frequency", SetFrequencyAction, FREQUENCY_SCHEMA @@ -421,63 +502,3 @@ async def tune_frequency_action_to_code(config, action_id, template_arg, args): template_ = await cg.templatable(frequency, args, cg.float_) cg.add(var.set_frequency(template_)) return var - - -async def set_var(config, id, setter): - if c := config.get(id): - cg.add(setter(c)) - - -async def set_binary_sensor(config, id, setter): - if c := config.get(id): - s = await binary_sensor.new_binary_sensor(c) - cg.add(setter(s)) - - -async def to_code(config): - var = cg.new_Pvariable(config[CONF_ID]) - await cg.register_component(var, config) - await i2c.register_i2c_device(var, config) - await set_var(config, CONF_CHIP_ID, var.set_chip_id) - await set_var(config, CONF_FREQUENCY, var.set_frequency) - await set_var(config, CONF_DEVIATION, var.set_deviation) - await set_var(config, CONF_MUTE, var.set_mute) - await set_var(config, CONF_MONO, var.set_mono) - await set_var(config, CONF_PRE_EMPHASIS, var.set_pre_emphasis) - await set_var(config, CONF_PGA, var.set_pga) - await set_var(config, CONF_RFGAIN, var.set_rfgain) - await set_var(config, CONF_PILOT_TONE_AMPLITUDE, var.set_pilot_tone_amplitude) - await set_var(config, CONF_BASS_BOOST_CONTROL, var.set_bass_boost_control) - await set_var(config, CONF_AUTO_PA_DOWN, var.set_auto_pa_down) - await set_var(config, CONF_PA_DOWN, var.set_pa_down) - await set_var(config, CONF_STANDBY_ENABLE, var.set_standby_enable) - await set_var(config, CONF_PA_BIAS, var.set_pa_bias) - await set_var(config, CONF_AUDIO_LIMITER_LEVEL, var.set_audio_limiter_level) - await set_var(config, CONF_SWITCH_MODE, var.set_switch_mode) - await set_var(config, CONF_AU_ENHANCE, var.set_au_enhance) - if ref_clk_config := config.get(CONF_REF_CLK): - await set_var(ref_clk_config, CONF_ENABLE, var.set_ref_clk_enable) - await set_var(ref_clk_config, CONF_REF_CLK, var.set_ref_clk) - if xtal_config := config.get(CONF_XTAL): - await set_var(xtal_config, CONF_ENABLE, var.set_xtal_enable) - await set_var(xtal_config, CONF_SEL, var.set_xtal_sel) - if alc_config := config.get(CONF_ALC): - await set_var(alc_config, CONF_ENABLE, var.set_alc_enable) - await set_var(alc_config, CONF_GAIN, var.set_alc_gain) - await set_var(alc_config, CONF_ATTACK_TIME, var.set_alc_attack_time) - await set_var(alc_config, CONF_DECAY_TIME, var.set_alc_decay_time) - await set_var(alc_config, CONF_HOLD_TIME, var.set_alc_hold_time) - await set_var(alc_config, CONF_HIGH, var.set_alc_high) - await set_var(alc_config, CONF_LOW, var.set_alc_low) - if silence_config := config.get(CONF_SILENCE): - await set_var(silence_config, CONF_DETECTION, var.set_silence_detection) - await set_var(silence_config, CONF_DURATION, var.set_silence_duration) - await set_var(silence_config, CONF_HIGH, var.set_silence_high) - await set_var(silence_config, CONF_LOW, var.set_silence_low) - await set_var(silence_config, CONF_HIGH_COUNTER, var.set_silence_high_counter) - await set_var(silence_config, CONF_LOW_COUNTER, var.set_silence_low_counter) - if sensor_config := config.get(CONF_SENSOR): - await set_binary_sensor(sensor_config, CONF_PW_OK, var.set_pw_ok_binary_sensor) - await set_binary_sensor( - sensor_config, CONF_SLNCID, var.set_slncid_binary_sensor - ) diff --git a/esphome/components/kt0803/kt0803.cpp b/esphome/components/kt0803/kt0803.cpp index e4eae3200a..0c64b9fbb1 100644 --- a/esphome/components/kt0803/kt0803.cpp +++ b/esphome/components/kt0803/kt0803.cpp @@ -133,8 +133,6 @@ void KT0803Component::setup() { } } - this->publish_pw_ok(); - this->publish_slncid(); this->publish_frequency(); this->publish_deviation(); this->publish_mute(); @@ -152,7 +150,7 @@ void KT0803Component::setup() { this->publish_switch_mode(); this->publish_au_enhance(); this->publish_ref_clk_enable(); - this->publish_ref_clk(); + this->publish_ref_clk_sel(); this->publish_xtal_enable(); this->publish_xtal_sel(); this->publish_alc_enable(); @@ -168,6 +166,8 @@ void KT0803Component::setup() { this->publish_silence_duration(); this->publish_silence_high_counter(); this->publish_silence_low_counter(); + this->publish_pw_ok_binary_sensor(); + this->publish_slncid_binary_sensor(); } void KT0803Component::dump_config() { @@ -201,8 +201,8 @@ void KT0803Component::update() { void KT0803Component::loop() { if (this->read_reg_(0x0F)) { - this->publish_pw_ok(); - this->publish_slncid(); + this->publish_pw_ok_binary_sensor(); + this->publish_slncid_binary_sensor(); } } @@ -516,16 +516,16 @@ void KT0803Component::set_ref_clk_enable(bool value) { bool KT0803Component::get_ref_clk_enable() { return this->state_.DCLK == 1; } -void KT0803Component::set_ref_clk(ReferenceClock value) { +void KT0803Component::set_ref_clk_sel(ReferenceClock value) { CHECK_ENUM(value) this->state_.REF_CLK = (uint8_t) value; if (this->chip_id_ == ChipId::KT0803L) { this->write_reg_(0x1E); } - this->publish_ref_clk(); + this->publish_ref_clk_sel(); } -ReferenceClock KT0803Component::get_ref_clk() { return (ReferenceClock) this->state_.REF_CLK; } +ReferenceClock KT0803Component::get_ref_clk_sel() { return (ReferenceClock) this->state_.REF_CLK; } void KT0803Component::set_xtal_enable(bool value) { this->state_.XTALD = value ? 0 : 1; @@ -715,9 +715,11 @@ SilenceLowLevelCounter KT0803Component::get_silence_low_counter() { return (SilenceLowLevelCounter) this->state_.SLNCCNTLOW; } -bool KT0803Component::get_pw_ok() { return this->state_.PW_OK != 0; } +bool KT0803Component::get_pw_ok_binary_sensor() { return this->state_.PW_OK != 0; } -bool KT0803Component::get_slncid() { return this->state_.SLNCID != 0; } +bool KT0803Component::get_slncid_binary_sensor() { return this->state_.SLNCID != 0; } + +// publish template void KT0803Component::publish(S *s, T state) { if (s != nullptr) { diff --git a/esphome/components/kt0803/kt0803.h b/esphome/components/kt0803/kt0803.h index 0388096430..43fdeadd8b 100644 --- a/esphome/components/kt0803/kt0803.h +++ b/esphome/components/kt0803/kt0803.h @@ -12,58 +12,11 @@ #include "esphome/components/text/text.h" #include #include "kt0803defs.h" +#include "kt0803sub.h" namespace esphome { namespace kt0803 { -#ifndef SUB_TEXT -#define SUB_TEXT(name) \ - protected: \ - text::Text *name##_text_{nullptr}; \ -\ - public: \ - void set_##name##_text(text::Text *text) { this->name##_text_ = text; } -#endif - -#define SUB_NUMBER_EX(name, type) \ - SUB_NUMBER(name) \ - void publish_##name() { this->publish(this->name##_number_, (float) this->get_##name()); } \ - void set_##name(type value); \ - type get_##name(); - -#define SUB_SWITCH_EX(name) \ - SUB_SWITCH(name) \ - void publish_##name() { this->publish_switch(this->name##_switch_, this->get_##name()); } \ - void set_##name(bool value); \ - bool get_##name(); - -#define SUB_SELECT_EX(name, type) \ - SUB_SELECT(name) \ - void publish_##name() { this->publish_select(this->name##_select_, (size_t) this->get_##name()); } \ - void set_##name(type value); \ - type get_##name(); - -#define SUB_TEXT_EX(name) \ - SUB_TEXT(name) \ - void publish_##name() { this->publish(this->name##_text_, this->get_##name()); } \ - void set_##name(const std::string &value); \ - std::string get_##name(); - -#define SUB_SENSOR_EX(name) \ - SUB_SENSOR(name) \ - void publish_##name() { this->publish(this->name##_sensor_, (float) this->get_##name()); } \ - float get_##name(); - -#define SUB_BINARY_SENSOR_EX(name) \ - SUB_BINARY_SENSOR(name) \ - void publish_##name() { this->publish(this->name##_binary_sensor_, this->get_##name()); } \ - bool get_##name(); - -#define SUB_TEXT_SENSOR_EX(name) \ - SUB_TEXT_SENSOR(name) \ - void publish_##name() { this->publish(this->name##_text_sensor_, this->get_##name()); } \ - std::string get_##name(); - class KT0803Component : public PollingComponent, public i2c::I2CDevice { ChipId chip_id_; // no way to detect it bool reset_; @@ -89,41 +42,41 @@ class KT0803Component : public PollingComponent, public i2c::I2CDevice { void update() override; void loop() override; - SUB_NUMBER_EX(frequency, float) - SUB_SELECT_EX(deviation, FrequencyDeviation) - SUB_SWITCH_EX(mute) - SUB_SWITCH_EX(mono) - SUB_SELECT_EX(pre_emphasis, PreEmphasis) - SUB_NUMBER_EX(pga, float) - SUB_NUMBER_EX(rfgain, float) - SUB_SELECT_EX(pilot_tone_amplitude, PilotToneAmplitude) - SUB_SELECT_EX(bass_boost_control, BassBoostControl) - SUB_SWITCH_EX(auto_pa_down) - SUB_SWITCH_EX(pa_down) - SUB_SWITCH_EX(standby_enable) - SUB_SWITCH_EX(pa_bias) - SUB_SELECT_EX(audio_limiter_level, AudioLimiterLevel) - SUB_SELECT_EX(switch_mode, SwitchMode) - SUB_SWITCH_EX(au_enhance) - SUB_SWITCH_EX(ref_clk_enable) - SUB_SELECT_EX(ref_clk, ReferenceClock) - SUB_SWITCH_EX(xtal_enable) - SUB_SELECT_EX(xtal_sel, XtalSel) - SUB_SWITCH_EX(alc_enable) - SUB_NUMBER_EX(alc_gain, float) - SUB_SELECT_EX(alc_attack_time, AlcTime) - SUB_SELECT_EX(alc_decay_time, AlcTime) - SUB_SELECT_EX(alc_hold_time, AlcHoldTime) - SUB_SELECT_EX(alc_high, AlcHigh) - SUB_SELECT_EX(alc_low, AlcLow) - SUB_SWITCH_EX(silence_detection) - SUB_SELECT_EX(silence_duration, SilenceLowAndHighLevelDurationTime) - SUB_SELECT_EX(silence_high, SilenceHigh) - SUB_SELECT_EX(silence_low, SilenceLow) - SUB_SELECT_EX(silence_high_counter, SilenceHighLevelCounter) - SUB_SELECT_EX(silence_low_counter, SilenceLowLevelCounter) - SUB_BINARY_SENSOR_EX(pw_ok) - SUB_BINARY_SENSOR_EX(slncid) + KT0803_SUB_NUMBER(frequency, float) + KT0803_SUB_SELECT(deviation, FrequencyDeviation) + KT0803_SUB_SWITCH(mute) + KT0803_SUB_SWITCH(mono) + KT0803_SUB_SELECT(pre_emphasis, PreEmphasis) + KT0803_SUB_NUMBER(pga, float) + KT0803_SUB_NUMBER(rfgain, float) + KT0803_SUB_SELECT(pilot_tone_amplitude, PilotToneAmplitude) + KT0803_SUB_SELECT(bass_boost_control, BassBoostControl) + KT0803_SUB_SWITCH(auto_pa_down) + KT0803_SUB_SWITCH(pa_down) + KT0803_SUB_SWITCH(standby_enable) + KT0803_SUB_SWITCH(pa_bias) + KT0803_SUB_SELECT(audio_limiter_level, AudioLimiterLevel) + KT0803_SUB_SELECT(switch_mode, SwitchMode) + KT0803_SUB_SWITCH(au_enhance) + KT0803_SUB_SWITCH(ref_clk_enable) + KT0803_SUB_SELECT(ref_clk_sel, ReferenceClock) + KT0803_SUB_SWITCH(xtal_enable) + KT0803_SUB_SELECT(xtal_sel, XtalSel) + KT0803_SUB_SWITCH(alc_enable) + KT0803_SUB_NUMBER(alc_gain, float) + KT0803_SUB_SELECT(alc_attack_time, AlcTime) + KT0803_SUB_SELECT(alc_decay_time, AlcTime) + KT0803_SUB_SELECT(alc_hold_time, AlcHoldTime) + KT0803_SUB_SELECT(alc_high, AlcHigh) + KT0803_SUB_SELECT(alc_low, AlcLow) + KT0803_SUB_SWITCH(silence_detection) + KT0803_SUB_SELECT(silence_duration, SilenceLowAndHighLevelDurationTime) + KT0803_SUB_SELECT(silence_high, SilenceHigh) + KT0803_SUB_SELECT(silence_low, SilenceLow) + KT0803_SUB_SELECT(silence_high_counter, SilenceHighLevelCounter) + KT0803_SUB_SELECT(silence_low_counter, SilenceLowLevelCounter) + KT0803_SUB_BINARY_SENSOR(pw_ok) + KT0803_SUB_BINARY_SENSOR(slncid) void set_chip_id(ChipId value); ChipId get_chip_id(); diff --git a/esphome/components/kt0803/kt0803defs.h b/esphome/components/kt0803/kt0803defs.h index ccbe5dec48..a5b63aa6bc 100644 --- a/esphome/components/kt0803/kt0803defs.h +++ b/esphome/components/kt0803/kt0803defs.h @@ -6,14 +6,11 @@ namespace kt0803 { static const float CHSEL_MIN = 70.0f; static const float CHSEL_MAX = 108.0f; static const float CHSEL_STEP = 0.05; - static const float PGA_MIN = -15; static const float PGA_MAX = 12; static const float PGA_STEP = 1; - static const float RFGAIN_MIN = 95.5f; static const float RFGAIN_MAX = 108.0f; - static const float ALC_GAIN_MIN = -15; static const float ALC_GAIN_MAX = 6; diff --git a/esphome/components/kt0803/kt0803sub.h b/esphome/components/kt0803/kt0803sub.h new file mode 100644 index 0000000000..767ab8f43d --- /dev/null +++ b/esphome/components/kt0803/kt0803sub.h @@ -0,0 +1,52 @@ +#pragma once + +#ifndef SUB_TEXT +#define SUB_TEXT(name) \ + protected: \ + text::Text *name##_text_{nullptr}; \ +\ + public: \ + void set_##name##_text(text::Text *text) { this->name##_text_ = text; } +#endif + +#define KT0803_SUB_NUMBER(name, type) \ + SUB_NUMBER(name) \ + void publish_##name() { this->publish(this->name##_number_, (float) this->get_##name()); } \ + void set_##name(type value); \ + type get_##name(); + +#define KT0803_SUB_SWITCH(name) \ + SUB_SWITCH(name) \ + void publish_##name() { this->publish_switch(this->name##_switch_, this->get_##name()); } \ + void set_##name(bool value); \ + bool get_##name(); + +#define KT0803_SUB_SELECT(name, type) \ + SUB_SELECT(name) \ + void publish_##name() { this->publish_select(this->name##_select_, (size_t) this->get_##name()); } \ + void set_##name(type value); \ + type get_##name(); + +#define KT0803_SUB_TEXT(name) \ + SUB_TEXT(name) \ + void publish_##name() { this->publish(this->name##_text_, this->get_##name()); } \ + void set_##name(const std::string &value); \ + std::string get_##name(); + +#define KT0803_SUB_SENSOR(name) \ + SUB_SENSOR(name) \ + void publish_##name##_sensor() { this->publish(this->name##_sensor_, (float) this->get_##name##_sensor()); } \ + float get_##name##_sensor(); + +#define KT0803_SUB_BINARY_SENSOR(name) \ + SUB_BINARY_SENSOR(name) \ + void publish_##name##_binary_sensor() { \ + this->publish(this->name##_binary_sensor_, this->get_##name##_binary_sensor()); \ + } \ + bool get_##name##_binary_sensor(); + +#define KT0803_SUB_TEXT_SENSOR(name) \ + SUB_TEXT_SENSOR(name) \ + void publish_##name##_text_sensor() { this->publish(this->name##_text_sensor_, this->get_##name##_text_sensor()); } \ + std::string get_##name##_text_sensor(); + diff --git a/esphome/components/kt0803/number/__init__.py b/esphome/components/kt0803/number/__init__.py index 50331e3bd8..97adc96de5 100644 --- a/esphome/components/kt0803/number/__init__.py +++ b/esphome/components/kt0803/number/__init__.py @@ -4,6 +4,7 @@ import esphome.config_validation as cv from esphome.const import ( CONF_FREQUENCY, CONF_GAIN, + CONF_MODE, UNIT_DECIBEL, DEVICE_CLASS_FREQUENCY, DEVICE_CLASS_SIGNAL_STRENGTH, @@ -18,6 +19,7 @@ from .. import ( CONF_RFGAIN, UNIT_MEGA_HERTZ, UNIT_DECIBEL_MICRO_VOLT, + for_each_conf, ) FrequencyNumber = kt0803_ns.class_("FrequencyNumber", number.Number) @@ -61,53 +63,36 @@ CONFIG_SCHEMA = cv.Schema( } ) - -async def new_number(p, config, id, setter, min_value, max_value, step): - if c := config.get(id): - n = await number.new_number( - c, min_value=min_value, max_value=max_value, step=step - ) - await cg.register_parented(n, p) - cg.add(setter(n)) - return n +VARIABLES = { + None: [ + [ + CONF_FREQUENCY, + kt0803_ns.CHSEL_MIN, + kt0803_ns.CHSEL_MAX, + kt0803_ns.CHSEL_STEP, + None, + ], + [CONF_PGA, kt0803_ns.PGA_MIN, kt0803_ns.PGA_MAX, kt0803_ns.PGA_STEP, None], + [CONF_RFGAIN, kt0803_ns.RFGAIN_MIN, kt0803_ns.RFGAIN_MAX, 0.1, None], + ], + CONF_ALC: [ + [CONF_GAIN, kt0803_ns.ALC_GAIN_MIN, kt0803_ns.ALC_GAIN_MAX, 3, None], + ], +} async def to_code(config): - p = await cg.get_variable(config[CONF_KT0803_ID]) - await new_number( - p, - config, - CONF_FREQUENCY, - p.set_frequency_number, - kt0803_ns.CHSEL_MIN, - kt0803_ns.CHSEL_MAX, - kt0803_ns.CHSEL_STEP, - ) - await new_number( - p, - config, - CONF_PGA, - p.set_pga_number, - kt0803_ns.PGA_MIN, - kt0803_ns.PGA_MAX, - kt0803_ns.PGA_STEP, - ) - await new_number( - p, - config, - CONF_RFGAIN, - p.set_rfgain_number, - kt0803_ns.RFGAIN_MIN, - kt0803_ns.RFGAIN_MAX, - 0.1, - ) - if alc_config := config.get(CONF_ALC): - await new_number( - p, - alc_config, - CONF_GAIN, - p.set_alc_gain_number, - kt0803_ns.ALC_GAIN_MIN, - kt0803_ns.ALC_GAIN_MAX, - 3, + parent = await cg.get_variable(config[CONF_KT0803_ID]) + + async def new_number(c, args, setter): + # only override mode when it's set to auto in user config + if CONF_MODE not in c or c[CONF_MODE] == number.NumberMode.NUMBER_MODE_AUTO: + if args[4] is not None: + c[CONF_MODE] = args[4] + n = await number.new_number( + c, min_value=args[1], max_value=args[2], step=args[3] ) + await cg.register_parented(n, parent) + cg.add(getattr(parent, setter + "_number")(n)) + + await for_each_conf(config, VARIABLES, new_number) diff --git a/esphome/components/kt0803/number/alc_gain_number.cpp b/esphome/components/kt0803/number/alc_gain_number.cpp deleted file mode 100644 index 5d9aefbf47..0000000000 --- a/esphome/components/kt0803/number/alc_gain_number.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "alc_gain_number.h" - -namespace esphome { -namespace kt0803 { - -void AlcGainNumber::control(float value) { - this->publish_state(value); - this->parent_->set_alc_gain(value); -} - -} // namespace kt0803 -} // namespace esphome diff --git a/esphome/components/kt0803/number/alc_gain_number.h b/esphome/components/kt0803/number/alc_gain_number.h deleted file mode 100644 index 1091bba7f8..0000000000 --- a/esphome/components/kt0803/number/alc_gain_number.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include "esphome/components/number/number.h" -#include "../kt0803.h" - -namespace esphome { -namespace kt0803 { - -class AlcGainNumber : public number::Number, public Parented { - public: - AlcGainNumber() = default; - - protected: - void control(float value) override; -}; - -} // namespace kt0803 -} // namespace esphome diff --git a/esphome/components/kt0803/number/frequency_number.cpp b/esphome/components/kt0803/number/frequency_number.cpp deleted file mode 100644 index 30cb39e8b5..0000000000 --- a/esphome/components/kt0803/number/frequency_number.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "frequency_number.h" - -namespace esphome { -namespace kt0803 { - -void FrequencyNumber::control(float value) { - this->publish_state(value); - this->parent_->set_frequency(value); -} - -} // namespace kt0803 -} // namespace esphome diff --git a/esphome/components/kt0803/number/frequency_number.h b/esphome/components/kt0803/number/frequency_number.h deleted file mode 100644 index ba7c69b49b..0000000000 --- a/esphome/components/kt0803/number/frequency_number.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include "esphome/components/number/number.h" -#include "../kt0803.h" - -namespace esphome { -namespace kt0803 { - -class FrequencyNumber : public number::Number, public Parented { - public: - FrequencyNumber() = default; - - protected: - void control(float value) override; -}; - -} // namespace kt0803 -} // namespace esphome diff --git a/esphome/components/kt0803/number/number.h b/esphome/components/kt0803/number/number.h new file mode 100644 index 0000000000..53c801b8df --- /dev/null +++ b/esphome/components/kt0803/number/number.h @@ -0,0 +1,54 @@ +#pragma once + +#include "esphome/components/number/number.h" +#include "../kt0803.h" + +namespace esphome { +namespace kt0803 { + +class AlcGainNumber : public number::Number, public Parented { + public: + AlcGainNumber() = default; + + protected: + void control(float value) override { + this->publish_state(value); + this->parent_->set_alc_gain(value); + } +}; + +class FrequencyNumber : public number::Number, public Parented { + public: + FrequencyNumber() = default; + + protected: + void control(float value) override { + this->publish_state(value); + this->parent_->set_frequency(value); + } +}; + +class PgaNumber : public number::Number, public Parented { + public: + PgaNumber() = default; + + protected: + void control(float value) override { + this->publish_state(value); + this->parent_->set_pga(value); + } +}; + +class RfGainNumber : public number::Number, public Parented { + public: + RfGainNumber() = default; + + protected: + void control(float value) override { + this->publish_state(value); + this->parent_->set_rfgain(value); + } +}; + +} // namespace kt0803 +} // namespace esphome diff --git a/esphome/components/kt0803/number/pga_number.cpp b/esphome/components/kt0803/number/pga_number.cpp deleted file mode 100644 index 876468ddeb..0000000000 --- a/esphome/components/kt0803/number/pga_number.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "pga_number.h" - -namespace esphome { -namespace kt0803 { - -void PgaNumber::control(float value) { - this->publish_state(value); - this->parent_->set_pga(value); -} - -} // namespace kt0803 -} // namespace esphome diff --git a/esphome/components/kt0803/number/pga_number.h b/esphome/components/kt0803/number/pga_number.h deleted file mode 100644 index d5adade8e4..0000000000 --- a/esphome/components/kt0803/number/pga_number.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include "esphome/components/number/number.h" -#include "../kt0803.h" - -namespace esphome { -namespace kt0803 { - -class PgaNumber : public number::Number, public Parented { - public: - PgaNumber() = default; - - protected: - void control(float value) override; -}; - -} // namespace kt0803 -} // namespace esphome diff --git a/esphome/components/kt0803/number/rfgain_number.cpp b/esphome/components/kt0803/number/rfgain_number.cpp deleted file mode 100644 index 04399b6b4e..0000000000 --- a/esphome/components/kt0803/number/rfgain_number.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "rfgain_number.h" - -namespace esphome { -namespace kt0803 { - -void RfGainNumber::control(float value) { - this->publish_state(value); - this->parent_->set_rfgain(value); -} - -} // namespace kt0803 -} // namespace esphome diff --git a/esphome/components/kt0803/number/rfgain_number.h b/esphome/components/kt0803/number/rfgain_number.h deleted file mode 100644 index 33e91fedaa..0000000000 --- a/esphome/components/kt0803/number/rfgain_number.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include "esphome/components/number/number.h" -#include "../kt0803.h" - -namespace esphome { -namespace kt0803 { - -class RfGainNumber : public number::Number, public Parented { - public: - RfGainNumber() = default; - - protected: - void control(float value) override; -}; - -} // namespace kt0803 -} // namespace esphome diff --git a/esphome/components/kt0803/select/__init__.py b/esphome/components/kt0803/select/__init__.py index 7335ab32eb..b77af22baa 100644 --- a/esphome/components/kt0803/select/__init__.py +++ b/esphome/components/kt0803/select/__init__.py @@ -48,6 +48,7 @@ from .. import ( SILENCE_LOW_AND_HIGH_LEVEL_DURATION_TIME, SILENCE_HIGH_LEVEL_COUNTER, SILENCE_LOW_LEVEL_COUNTER, + for_each_conf, ) FrequencyDeviationSelect = kt0803_ns.class_("FrequencyDeviationSelect", select.Select) @@ -189,88 +190,44 @@ CONFIG_SCHEMA = cv.Schema( } ) - -async def new_select(p, config, id, setter, options): - if c := config.get(id): - s = await select.new_select(c, options=list(options.keys())) - await cg.register_parented(s, p) - cg.add(setter(s)) - return s +VARIABLES = { + None: [ + [CONF_DEVIATION, FREQUENCY_DEVIATION], + [CONF_PRE_EMPHASIS, PRE_EMPHASIS], + [CONF_PILOT_TONE_AMPLITUDE, PILOT_TONE_AMPLITUDE], + [CONF_BASS_BOOST_CONTROL, BASS_BOOST_CONTROL], + [CONF_AUDIO_LIMITER_LEVEL, AUDIO_LIMITER_LEVEL], + [CONF_SWITCH_MODE, SWITCH_MODE], + ], + CONF_REF_CLK: [ + [CONF_SEL, REFERENCE_CLOCK], + ], + CONF_XTAL: [ + [CONF_SEL, XTAL_SEL], + ], + CONF_ALC: [ + [CONF_ATTACK_TIME, ALC_TIME], + [CONF_DECAY_TIME, ALC_TIME], + [CONF_HOLD_TIME, ALC_HOLD_TIME], + [CONF_HIGH, ALC_HIGH], + [CONF_LOW, ALC_LOW], + ], + CONF_SILENCE: [ + [CONF_DURATION, SILENCE_LOW_AND_HIGH_LEVEL_DURATION_TIME], + [CONF_HIGH, SILENCE_HIGH], + [CONF_LOW, SILENCE_LOW], + [CONF_HIGH_COUNTER, SILENCE_HIGH_LEVEL_COUNTER], + [CONF_LOW_COUNTER, SILENCE_LOW_LEVEL_COUNTER], + ], +} async def to_code(config): - p = await cg.get_variable(config[CONF_KT0803_ID]) - await new_select( - p, config, CONF_DEVIATION, p.set_deviation_select, FREQUENCY_DEVIATION - ) - await new_select( - p, config, CONF_PRE_EMPHASIS, p.set_pre_emphasis_select, PRE_EMPHASIS - ) - await new_select( - p, - config, - CONF_PILOT_TONE_AMPLITUDE, - p.set_pilot_tone_amplitude_select, - PILOT_TONE_AMPLITUDE, - ) - await new_select( - p, - config, - CONF_BASS_BOOST_CONTROL, - p.set_bass_boost_control_select, - BASS_BOOST_CONTROL, - ) - await new_select( - p, - config, - CONF_AUDIO_LIMITER_LEVEL, - p.set_audio_limiter_level_select, - AUDIO_LIMITER_LEVEL, - ) - await new_select(p, config, CONF_SWITCH_MODE, p.set_switch_mode_select, SWITCH_MODE) - if ref_clk_config := config.get(CONF_REF_CLK): - await new_select( - p, ref_clk_config, CONF_REF_CLK, p.set_ref_clk_select, REFERENCE_CLOCK - ) - if xtal_config := config.get(CONF_XTAL): - await new_select(p, xtal_config, CONF_SEL, p.set_xtal_sel_select, XTAL_SEL) - if alc_config := config.get(CONF_ALC): - await new_select( - p, alc_config, CONF_ATTACK_TIME, p.set_alc_attack_time_select, ALC_TIME - ) - await new_select( - p, alc_config, CONF_DECAY_TIME, p.set_alc_decay_time_select, ALC_TIME - ) - await new_select( - p, alc_config, CONF_HOLD_TIME, p.set_alc_hold_time_select, ALC_HOLD_TIME - ) - await new_select(p, alc_config, CONF_HIGH, p.set_alc_high_select, ALC_HIGH) - await new_select(p, alc_config, CONF_LOW, p.set_alc_low_select, ALC_LOW) - if silence_config := config.get(CONF_SILENCE): - await new_select( - p, - silence_config, - CONF_DURATION, - p.set_silence_duration_select, - SILENCE_LOW_AND_HIGH_LEVEL_DURATION_TIME, - ) - await new_select( - p, silence_config, CONF_HIGH, p.set_silence_high_select, SILENCE_HIGH - ) - await new_select( - p, silence_config, CONF_LOW, p.set_silence_low_select, SILENCE_LOW - ) - await new_select( - p, - silence_config, - CONF_HIGH_COUNTER, - p.set_silence_high_counter_select, - SILENCE_HIGH_LEVEL_COUNTER, - ) - await new_select( - p, - silence_config, - CONF_LOW_COUNTER, - p.set_silence_low_counter_select, - SILENCE_LOW_LEVEL_COUNTER, - ) + parent = await cg.get_variable(config[CONF_KT0803_ID]) + + async def new_select(c, args, setter): + s = await select.new_select(c, options=list(args[1].keys())) + await cg.register_parented(s, parent) + cg.add(getattr(parent, setter + "_select")(s)) + + await for_each_conf(config, VARIABLES, new_select) diff --git a/esphome/components/kt0803/select/alc_attack_time_select.cpp b/esphome/components/kt0803/select/alc_attack_time_select.cpp deleted file mode 100644 index 0cc2948b82..0000000000 --- a/esphome/components/kt0803/select/alc_attack_time_select.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "alc_attack_time_select.h" - -namespace esphome { -namespace kt0803 { - -void AlcAttackTimeSelect::control(const std::string &value) { - this->publish_state(value); - if (auto index = this->active_index()) { - this->parent_->set_alc_attack_time((AlcTime) *index); - } -} - -} // namespace kt0803 -} // namespace esphome diff --git a/esphome/components/kt0803/select/alc_attack_time_select.h b/esphome/components/kt0803/select/alc_attack_time_select.h deleted file mode 100644 index fe364f1fc1..0000000000 --- a/esphome/components/kt0803/select/alc_attack_time_select.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include "esphome/components/select/select.h" -#include "../kt0803.h" - -namespace esphome { -namespace kt0803 { - -class AlcAttackTimeSelect : public select::Select, public Parented { - public: - AlcAttackTimeSelect() = default; - - protected: - void control(const std::string &value) override; -}; - -} // namespace kt0803 -} // namespace esphome diff --git a/esphome/components/kt0803/select/alc_decay_time_select.cpp b/esphome/components/kt0803/select/alc_decay_time_select.cpp deleted file mode 100644 index 4b8312d419..0000000000 --- a/esphome/components/kt0803/select/alc_decay_time_select.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "alc_decay_time_select.h" - -namespace esphome { -namespace kt0803 { - -void AlcDecayTimeSelect::control(const std::string &value) { - this->publish_state(value); - if (auto index = this->active_index()) { - this->parent_->set_alc_decay_time((AlcTime) *index); - } -} - -} // namespace kt0803 -} // namespace esphome diff --git a/esphome/components/kt0803/select/alc_decay_time_select.h b/esphome/components/kt0803/select/alc_decay_time_select.h deleted file mode 100644 index 6785ea9a42..0000000000 --- a/esphome/components/kt0803/select/alc_decay_time_select.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include "esphome/components/select/select.h" -#include "../kt0803.h" - -namespace esphome { -namespace kt0803 { - -class AlcDecayTimeSelect : public select::Select, public Parented { - public: - AlcDecayTimeSelect() = default; - - protected: - void control(const std::string &value) override; -}; - -} // namespace kt0803 -} // namespace esphome diff --git a/esphome/components/kt0803/select/alc_high_select.cpp b/esphome/components/kt0803/select/alc_high_select.cpp deleted file mode 100644 index 321e8e0803..0000000000 --- a/esphome/components/kt0803/select/alc_high_select.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "alc_high_select.h" - -namespace esphome { -namespace kt0803 { - -void AlcHighSelect::control(const std::string &value) { - this->publish_state(value); - if (auto index = this->active_index()) { - this->parent_->set_alc_high((AlcHigh) *index); - } -} - -} // namespace kt0803 -} // namespace esphome diff --git a/esphome/components/kt0803/select/alc_high_select.h b/esphome/components/kt0803/select/alc_high_select.h deleted file mode 100644 index 154f4ff6b0..0000000000 --- a/esphome/components/kt0803/select/alc_high_select.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include "esphome/components/select/select.h" -#include "../kt0803.h" - -namespace esphome { -namespace kt0803 { - -class AlcHighSelect : public select::Select, public Parented { - public: - AlcHighSelect() = default; - - protected: - void control(const std::string &value) override; -}; - -} // namespace kt0803 -} // namespace esphome diff --git a/esphome/components/kt0803/select/alc_hold_time_select.cpp b/esphome/components/kt0803/select/alc_hold_time_select.cpp deleted file mode 100644 index a1e0732bad..0000000000 --- a/esphome/components/kt0803/select/alc_hold_time_select.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "alc_hold_time_select.h" - -namespace esphome { -namespace kt0803 { - -void AlcHoldTimeSelect::control(const std::string &value) { - this->publish_state(value); - if (auto index = this->active_index()) { - this->parent_->set_alc_hold_time((AlcHoldTime) *index); - } -} - -} // namespace kt0803 -} // namespace esphome diff --git a/esphome/components/kt0803/select/alc_hold_time_select.h b/esphome/components/kt0803/select/alc_hold_time_select.h deleted file mode 100644 index cbc430b9f6..0000000000 --- a/esphome/components/kt0803/select/alc_hold_time_select.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include "esphome/components/select/select.h" -#include "../kt0803.h" - -namespace esphome { -namespace kt0803 { - -class AlcHoldTimeSelect : public select::Select, public Parented { - public: - AlcHoldTimeSelect() = default; - - protected: - void control(const std::string &value) override; -}; - -} // namespace kt0803 -} // namespace esphome diff --git a/esphome/components/kt0803/select/alc_low_select.cpp b/esphome/components/kt0803/select/alc_low_select.cpp deleted file mode 100644 index 1e1dc648d4..0000000000 --- a/esphome/components/kt0803/select/alc_low_select.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "alc_low_select.h" - -namespace esphome { -namespace kt0803 { - -void AlcLowSelect::control(const std::string &value) { - this->publish_state(value); - if (auto index = this->active_index()) { - this->parent_->set_alc_low((AlcLow) *index); - } -} - -} // namespace kt0803 -} // namespace esphome diff --git a/esphome/components/kt0803/select/alc_low_select.h b/esphome/components/kt0803/select/alc_low_select.h deleted file mode 100644 index 90f5fa2386..0000000000 --- a/esphome/components/kt0803/select/alc_low_select.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include "esphome/components/select/select.h" -#include "../kt0803.h" - -namespace esphome { -namespace kt0803 { - -class AlcLowSelect : public select::Select, public Parented { - public: - AlcLowSelect() = default; - - protected: - void control(const std::string &value) override; -}; - -} // namespace kt0803 -} // namespace esphome diff --git a/esphome/components/kt0803/select/audio_limiter_level_select.cpp b/esphome/components/kt0803/select/audio_limiter_level_select.cpp deleted file mode 100644 index 8a3a7429c6..0000000000 --- a/esphome/components/kt0803/select/audio_limiter_level_select.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "audio_limiter_level_select.h" - -namespace esphome { -namespace kt0803 { - -void AudioLimiterLevelSelect::control(const std::string &value) { - this->publish_state(value); - if (auto index = this->active_index()) { - this->parent_->set_audio_limiter_level((AudioLimiterLevel) *index); - } -} - -} // namespace kt0803 -} // namespace esphome diff --git a/esphome/components/kt0803/select/audio_limiter_level_select.h b/esphome/components/kt0803/select/audio_limiter_level_select.h deleted file mode 100644 index 3c4533b91d..0000000000 --- a/esphome/components/kt0803/select/audio_limiter_level_select.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include "esphome/components/select/select.h" -#include "../kt0803.h" - -namespace esphome { -namespace kt0803 { - -class AudioLimiterLevelSelect : public select::Select, public Parented { - public: - AudioLimiterLevelSelect() = default; - - protected: - void control(const std::string &value) override; -}; - -} // namespace kt0803 -} // namespace esphome diff --git a/esphome/components/kt0803/select/bass_boost_control_select.cpp b/esphome/components/kt0803/select/bass_boost_control_select.cpp deleted file mode 100644 index 10be159fb7..0000000000 --- a/esphome/components/kt0803/select/bass_boost_control_select.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "bass_boost_control_select.h" - -namespace esphome { -namespace kt0803 { - -void BassBoostControlSelect::control(const std::string &value) { - this->publish_state(value); - if (auto index = this->active_index()) { - this->parent_->set_bass_boost_control((BassBoostControl) *index); - } -} - -} // namespace kt0803 -} // namespace esphome diff --git a/esphome/components/kt0803/select/bass_boost_control_select.h b/esphome/components/kt0803/select/bass_boost_control_select.h deleted file mode 100644 index 02e9233e73..0000000000 --- a/esphome/components/kt0803/select/bass_boost_control_select.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include "esphome/components/select/select.h" -#include "../kt0803.h" - -namespace esphome { -namespace kt0803 { - -class BassBoostControlSelect : public select::Select, public Parented { - public: - BassBoostControlSelect() = default; - - protected: - void control(const std::string &value) override; -}; - -} // namespace kt0803 -} // namespace esphome diff --git a/esphome/components/kt0803/select/deviation_select.cpp b/esphome/components/kt0803/select/deviation_select.cpp deleted file mode 100644 index 4e12a7d8e5..0000000000 --- a/esphome/components/kt0803/select/deviation_select.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "deviation_select.h" - -namespace esphome { -namespace kt0803 { - -void FrequencyDeviationSelect::control(const std::string &value) { - this->publish_state(value); - if (auto index = this->active_index()) { - this->parent_->set_deviation((FrequencyDeviation) *index); - } -} - -} // namespace kt0803 -} // namespace esphome diff --git a/esphome/components/kt0803/select/deviation_select.h b/esphome/components/kt0803/select/deviation_select.h deleted file mode 100644 index 6d37614ddc..0000000000 --- a/esphome/components/kt0803/select/deviation_select.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include "esphome/components/select/select.h" -#include "../kt0803.h" - -namespace esphome { -namespace kt0803 { - -class FrequencyDeviationSelect : public select::Select, public Parented { - public: - FrequencyDeviationSelect() = default; - - protected: - void control(const std::string &value) override; -}; - -} // namespace kt0803 -} // namespace esphome diff --git a/esphome/components/kt0803/select/pilot_tone_amplitude_select.cpp b/esphome/components/kt0803/select/pilot_tone_amplitude_select.cpp deleted file mode 100644 index deb52b743a..0000000000 --- a/esphome/components/kt0803/select/pilot_tone_amplitude_select.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "pilot_tone_amplitude_select.h" - -namespace esphome { -namespace kt0803 { - -void PilotToneAmplitudeSelect::control(const std::string &value) { - this->publish_state(value); - if (auto index = this->active_index()) { - this->parent_->set_pilot_tone_amplitude((PilotToneAmplitude) *index); - } -} - -} // namespace kt0803 -} // namespace esphome diff --git a/esphome/components/kt0803/select/pilot_tone_amplitude_select.h b/esphome/components/kt0803/select/pilot_tone_amplitude_select.h deleted file mode 100644 index be71d3b148..0000000000 --- a/esphome/components/kt0803/select/pilot_tone_amplitude_select.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include "esphome/components/select/select.h" -#include "../kt0803.h" - -namespace esphome { -namespace kt0803 { - -class PilotToneAmplitudeSelect : public select::Select, public Parented { - public: - PilotToneAmplitudeSelect() = default; - - protected: - void control(const std::string &value) override; -}; - -} // namespace kt0803 -} // namespace esphome diff --git a/esphome/components/kt0803/select/pre_emphasis_select.cpp b/esphome/components/kt0803/select/pre_emphasis_select.cpp deleted file mode 100644 index ad582c2493..0000000000 --- a/esphome/components/kt0803/select/pre_emphasis_select.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "pre_emphasis_select.h" - -namespace esphome { -namespace kt0803 { - -void PreEmphasisSelect::control(const std::string &value) { - this->publish_state(value); - if (auto index = this->active_index()) { - this->parent_->set_pre_emphasis((PreEmphasis) *index); - } -} - -} // namespace kt0803 -} // namespace esphome diff --git a/esphome/components/kt0803/select/pre_emphasis_select.h b/esphome/components/kt0803/select/pre_emphasis_select.h deleted file mode 100644 index a4017953f1..0000000000 --- a/esphome/components/kt0803/select/pre_emphasis_select.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include "esphome/components/select/select.h" -#include "../kt0803.h" - -namespace esphome { -namespace kt0803 { - -class PreEmphasisSelect : public select::Select, public Parented { - public: - PreEmphasisSelect() = default; - - protected: - void control(const std::string &value) override; -}; - -} // namespace kt0803 -} // namespace esphome diff --git a/esphome/components/kt0803/select/ref_clk_select.cpp b/esphome/components/kt0803/select/ref_clk_select.cpp deleted file mode 100644 index 5584fd1780..0000000000 --- a/esphome/components/kt0803/select/ref_clk_select.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "ref_clk_select.h" - -namespace esphome { -namespace kt0803 { - -void RefClkSelect::control(const std::string &value) { - this->publish_state(value); - if (auto index = this->active_index()) { - this->parent_->set_ref_clk((ReferenceClock) *index); - } -} - -} // namespace kt0803 -} // namespace esphome diff --git a/esphome/components/kt0803/select/ref_clk_select.h b/esphome/components/kt0803/select/ref_clk_select.h deleted file mode 100644 index ee2352f193..0000000000 --- a/esphome/components/kt0803/select/ref_clk_select.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include "esphome/components/select/select.h" -#include "../kt0803.h" - -namespace esphome { -namespace kt0803 { - -class RefClkSelect : public select::Select, public Parented { - public: - RefClkSelect() = default; - - protected: - void control(const std::string &value) override; -}; - -} // namespace kt0803 -} // namespace esphome diff --git a/esphome/components/kt0803/select/select.h b/esphome/components/kt0803/select/select.h new file mode 100644 index 0000000000..708d7f1f53 --- /dev/null +++ b/esphome/components/kt0803/select/select.h @@ -0,0 +1,190 @@ +#pragma once + +#include "esphome/components/select/select.h" +#include "../kt0803.h" + +namespace esphome { +namespace kt0803 { + +class AlcAttackTimeSelect : public select::Select, public Parented { + protected: + void control(const std::string &value) override { + this->publish_state(value); + if (auto index = this->active_index()) { + this->parent_->set_alc_attack_time((AlcTime) *index); + } + } +}; + +class AlcDecayTimeSelect : public select::Select, public Parented { + protected: + void control(const std::string &value) override { + this->publish_state(value); + if (auto index = this->active_index()) { + this->parent_->set_alc_decay_time((AlcTime) *index); + } + } +}; + +class AlcHighSelect : public select::Select, public Parented { + protected: + void control(const std::string &value) override { + this->publish_state(value); + if (auto index = this->active_index()) { + this->parent_->set_alc_high((AlcHigh) *index); + } + } +}; + +class AlcHoldTimeSelect : public select::Select, public Parented { + protected: + void control(const std::string &value) override { + this->publish_state(value); + if (auto index = this->active_index()) { + this->parent_->set_alc_hold_time((AlcHoldTime) *index); + } + } +}; + +class AlcLowSelect : public select::Select, public Parented { + protected: + void control(const std::string &value) override { + this->publish_state(value); + if (auto index = this->active_index()) { + this->parent_->set_alc_low((AlcLow) *index); + } + } +}; + +class AudioLimiterLevelSelect : public select::Select, public Parented { + protected: + void control(const std::string &value) override { + this->publish_state(value); + if (auto index = this->active_index()) { + this->parent_->set_audio_limiter_level((AudioLimiterLevel) *index); + } + } +}; + +class BassBoostControlSelect : public select::Select, public Parented { + protected: + void control(const std::string &value) override { + this->publish_state(value); + if (auto index = this->active_index()) { + this->parent_->set_bass_boost_control((BassBoostControl) *index); + } + } +}; + +class FrequencyDeviationSelect : public select::Select, public Parented { + protected: + void control(const std::string &value) override { + this->publish_state(value); + if (auto index = this->active_index()) { + this->parent_->set_deviation((FrequencyDeviation) *index); + } + } +}; + +class PilotToneAmplitudeSelect : public select::Select, public Parented { + protected: + void control(const std::string &value) override { + this->publish_state(value); + if (auto index = this->active_index()) { + this->parent_->set_pilot_tone_amplitude((PilotToneAmplitude) *index); + } + } +}; + +class PreEmphasisSelect : public select::Select, public Parented { + protected: + void control(const std::string &value) override { + this->publish_state(value); + if (auto index = this->active_index()) { + this->parent_->set_pre_emphasis((PreEmphasis) *index); + } + } +}; + +class RefClkSelect : public select::Select, public Parented { + protected: + void control(const std::string &value) override { + this->publish_state(value); + if (auto index = this->active_index()) { + this->parent_->set_ref_clk_sel((ReferenceClock) *index); + } + } +}; + +class SilenceDurationSelect : public select::Select, public Parented { + protected: + void control(const std::string &value) override { + this->publish_state(value); + if (auto index = this->active_index()) { + this->parent_->set_silence_duration((SilenceLowAndHighLevelDurationTime) *index); + } + } +}; + +class SilenceHighCounterSelect : public select::Select, public Parented { + protected: + void control(const std::string &value) override { + this->publish_state(value); + if (auto index = this->active_index()) { + this->parent_->set_silence_high_counter((SilenceHighLevelCounter) *index); + } + } +}; + +class SilenceHighSelect : public select::Select, public Parented { + protected: + void control(const std::string &value) override { + this->publish_state(value); + if (auto index = this->active_index()) { + this->parent_->set_silence_high((SilenceHigh) *index); + } + } +}; + +class SilenceLowCounterSelect : public select::Select, public Parented { + protected: + void control(const std::string &value) override { + this->publish_state(value); + if (auto index = this->active_index()) { + this->parent_->set_silence_low_counter((SilenceLowLevelCounter) *index); + } + } +}; + +class SilenceLowSelect : public select::Select, public Parented { + protected: + void control(const std::string &value) override { + this->publish_state(value); + if (auto index = this->active_index()) { + this->parent_->set_silence_low((SilenceLow) *index); + } + } +}; + +class SwitchModeSelect : public select::Select, public Parented { + protected: + void control(const std::string &value) override { + this->publish_state(value); + if (auto index = this->active_index()) { + this->parent_->set_switch_mode((SwitchMode) *index); + } + } +}; + +class XtalSelSelect : public select::Select, public Parented { + protected: + void control(const std::string &value) override { + this->publish_state(value); + if (auto index = this->active_index()) { + this->parent_->set_xtal_sel((XtalSel) *index); + } + } +}; + +} // namespace kt0803 +} // namespace esphome diff --git a/esphome/components/kt0803/select/silence_duration_select.cpp b/esphome/components/kt0803/select/silence_duration_select.cpp deleted file mode 100644 index d9e9fa5a28..0000000000 --- a/esphome/components/kt0803/select/silence_duration_select.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "silence_duration_select.h" - -namespace esphome { -namespace kt0803 { - -void SilenceDurationSelect::control(const std::string &value) { - this->publish_state(value); - if (auto index = this->active_index()) { - this->parent_->set_silence_duration((SilenceLowAndHighLevelDurationTime) *index); - } -} - -} // namespace kt0803 -} // namespace esphome diff --git a/esphome/components/kt0803/select/silence_duration_select.h b/esphome/components/kt0803/select/silence_duration_select.h deleted file mode 100644 index d58e755b25..0000000000 --- a/esphome/components/kt0803/select/silence_duration_select.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include "esphome/components/select/select.h" -#include "../kt0803.h" - -namespace esphome { -namespace kt0803 { - -class SilenceDurationSelect : public select::Select, public Parented { - public: - SilenceDurationSelect() = default; - - protected: - void control(const std::string &value) override; -}; - -} // namespace kt0803 -} // namespace esphome diff --git a/esphome/components/kt0803/select/silence_high_counter_select.cpp b/esphome/components/kt0803/select/silence_high_counter_select.cpp deleted file mode 100644 index 94ec5e06a8..0000000000 --- a/esphome/components/kt0803/select/silence_high_counter_select.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "silence_high_counter_select.h" - -namespace esphome { -namespace kt0803 { - -void SilenceHighCounterSelect::control(const std::string &value) { - this->publish_state(value); - if (auto index = this->active_index()) { - this->parent_->set_silence_high_counter((SilenceHighLevelCounter) *index); - } -} - -} // namespace kt0803 -} // namespace esphome diff --git a/esphome/components/kt0803/select/silence_high_counter_select.h b/esphome/components/kt0803/select/silence_high_counter_select.h deleted file mode 100644 index f21e0cae5a..0000000000 --- a/esphome/components/kt0803/select/silence_high_counter_select.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include "esphome/components/select/select.h" -#include "../kt0803.h" - -namespace esphome { -namespace kt0803 { - -class SilenceHighCounterSelect : public select::Select, public Parented { - public: - SilenceHighCounterSelect() = default; - - protected: - void control(const std::string &value) override; -}; - -} // namespace kt0803 -} // namespace esphome diff --git a/esphome/components/kt0803/select/silence_high_select.cpp b/esphome/components/kt0803/select/silence_high_select.cpp deleted file mode 100644 index fe273f5a62..0000000000 --- a/esphome/components/kt0803/select/silence_high_select.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "silence_high_select.h" - -namespace esphome { -namespace kt0803 { - -void SilenceHighSelect::control(const std::string &value) { - this->publish_state(value); - if (auto index = this->active_index()) { - this->parent_->set_silence_high((SilenceHigh) *index); - } -} - -} // namespace kt0803 -} // namespace esphome diff --git a/esphome/components/kt0803/select/silence_high_select.h b/esphome/components/kt0803/select/silence_high_select.h deleted file mode 100644 index ca9fba0e8d..0000000000 --- a/esphome/components/kt0803/select/silence_high_select.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include "esphome/components/select/select.h" -#include "../kt0803.h" - -namespace esphome { -namespace kt0803 { - -class SilenceHighSelect : public select::Select, public Parented { - public: - SilenceHighSelect() = default; - - protected: - void control(const std::string &value) override; -}; - -} // namespace kt0803 -} // namespace esphome diff --git a/esphome/components/kt0803/select/silence_low_counter_select.cpp b/esphome/components/kt0803/select/silence_low_counter_select.cpp deleted file mode 100644 index 061f33c7dc..0000000000 --- a/esphome/components/kt0803/select/silence_low_counter_select.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "silence_low_counter_select.h" - -namespace esphome { -namespace kt0803 { - -void SilenceLowCounterSelect::control(const std::string &value) { - this->publish_state(value); - if (auto index = this->active_index()) { - this->parent_->set_silence_low_counter((SilenceLowLevelCounter) *index); - } -} - -} // namespace kt0803 -} // namespace esphome diff --git a/esphome/components/kt0803/select/silence_low_counter_select.h b/esphome/components/kt0803/select/silence_low_counter_select.h deleted file mode 100644 index 364cf88656..0000000000 --- a/esphome/components/kt0803/select/silence_low_counter_select.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include "esphome/components/select/select.h" -#include "../kt0803.h" - -namespace esphome { -namespace kt0803 { - -class SilenceLowCounterSelect : public select::Select, public Parented { - public: - SilenceLowCounterSelect() = default; - - protected: - void control(const std::string &value) override; -}; - -} // namespace kt0803 -} // namespace esphome diff --git a/esphome/components/kt0803/select/silence_low_select.cpp b/esphome/components/kt0803/select/silence_low_select.cpp deleted file mode 100644 index 5371053e37..0000000000 --- a/esphome/components/kt0803/select/silence_low_select.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "silence_low_select.h" - -namespace esphome { -namespace kt0803 { - -void SilenceLowSelect::control(const std::string &value) { - this->publish_state(value); - if (auto index = this->active_index()) { - this->parent_->set_silence_low((SilenceLow) *index); - } -} - -} // namespace kt0803 -} // namespace esphome diff --git a/esphome/components/kt0803/select/silence_low_select.h b/esphome/components/kt0803/select/silence_low_select.h deleted file mode 100644 index 81d773d245..0000000000 --- a/esphome/components/kt0803/select/silence_low_select.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include "esphome/components/select/select.h" -#include "../kt0803.h" - -namespace esphome { -namespace kt0803 { - -class SilenceLowSelect : public select::Select, public Parented { - public: - SilenceLowSelect() = default; - - protected: - void control(const std::string &value) override; -}; - -} // namespace kt0803 -} // namespace esphome diff --git a/esphome/components/kt0803/select/switch_mode_select.cpp b/esphome/components/kt0803/select/switch_mode_select.cpp deleted file mode 100644 index cc3f3eb610..0000000000 --- a/esphome/components/kt0803/select/switch_mode_select.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "switch_mode_select.h" - -namespace esphome { -namespace kt0803 { - -void SwitchModeSelect::control(const std::string &value) { - this->publish_state(value); - if (auto index = this->active_index()) { - this->parent_->set_switch_mode((SwitchMode) *index); - } -} - -} // namespace kt0803 -} // namespace esphome diff --git a/esphome/components/kt0803/select/switch_mode_select.h b/esphome/components/kt0803/select/switch_mode_select.h deleted file mode 100644 index 5d716ec56a..0000000000 --- a/esphome/components/kt0803/select/switch_mode_select.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include "esphome/components/select/select.h" -#include "../kt0803.h" - -namespace esphome { -namespace kt0803 { - -class SwitchModeSelect : public select::Select, public Parented { - public: - SwitchModeSelect() = default; - - protected: - void control(const std::string &value) override; -}; - -} // namespace kt0803 -} // namespace esphome diff --git a/esphome/components/kt0803/select/xtal_sel_select.cpp b/esphome/components/kt0803/select/xtal_sel_select.cpp deleted file mode 100644 index ba00e65565..0000000000 --- a/esphome/components/kt0803/select/xtal_sel_select.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "xtal_sel_select.h" - -namespace esphome { -namespace kt0803 { - -void XtalSelSelect::control(const std::string &value) { - this->publish_state(value); - if (auto index = this->active_index()) { - this->parent_->set_xtal_sel((XtalSel) *index); - } -} - -} // namespace kt0803 -} // namespace esphome diff --git a/esphome/components/kt0803/select/xtal_sel_select.h b/esphome/components/kt0803/select/xtal_sel_select.h deleted file mode 100644 index 54c8016241..0000000000 --- a/esphome/components/kt0803/select/xtal_sel_select.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include "esphome/components/select/select.h" -#include "../kt0803.h" - -namespace esphome { -namespace kt0803 { - -class XtalSelSelect : public select::Select, public Parented { - public: - XtalSelSelect() = default; - - protected: - void control(const std::string &value) override; -}; - -} // namespace kt0803 -} // namespace esphome diff --git a/esphome/components/kt0803/switch/__init__.py b/esphome/components/kt0803/switch/__init__.py index 6c5b6707a4..f2753492f6 100644 --- a/esphome/components/kt0803/switch/__init__.py +++ b/esphome/components/kt0803/switch/__init__.py @@ -27,6 +27,7 @@ from .. import ( ICON_EAR_HEARING, ICON_SINE_WAVE, ICON_SLEEP, + for_each_conf, ) MuteSwitch = kt0803_ns.class_("MuteSwitch", switch.Switch) @@ -138,31 +139,37 @@ CONFIG_SCHEMA = cv.Schema( } ) - -async def new_switch(p, config, id, setter): - if c := config.get(id): - s = await switch.new_switch(c) - await cg.register_parented(s, p) - cg.add(setter(s)) - return s +VARIABLES = { + None: [ + [CONF_MUTE], + [CONF_MONO], + [CONF_AUTO_PA_DOWN], + [CONF_PA_DOWN], + [CONF_STANDBY_ENABLE], + [CONF_PA_BIAS], + [CONF_AU_ENHANCE], + ], + CONF_REF_CLK: [ + [CONF_ENABLE], + ], + CONF_XTAL: [ + [CONF_ENABLE], + ], + CONF_ALC: [ + [CONF_ENABLE], + ], + CONF_SILENCE: [ + [CONF_DETECTION], + ], +} async def to_code(config): - p = await cg.get_variable(config[CONF_KT0803_ID]) - await new_switch(p, config, CONF_MUTE, p.set_mute_switch) - await new_switch(p, config, CONF_MONO, p.set_mono_switch) - await new_switch(p, config, CONF_AUTO_PA_DOWN, p.set_auto_pa_down_switch) - await new_switch(p, config, CONF_PA_DOWN, p.set_pa_down_switch) - await new_switch(p, config, CONF_STANDBY_ENABLE, p.set_standby_enable_switch) - await new_switch(p, config, CONF_PA_BIAS, p.set_pa_bias_switch) - await new_switch(p, config, CONF_AU_ENHANCE, p.set_au_enhance_switch) - if ref_clk_config := config.get(CONF_REF_CLK): - await new_switch(p, ref_clk_config, CONF_ENABLE, p.set_ref_clk_enable_switch) - if xtal_config := config.get(CONF_XTAL): - await new_switch(p, xtal_config, CONF_ENABLE, p.set_xtal_enable_switch) - if alc_config := config.get(CONF_ALC): - await new_switch(p, alc_config, CONF_ENABLE, p.set_alc_enable_switch) - if silence_config := config.get(CONF_SILENCE): - await new_switch( - p, silence_config, CONF_DETECTION, p.set_silence_detection_switch - ) + parent = await cg.get_variable(config[CONF_KT0803_ID]) + + async def new_switch(c, args, setter): + s = await switch.new_switch(c) + await cg.register_parented(s, parent) + cg.add(getattr(parent, setter + "_switch")(s)) + + await for_each_conf(config, VARIABLES, new_switch) diff --git a/esphome/components/kt0803/switch/alc_enable_switch.cpp b/esphome/components/kt0803/switch/alc_enable_switch.cpp deleted file mode 100644 index 672b92f6f3..0000000000 --- a/esphome/components/kt0803/switch/alc_enable_switch.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "alc_enable_switch.h" - -namespace esphome { -namespace kt0803 { - -void AlcEnableSwitch::write_state(bool value) { - this->publish_state(value); - this->parent_->set_alc_enable(value); -} - -} // namespace kt0803 -} // namespace esphome diff --git a/esphome/components/kt0803/switch/alc_enable_switch.h b/esphome/components/kt0803/switch/alc_enable_switch.h deleted file mode 100644 index f24c79c30d..0000000000 --- a/esphome/components/kt0803/switch/alc_enable_switch.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include "esphome/components/switch/switch.h" -#include "../kt0803.h" - -namespace esphome { -namespace kt0803 { - -class AlcEnableSwitch : public switch_::Switch, public Parented { - public: - AlcEnableSwitch() = default; - - protected: - void write_state(bool value) override; -}; - -} // namespace kt0803 -} // namespace esphome diff --git a/esphome/components/kt0803/switch/au_enhance_switch.cpp b/esphome/components/kt0803/switch/au_enhance_switch.cpp deleted file mode 100644 index 3047b73227..0000000000 --- a/esphome/components/kt0803/switch/au_enhance_switch.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "au_enhance_switch.h" - -namespace esphome { -namespace kt0803 { - -void AuEnhanceSwitch::write_state(bool value) { - this->publish_state(value); - this->parent_->set_au_enhance(value); -} - -} // namespace kt0803 -} // namespace esphome diff --git a/esphome/components/kt0803/switch/au_enhance_switch.h b/esphome/components/kt0803/switch/au_enhance_switch.h deleted file mode 100644 index da746d7113..0000000000 --- a/esphome/components/kt0803/switch/au_enhance_switch.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include "esphome/components/switch/switch.h" -#include "../kt0803.h" - -namespace esphome { -namespace kt0803 { - -class AuEnhanceSwitch : public switch_::Switch, public Parented { - public: - AuEnhanceSwitch() = default; - - protected: - void write_state(bool value) override; -}; - -} // namespace kt0803 -} // namespace esphome diff --git a/esphome/components/kt0803/switch/auto_pa_down_switch.cpp b/esphome/components/kt0803/switch/auto_pa_down_switch.cpp deleted file mode 100644 index 6942c0f9e5..0000000000 --- a/esphome/components/kt0803/switch/auto_pa_down_switch.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "auto_pa_down_switch.h" - -namespace esphome { -namespace kt0803 { - -void AutoPaDownSwitch::write_state(bool value) { - this->publish_state(value); - this->parent_->set_auto_pa_down(value); -} - -} // namespace kt0803 -} // namespace esphome diff --git a/esphome/components/kt0803/switch/auto_pa_down_switch.h b/esphome/components/kt0803/switch/auto_pa_down_switch.h deleted file mode 100644 index aaafade18f..0000000000 --- a/esphome/components/kt0803/switch/auto_pa_down_switch.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include "esphome/components/switch/switch.h" -#include "../kt0803.h" - -namespace esphome { -namespace kt0803 { - -class AutoPaDownSwitch : public switch_::Switch, public Parented { - public: - AutoPaDownSwitch() = default; - - protected: - void write_state(bool value) override; -}; - -} // namespace kt0803 -} // namespace esphome diff --git a/esphome/components/kt0803/switch/mono_switch.cpp b/esphome/components/kt0803/switch/mono_switch.cpp deleted file mode 100644 index 4633d4a9fb..0000000000 --- a/esphome/components/kt0803/switch/mono_switch.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "mono_switch.h" - -namespace esphome { -namespace kt0803 { - -void MonoSwitch::write_state(bool value) { - this->publish_state(value); - this->parent_->set_mono(value); -} - -} // namespace kt0803 -} // namespace esphome diff --git a/esphome/components/kt0803/switch/mono_switch.h b/esphome/components/kt0803/switch/mono_switch.h deleted file mode 100644 index e4f9d0c217..0000000000 --- a/esphome/components/kt0803/switch/mono_switch.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include "esphome/components/switch/switch.h" -#include "../kt0803.h" - -namespace esphome { -namespace kt0803 { - -class MonoSwitch : public switch_::Switch, public Parented { - public: - MonoSwitch() = default; - - protected: - void write_state(bool value) override; -}; - -} // namespace kt0803 -} // namespace esphome diff --git a/esphome/components/kt0803/switch/mute_switch.cpp b/esphome/components/kt0803/switch/mute_switch.cpp deleted file mode 100644 index 503db57ff6..0000000000 --- a/esphome/components/kt0803/switch/mute_switch.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "mute_switch.h" - -namespace esphome { -namespace kt0803 { - -void MuteSwitch::write_state(bool value) { - this->publish_state(value); - this->parent_->set_mute(value); -} - -} // namespace kt0803 -} // namespace esphome diff --git a/esphome/components/kt0803/switch/mute_switch.h b/esphome/components/kt0803/switch/mute_switch.h deleted file mode 100644 index 79ecdd9014..0000000000 --- a/esphome/components/kt0803/switch/mute_switch.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include "esphome/components/switch/switch.h" -#include "../kt0803.h" - -namespace esphome { -namespace kt0803 { - -class MuteSwitch : public switch_::Switch, public Parented { - public: - MuteSwitch() = default; - - protected: - void write_state(bool value) override; -}; - -} // namespace kt0803 -} // namespace esphome diff --git a/esphome/components/kt0803/switch/pa_bias_switch.cpp b/esphome/components/kt0803/switch/pa_bias_switch.cpp deleted file mode 100644 index 69c6d0cdd4..0000000000 --- a/esphome/components/kt0803/switch/pa_bias_switch.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "pa_bias_switch.h" - -namespace esphome { -namespace kt0803 { - -void PaBiasSwitch::write_state(bool value) { - this->publish_state(value); - this->parent_->set_pa_bias(value); -} - -} // namespace kt0803 -} // namespace esphome diff --git a/esphome/components/kt0803/switch/pa_bias_switch.h b/esphome/components/kt0803/switch/pa_bias_switch.h deleted file mode 100644 index 7ee15b9dca..0000000000 --- a/esphome/components/kt0803/switch/pa_bias_switch.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include "esphome/components/switch/switch.h" -#include "../kt0803.h" - -namespace esphome { -namespace kt0803 { - -class PaBiasSwitch : public switch_::Switch, public Parented { - public: - PaBiasSwitch() = default; - - protected: - void write_state(bool value) override; -}; - -} // namespace kt0803 -} // namespace esphome diff --git a/esphome/components/kt0803/switch/pa_down_switch.cpp b/esphome/components/kt0803/switch/pa_down_switch.cpp deleted file mode 100644 index 0aa86ba388..0000000000 --- a/esphome/components/kt0803/switch/pa_down_switch.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "pa_down_switch.h" - -namespace esphome { -namespace kt0803 { - -void PaDownSwitch::write_state(bool value) { - this->publish_state(value); - this->parent_->set_pa_down(value); -} - -} // namespace kt0803 -} // namespace esphome diff --git a/esphome/components/kt0803/switch/pa_down_switch.h b/esphome/components/kt0803/switch/pa_down_switch.h deleted file mode 100644 index 0efa15863c..0000000000 --- a/esphome/components/kt0803/switch/pa_down_switch.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include "esphome/components/switch/switch.h" -#include "../kt0803.h" - -namespace esphome { -namespace kt0803 { - -class PaDownSwitch : public switch_::Switch, public Parented { - public: - PaDownSwitch() = default; - - protected: - void write_state(bool value) override; -}; - -} // namespace kt0803 -} // namespace esphome diff --git a/esphome/components/kt0803/switch/ref_clk_enable_switch.cpp b/esphome/components/kt0803/switch/ref_clk_enable_switch.cpp deleted file mode 100644 index 87392aae50..0000000000 --- a/esphome/components/kt0803/switch/ref_clk_enable_switch.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "ref_clk_enable_switch.h" - -namespace esphome { -namespace kt0803 { - -void RefClkEnableSwitch::write_state(bool value) { - this->publish_state(value); - this->parent_->set_ref_clk_enable(value); -} - -} // namespace kt0803 -} // namespace esphome diff --git a/esphome/components/kt0803/switch/ref_clk_enable_switch.h b/esphome/components/kt0803/switch/ref_clk_enable_switch.h deleted file mode 100644 index a5d164011f..0000000000 --- a/esphome/components/kt0803/switch/ref_clk_enable_switch.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include "esphome/components/switch/switch.h" -#include "../kt0803.h" - -namespace esphome { -namespace kt0803 { - -class RefClkEnableSwitch : public switch_::Switch, public Parented { - public: - RefClkEnableSwitch() = default; - - protected: - void write_state(bool value) override; -}; - -} // namespace kt0803 -} // namespace esphome diff --git a/esphome/components/kt0803/switch/silence_detection_switch.cpp b/esphome/components/kt0803/switch/silence_detection_switch.cpp deleted file mode 100644 index 273d9481bb..0000000000 --- a/esphome/components/kt0803/switch/silence_detection_switch.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "silence_detection_switch.h" - -namespace esphome { -namespace kt0803 { - -void SilenceDetectionSwitch::write_state(bool value) { - this->publish_state(value); - this->parent_->set_silence_detection(value); -} - -} // namespace kt0803 -} // namespace esphome diff --git a/esphome/components/kt0803/switch/silence_detection_switch.h b/esphome/components/kt0803/switch/silence_detection_switch.h deleted file mode 100644 index 09cbc96559..0000000000 --- a/esphome/components/kt0803/switch/silence_detection_switch.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include "esphome/components/switch/switch.h" -#include "../kt0803.h" - -namespace esphome { -namespace kt0803 { - -class SilenceDetectionSwitch : public switch_::Switch, public Parented { - public: - SilenceDetectionSwitch() = default; - - protected: - void write_state(bool value) override; -}; - -} // namespace kt0803 -} // namespace esphome diff --git a/esphome/components/kt0803/switch/standby_enable_switch.cpp b/esphome/components/kt0803/switch/standby_enable_switch.cpp deleted file mode 100644 index 364a83b60a..0000000000 --- a/esphome/components/kt0803/switch/standby_enable_switch.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "standby_enable_switch.h" - -namespace esphome { -namespace kt0803 { - -void StandbyEnableSwitch::write_state(bool value) { - this->publish_state(value); - this->parent_->set_standby_enable(value); -} - -} // namespace kt0803 -} // namespace esphome diff --git a/esphome/components/kt0803/switch/standby_enable_switch.h b/esphome/components/kt0803/switch/standby_enable_switch.h deleted file mode 100644 index 9f2e717c7b..0000000000 --- a/esphome/components/kt0803/switch/standby_enable_switch.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include "esphome/components/switch/switch.h" -#include "../kt0803.h" - -namespace esphome { -namespace kt0803 { - -class StandbyEnableSwitch : public switch_::Switch, public Parented { - public: - StandbyEnableSwitch() = default; - - protected: - void write_state(bool value) override; -}; - -} // namespace kt0803 -} // namespace esphome diff --git a/esphome/components/kt0803/switch/switch.h b/esphome/components/kt0803/switch/switch.h new file mode 100644 index 0000000000..76ed0a9fc8 --- /dev/null +++ b/esphome/components/kt0803/switch/switch.h @@ -0,0 +1,98 @@ +#pragma once + +#include "esphome/components/switch/switch.h" +#include "../kt0803.h" + +namespace esphome { +namespace kt0803 { + +class AlcEnableSwitch : public switch_::Switch, public Parented { + protected: + void write_state(bool value) override { + this->publish_state(value); + this->parent_->set_alc_enable(value); + } +}; + +class AuEnhanceSwitch : public switch_::Switch, public Parented { + protected: + void write_state(bool value) override { + this->publish_state(value); + this->parent_->set_au_enhance(value); + } +}; + +class AutoPaDownSwitch : public switch_::Switch, public Parented { + protected: + void write_state(bool value) override { + this->publish_state(value); + this->parent_->set_auto_pa_down(value); + } +}; + +class MonoSwitch : public switch_::Switch, public Parented { + protected: + void write_state(bool value) override { + this->publish_state(value); + this->parent_->set_mono(value); + } +}; + +class MuteSwitch : public switch_::Switch, public Parented { + protected: + void write_state(bool value) override { + this->publish_state(value); + this->parent_->set_mute(value); + } +}; + +class PaBiasSwitch : public switch_::Switch, public Parented { + protected: + void write_state(bool value) override { + this->publish_state(value); + this->parent_->set_pa_bias(value); + } +}; + +class PaDownSwitch : public switch_::Switch, public Parented { + protected: + void write_state(bool value) override { + this->publish_state(value); + this->parent_->set_pa_down(value); + } +}; + +class RefClkEnableSwitch : public switch_::Switch, public Parented { + protected: + void write_state(bool value) override { + this->publish_state(value); + this->parent_->set_ref_clk_enable(value); + } +}; + +class SilenceDetectionSwitch : public switch_::Switch, public Parented { + protected: + void write_state(bool value) override { + this->publish_state(value); + this->parent_->set_silence_detection(value); + } +}; + +class StandbyEnableSwitch : public switch_::Switch, public Parented { + protected: + void write_state(bool value) override { + this->publish_state(value); + this->parent_->set_standby_enable(value); + } +}; + +class XtalEnableSwitch : public switch_::Switch, public Parented { + protected: + void write_state(bool value) override { + this->publish_state(value); + this->parent_->set_xtal_enable(value); + } +}; + +} // namespace kt0803 +} // namespace esphome diff --git a/esphome/components/kt0803/switch/xtal_enable_switch.cpp b/esphome/components/kt0803/switch/xtal_enable_switch.cpp deleted file mode 100644 index 82b5d5101e..0000000000 --- a/esphome/components/kt0803/switch/xtal_enable_switch.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "xtal_enable_switch.h" - -namespace esphome { -namespace kt0803 { - -void XtalEnableSwitch::write_state(bool value) { - this->publish_state(value); - this->parent_->set_xtal_enable(value); -} - -} // namespace kt0803 -} // namespace esphome diff --git a/esphome/components/kt0803/switch/xtal_enable_switch.h b/esphome/components/kt0803/switch/xtal_enable_switch.h deleted file mode 100644 index d0d193749a..0000000000 --- a/esphome/components/kt0803/switch/xtal_enable_switch.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include "esphome/components/switch/switch.h" -#include "../kt0803.h" - -namespace esphome { -namespace kt0803 { - -class XtalEnableSwitch : public switch_::Switch, public Parented { - public: - XtalEnableSwitch() = default; - - protected: - void write_state(bool value) override; -}; - -} // namespace kt0803 -} // namespace esphome