attach light
This commit is contained in:
@@ -25,6 +25,7 @@ void AppStatus::dump_config() {
|
|||||||
ESP_LOGCONFIG(TAG, "App status binary sensor");
|
ESP_LOGCONFIG(TAG, "App status binary sensor");
|
||||||
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_));
|
||||||
|
ESP_LOGCONFIG(TAG, " has light = %s", TRUEFALSE(this->light_ != nullptr));
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t AppStatus::get_status_() const {
|
uint8_t AppStatus::get_status_() const {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include "esphome/core/component.h"
|
#include "esphome/core/component.h"
|
||||||
#include "esphome/components/binary_sensor/binary_sensor.h"
|
#include "esphome/components/binary_sensor/binary_sensor.h"
|
||||||
|
#include "esphome/components/light/light_state.h"
|
||||||
|
|
||||||
namespace esphome {
|
namespace esphome {
|
||||||
namespace app_status {
|
namespace app_status {
|
||||||
@@ -16,11 +17,13 @@ class AppStatus : public binary_sensor::BinarySensor, public Component {
|
|||||||
|
|
||||||
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; }
|
||||||
|
void set_light(light::LightState *light) { this->light_ = light; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
uint8_t last_status_{0xFF};
|
uint8_t last_status_{0xFF};
|
||||||
bool include_warnings_{true};
|
bool include_warnings_{true};
|
||||||
bool include_errors_{true};
|
bool include_errors_{true};
|
||||||
|
light::LightState *light_{nullptr};
|
||||||
|
|
||||||
uint8_t get_status_() const;
|
uint8_t get_status_() const;
|
||||||
void publish_status_(uint8_t status);
|
void publish_status_(uint8_t status);
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
# Ref: https://github.com/esphome/starter-components/blob/main/components/empty_binary_sensor/binary_sensor.py
|
# Ref: https://github.com/esphome/starter-components/blob/main/components/empty_binary_sensor/binary_sensor.py
|
||||||
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, light
|
||||||
from esphome.const import CONF_ID
|
from esphome.const import CONF_ID, CONF_LIGHT_ID
|
||||||
|
|
||||||
CONF_DETECT_STATUS = "detect_status"
|
CONF_DETECT_STATUS = "detect_status"
|
||||||
CONF_WARNING = "warning"
|
CONF_WARNING = "warning"
|
||||||
@@ -15,6 +15,7 @@ AppStatus = app_status_ns.class_("AppStatus", binary_sensor.BinarySensor, cg.Com
|
|||||||
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.one_of(CONF_ERROR, CONF_WARNING)),
|
cv.Optional(CONF_DETECT_STATUS, default=[CONF_WARNING, CONF_ERROR]): cv.ensure_list(cv.one_of(CONF_ERROR, CONF_WARNING)),
|
||||||
|
cv.Optional(CONF_LIGHT_ID): cv.use_id(light.LightState),
|
||||||
}).extend(cv.COMPONENT_SCHEMA)
|
}).extend(cv.COMPONENT_SCHEMA)
|
||||||
|
|
||||||
async def to_code(config):
|
async def to_code(config):
|
||||||
@@ -22,3 +23,9 @@ async def to_code(config):
|
|||||||
await cg.register_component(var, config)
|
await cg.register_component(var, config)
|
||||||
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]))
|
||||||
|
|
||||||
|
# XXX - we shouldn't set the light directly from here. Maybe control the light blinking from an output or a light or a switch?
|
||||||
|
# - or maybe we want to, for convenience
|
||||||
|
if CONF_LIGHT_ID in config:
|
||||||
|
light = await cg.get_variable(config[CONF_LIGHT_ID])
|
||||||
|
cg.add(var.set_light(light));
|
||||||
|
|||||||
Reference in New Issue
Block a user