mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-05-19 04:33:27 +02:00
8e75980ebd
* Cleanup dashboard JS * Add vscode * Save start_mark/end_mark * Updates * Updates * Remove need for cv.nameable It's a bit hacky but removes so much bloat from integrations * Add enum helper * Document APIs, and Improvements * Fixes * Fixes * Update PULL_REQUEST_TEMPLATE.md * Updates * Updates * Updates
27 lines
1011 B
Python
27 lines
1011 B
Python
import esphome.codegen as cg
|
|
import esphome.config_validation as cv
|
|
from esphome.const import CONF_COMPONENTS, CONF_ID, CONF_LAMBDA
|
|
|
|
custom_component_ns = cg.esphome_ns.namespace('custom_component')
|
|
CustomComponentConstructor = custom_component_ns.class_('CustomComponentConstructor')
|
|
|
|
MULTI_CONF = True
|
|
CONFIG_SCHEMA = cv.Schema({
|
|
cv.GenerateID(): cv.declare_id(CustomComponentConstructor),
|
|
cv.Required(CONF_LAMBDA): cv.lambda_,
|
|
cv.Optional(CONF_COMPONENTS): cv.ensure_list(cv.Schema({
|
|
cv.GenerateID(): cv.declare_id(cg.Component)
|
|
}).extend(cv.COMPONENT_SCHEMA)),
|
|
})
|
|
|
|
|
|
def to_code(config):
|
|
template_ = yield cg.process_lambda(
|
|
config[CONF_LAMBDA], [], return_type=cg.std_vector.template(cg.ComponentPtr))
|
|
|
|
rhs = CustomComponentConstructor(template_)
|
|
var = cg.variable(config[CONF_ID], rhs)
|
|
for i, conf in enumerate(config.get(CONF_COMPONENTS, [])):
|
|
comp = cg.Pvariable(conf[CONF_ID], var.get_component(i))
|
|
yield cg.register_component(comp, conf)
|