mirror of
https://github.com/esphome/esphome.git
synced 2025-04-09 20:30:31 +01:00
Co-authored-by: Maurits <maurits@vloop.nl> Co-authored-by: mauritskorse <mauritskorse@gmail.com> Co-authored-by: Daniel Dunn <dannydunn@eternityforest.com> Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
34 lines
750 B
C++
34 lines
750 B
C++
#pragma once
|
|
|
|
#include "esphome/core/automation.h"
|
|
#include "esphome/core/component.h"
|
|
#include "text.h"
|
|
|
|
namespace esphome {
|
|
namespace text {
|
|
|
|
class TextStateTrigger : public Trigger<std::string> {
|
|
public:
|
|
explicit TextStateTrigger(Text *parent) {
|
|
parent->add_on_state_callback([this](const std::string &value) { this->trigger(value); });
|
|
}
|
|
};
|
|
|
|
template<typename... Ts> class TextSetAction : public Action<Ts...> {
|
|
public:
|
|
explicit TextSetAction(Text *text) : text_(text) {}
|
|
TEMPLATABLE_VALUE(std::string, value)
|
|
|
|
void play(Ts... x) override {
|
|
auto call = this->text_->make_call();
|
|
call.set_value(this->value_.value(x...));
|
|
call.perform();
|
|
}
|
|
|
|
protected:
|
|
Text *text_;
|
|
};
|
|
|
|
} // namespace text
|
|
} // namespace esphome
|