ESPHome 2026.11.0b6
Loading...
Searching...
No Matches
hoermann_hcp_text_sensor.cpp
Go to the documentation of this file.
2
3#include "esphome/core/log.h"
5
6namespace esphome::hoermann_hcp {
7
8ESPHOME_LOG_TAG(TAG, "hoermann_hcp.text_sensor");
9
10// Indexed by DoorState. Each fits the 15 characters std::string keeps inline, so publishing never allocates.
11PROGMEM_STRING_TABLE(DoorStateStrings, "Open", "Opening", "Closed", "Closing", "Half open", "Moving to vent",
12 "Vent position", "Moving to half", "Stopped");
13static_assert(DoorStateStrings::COUNT == static_cast<size_t>(DoorState::STOPPED) + 1,
14 "DoorStateStrings must list every DoorState in order");
15
17 this->parent_->add_on_state_callback([this]() { this->update_from_state_(); });
18 // A state decoded before the callback was added would otherwise wait for the next change.
19 this->update_from_state_();
20}
21
22void HoermannHcpDoorStateTextSensor::dump_config() { LOG_TEXT_SENSOR("", "Hoermann HCP Door State", this); }
23
25 // The last state stays while the bus controller is gone, and is published again once it is back.
26 if (!this->parent_->is_valid()) {
27 this->published_ = false;
28 return;
29 }
30 if (!this->parent_->is_door_state_known())
31 return;
32 // Any hub change runs this, so only a new door state is published.
33 const DoorState state = this->parent_->get_door_state();
34 if (this->published_ && state == this->published_state_)
35 return;
36 this->published_ = true;
37 this->published_state_ = state;
38 this->publish_state(DoorStateStrings::get_progmem_str(static_cast<uint8_t>(state), DoorStateStrings::LAST_INDEX));
39}
40
41} // namespace esphome::hoermann_hcp
void publish_state(const std::string &state)
Definition text_sensor.h:42
PROGMEM_STRING_TABLE(DoorStateStrings, "Open", "Opening", "Closed", "Closing", "Half open", "Moving to vent", "Vent position", "Moving to half", "Stopped")
ESPHOME_LOG_TAG(TAG, "hoermann_hcp.binary_sensor")