mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-06-01 18:48:28 +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.
103 lines
2.6 KiB
C++
103 lines
2.6 KiB
C++
#pragma once
|
|
|
|
#include "esphome/core/component.h"
|
|
#include "esphome/core/automation.h"
|
|
#include "cover.h"
|
|
|
|
namespace esphome {
|
|
namespace cover {
|
|
|
|
template<typename... Ts> class OpenAction : public Action<Ts...> {
|
|
public:
|
|
explicit OpenAction(Cover *cover) : cover_(cover) {}
|
|
|
|
protected:
|
|
void play_(Ts... x) override { this->cover_->open(); }
|
|
|
|
Cover *cover_;
|
|
};
|
|
|
|
template<typename... Ts> class CloseAction : public Action<Ts...> {
|
|
public:
|
|
explicit CloseAction(Cover *cover) : cover_(cover) {}
|
|
|
|
protected:
|
|
void play_(Ts... x) override { this->cover_->close(); }
|
|
|
|
Cover *cover_;
|
|
};
|
|
|
|
template<typename... Ts> class StopAction : public Action<Ts...> {
|
|
public:
|
|
explicit StopAction(Cover *cover) : cover_(cover) {}
|
|
|
|
protected:
|
|
void play_(Ts... x) override { this->cover_->stop(); }
|
|
|
|
Cover *cover_;
|
|
};
|
|
|
|
template<typename... Ts> class ControlAction : public Action<Ts...> {
|
|
public:
|
|
explicit ControlAction(Cover *cover) : cover_(cover) {}
|
|
|
|
TEMPLATABLE_VALUE(bool, stop)
|
|
TEMPLATABLE_VALUE(float, position)
|
|
TEMPLATABLE_VALUE(float, tilt)
|
|
|
|
protected:
|
|
void play_(Ts... x) override {
|
|
auto call = this->cover_->make_call();
|
|
if (this->stop_.has_value())
|
|
call.set_stop(this->stop_.value(x...));
|
|
if (this->position_.has_value())
|
|
call.set_position(this->position_.value(x...));
|
|
if (this->tilt_.has_value())
|
|
call.set_tilt(this->tilt_.value(x...));
|
|
call.perform();
|
|
}
|
|
|
|
Cover *cover_;
|
|
};
|
|
|
|
template<typename... Ts> class CoverPublishAction : public Action<Ts...> {
|
|
public:
|
|
CoverPublishAction(Cover *cover) : cover_(cover) {}
|
|
TEMPLATABLE_VALUE(float, position)
|
|
TEMPLATABLE_VALUE(float, tilt)
|
|
TEMPLATABLE_VALUE(CoverOperation, current_operation)
|
|
|
|
protected:
|
|
void play_(Ts... x) override {
|
|
if (this->position_.has_value())
|
|
this->cover_->position = this->position_.value(x...);
|
|
if (this->tilt_.has_value())
|
|
this->cover_->tilt = this->tilt_.value(x...);
|
|
if (this->current_operation_.has_value())
|
|
this->cover_->current_operation = this->current_operation_.value(x...);
|
|
this->cover_->publish_state();
|
|
}
|
|
|
|
Cover *cover_;
|
|
};
|
|
|
|
template<typename... Ts> class CoverIsOpenCondition : public Condition<Ts...> {
|
|
public:
|
|
CoverIsOpenCondition(Cover *cover) : cover_(cover) {}
|
|
bool check(Ts... x) override { return this->cover_->is_fully_open(); }
|
|
|
|
protected:
|
|
Cover *cover_;
|
|
};
|
|
template<typename... Ts> class CoverIsClosedCondition : public Condition<Ts...> {
|
|
public:
|
|
CoverIsClosedCondition(Cover *cover) : cover_(cover) {}
|
|
bool check(Ts... x) override { return this->cover_->is_fully_closed(); }
|
|
|
|
protected:
|
|
Cover *cover_;
|
|
};
|
|
|
|
} // namespace cover
|
|
} // namespace esphome
|