32 lines
1.4 KiB
Python
32 lines
1.4 KiB
Python
# dlitz 2025
|
|
# Ref: https://github.com/esphome/starter-components/blob/main/components/empty_binary_sensor/binary_sensor.py
|
|
import esphome.codegen as cg
|
|
import esphome.config_validation as cv
|
|
from esphome.components import binary_sensor, light
|
|
from esphome.const import CONF_ID, CONF_LIGHT_ID
|
|
|
|
CONF_DETECT_STATUS = "detect_status"
|
|
CONF_WARNING = "warning"
|
|
CONF_ERROR = "error"
|
|
|
|
app_status_ns = cg.esphome_ns.namespace("app_status")
|
|
AppStatus = app_status_ns.class_("AppStatus", binary_sensor.BinarySensor, cg.Component)
|
|
|
|
CONFIG_SCHEMA = binary_sensor.binary_sensor_schema(AppStatus).extend({
|
|
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_LIGHT_ID): cv.use_id(light.LightState),
|
|
}).extend(cv.COMPONENT_SCHEMA)
|
|
|
|
async def to_code(config):
|
|
var = await binary_sensor.new_binary_sensor(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_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));
|