ESPHome
2026.11.0b6
Loading...
Searching...
No Matches
esphome
components
hoermann_hcp
text_sensor
hoermann_hcp_text_sensor.cpp
Go to the documentation of this file.
1
#include "
hoermann_hcp_text_sensor.h
"
2
3
#include "
esphome/core/log.h
"
4
#include "
esphome/core/progmem.h
"
5
6
namespace
esphome::hoermann_hcp
{
7
8
ESPHOME_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.
11
PROGMEM_STRING_TABLE
(DoorStateStrings,
"Open"
,
"Opening"
,
"Closed"
,
"Closing"
,
"Half open"
,
"Moving to vent"
,
12
"Vent position"
,
"Moving to half"
,
"Stopped"
);
13
static_assert
(DoorStateStrings::COUNT ==
static_cast<
size_t
>
(
DoorState::STOPPED
) + 1,
14
"DoorStateStrings must list every DoorState in order"
);
15
16
void
HoermannHcpDoorStateTextSensor::setup
() {
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
22
void
HoermannHcpDoorStateTextSensor::dump_config
() { LOG_TEXT_SENSOR(
""
,
"Hoermann HCP Door State"
,
this
); }
23
24
void
HoermannHcpDoorStateTextSensor::update_from_state_
() {
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
esphome::hoermann_hcp::HoermannHcpDoorStateTextSensor::update_from_state_
void update_from_state_()
Definition
hoermann_hcp_text_sensor.cpp:24
esphome::hoermann_hcp::HoermannHcpDoorStateTextSensor::parent_
HoermannHcp *const parent_
Definition
hoermann_hcp_text_sensor.h:19
esphome::hoermann_hcp::HoermannHcpDoorStateTextSensor::published_
bool published_
Definition
hoermann_hcp_text_sensor.h:21
esphome::hoermann_hcp::HoermannHcpDoorStateTextSensor::published_state_
DoorState published_state_
Definition
hoermann_hcp_text_sensor.h:20
esphome::hoermann_hcp::HoermannHcpDoorStateTextSensor::dump_config
void dump_config() override
Definition
hoermann_hcp_text_sensor.cpp:22
esphome::hoermann_hcp::HoermannHcpDoorStateTextSensor::setup
void setup() override
Definition
hoermann_hcp_text_sensor.cpp:16
esphome::text_sensor::TextSensor::state
std::string state
Definition
text_sensor.h:31
esphome::text_sensor::TextSensor::publish_state
void publish_state(const std::string &state)
Definition
text_sensor.h:42
hoermann_hcp_text_sensor.h
log.h
esphome::hoermann_hcp
Definition
hoermann_hcp_binary_sensor.cpp:5
esphome::hoermann_hcp::DoorState
DoorState
Definition
hoermann_hcp.h:19
esphome::hoermann_hcp::DoorState::STOPPED
@ STOPPED
esphome::hoermann_hcp::PROGMEM_STRING_TABLE
PROGMEM_STRING_TABLE(DoorStateStrings, "Open", "Opening", "Closed", "Closing", "Half open", "Moving to vent", "Vent position", "Moving to half", "Stopped")
esphome::hoermann_hcp::ESPHOME_LOG_TAG
ESPHOME_LOG_TAG(TAG, "hoermann_hcp.binary_sensor")
progmem.h
Generated by
1.12.0