ESPHome 2026.3.0-dev
Loading...
Searching...
No Matches
automation.h
Go to the documentation of this file.
1#pragma once
2
4#include "media_player.h"
5
6namespace esphome {
7
8namespace media_player {
9
10template<MediaPlayerCommand Command, typename... Ts>
11class MediaPlayerCommandAction : public Action<Ts...>, public Parented<MediaPlayer> {
12 public:
13 TEMPLATABLE_VALUE(bool, announcement);
14 void play(const Ts &...x) override {
15 this->parent_->make_call().set_command(Command).set_announcement(this->announcement_.value(x...)).perform();
16 }
17};
18
19template<typename... Ts>
21template<typename... Ts>
23template<typename... Ts>
25template<typename... Ts>
27template<typename... Ts>
29template<typename... Ts>
31template<typename... Ts>
33template<typename... Ts>
35template<typename... Ts>
37template<typename... Ts>
39template<typename... Ts>
41template<typename... Ts>
43template<typename... Ts>
45template<typename... Ts>
47template<typename... Ts>
49template<typename... Ts>
51template<typename... Ts>
53template<typename... Ts>
55template<typename... Ts>
57
58template<typename... Ts> class PlayMediaAction : public Action<Ts...>, public Parented<MediaPlayer> {
59 TEMPLATABLE_VALUE(std::string, media_url)
60 TEMPLATABLE_VALUE(bool, announcement)
61 void play(const Ts &...x) override {
62 this->parent_->make_call()
63 .set_media_url(this->media_url_.value(x...))
64 .set_announcement(this->announcement_.value(x...))
65 .perform();
66 }
67};
68
69template<typename... Ts> class VolumeSetAction : public Action<Ts...>, public Parented<MediaPlayer> {
70 TEMPLATABLE_VALUE(float, volume)
71 void play(const Ts &...x) override { this->parent_->make_call().set_volume(this->volume_.value(x...)).perform(); }
72};
73
74class StateTrigger : public Trigger<> {
75 public:
76 explicit StateTrigger(MediaPlayer *player) {
77 player->add_on_state_callback([this]() { this->trigger(); });
78 }
79};
80
81template<MediaPlayerState State> class MediaPlayerStateTrigger : public Trigger<> {
82 public:
84 player->add_on_state_callback([this, player]() {
85 if (player->state == State)
86 this->trigger();
87 });
88 }
89};
90
97
98template<typename... Ts> class IsIdleCondition : public Condition<Ts...>, public Parented<MediaPlayer> {
99 public:
100 bool check(const Ts &...x) override { return this->parent_->state == MediaPlayerState::MEDIA_PLAYER_STATE_IDLE; }
101};
102
103template<typename... Ts> class IsPlayingCondition : public Condition<Ts...>, public Parented<MediaPlayer> {
104 public:
105 bool check(const Ts &...x) override { return this->parent_->state == MediaPlayerState::MEDIA_PLAYER_STATE_PLAYING; }
106};
107
108template<typename... Ts> class IsPausedCondition : public Condition<Ts...>, public Parented<MediaPlayer> {
109 public:
110 bool check(const Ts &...x) override { return this->parent_->state == MediaPlayerState::MEDIA_PLAYER_STATE_PAUSED; }
111};
112
113template<typename... Ts> class IsAnnouncingCondition : public Condition<Ts...>, public Parented<MediaPlayer> {
114 public:
115 bool check(const Ts &...x) override {
117 }
118};
119
120template<typename... Ts> class IsOnCondition : public Condition<Ts...>, public Parented<MediaPlayer> {
121 public:
122 bool check(const Ts &...x) override { return this->parent_->state == MediaPlayerState::MEDIA_PLAYER_STATE_ON; }
123};
124
125template<typename... Ts> class IsOffCondition : public Condition<Ts...>, public Parented<MediaPlayer> {
126 public:
127 bool check(const Ts &...x) override { return this->parent_->state == MediaPlayerState::MEDIA_PLAYER_STATE_OFF; }
128};
129
130template<typename... Ts> class IsMutedCondition : public Condition<Ts...>, public Parented<MediaPlayer> {
131 public:
132 bool check(const Ts &...x) override { return this->parent_->is_muted(); }
133};
134
135} // namespace media_player
136} // namespace esphome
virtual void play(const Ts &...x)=0
Base class for all automation conditions.
Definition automation.h:304
Helper class to easily give an object a parent of type T.
Definition helpers.h:1618
void trigger(const Ts &...x)
Definition automation.h:325
bool check(const Ts &...x) override
Definition automation.h:115
bool check(const Ts &...x) override
Definition automation.h:100
bool check(const Ts &...x) override
Definition automation.h:132
bool check(const Ts &...x) override
Definition automation.h:127
bool check(const Ts &...x) override
Definition automation.h:122
bool check(const Ts &...x) override
Definition automation.h:110
bool check(const Ts &...x) override
Definition automation.h:105
void add_on_state_callback(std::function< void()> &&callback)
StateTrigger(MediaPlayer *player)
Definition automation.h:76
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
uint16_t x
Definition tt21100.cpp:5