2018-12-05 21:22:06 +01:00
|
|
|
import voluptuous as vol
|
|
|
|
|
|
|
|
import esphomeyaml.config_validation as cv
|
|
|
|
from esphomeyaml.const import CONF_ID, CONF_LAMBDA, CONF_COMPONENTS
|
2019-01-29 16:21:00 +01:00
|
|
|
from esphomeyaml.cpp_generator import process_lambda, variable, Pvariable
|
2018-12-05 21:22:06 +01:00
|
|
|
from esphomeyaml.cpp_helpers import setup_component
|
|
|
|
from esphomeyaml.cpp_types import Component, ComponentPtr, esphomelib_ns, std_vector
|
|
|
|
|
|
|
|
CustomComponentConstructor = esphomelib_ns.class_('CustomComponentConstructor')
|
|
|
|
MULTI_CONF = True
|
|
|
|
|
|
|
|
CONFIG_SCHEMA = vol.Schema({
|
|
|
|
cv.GenerateID(): cv.declare_variable_id(CustomComponentConstructor),
|
|
|
|
vol.Required(CONF_LAMBDA): cv.lambda_,
|
2018-12-18 19:31:43 +01:00
|
|
|
vol.Optional(CONF_COMPONENTS): cv.ensure_list(vol.Schema({
|
2018-12-05 21:22:06 +01:00
|
|
|
cv.GenerateID(): cv.declare_variable_id(Component)
|
2018-12-18 19:31:43 +01:00
|
|
|
}).extend(cv.COMPONENT_SCHEMA.schema)),
|
2018-12-05 21:22:06 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
def to_code(config):
|
|
|
|
for template_ in process_lambda(config[CONF_LAMBDA], [],
|
|
|
|
return_type=std_vector.template(ComponentPtr)):
|
|
|
|
yield
|
|
|
|
|
|
|
|
rhs = CustomComponentConstructor(template_)
|
|
|
|
custom = variable(config[CONF_ID], rhs)
|
2019-01-29 16:21:00 +01:00
|
|
|
for i, comp_config in enumerate(config.get(CONF_COMPONENTS, [])):
|
|
|
|
comp = Pvariable(comp_config[CONF_ID], custom.get_component(i))
|
|
|
|
setup_component(comp, comp_config)
|
2018-12-05 21:22:06 +01:00
|
|
|
|
|
|
|
|
|
|
|
BUILD_FLAGS = '-DUSE_CUSTOM_COMPONENT'
|