1
0
mirror of https://github.com/esphome/esphome.git synced 2025-04-03 17:30:28 +01:00
esphome/esphome/components/time_based/time_based_cover.h
X-Ryl669 d75daa9644
Add always trigger stop (#4249)
* feat: Add manual control config override 1/3

* feat: Add manual control config override 2/3

* feat: Add manual control config override 3/3

* No magical number is better

Co-authored-by: Guillermo Ruffino <glm.net@gmail.com>

---------

Co-authored-by: Guillermo Ruffino <glm.net@gmail.com>
2023-04-12 21:16:44 +00:00

55 lines
1.8 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_manual_control(bool value) { this->manual_control_ = 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 manual_control_{false};
bool assumed_state_{false};
cover::CoverOperation last_operation_{cover::COVER_OPERATION_OPENING};
};
} // namespace time_based
} // namespace esphome