50 lines
1.2 KiB
C++
50 lines
1.2 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);
|
|
this->last_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;
|
|
}
|
|
this->publish_state(result);
|
|
}
|
|
|
|
} // namespace app_status
|
|
} // namespace esphome
|
|
|
|
// vim:set sw=2:
|