ESPHome 2026.11.0b6
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
7ESPHOME_LOG_TAG(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->status_comm_result(this->parent_->is_valid(), LOG_STR("bus controller not responding"))) {
43 // The door can now move unheard, so drop the baseline a direction would be inferred from and stop
44 // reporting motion instead of leaving the cover travelling until the controller returns.
45 this->previous_position_ = NAN;
48 this->publish_state();
49 }
50 return;
51 }
52
53 const auto previous_operation = this->current_operation;
54 const float current_position = this->parent_->get_current_position();
55 switch (this->parent_->get_door_state()) {
58 break;
61 break;
64 // These states carry no direction, so keep the current one until the position actually moves.
65 if (!std::isnan(this->previous_position_) && current_position != this->previous_position_) {
68 }
69 break;
70 default:
72 break;
73 }
74 this->previous_position_ = current_position;
75
76 // Compare against the position last published, which starts at COVER_OPEN rather than at zero.
77 const bool changed = this->position != current_position || previous_operation != this->current_operation;
78 this->position = current_position;
79 if (changed) {
80 // The bus reports the position on every broadcast, so nothing here is worth restoring from flash.
81 this->publish_state(false);
82 }
83}
84
85} // namespace esphome::hoermann_hcp
bool status_comm_result(bool ok)
Clears the warning when ok, else sets it with message (default "Communication failed"); returns ok.
const optional< bool > & get_toggle() const
Definition cover.cpp:101
const optional< float > & get_position() const
Definition cover.cpp:99
CoverOperation current_operation
The current operation of the cover (idle, opening, closing).
Definition cover.h:120
void publish_state(bool save=true)
Publish the current state of the cover.
Definition cover.cpp:158
float position
The position of the cover from 0.0 (fully closed) to 1.0 (fully open).
Definition cover.h:126
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
@ COVER_OPERATION_OPENING
The cover is currently opening.
Definition cover.h:88
@ COVER_OPERATION_CLOSING
The cover is currently closing.
Definition cover.h:90
@ COVER_OPERATION_IDLE
The cover is currently idle (not moving)
Definition cover.h:86
ESPHOME_LOG_TAG(TAG, "hoermann_hcp.binary_sensor")