Files
esphome-rgb-status-leds/components/app_status/app_status.cpp

68 lines
1.8 KiB
C++

#include "esphome/core/log.h"
#include "esphome/core/application.h"
#include "app_status.h"
namespace esphome {
namespace app_status {
static const char *TAG = "app_status.binary_sensor";
void AppStatus::setup() {
}
void AppStatus::loop() {
auto status = App.get_app_state() & STATUS_LED_MASK;
if (status == this->last_status_) {
return;
}
this->publish_status_(status);
}
void AppStatus::dump_config() {
ESP_LOGCONFIG(TAG, "App status binary sensor");
ESP_LOGCONFIG(TAG, " include warnings = %s", TRUEFALSE(this->include_warnings_));
ESP_LOGCONFIG(TAG, " include errors = %s", TRUEFALSE(this->include_errors_));
ESP_LOGCONFIG(TAG, " has light = %s", TRUEFALSE(this->light_ != nullptr));
}
uint8_t AppStatus::get_status_() const {
return App.get_app_state() & STATUS_LED_MASK;
}
void AppStatus::publish_status_(uint8_t status) {
bool result = false;
if (this->include_errors_ && (status & STATUS_LED_ERROR)) {
result = true;
}
if (this->include_warnings_ && (status & STATUS_LED_WARNING)) {
result = true;
}
if (this->light_ != nullptr) {
if (this->last_status_ == 0 && status != 0) {
this->saved_light_values_ = this->light_->current_values;
auto call = this->light_->turn_on();
call.set_brightness(0.30);
call.set_rgb(1.0, 0.0, 1.0);
call.set_transition_length(0);
call.set_publish(false);
call.perform();
} else if (this->last_status_ != 0 && status == 0) {
auto call = this->light_->make_call();
//call.from_light_color_values(this->saved_light_values_);
call.from_light_color_values(this->light_->remote_values);
call.set_transition_length(0);
call.set_publish(false);
call.perform();
}
}
this->last_status_ = status;
this->publish_state(result);
}
} // namespace app_status
} // namespace esphome
// vim:set sw=2: