esphome/esphome/components/time_based/time_based_cover.h
Daniel Müller 2eb5f89d82
Add cover toggle support (#1809)
* Add cover toggle support

Step through open/stop/close/stop sequence with every toggle

* Move the cover toggle logic to perform()

* Add clang-tidy CI suggestion

* Implement cover toggle action as cover trait

* Handle toggle correctly if cover fully closed on POR

* Fix CI finding

* Add deprecated warning

* Don't add already deprecated interface

Co-authored-by: Oxan van Leeuwen <oxan@oxanvanleeuwen.nl>

* Don't add already deprecated interface

Co-authored-by: Oxan van Leeuwen <oxan@oxanvanleeuwen.nl>

* Don't add already deprecated interface

Co-authored-by: Oxan van Leeuwen <oxan@oxanvanleeuwen.nl>

Co-authored-by: Mueller, Daniel <daniel.mueller@karlstorz.com>
Co-authored-by: Oxan van Leeuwen <oxan@oxanvanleeuwen.nl>
2021-09-27 22:31:15 +02:00

52 lines
1.7 KiB
C++

#pragma once
#include "esphome/core/component.h"
#include "esphome/core/automation.h"
#include "esphome/components/cover/cover.h"
namespace esphome {
namespace time_based {
class TimeBasedCover : public cover::Cover, public Component {
public:
void setup() override;
void loop() override;
void dump_config() override;
float get_setup_priority() const override;
Trigger<> *get_open_trigger() const { return this->open_trigger_; }
Trigger<> *get_close_trigger() const { return this->close_trigger_; }
Trigger<> *get_stop_trigger() const { return this->stop_trigger_; }
void set_open_duration(uint32_t open_duration) { this->open_duration_ = open_duration; }
void set_close_duration(uint32_t close_duration) { this->close_duration_ = close_duration; }
cover::CoverTraits get_traits() override;
void set_has_built_in_endstop(bool value) { this->has_built_in_endstop_ = value; }
void set_assumed_state(bool value) { this->assumed_state_ = value; }
protected:
void control(const cover::CoverCall &call) override;
void stop_prev_trigger_();
bool is_at_target_() const;
void start_direction_(cover::CoverOperation dir);
void recompute_position_();
Trigger<> *open_trigger_{new Trigger<>()};
uint32_t open_duration_;
Trigger<> *close_trigger_{new Trigger<>()};
uint32_t close_duration_;
Trigger<> *stop_trigger_{new Trigger<>()};
Trigger<> *prev_command_trigger_{nullptr};
uint32_t last_recompute_time_{0};
uint32_t start_dir_time_{0};
uint32_t last_publish_time_{0};
float target_position_{0};
bool has_built_in_endstop_{false};
bool assumed_state_{false};
cover::CoverOperation last_operation_{cover::COVER_OPERATION_OPENING};
};
} // namespace time_based
} // namespace esphome