mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-05-27 00:17:22 +02:00
a62b6548d2
Apparently play()/stop() etc. are not meant to be called directly by users of the class and if they're called directly that would not give the expected result for the classes that have an empty play(). Make all methods except play_complex, stop_comples and is_running protected. While there also make RemoteTransmitterActionBase::encode protected.
41 lines
1.1 KiB
C++
41 lines
1.1 KiB
C++
#pragma once
|
|
|
|
#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<std::string> {
|
|
public:
|
|
explicit TextSensorStateTrigger(TextSensor *parent) {
|
|
parent->add_on_state_callback([this](std::string value) { this->trigger(value); });
|
|
}
|
|
};
|
|
|
|
template<typename... Ts> class TextSensorStateCondition : public Condition<Ts...> {
|
|
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<typename... Ts> class TextSensorPublishAction : public Action<Ts...> {
|
|
public:
|
|
TextSensorPublishAction(TextSensor *sensor) : sensor_(sensor) {}
|
|
TEMPLATABLE_VALUE(std::string, state)
|
|
|
|
protected:
|
|
void play_(Ts... x) override { this->sensor_->publish_state(this->state_.value(x...)); }
|
|
TextSensor *sensor_;
|
|
};
|
|
|
|
} // namespace text_sensor
|
|
} // namespace esphome
|