mirror of
https://github.com/esphome/esphome.git
synced 2024-12-04 04:28:19 +01:00
27 lines
976 B
Python
27 lines
976 B
Python
import esphome.codegen as cg
|
|
import esphome.config_validation as cv
|
|
from esphome.components import switch
|
|
from esphome.const import CONF_ID, CONF_LAMBDA, CONF_SWITCHES
|
|
from .. import custom_ns
|
|
|
|
CustomSwitchConstructor = custom_ns.class_('CustomSwitchConstructor')
|
|
|
|
CONFIG_SCHEMA = cv.Schema({
|
|
cv.GenerateID(): cv.declare_id(CustomSwitchConstructor),
|
|
cv.Required(CONF_LAMBDA): cv.returning_lambda,
|
|
cv.Required(CONF_SWITCHES):
|
|
cv.ensure_list(switch.SWITCH_SCHEMA.extend({
|
|
cv.GenerateID(): cv.declare_id(switch.Switch),
|
|
})),
|
|
})
|
|
|
|
|
|
def to_code(config):
|
|
template_ = yield cg.process_lambda(
|
|
config[CONF_LAMBDA], [], return_type=cg.std_vector.template(switch.SwitchPtr))
|
|
|
|
rhs = CustomSwitchConstructor(template_)
|
|
var = cg.variable(config[CONF_ID], rhs)
|
|
for i, conf in enumerate(config[CONF_SWITCHES]):
|
|
switch_ = cg.Pvariable(conf[CONF_ID], var.get_switch(i))
|
|
yield switch.register_switch(switch_, conf)
|