[speaker_source] Use register_apply_action for speaker_source.set_playlist_delay (#19686)

This commit is contained in:
J. Nick Koston
2026-09-25 20:30:16 -04:00
committed by GitHub
parent d34b21cb7e
commit 3a9048cc62
2 changed files with 5 additions and 54 deletions
@@ -1,29 +0,0 @@
#pragma once
#include "esphome/core/defines.h"
#ifdef USE_ESP32
#include "esphome/core/automation.h"
#include "speaker_source_media_player.h"
namespace esphome::speaker_source {
template<typename... Ts> class SetPlaylistDelayAction final : public Action<Ts...> {
public:
explicit SetPlaylistDelayAction(SpeakerSourceMediaPlayer *parent) : parent_(parent) {}
TEMPLATABLE_VALUE(uint8_t, pipeline)
TEMPLATABLE_VALUE(uint32_t, delay)
void play(const Ts &...x) override {
this->parent_->set_playlist_delay_ms(this->pipeline_.value(x...), this->delay_.value(x...));
}
protected:
SpeakerSourceMediaPlayer *parent_;
};
} // namespace esphome::speaker_source
#endif // USE_ESP32
@@ -16,8 +16,6 @@ from esphome.const import (
CONF_SAMPLE_RATE,
CONF_SPEAKER,
)
from esphome.core import ID
from esphome.cpp_generator import MockObj, TemplateArgsType
from esphome.types import ConfigType
AUTO_LOAD = ["audio"]
@@ -59,10 +57,6 @@ _PIPELINE_INFO = {
),
}
SetPlaylistDelayAction = speaker_source_ns.class_(
"SetPlaylistDelayAction", automation.Action
)
_validate_pipeline = media_player.validate_preferred_format(
"speaker_source media_player", CONF_SPEAKER
@@ -232,25 +226,11 @@ SET_PLAYLIST_DELAY_ACTION_SCHEMA = cv.Schema(
)
@automation.register_action(
automation.register_apply_action(
"speaker_source.set_playlist_delay",
SetPlaylistDelayAction,
SET_PLAYLIST_DELAY_ACTION_SCHEMA,
synchronous=True,
automation.ApplyCall(
"set_playlist_delay_ms({}, {})",
((CONF_PIPELINE, cg.uint8), (CONF_DELAY, cg.uint32)),
),
)
async def set_playlist_delay_action_to_code(
config: ConfigType,
action_id: ID,
template_arg: cg.TemplateArguments,
args: TemplateArgsType,
) -> MockObj:
parent = await cg.get_variable(config[CONF_ID])
var = cg.new_Pvariable(action_id, template_arg, parent)
template_ = await cg.templatable(config[CONF_PIPELINE], args, cg.uint8)
cg.add(var.set_pipeline(template_))
template_ = await cg.templatable(config[CONF_DELAY], args, cg.uint32)
cg.add(var.set_delay(template_))
return var