#pragma once #include "esphome/core/automation.h" #include "speaker.h" #include namespace esphome { namespace speaker { template class PlayAction : public Action, public Parented { public: void set_data_template(std::function(Ts...)> func) { this->data_func_ = func; this->static_ = false; } void set_data_static(const std::vector &data) { this->data_static_ = data; this->static_ = true; } void play(Ts... x) override { if (this->static_) { this->parent_->play(this->data_static_); } else { auto val = this->data_func_(x...); this->parent_->play(val); } } protected: bool static_{false}; std::function(Ts...)> data_func_{}; std::vector data_static_{}; }; template class VolumeSetAction : public Action, public Parented { TEMPLATABLE_VALUE(float, volume) void play(Ts... x) override { this->parent_->set_volume(this->volume_.value(x...)); } }; template class MuteOnAction : public Action { public: explicit MuteOnAction(Speaker *speaker) : speaker_(speaker) {} void play(Ts... x) override { this->speaker_->set_mute_state(true); } protected: Speaker *speaker_; }; template class MuteOffAction : public Action { public: explicit MuteOffAction(Speaker *speaker) : speaker_(speaker) {} void play(Ts... x) override { this->speaker_->set_mute_state(false); } protected: Speaker *speaker_; }; template class StopAction : public Action, public Parented { public: void play(Ts... x) override { this->parent_->stop(); } }; template class FinishAction : public Action, public Parented { public: void play(Ts... x) override { this->parent_->finish(); } }; template class IsPlayingCondition : public Condition, public Parented { public: bool check(Ts... x) override { return this->parent_->is_running(); } }; template class IsStoppedCondition : public Condition, public Parented { public: bool check(Ts... x) override { return this->parent_->is_stopped(); } }; } // namespace speaker } // namespace esphome