2019-05-15 10:55:35 +02:00
|
|
|
import esphome.codegen as cg
|
|
|
|
import esphome.config_validation as cv
|
|
|
|
from esphome.components import cover
|
|
|
|
from esphome.const import CONF_ID, CONF_LAMBDA
|
|
|
|
from .. import custom_ns
|
|
|
|
|
2021-03-07 20:03:16 +01:00
|
|
|
CustomCoverConstructor = custom_ns.class_("CustomCoverConstructor")
|
|
|
|
CONF_COVERS = "covers"
|
2019-05-15 10:55:35 +02:00
|
|
|
|
2021-03-07 20:03:16 +01:00
|
|
|
CONFIG_SCHEMA = cv.Schema(
|
|
|
|
{
|
|
|
|
cv.GenerateID(): cv.declare_id(CustomCoverConstructor),
|
|
|
|
cv.Required(CONF_LAMBDA): cv.returning_lambda,
|
|
|
|
cv.Required(CONF_COVERS): cv.ensure_list(cover.COVER_SCHEMA),
|
|
|
|
}
|
|
|
|
)
|
2019-05-15 10:55:35 +02:00
|
|
|
|
|
|
|
|
2021-05-24 10:58:29 +02:00
|
|
|
async def to_code(config):
|
|
|
|
template_ = await cg.process_lambda(
|
2021-03-07 20:03:16 +01:00
|
|
|
config[CONF_LAMBDA],
|
|
|
|
[],
|
|
|
|
return_type=cg.std_vector.template(cover.Cover.operator("ptr")),
|
|
|
|
)
|
2019-05-15 10:55:35 +02:00
|
|
|
|
|
|
|
rhs = CustomCoverConstructor(template_)
|
|
|
|
custom = cg.variable(config[CONF_ID], rhs)
|
|
|
|
for i, conf in enumerate(config[CONF_COVERS]):
|
|
|
|
rhs = custom.Pget_cover(i)
|
2021-05-24 10:58:29 +02:00
|
|
|
await cover.register_cover(rhs, conf)
|