#pragma once #include "esphome/core/component.h" #include "esphome/core/automation.h" #include "cover.h" namespace esphome { namespace cover { template class OpenAction : public Action { public: explicit OpenAction(Cover *cover) : cover_(cover) {} void play(Ts... x) override { this->cover_->open(); } protected: Cover *cover_; }; template class CloseAction : public Action { public: explicit CloseAction(Cover *cover) : cover_(cover) {} void play(Ts... x) override { this->cover_->close(); } protected: Cover *cover_; }; template class StopAction : public Action { public: explicit StopAction(Cover *cover) : cover_(cover) {} void play(Ts... x) override { this->cover_->stop(); } protected: Cover *cover_; }; template class ControlAction : public Action { public: explicit ControlAction(Cover *cover) : cover_(cover) {} TEMPLATABLE_VALUE(bool, stop) TEMPLATABLE_VALUE(float, position) TEMPLATABLE_VALUE(float, tilt) 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(); } protected: Cover *cover_; }; template class CoverPublishAction : public Action { public: CoverPublishAction(Cover *cover) : cover_(cover) {} TEMPLATABLE_VALUE(float, position) TEMPLATABLE_VALUE(float, tilt) TEMPLATABLE_VALUE(CoverOperation, current_operation) 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(); } protected: Cover *cover_; }; template class CoverIsOpenCondition : public Condition { public: CoverIsOpenCondition(Cover *cover) : cover_(cover) {} bool check(Ts... x) override { return this->cover_->is_fully_open(); } protected: Cover *cover_; }; template class CoverIsClosedCondition : public Condition { public: CoverIsClosedCondition(Cover *cover) : cover_(cover) {} bool check(Ts... x) override { return this->cover_->is_fully_closed(); } protected: Cover *cover_; }; } // namespace cover } // namespace esphome