app_status: Remove "inverted", because this can already be done using binary_sensor filters

This commit is contained in:
2025-10-14 02:45:49 -06:00
parent d71f296313
commit a8ddd42e95
4 changed files with 4 additions and 11 deletions

View File

@@ -23,5 +23,6 @@ binary_sensor:
detect_status: detect_status:
- warning - warning
- error - error
inverted: true filters:
- invert:
``` ```

View File

@@ -12,7 +12,7 @@ void AppStatus::setup() {
} }
void AppStatus::update() { void AppStatus::update() {
ESP_LOGV(TAG, "update() called; inverted = %s", TRUEFALSE(this->inverted_)); ESP_LOGV(TAG, "update() called", TRUEFALSE(this->inverted_));
bool result = false; bool result = false;
auto app_state = App.get_app_state() & STATUS_LED_MASK; auto app_state = App.get_app_state() & STATUS_LED_MASK;
if (this->include_errors_ && (app_state & STATUS_LED_ERROR)) { if (this->include_errors_ && (app_state & STATUS_LED_ERROR)) {
@@ -21,15 +21,11 @@ void AppStatus::update() {
if (this->include_warnings_ && (app_state & STATUS_LED_WARNING)) { if (this->include_warnings_ && (app_state & STATUS_LED_WARNING)) {
result = true; result = true;
} }
if (this->inverted_) {
result = !result;
}
this->publish_state(result); this->publish_state(result);
} }
void AppStatus::dump_config() { void AppStatus::dump_config() {
ESP_LOGCONFIG(TAG, "App status binary sensor"); ESP_LOGCONFIG(TAG, "App status binary sensor");
ESP_LOGCONFIG(TAG, " inverted = %s", TRUEFALSE(this->inverted_));
ESP_LOGCONFIG(TAG, " include warnings = %s", TRUEFALSE(this->include_warnings_)); ESP_LOGCONFIG(TAG, " include warnings = %s", TRUEFALSE(this->include_warnings_));
ESP_LOGCONFIG(TAG, " include errors = %s", TRUEFALSE(this->include_errors_)); ESP_LOGCONFIG(TAG, " include errors = %s", TRUEFALSE(this->include_errors_));
} }

View File

@@ -15,13 +15,11 @@ class AppStatus : public binary_sensor::BinarySensor, public PollingComponent {
//float get_loop_priority() const override { return 50.0f; } //float get_loop_priority() const override { return 50.0f; }
void set_inverted(bool value) { this->inverted_ = value; }
void set_include_errors(bool allow) { this->include_errors_ = allow; } void set_include_errors(bool allow) { this->include_errors_ = allow; }
void set_include_warnings(bool allow) { this->include_warnings_ = allow; } void set_include_warnings(bool allow) { this->include_warnings_ = allow; }
protected: protected:
//uint8_t last_app_state_(0xFF); //uint8_t last_app_state_(0xFF);
bool inverted_{false};
bool include_warnings_{true}; bool include_warnings_{true};
bool include_errors_{true}; bool include_errors_{true};
}; };

View File

@@ -3,7 +3,7 @@
import esphome.codegen as cg import esphome.codegen as cg
import esphome.config_validation as cv import esphome.config_validation as cv
from esphome.components import binary_sensor from esphome.components import binary_sensor
from esphome.const import CONF_ID, CONF_INVERTED from esphome.const import CONF_ID
CONF_DETECT_STATUS = "detect_status" CONF_DETECT_STATUS = "detect_status"
CONF_WARNING = "warning" CONF_WARNING = "warning"
@@ -21,12 +21,10 @@ AppStatus = app_status_ns.class_("AppStatus", binary_sensor.BinarySensor, cg.Pol
CONFIG_SCHEMA = binary_sensor.binary_sensor_schema(AppStatus).extend({ CONFIG_SCHEMA = binary_sensor.binary_sensor_schema(AppStatus).extend({
cv.GenerateID(): cv.declare_id(AppStatus), cv.GenerateID(): cv.declare_id(AppStatus),
cv.Optional(CONF_DETECT_STATUS, default=[CONF_WARNING, CONF_ERROR]): cv.ensure_list(cv.enum(DETECT_STATUS_ENUM)), cv.Optional(CONF_DETECT_STATUS, default=[CONF_WARNING, CONF_ERROR]): cv.ensure_list(cv.enum(DETECT_STATUS_ENUM)),
cv.Optional(CONF_INVERTED, default=False): cv.boolean,
}).extend(cv.polling_component_schema(default_update_interval="1s")) }).extend(cv.polling_component_schema(default_update_interval="1s"))
async def to_code(config): async def to_code(config):
var = await binary_sensor.new_binary_sensor(config) var = await binary_sensor.new_binary_sensor(config)
await cg.register_component(var, config) await cg.register_component(var, config)
cg.add(var.set_inverted(config[CONF_INVERTED]))
cg.add(var.set_include_warnings(CONF_WARNING in config[CONF_DETECT_STATUS])) cg.add(var.set_include_warnings(CONF_WARNING in config[CONF_DETECT_STATUS]))
cg.add(var.set_include_errors(CONF_ERROR in config[CONF_DETECT_STATUS])) cg.add(var.set_include_errors(CONF_ERROR in config[CONF_DETECT_STATUS]))