ESPHome 2026.6.0-dev
Loading...
Searching...
No Matches
automation.h
Go to the documentation of this file.
1#pragma once
2
4#include "microphone.h"
5
6#include <vector>
7
9
10template<typename... Ts> class CaptureAction : public Action<Ts...>, public Parented<Microphone> {
11 void play(const Ts &...x) override { this->parent_->start(); }
12};
13
14template<typename... Ts> class StopCaptureAction : public Action<Ts...>, public Parented<Microphone> {
15 void play(const Ts &...x) override { this->parent_->stop(); }
16};
17
18template<typename... Ts> class MuteAction : public Action<Ts...>, public Parented<Microphone> {
19 void play(const Ts &...x) override { this->parent_->set_mute_state(true); }
20};
21template<typename... Ts> class UnmuteAction : public Action<Ts...>, public Parented<Microphone> {
22 void play(const Ts &...x) override { this->parent_->set_mute_state(false); }
23};
24
25class DataTrigger : public Trigger<const std::vector<uint8_t> &> {
26 public:
27 explicit DataTrigger(Microphone *mic) {
28 mic->add_data_callback([this](const std::vector<uint8_t> &data) { this->trigger(data); });
29 }
30};
31
32template<typename... Ts> class IsCapturingCondition : public Condition<Ts...>, public Parented<Microphone> {
33 public:
34 bool check(const Ts &...x) override { return this->parent_->is_running(); }
35};
36
37template<typename... Ts> class IsMutedCondition : public Condition<Ts...>, public Parented<Microphone> {
38 public:
39 bool check(const Ts &...x) override { return this->parent_->get_mute_state(); }
40};
41
42} // namespace esphome::microphone
Base class for all automation conditions.
Definition automation.h:438
Helper class to easily give an object a parent of type T.
Definition helpers.h:1861
void trigger(const Ts &...x) ESPHOME_ALWAYS_INLINE
Definition automation.h:461
bool check(const Ts &...x) override
Definition automation.h:34
bool check(const Ts &...x) override
Definition automation.h:39
void add_data_callback(F &&data_callback)
Definition microphone.h:23
uint16_t x
Definition tt21100.cpp:5