ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
hoermann_hcp_light.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.light");
8
10 auto traits = light::LightTraits();
11 traits.set_supported_color_modes({light::ColorMode::ON_OFF});
12 return traits;
13}
14
16 // Nothing is known about the lamp until the bus controller is heard from, so flag the entity until then.
17 this->status_set_warning(LOG_STR("waiting for the bus controller"));
18 this->parent_->add_on_state_callback([this]() { this->update_from_state_(); });
19}
20
22
24 bool binary;
26 // A publish of ours only reaches write_state() a loop pass later, by which time the lamp may have moved on,
27 // so it is recognised by the value it carried rather than by the current one.
28 const optional<bool> published = this->published_state_;
29 this->published_state_.reset();
30 // LightState::setup() always performs a call, so the very first write here is the restored state coming back
31 // rather than a request.
32 const bool restored = !this->boot_replay_done_;
33 this->boot_replay_done_ = true;
34 const bool heading_on = this->parent_->is_light_heading_on();
35 if (binary == heading_on)
36 return;
37 if (restored) {
38 ESP_LOGD(TAG, "Ignoring the restored state, the door decides what the lamp is doing");
39 } else if (published != binary) {
40 // Refused until the door has reported the lamp, as commanding an unread one could switch off a lit lamp.
41 if (this->parent_->set_light(binary))
42 return;
43 ESP_LOGW(TAG, "Door has not reported the lamp yet, ignoring the requested state");
44 }
45 // Nothing was sent, so the entity has to go back to showing the lamp rather than the request.
46 this->publish_lamp_state_(heading_on);
47}
48
50 if (this->light_state_ == nullptr)
51 return;
52 if (!this->parent_->is_valid()) {
53 this->status_set_warning(LOG_STR("bus controller not responding"));
54 return;
55 }
56 if (!this->parent_->is_light_known()) {
57 // Commands are refused until the door says, so say so rather than looking healthy and doing nothing.
58 this->status_set_warning(LOG_STR("door has not reported the lamp"));
59 return;
60 }
62 const bool heading_on = this->parent_->is_light_heading_on();
63 if (this->light_state_->remote_values.is_on() != heading_on)
64 this->publish_lamp_state_(heading_on);
65}
66
67// Re-enters write_state() a loop pass later, where published_state_ marks the write as ours.
69 this->published_state_ = on;
70 auto call = this->light_state_->make_call();
71 call.set_state(on);
72 // The bus reports the lamp on every broadcast, so nothing here is worth restoring from flash.
73 call.set_save(false);
74 call.perform();
75}
76
77} // namespace esphome::hoermann_hcp
void status_clear_warning()
Definition component.h:291
light::LightTraits get_traits() override
void write_state(light::LightState *state) override
void setup_state(light::LightState *state) override
LightCall & set_save(bool save)
Set whether this light call should trigger a save state to recover them at startup....
LightCall & set_state(optional< bool > state)
Set the binary ON/OFF state of the light.
bool is_on() const
Get the binary true/false state of these light color values.
This class represents the communication layer between the front-end MQTT layer and the hardware outpu...
Definition light_state.h:68
LightColorValues remote_values
The remote color values reported to the frontend.
void current_values_as_binary(bool *binary)
The result of all the current_values_as_* methods have gamma correction applied.
This class is used to represent the capabilities of a light.
Definition light_traits.h:9
bool state
Definition fan.h:2
ESPHOME_LOG_TAG(TAG, "hoermann_hcp.binary_sensor")
@ ON_OFF
Only on/off control.