ESPHome  2024.11.0
current_based_cover.h
Go to the documentation of this file.
1 #pragma once
2 
7 #include <cfloat>
8 
9 namespace esphome {
10 namespace current_based {
11 
12 class CurrentBasedCover : public cover::Cover, public Component {
13  public:
14  void setup() override;
15  void loop() override;
16  void dump_config() override;
17  float get_setup_priority() const override;
18 
19  Trigger<> *get_stop_trigger() const { return this->stop_trigger_; }
20 
21  Trigger<> *get_open_trigger() const { return this->open_trigger_; }
22  void set_open_sensor(sensor::Sensor *open_sensor) { this->open_sensor_ = open_sensor; }
23  void set_open_moving_current_threshold(float open_moving_current_threshold) {
24  this->open_moving_current_threshold_ = open_moving_current_threshold;
25  }
26  void set_open_obstacle_current_threshold(float open_obstacle_current_threshold) {
27  this->open_obstacle_current_threshold_ = open_obstacle_current_threshold;
28  }
29  void set_open_duration(uint32_t open_duration) { this->open_duration_ = open_duration; }
30 
31  Trigger<> *get_close_trigger() const { return this->close_trigger_; }
32  void set_close_sensor(sensor::Sensor *close_sensor) { this->close_sensor_ = close_sensor; }
33  void set_close_moving_current_threshold(float close_moving_current_threshold) {
34  this->close_moving_current_threshold_ = close_moving_current_threshold;
35  }
36  void set_close_obstacle_current_threshold(float close_obstacle_current_threshold) {
37  this->close_obstacle_current_threshold_ = close_obstacle_current_threshold;
38  }
39  void set_close_duration(uint32_t close_duration) { this->close_duration_ = close_duration; }
40 
41  void set_max_duration(uint32_t max_duration) { this->max_duration_ = max_duration; }
42  void set_obstacle_rollback(float obstacle_rollback) { this->obstacle_rollback_ = obstacle_rollback; }
43 
44  void set_malfunction_detection(bool malfunction_detection) { this->malfunction_detection_ = malfunction_detection; }
45  void set_start_sensing_delay(uint32_t start_sensing_delay) { this->start_sensing_delay_ = start_sensing_delay; }
46 
48 
49  cover::CoverTraits get_traits() override;
50 
51  protected:
52  void control(const cover::CoverCall &call) override;
53  void stop_prev_trigger_();
54 
55  bool is_at_target_() const;
56  bool is_opening_() const;
57  bool is_opening_blocked_() const;
58  bool is_closing_() const;
59  bool is_closing_blocked_() const;
60  bool is_initial_delay_finished_() const;
61 
62  void direction_idle_(float new_position = FLT_MAX);
64 
65  void recompute_position_();
66 
68 
73  uint32_t open_duration_;
74 
79  uint32_t close_duration_;
80 
81  uint32_t max_duration_{UINT32_MAX};
86 
88  uint32_t last_recompute_time_{0};
89  uint32_t start_dir_time_{0};
90  uint32_t last_publish_time_{0};
91  float target_position_{0};
92 
94 };
95 
96 } // namespace current_based
97 } // namespace esphome
void set_open_sensor(sensor::Sensor *open_sensor)
void start_direction_(cover::CoverOperation dir)
void set_obstacle_rollback(float obstacle_rollback)
void direction_idle_(float new_position=FLT_MAX)
Base class for all cover devices.
Definition: cover.h:111
CoverOperation
Enum encoding the current operation of a cover.
Definition: cover.h:80
void set_close_duration(uint32_t close_duration)
void set_open_duration(uint32_t open_duration)
void set_open_moving_current_threshold(float open_moving_current_threshold)
void set_close_obstacle_current_threshold(float close_obstacle_current_threshold)
void set_close_sensor(sensor::Sensor *close_sensor)
void set_malfunction_detection(bool malfunction_detection)
void set_close_moving_current_threshold(float close_moving_current_threshold)
void set_start_sensing_delay(uint32_t start_sensing_delay)
void set_open_obstacle_current_threshold(float open_obstacle_current_threshold)
void set_max_duration(uint32_t max_duration)
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
Base-class for all sensors.
Definition: sensor.h:57
The cover is currently opening.
Definition: cover.h:84
void control(const cover::CoverCall &call) override