mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-06-05 04:18:29 +02:00
Add text component (#5336)
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>
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
#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
|
||||
Reference in New Issue
Block a user