mirror of
https://github.com/esphome/esphome.git
synced 2025-03-27 21:18:18 +00:00
27 lines
914 B
Python
27 lines
914 B
Python
import esphome.codegen as cg
|
|
import esphome.config_validation as cv
|
|
from esphome.components import light
|
|
from esphome.const import CONF_ID, CONF_LAMBDA
|
|
from .. import custom_ns
|
|
|
|
CustomLightOutputConstructor = custom_ns.class_('CustomLightOutputConstructor')
|
|
CONF_LIGHTS = 'lights'
|
|
|
|
CONFIG_SCHEMA = cv.Schema({
|
|
cv.GenerateID(): cv.declare_id(CustomLightOutputConstructor),
|
|
cv.Required(CONF_LAMBDA): cv.returning_lambda,
|
|
cv.Required(CONF_LIGHTS): cv.ensure_list(light.ADDRESSABLE_LIGHT_SCHEMA),
|
|
})
|
|
|
|
|
|
def to_code(config):
|
|
template_ = yield cg.process_lambda(
|
|
config[CONF_LAMBDA], [],
|
|
return_type=cg.std_vector.template(light.LightOutput.operator('ptr')))
|
|
|
|
rhs = CustomLightOutputConstructor(template_)
|
|
custom = cg.variable(config[CONF_ID], rhs)
|
|
for i, conf in enumerate(config[CONF_LIGHTS]):
|
|
rhs = custom.Pget_light(i)
|
|
yield light.register_light(rhs, conf)
|