ESPHome 2026.8.0b4
Loading...
Searching...
No Matches
hoermann_hcp_cover.cpp
Go to the documentation of this file.
2
3#include "esphome/core/log.h"
4
5namespace esphome::hoermann_hcp {
6
7static const char *const TAG = "hoermann_hcp.cover";
8
10 cover::CoverTraits traits;
11 traits.set_supports_position(true);
12 traits.set_supports_stop(true);
13 traits.set_supports_toggle(true);
14 return traits;
15}
16
18 // Nothing is published before the bus controller is heard from, and the untouched position reads as fully
19 // open, so flag the entity until the first contact clears it again.
20 this->status_set_warning("waiting for the bus controller");
21 this->parent_->add_on_state_callback([this]() { this->update_from_state_(); });
22}
23
24void HoermannHcpCover::dump_config() { LOG_COVER("", "Hoermann HCP Cover", this); }
25
27 bool accepted = true;
28 if (call.get_stop())
29 accepted &= this->parent_->stop_door();
30 if (call.get_toggle().has_value())
31 accepted &= this->parent_->impulse_door();
32 if (const auto position = call.get_position())
33 accepted &= this->parent_->set_position(*position);
34 if (!accepted) {
35 // The command never reached the door, so publish the unchanged state over the one the caller assumed.
36 ESP_LOGW(TAG, "Command was not accepted by the door");
37 this->publish_state(false);
38 }
39}
40
42 if (!this->parent_->is_valid()) {
43 this->status_set_warning();
44 // The door can now move unheard, so drop the baseline a direction would be inferred from and stop
45 // reporting motion instead of leaving the cover travelling until the controller returns.
46 this->previous_position_ = NAN;
49 this->publish_state();
50 }
51 return;
52 }
54
55 const auto previous_operation = this->current_operation;
56 const float current_position = this->parent_->get_current_position();
57 switch (this->parent_->get_door_state()) {
60 break;
63 break;
66 // These states carry no direction, so keep the current one until the position actually moves.
67 if (!std::isnan(this->previous_position_) && current_position != this->previous_position_) {
70 }
71 break;
72 default:
74 break;
75 }
76 this->previous_position_ = current_position;
77
78 // Compare against the position last published, which starts at COVER_OPEN rather than at zero.
79 const bool changed = this->position != current_position || previous_operation != this->current_operation;
80 this->position = current_position;
81 if (changed) {
82 // The bus reports the position on every broadcast, so nothing here is worth restoring from flash.
83 this->publish_state(false);
84 }
85}
86
87} // namespace esphome::hoermann_hcp
void status_clear_warning()
Definition component.h:289
const optional< bool > & get_toggle() const
Definition cover.cpp:94
const optional< float > & get_position() const
Definition cover.cpp:92
CoverOperation current_operation
The current operation of the cover (idle, opening, closing).
Definition cover.h:115
void publish_state(bool save=true)
Publish the current state of the cover.
Definition cover.cpp:142
float position
The position of the cover from 0.0 (fully closed) to 1.0 (fully open).
Definition cover.h:121
void set_supports_stop(bool supports_stop)
void set_supports_position(bool supports_position)
void set_supports_toggle(bool supports_toggle)
cover::CoverTraits get_traits() override
void control(const cover::CoverCall &call) override
void add_on_state_callback(F &&callback)
@ COVER_OPERATION_OPENING
The cover is currently opening.
Definition cover.h:83
@ COVER_OPERATION_CLOSING
The cover is currently closing.
Definition cover.h:85
@ COVER_OPERATION_IDLE
The cover is currently idle (not moving)
Definition cover.h:81