#pragma once #include #include "esphome/core/component.h" #include "esphome/core/automation.h" #include "esphome/components/text_sensor/text_sensor.h" namespace esphome { namespace text_sensor { class TextSensorStateTrigger : public Trigger { public: explicit TextSensorStateTrigger(TextSensor *parent) { parent->add_on_state_callback([this](const std::string &value) { this->trigger(value); }); } }; class TextSensorStateRawTrigger : public Trigger { public: explicit TextSensorStateRawTrigger(TextSensor *parent) { parent->add_on_raw_state_callback([this](const std::string &value) { this->trigger(value); }); } }; template class TextSensorStateCondition : public Condition { public: explicit TextSensorStateCondition(TextSensor *parent) : parent_(parent) {} TEMPLATABLE_VALUE(std::string, state) bool check(Ts... x) override { return this->parent_->state == this->state_.value(x...); } protected: TextSensor *parent_; }; template class TextSensorPublishAction : public Action { public: TextSensorPublishAction(TextSensor *sensor) : sensor_(sensor) {} TEMPLATABLE_VALUE(std::string, state) void play(Ts... x) override { this->sensor_->publish_state(this->state_.value(x...)); } protected: TextSensor *sensor_; }; } // namespace text_sensor } // namespace esphome