Files
esphome-dev/esphome/components/output/automation.h
T
Andrew Zaborowski a62b6548d2 Make some Action methods protected
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.
2020-05-01 12:44:30 +02:00

45 lines
1.0 KiB
C++

#pragma once
#include "esphome/core/component.h"
#include "esphome/core/automation.h"
#include "esphome/components/output/binary_output.h"
#include "esphome/components/output/float_output.h"
namespace esphome {
namespace output {
template<typename... Ts> class TurnOffAction : public Action<Ts...> {
public:
TurnOffAction(BinaryOutput *output) : output_(output) {}
protected:
void play_(Ts... x) override { this->output_->turn_off(); }
BinaryOutput *output_;
};
template<typename... Ts> class TurnOnAction : public Action<Ts...> {
public:
TurnOnAction(BinaryOutput *output) : output_(output) {}
protected:
void play_(Ts... x) override { this->output_->turn_on(); }
BinaryOutput *output_;
};
template<typename... Ts> class SetLevelAction : public Action<Ts...> {
public:
SetLevelAction(FloatOutput *output) : output_(output) {}
TEMPLATABLE_VALUE(float, level)
protected:
void play_(Ts... x) override { this->output_->set_level(this->level_.value(x...)); }
FloatOutput *output_;
};
} // namespace output
} // namespace esphome