ESPHome 2026.6.0-dev
Loading...
Searching...
No Matches
status_led_light.cpp
Go to the documentation of this file.
1#include "status_led_light.h"
2#include "esphome/core/log.h"
4#include <cinttypes>
5
7
8static const char *const TAG = "status_led";
9
11 uint8_t new_state = App.get_app_state() & STATUS_LED_MASK;
12
13 if (new_state != this->last_app_state_) {
14 ESP_LOGV(TAG, "New app state 0x%02X", new_state);
15 }
16
17 if ((new_state & STATUS_LED_ERROR) != 0u) {
18 this->output_state_(millis() % 250u < 150u);
19 this->last_app_state_ = new_state;
20 } else if ((new_state & STATUS_LED_WARNING) != 0u) {
21 this->output_state_(millis() % 1500u < 250u);
22 this->last_app_state_ = new_state;
23 } else if (new_state != this->last_app_state_) {
24 // if no error/warning -> restore light state or turn off
25 bool state = false;
26
27 if (lightstate_)
29 ESP_LOGD(TAG, "Restoring light state %s", ONOFF(state));
30
31 this->output_state_(state);
32 this->last_app_state_ = new_state;
33 }
34}
35
38 ESP_LOGD(TAG, "'%s': Setting initial state", state->get_name().c_str());
39 this->write_state(state);
40}
41
43 bool binary;
44 state->current_values_as_binary(&binary);
45
46 // if in warning/error, don't overwrite the status_led
47 // once it is back to OK, the loop will restore the state
49 ESP_LOGD(TAG, "'%s': Setting state %s", state->get_name().c_str(), ONOFF(binary));
50 this->output_state_(binary);
51 }
52}
53
55 if (this->pin_ != nullptr) {
56 this->pin_->setup();
57 this->pin_->digital_write(false);
58 }
59}
60
62 ESP_LOGCONFIG(TAG, "Status Led Light:");
63 LOG_PIN(" Pin: ", this->pin_);
64}
65
67 if (this->pin_ != nullptr)
68 this->pin_->digital_write(state);
69 if (this->output_ != nullptr)
70 this->output_->set_state(state);
71}
72
73} // namespace esphome::status_led
uint8_t get_app_state() const
Return the public app state status bits (STATUS_LED_* only).
virtual void setup()=0
virtual void digital_write(bool value)=0
This class represents the communication layer between the front-end MQTT layer and the hardware outpu...
Definition light_state.h:93
void current_values_as_binary(bool *binary)
The result of all the current_values_as_* methods have gamma correction applied.
virtual void set_state(bool state)
Enable or disable this binary output.
void write_state(light::LightState *state) override
void setup_state(light::LightState *state) override
bool state
Definition fan.h:2
constexpr uint8_t STATUS_LED_MASK
Definition component.h:86
constexpr uint8_t STATUS_LED_WARNING
Definition component.h:88
uint32_t IRAM_ATTR HOT millis()
Definition hal.cpp:28
Application App
Global storage of Application pointer - only one Application can exist.
constexpr uint8_t STATUS_LED_ERROR
Definition component.h:89