Initial commit
This commit is contained in:
12
components/color_status_led/README.md
Normal file
12
components/color_status_led/README.md
Normal file
@@ -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.
|
||||
0
components/color_status_led/__init__.py
Normal file
0
components/color_status_led/__init__.py
Normal file
35
components/color_status_led/color_status_led.cpp
Normal file
35
components/color_status_led/color_status_led.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
#include "esphome/core/log.h"
|
||||
#include "esphome/core/application.h"
|
||||
#include "color_status_led.h"
|
||||
#include <cinttypes>
|
||||
|
||||
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:
|
||||
24
components/color_status_led/color_status_led.h
Normal file
24
components/color_status_led/color_status_led.h
Normal file
@@ -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:
|
||||
15
components/color_status_led/switch.py
Normal file
15
components/color_status_led/switch.py
Normal file
@@ -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)
|
||||
Reference in New Issue
Block a user