ESPHome  2024.4.1
feedback_cover.h
Go to the documentation of this file.
1 #pragma once
2 
5 
6 #ifdef USE_BINARY_SENSOR
8 #endif
10 
11 namespace esphome {
12 namespace feedback {
13 
14 class FeedbackCover : public cover::Cover, public Component {
15  public:
16  void setup() override;
17  void loop() override;
18  void dump_config() override;
19  float get_setup_priority() const override { return setup_priority::DATA; };
20 
21  Trigger<> *get_open_trigger() const { return this->open_trigger_; }
22  Trigger<> *get_close_trigger() const { return this->close_trigger_; }
23  Trigger<> *get_stop_trigger() const { return this->stop_trigger_; }
24 
25 #ifdef USE_BINARY_SENSOR
27  void set_open_sensor(binary_sensor::BinarySensor *open_feedback);
30  void set_close_sensor(binary_sensor::BinarySensor *close_feedback);
32 #endif
33  void set_open_duration(uint32_t duration) { this->open_duration_ = duration; }
34  void set_close_duration(uint32_t duration) { this->close_duration_ = duration; }
35  void set_has_built_in_endstop(bool value) { this->has_built_in_endstop_ = value; }
36  void set_assumed_state(bool value) { this->assumed_state_ = value; }
37  void set_max_duration(uint32_t max_duration) { this->max_duration_ = max_duration; }
38  void set_obstacle_rollback(float obstacle_rollback) { this->obstacle_rollback_ = obstacle_rollback; }
39  void set_update_interval(uint32_t interval) { this->update_interval_ = interval; }
40  void set_infer_endstop(bool infer_endstop) { this->infer_endstop_ = infer_endstop; }
41  void set_direction_change_waittime(uint32_t waittime) { this->direction_change_waittime_ = waittime; }
42  void set_acceleration_wait_time(uint32_t waittime) { this->acceleration_wait_time_ = waittime; }
43 
44  cover::CoverTraits get_traits() override;
45 
46  protected:
47  void control(const cover::CoverCall &call) override;
48  void stop_prev_trigger_();
49  bool is_at_target_() const;
52  void endstop_reached_(bool open_endstop);
53  void recompute_position_();
54  void set_current_operation_(cover::CoverOperation operation, bool is_triggered);
55 
56 #ifdef USE_BINARY_SENSOR
63 
64 #endif
68 
69  uint32_t open_duration_{0};
70  uint32_t close_duration_{0};
71  uint32_t max_duration_{UINT32_MAX};
74  bool has_built_in_endstop_{false};
75  bool assumed_state_{false};
76  bool infer_endstop_{false};
78 
82  uint32_t last_recompute_time_{0};
83  uint32_t start_dir_time_{0};
84  uint32_t last_publish_time_{0};
85  float target_position_{0};
86  uint32_t update_interval_{1000};
87 };
88 
89 } // namespace feedback
90 } // namespace esphome
binary_sensor::BinarySensor * open_endstop_
const float DATA
For components that import data from directly connected sensors like DHT.
Definition: component.cpp:19
Base class for all cover devices.
Definition: cover.h:111
void set_close_endstop(binary_sensor::BinarySensor *close_endstop)
void set_open_duration(uint32_t duration)
void set_current_operation_(cover::CoverOperation operation, bool is_triggered)
void endstop_reached_(bool open_endstop)
binary_sensor::BinarySensor * open_obstacle_
void set_close_duration(uint32_t duration)
CoverOperation
Enum encoding the current operation of a cover.
Definition: cover.h:80
cover::CoverOperation current_trigger_operation_
void update_operation_(cover::CoverOperation dir)
void set_open_sensor(binary_sensor::BinarySensor *open_feedback)
Trigger * get_close_trigger() const
void control(const cover::CoverCall &call) override
binary_sensor::BinarySensor * open_feedback_
void start_direction_(cover::CoverOperation dir)
void set_infer_endstop(bool infer_endstop)
void set_close_obstacle_sensor(binary_sensor::BinarySensor *close_obstacle)
The cover is currently idle (not moving)
Definition: cover.h:82
void set_close_sensor(binary_sensor::BinarySensor *close_feedback)
cover::CoverOperation last_operation_
binary_sensor::BinarySensor * close_feedback_
binary_sensor::BinarySensor * close_endstop_
Trigger * get_open_trigger() const
void set_direction_change_waittime(uint32_t waittime)
void set_open_endstop(binary_sensor::BinarySensor *open_endstop)
void set_has_built_in_endstop(bool value)
void set_max_duration(uint32_t max_duration)
void set_obstacle_rollback(float obstacle_rollback)
cover::CoverTraits get_traits() override
This is a workaround until we can figure out a way to get the tflite-micro idf component code availab...
Definition: a01nyub.cpp:7
void set_update_interval(uint32_t interval)
Base class for all binary_sensor-type classes.
Definition: binary_sensor.h:37
void set_open_obstacle_sensor(binary_sensor::BinarySensor *open_obstacle)
Trigger * get_stop_trigger() const
void set_acceleration_wait_time(uint32_t waittime)
float get_setup_priority() const override
The cover is currently opening.
Definition: cover.h:84
optional< uint32_t > direction_change_waittime_
binary_sensor::BinarySensor * close_obstacle_