mirror of
https://github.com/esphome/esphome.git
synced 2025-01-07 13:21:44 +01:00
add missing set_frequency action
This commit is contained in:
parent
290c5c3d5a
commit
c908cfc9cd
3 changed files with 27 additions and 1 deletions
|
@ -26,7 +26,7 @@ UNIT_MEGA_HERTZ = "MHz"
|
|||
UNIT_KILO_HERTZ = "kHz"
|
||||
UNIT_MILLI_VOLT = "mV"
|
||||
UNIT_MICRO_AMPERE = "mA"
|
||||
UNIT_DECIBEL_MICRO_VOLT = "dBµV"
|
||||
UNIT_DECIBEL_MICRO_VOLT = "dBuV"
|
||||
|
||||
ICON_VOLUME_MUTE = "mdi:volume-mute"
|
||||
ICON_EAR_HEARING = "mdi:ear-hearing"
|
||||
|
@ -361,6 +361,24 @@ CONFIG_SCHEMA = (
|
|||
)
|
||||
|
||||
|
||||
FREQUENCY_SCHEMA = automation.maybe_simple_id(
|
||||
{
|
||||
cv.GenerateID(): cv.use_id(KT0803Component),
|
||||
cv.Required(CONF_FREQUENCY): cv.float_range(min = 70, max = 108),
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@automation.register_action("kt0803.set_frequency", SetFrequencyAction, FREQUENCY_SCHEMA)
|
||||
async def tune_frequency_action_to_code(config, action_id, template_arg, args):
|
||||
var = cg.new_Pvariable(action_id, template_arg)
|
||||
await cg.register_parented(var, config[CONF_ID])
|
||||
if frequency := config.get(CONF_FREQUENCY):
|
||||
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))
|
||||
|
|
|
@ -198,5 +198,12 @@ class KT0803Component : public PollingComponent, public i2c::I2CDevice {
|
|||
AlcLow get_alc_low();
|
||||
};
|
||||
|
||||
template<typename... Ts> class SetFrequencyAction : public Action<Ts...>, public Parented<KT0803Component> {
|
||||
TEMPLATABLE_VALUE(float, frequency)
|
||||
void play(Ts... x) override {
|
||||
this->parent_->set_frequency(this->frequency_.value(x...));
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace kt0803
|
||||
} // namespace esphome
|
||||
|
|
|
@ -22,6 +22,7 @@ enum class ChipId {
|
|||
KT0803K,
|
||||
KT0803M,
|
||||
KT0803L,
|
||||
LAST,
|
||||
};
|
||||
|
||||
enum class PreEmphasis {
|
||||
|
|
Loading…
Reference in a new issue