ESPHome  2024.9.2
endstop_cover.h
Go to the documentation of this file.
1 #pragma once
2 
7 
8 namespace esphome {
9 namespace endstop {
10 
11 class EndstopCover : public cover::Cover, public Component {
12  public:
13  void setup() override;
14  void loop() override;
15  void dump_config() override;
16  float get_setup_priority() const override;
17 
18  Trigger<> *get_open_trigger() const { return this->open_trigger_; }
19  Trigger<> *get_close_trigger() const { return this->close_trigger_; }
20  Trigger<> *get_stop_trigger() const { return this->stop_trigger_; }
21  void set_open_endstop(binary_sensor::BinarySensor *open_endstop) { this->open_endstop_ = open_endstop; }
22  void set_close_endstop(binary_sensor::BinarySensor *close_endstop) { this->close_endstop_ = close_endstop; }
23  void set_open_duration(uint32_t open_duration) { this->open_duration_ = open_duration; }
24  void set_close_duration(uint32_t close_duration) { this->close_duration_ = close_duration; }
25  void set_max_duration(uint32_t max_duration) { this->max_duration_ = max_duration; }
26 
27  cover::CoverTraits get_traits() override;
28 
29  protected:
30  void control(const cover::CoverCall &call) override;
31  void stop_prev_trigger_();
32  bool is_open_() const { return this->open_endstop_->state; }
33  bool is_closed_() const { return this->close_endstop_->state; }
34  bool is_at_target_() const;
35 
37 
38  void recompute_position_();
39 
43  uint32_t open_duration_;
45  uint32_t close_duration_;
47  uint32_t max_duration_{UINT32_MAX};
48 
50  uint32_t last_recompute_time_{0};
51  uint32_t start_dir_time_{0};
52  uint32_t last_publish_time_{0};
53  float target_position_{0};
55 };
56 
57 } // namespace endstop
58 } // namespace esphome
Base class for all cover devices.
Definition: cover.h:111
cover::CoverTraits get_traits() override
CoverOperation
Enum encoding the current operation of a cover.
Definition: cover.h:80
binary_sensor::BinarySensor * close_endstop_
Definition: endstop_cover.h:41
void set_close_endstop(binary_sensor::BinarySensor *close_endstop)
Definition: endstop_cover.h:22
Trigger * get_stop_trigger() const
Definition: endstop_cover.h:20
cover::CoverOperation last_operation_
Definition: endstop_cover.h:54
void set_max_duration(uint32_t max_duration)
Definition: endstop_cover.h:25
void set_close_duration(uint32_t close_duration)
Definition: endstop_cover.h:24
void set_open_duration(uint32_t open_duration)
Definition: endstop_cover.h:23
bool state
The current reported state of the binary sensor.
Definition: binary_sensor.h:61
void start_direction_(cover::CoverOperation dir)
Trigger * get_open_trigger() const
Definition: endstop_cover.h:18
void set_open_endstop(binary_sensor::BinarySensor *open_endstop)
Definition: endstop_cover.h:21
Trigger * get_close_trigger() const
Definition: endstop_cover.h:19
binary_sensor::BinarySensor * open_endstop_
Definition: endstop_cover.h:40
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
Base class for all binary_sensor-type classes.
Definition: binary_sensor.h:37
void control(const cover::CoverCall &call) override
The cover is currently opening.
Definition: cover.h:84
float get_setup_priority() const override