From a84e3f021b8f40dc1ce7640a8c71069e4b260696 Mon Sep 17 00:00:00 2001 From: Darsey Litzenberger Date: Mon, 13 Oct 2025 23:26:07 -0600 Subject: [PATCH] Initial commit --- components/color_status_led/README.md | 12 +++++++ components/color_status_led/__init__.py | 0 .../color_status_led/color_status_led.cpp | 35 +++++++++++++++++++ .../color_status_led/color_status_led.h | 24 +++++++++++++ components/color_status_led/switch.py | 15 ++++++++ 5 files changed, 86 insertions(+) create mode 100644 components/color_status_led/README.md create mode 100644 components/color_status_led/__init__.py create mode 100644 components/color_status_led/color_status_led.cpp create mode 100644 components/color_status_led/color_status_led.h create mode 100644 components/color_status_led/switch.py diff --git a/components/color_status_led/README.md b/components/color_status_led/README.md new file mode 100644 index 0000000..1b3f982 --- /dev/null +++ b/components/color_status_led/README.md @@ -0,0 +1,12 @@ +This should override an RGB LED when app status has warnings or errors, and then restore its state when status is OK. + +```yaml +# example configuration: + +switch: + - platform: color_status_led + name: Color Status LED + light: my_light +``` + +Eventually, this functionality should be folded back into the core `status_led` platform. diff --git a/components/color_status_led/__init__.py b/components/color_status_led/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/components/color_status_led/color_status_led.cpp b/components/color_status_led/color_status_led.cpp new file mode 100644 index 0000000..0e0fc40 --- /dev/null +++ b/components/color_status_led/color_status_led.cpp @@ -0,0 +1,35 @@ +#include "esphome/core/log.h" +#include "esphome/core/application.h" +#include "color_status_led.h" +#include + +namespace esphome { +namespace color_status_led { + +static const char *TAG = "color_status_led.switch"; + +void ColorStatusLED::loop() { + uint8_t new_state = App.get_app_state() & STATUS_LED_MASK; + + if (new_state == this->last_app_state_) { + return; + } + + ESP_LOGV(TAG, "New app state 0x%02X", new_state); + this->last_app_state = new_state; +} + + +void ColorStatusLED::write_state(bool state) { + +} + +void ColorStatusLED::dump_config() { + ESP_LOGCONFIG(TAG, "Color status LED"); + // TODO: Indicate which light is being used +} + +} // namespace color_status_led +} // namespace esphome + +// vim:set sw=2: diff --git a/components/color_status_led/color_status_led.h b/components/color_status_led/color_status_led.h new file mode 100644 index 0000000..94c2a15 --- /dev/null +++ b/components/color_status_led/color_status_led.h @@ -0,0 +1,24 @@ +#pragma once + +#include "esphome/core/component.h" +#include "esphome/component/switch/switch.h" + +namespace esphome { +namespace color_status_led { + +class ColorStatusLED : public switch_::Switch, public Component { + public: + void loop() override; + void write_state(bool state) override; + void dump_config() override; + + float get_loop_priority() const override { return 50.0f; } + + protected: + uint8_t last_app_state_(0xFF); +}; + +} // namespace color_status_led +} // namespace esphome + +// vim:set sw=2: diff --git a/components/color_status_led/switch.py b/components/color_status_led/switch.py new file mode 100644 index 0000000..4660653 --- /dev/null +++ b/components/color_status_led/switch.py @@ -0,0 +1,15 @@ +# dlitz 2025 +# Ref: https://github.com/esphome/starter-components/blob/main/components/empty_switch/switch.py +import esphome.codegen as cg +import esphome.config_validation as cv +from esphome.components import switch +from esphome.const import CONF_ID + +color_status_led_ns = cg.esphome_ns.namespace("color_status_led") +ColorStatusLED = color_status_led_ns.class_("ColorStatusLED", switch.Switch, cg.Component) + +CONFIG_SCHEMA = switch.switch_schema(ColorStatusLED).extend(cv.COMPONENT_SCHEMA) + +async def to_code(config): + var = await switch.new_switch(config) + await cg.register_component(var, config)