mirror of
https://github.com/esphome/esphome.git
synced 2025-01-30 23:02:14 +01:00
[custom] Remove platforms (#8119)
This commit is contained in:
parent
78ce8f014a
commit
4843bbd38a
@ -1,3 +0,0 @@
|
||||
import esphome.codegen as cg
|
||||
|
||||
custom_ns = cg.esphome_ns.namespace("custom")
|
@ -1,31 +1,5 @@
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome.components import binary_sensor
|
||||
from esphome.const import CONF_BINARY_SENSORS, CONF_ID, CONF_LAMBDA
|
||||
from .. import custom_ns
|
||||
|
||||
CustomBinarySensorConstructor = custom_ns.class_("CustomBinarySensorConstructor")
|
||||
|
||||
CONFIG_SCHEMA = cv.Schema(
|
||||
{
|
||||
cv.GenerateID(): cv.declare_id(CustomBinarySensorConstructor),
|
||||
cv.Required(CONF_LAMBDA): cv.returning_lambda,
|
||||
cv.Required(CONF_BINARY_SENSORS): cv.ensure_list(
|
||||
binary_sensor.binary_sensor_schema()
|
||||
),
|
||||
}
|
||||
CONFIG_SCHEMA = cv.invalid(
|
||||
'The "custom" component has been removed. Consider conversion to an external component.\nhttps://esphome.io/guides/contributing#a-note-about-custom-components'
|
||||
)
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
template_ = await cg.process_lambda(
|
||||
config[CONF_LAMBDA],
|
||||
[],
|
||||
return_type=cg.std_vector.template(binary_sensor.BinarySensorPtr),
|
||||
)
|
||||
|
||||
rhs = CustomBinarySensorConstructor(template_)
|
||||
custom = cg.variable(config[CONF_ID], rhs)
|
||||
for i, conf in enumerate(config[CONF_BINARY_SENSORS]):
|
||||
rhs = custom.Pget_binary_sensor(i)
|
||||
await binary_sensor.register_binary_sensor(rhs, conf)
|
||||
|
@ -1,16 +0,0 @@
|
||||
#include "custom_binary_sensor.h"
|
||||
#include "esphome/core/log.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace custom {
|
||||
|
||||
static const char *const TAG = "custom.binary_sensor";
|
||||
|
||||
void CustomBinarySensorConstructor::dump_config() {
|
||||
for (auto *child : this->binary_sensors_) {
|
||||
LOG_BINARY_SENSOR("", "Custom Binary Sensor", child);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace custom
|
||||
} // namespace esphome
|
@ -1,26 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/components/binary_sensor/binary_sensor.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace esphome {
|
||||
namespace custom {
|
||||
|
||||
class CustomBinarySensorConstructor : public Component {
|
||||
public:
|
||||
CustomBinarySensorConstructor(const std::function<std::vector<binary_sensor::BinarySensor *>()> &init) {
|
||||
this->binary_sensors_ = init();
|
||||
}
|
||||
|
||||
binary_sensor::BinarySensor *get_binary_sensor(int i) { return this->binary_sensors_[i]; }
|
||||
|
||||
void dump_config() override;
|
||||
|
||||
protected:
|
||||
std::vector<binary_sensor::BinarySensor *> binary_sensors_;
|
||||
};
|
||||
|
||||
} // namespace custom
|
||||
} // namespace esphome
|
@ -1,30 +1,5 @@
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome.components import climate
|
||||
from esphome.const import CONF_ID, CONF_LAMBDA
|
||||
from .. import custom_ns
|
||||
|
||||
CustomClimateConstructor = custom_ns.class_("CustomClimateConstructor")
|
||||
CONF_CLIMATES = "climates"
|
||||
|
||||
CONFIG_SCHEMA = cv.Schema(
|
||||
{
|
||||
cv.GenerateID(): cv.declare_id(CustomClimateConstructor),
|
||||
cv.Required(CONF_LAMBDA): cv.returning_lambda,
|
||||
cv.Required(CONF_CLIMATES): cv.ensure_list(climate.CLIMATE_SCHEMA),
|
||||
}
|
||||
CONFIG_SCHEMA = cv.invalid(
|
||||
'The "custom" component has been removed. Consider conversion to an external component.\nhttps://esphome.io/guides/contributing#a-note-about-custom-components'
|
||||
)
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
template_ = await cg.process_lambda(
|
||||
config[CONF_LAMBDA],
|
||||
[],
|
||||
return_type=cg.std_vector.template(climate.Climate.operator("ptr")),
|
||||
)
|
||||
|
||||
rhs = CustomClimateConstructor(template_)
|
||||
custom = cg.variable(config[CONF_ID], rhs)
|
||||
for i, conf in enumerate(config[CONF_CLIMATES]):
|
||||
rhs = custom.Pget_climate(i)
|
||||
await climate.register_climate(rhs, conf)
|
||||
|
@ -1,22 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/components/climate/climate.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace esphome {
|
||||
namespace custom {
|
||||
|
||||
class CustomClimateConstructor {
|
||||
public:
|
||||
CustomClimateConstructor(const std::function<std::vector<climate::Climate *>()> &init) { this->climates_ = init(); }
|
||||
|
||||
climate::Climate *get_climate(int i) { return this->climates_[i]; }
|
||||
|
||||
protected:
|
||||
std::vector<climate::Climate *> climates_;
|
||||
};
|
||||
|
||||
} // namespace custom
|
||||
} // namespace esphome
|
@ -1,30 +1,5 @@
|
||||
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
|
||||
|
||||
CustomCoverConstructor = custom_ns.class_("CustomCoverConstructor")
|
||||
CONF_COVERS = "covers"
|
||||
|
||||
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),
|
||||
}
|
||||
CONFIG_SCHEMA = cv.invalid(
|
||||
'The "custom" component has been removed. Consider conversion to an external component.\nhttps://esphome.io/guides/contributing#a-note-about-custom-components'
|
||||
)
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
template_ = await cg.process_lambda(
|
||||
config[CONF_LAMBDA],
|
||||
[],
|
||||
return_type=cg.std_vector.template(cover.Cover.operator("ptr")),
|
||||
)
|
||||
|
||||
rhs = CustomCoverConstructor(template_)
|
||||
custom = cg.variable(config[CONF_ID], rhs)
|
||||
for i, conf in enumerate(config[CONF_COVERS]):
|
||||
rhs = custom.Pget_cover(i)
|
||||
await cover.register_cover(rhs, conf)
|
||||
|
@ -1,21 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/cover/cover.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace esphome {
|
||||
namespace custom {
|
||||
|
||||
class CustomCoverConstructor {
|
||||
public:
|
||||
CustomCoverConstructor(const std::function<std::vector<cover::Cover *>()> &init) { this->covers_ = init(); }
|
||||
|
||||
cover::Cover *get_cover(int i) { return this->covers_[i]; }
|
||||
|
||||
protected:
|
||||
std::vector<cover::Cover *> covers_;
|
||||
};
|
||||
|
||||
} // namespace custom
|
||||
} // namespace esphome
|
@ -1,30 +1,5 @@
|
||||
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),
|
||||
}
|
||||
CONFIG_SCHEMA = cv.invalid(
|
||||
'The "custom" component has been removed. Consider conversion to an external component.\nhttps://esphome.io/guides/contributing#a-note-about-custom-components'
|
||||
)
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
template_ = await 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)
|
||||
await light.register_light(rhs, conf)
|
||||
|
@ -1,24 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/components/light/light_output.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace esphome {
|
||||
namespace custom {
|
||||
|
||||
class CustomLightOutputConstructor {
|
||||
public:
|
||||
CustomLightOutputConstructor(const std::function<std::vector<light::LightOutput *>()> &init) {
|
||||
this->outputs_ = init();
|
||||
}
|
||||
|
||||
light::LightOutput *get_light(int i) { return this->outputs_[i]; }
|
||||
|
||||
protected:
|
||||
std::vector<light::LightOutput *> outputs_;
|
||||
};
|
||||
|
||||
} // namespace custom
|
||||
} // namespace esphome
|
@ -1,61 +1,5 @@
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome.components import output
|
||||
from esphome.const import CONF_ID, CONF_LAMBDA, CONF_OUTPUTS, CONF_TYPE, CONF_BINARY
|
||||
from .. import custom_ns
|
||||
|
||||
CustomBinaryOutputConstructor = custom_ns.class_("CustomBinaryOutputConstructor")
|
||||
CustomFloatOutputConstructor = custom_ns.class_("CustomFloatOutputConstructor")
|
||||
|
||||
CONF_FLOAT = "float"
|
||||
|
||||
CONFIG_SCHEMA = cv.typed_schema(
|
||||
{
|
||||
CONF_BINARY: cv.Schema(
|
||||
{
|
||||
cv.GenerateID(): cv.declare_id(CustomBinaryOutputConstructor),
|
||||
cv.Required(CONF_LAMBDA): cv.returning_lambda,
|
||||
cv.Required(CONF_OUTPUTS): cv.ensure_list(
|
||||
output.BINARY_OUTPUT_SCHEMA.extend(
|
||||
{
|
||||
cv.GenerateID(): cv.declare_id(output.BinaryOutput),
|
||||
}
|
||||
)
|
||||
),
|
||||
}
|
||||
),
|
||||
CONF_FLOAT: cv.Schema(
|
||||
{
|
||||
cv.GenerateID(): cv.declare_id(CustomFloatOutputConstructor),
|
||||
cv.Required(CONF_LAMBDA): cv.returning_lambda,
|
||||
cv.Required(CONF_OUTPUTS): cv.ensure_list(
|
||||
output.FLOAT_OUTPUT_SCHEMA.extend(
|
||||
{
|
||||
cv.GenerateID(): cv.declare_id(output.FloatOutput),
|
||||
}
|
||||
)
|
||||
),
|
||||
}
|
||||
),
|
||||
},
|
||||
lower=True,
|
||||
CONFIG_SCHEMA = cv.invalid(
|
||||
'The "custom" component has been removed. Consider conversion to an external component.\nhttps://esphome.io/guides/contributing#a-note-about-custom-components'
|
||||
)
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
type = config[CONF_TYPE]
|
||||
if type == "binary":
|
||||
ret_type = output.BinaryOutputPtr
|
||||
klass = CustomBinaryOutputConstructor
|
||||
else:
|
||||
ret_type = output.FloatOutputPtr
|
||||
klass = CustomFloatOutputConstructor
|
||||
template_ = await cg.process_lambda(
|
||||
config[CONF_LAMBDA], [], return_type=cg.std_vector.template(ret_type)
|
||||
)
|
||||
|
||||
rhs = klass(template_)
|
||||
custom = cg.variable(config[CONF_ID], rhs)
|
||||
for i, conf in enumerate(config[CONF_OUTPUTS]):
|
||||
out = cg.Pvariable(conf[CONF_ID], custom.get_output(i))
|
||||
await output.register_output(out, conf)
|
||||
|
@ -1,37 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/components/output/binary_output.h"
|
||||
#include "esphome/components/output/float_output.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace esphome {
|
||||
namespace custom {
|
||||
|
||||
class CustomBinaryOutputConstructor {
|
||||
public:
|
||||
CustomBinaryOutputConstructor(const std::function<std::vector<output::BinaryOutput *>()> &init) {
|
||||
this->outputs_ = init();
|
||||
}
|
||||
|
||||
output::BinaryOutput *get_output(int i) { return this->outputs_[i]; }
|
||||
|
||||
protected:
|
||||
std::vector<output::BinaryOutput *> outputs_;
|
||||
};
|
||||
|
||||
class CustomFloatOutputConstructor {
|
||||
public:
|
||||
CustomFloatOutputConstructor(const std::function<std::vector<output::FloatOutput *>()> &init) {
|
||||
this->outputs_ = init();
|
||||
}
|
||||
|
||||
output::FloatOutput *get_output(int i) { return this->outputs_[i]; }
|
||||
|
||||
protected:
|
||||
std::vector<output::FloatOutput *> outputs_;
|
||||
};
|
||||
|
||||
} // namespace custom
|
||||
} // namespace esphome
|
@ -1,27 +1,5 @@
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome.components import sensor
|
||||
from esphome.const import CONF_ID, CONF_LAMBDA, CONF_SENSORS
|
||||
from .. import custom_ns
|
||||
|
||||
CustomSensorConstructor = custom_ns.class_("CustomSensorConstructor")
|
||||
|
||||
CONFIG_SCHEMA = cv.Schema(
|
||||
{
|
||||
cv.GenerateID(): cv.declare_id(CustomSensorConstructor),
|
||||
cv.Required(CONF_LAMBDA): cv.returning_lambda,
|
||||
cv.Required(CONF_SENSORS): cv.ensure_list(sensor.sensor_schema()),
|
||||
}
|
||||
CONFIG_SCHEMA = cv.invalid(
|
||||
'The "custom" component has been removed. Consider conversion to an external component.\nhttps://esphome.io/guides/contributing#a-note-about-custom-components'
|
||||
)
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
template_ = await cg.process_lambda(
|
||||
config[CONF_LAMBDA], [], return_type=cg.std_vector.template(sensor.SensorPtr)
|
||||
)
|
||||
|
||||
rhs = CustomSensorConstructor(template_)
|
||||
var = cg.variable(config[CONF_ID], rhs)
|
||||
for i, conf in enumerate(config[CONF_SENSORS]):
|
||||
sens = cg.Pvariable(conf[CONF_ID], var.get_sensor(i))
|
||||
await sensor.register_sensor(sens, conf)
|
||||
|
@ -1,16 +0,0 @@
|
||||
#include "custom_sensor.h"
|
||||
#include "esphome/core/log.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace custom {
|
||||
|
||||
static const char *const TAG = "custom.sensor";
|
||||
|
||||
void CustomSensorConstructor::dump_config() {
|
||||
for (auto *child : this->sensors_) {
|
||||
LOG_SENSOR("", "Custom Sensor", child);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace custom
|
||||
} // namespace esphome
|
@ -1,24 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/components/sensor/sensor.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace esphome {
|
||||
namespace custom {
|
||||
|
||||
class CustomSensorConstructor : public Component {
|
||||
public:
|
||||
CustomSensorConstructor(const std::function<std::vector<sensor::Sensor *>()> &init) { this->sensors_ = init(); }
|
||||
|
||||
sensor::Sensor *get_sensor(int i) { return this->sensors_[i]; }
|
||||
|
||||
void dump_config() override;
|
||||
|
||||
protected:
|
||||
std::vector<sensor::Sensor *> sensors_;
|
||||
};
|
||||
|
||||
} // namespace custom
|
||||
} // namespace esphome
|
@ -1,27 +1,5 @@
|
||||
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(switch.Switch)),
|
||||
}
|
||||
CONFIG_SCHEMA = cv.invalid(
|
||||
'The "custom" component has been removed. Consider conversion to an external component.\nhttps://esphome.io/guides/contributing#a-note-about-custom-components'
|
||||
)
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
template_ = await 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))
|
||||
await switch.register_switch(switch_, conf)
|
||||
|
@ -1,16 +0,0 @@
|
||||
#include "custom_switch.h"
|
||||
#include "esphome/core/log.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace custom {
|
||||
|
||||
static const char *const TAG = "custom.switch";
|
||||
|
||||
void CustomSwitchConstructor::dump_config() {
|
||||
for (auto *child : this->switches_) {
|
||||
LOG_SWITCH("", "Custom Switch", child);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace custom
|
||||
} // namespace esphome
|
@ -1,24 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/components/switch/switch.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace esphome {
|
||||
namespace custom {
|
||||
|
||||
class CustomSwitchConstructor : public Component {
|
||||
public:
|
||||
CustomSwitchConstructor(const std::function<std::vector<switch_::Switch *>()> &init) { this->switches_ = init(); }
|
||||
|
||||
switch_::Switch *get_switch(int i) { return this->switches_[i]; }
|
||||
|
||||
void dump_config() override;
|
||||
|
||||
protected:
|
||||
std::vector<switch_::Switch *> switches_;
|
||||
};
|
||||
|
||||
} // namespace custom
|
||||
} // namespace esphome
|
@ -1,32 +1,5 @@
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome.components import text_sensor
|
||||
from esphome.const import CONF_ID, CONF_LAMBDA, CONF_TEXT_SENSORS
|
||||
from .. import custom_ns
|
||||
|
||||
CustomTextSensorConstructor = custom_ns.class_("CustomTextSensorConstructor")
|
||||
|
||||
CONFIG_SCHEMA = cv.Schema(
|
||||
{
|
||||
cv.GenerateID(): cv.declare_id(CustomTextSensorConstructor),
|
||||
cv.Required(CONF_LAMBDA): cv.returning_lambda,
|
||||
cv.Required(CONF_TEXT_SENSORS): cv.ensure_list(
|
||||
text_sensor.text_sensor_schema()
|
||||
),
|
||||
}
|
||||
CONFIG_SCHEMA = cv.invalid(
|
||||
'The "custom" component has been removed. Consider conversion to an external component.\nhttps://esphome.io/guides/contributing#a-note-about-custom-components'
|
||||
)
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
template_ = await cg.process_lambda(
|
||||
config[CONF_LAMBDA],
|
||||
[],
|
||||
return_type=cg.std_vector.template(text_sensor.TextSensorPtr),
|
||||
)
|
||||
|
||||
rhs = CustomTextSensorConstructor(template_)
|
||||
var = cg.variable(config[CONF_ID], rhs)
|
||||
|
||||
for i, conf in enumerate(config[CONF_TEXT_SENSORS]):
|
||||
text = cg.Pvariable(conf[CONF_ID], var.get_text_sensor(i))
|
||||
await text_sensor.register_text_sensor(text, conf)
|
||||
|
@ -1,16 +0,0 @@
|
||||
#include "custom_text_sensor.h"
|
||||
#include "esphome/core/log.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace custom {
|
||||
|
||||
static const char *const TAG = "custom.text_sensor";
|
||||
|
||||
void CustomTextSensorConstructor::dump_config() {
|
||||
for (auto *child : this->text_sensors_) {
|
||||
LOG_TEXT_SENSOR("", "Custom Text Sensor", child);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace custom
|
||||
} // namespace esphome
|
@ -1,26 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/components/text_sensor/text_sensor.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace esphome {
|
||||
namespace custom {
|
||||
|
||||
class CustomTextSensorConstructor : public Component {
|
||||
public:
|
||||
CustomTextSensorConstructor(const std::function<std::vector<text_sensor::TextSensor *>()> &init) {
|
||||
this->text_sensors_ = init();
|
||||
}
|
||||
|
||||
text_sensor::TextSensor *get_text_sensor(int i) { return this->text_sensors_[i]; }
|
||||
|
||||
void dump_config() override;
|
||||
|
||||
protected:
|
||||
std::vector<text_sensor::TextSensor *> text_sensors_;
|
||||
};
|
||||
|
||||
} // namespace custom
|
||||
} // namespace esphome
|
@ -1,31 +1,7 @@
|
||||
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.returning_lambda,
|
||||
cv.Optional(CONF_COMPONENTS): cv.ensure_list(
|
||||
cv.Schema({cv.GenerateID(): cv.declare_id(cg.Component)}).extend(
|
||||
cv.COMPONENT_SCHEMA
|
||||
)
|
||||
),
|
||||
}
|
||||
|
||||
CONFIG_SCHEMA = cv.invalid(
|
||||
'The "custom" component has been removed. Consider conversion to an external component.\nhttps://esphome.io/guides/contributing#a-note-about-custom-components'
|
||||
)
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
template_ = await 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))
|
||||
await cg.register_component(comp, conf)
|
||||
|
@ -1,28 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/core/application.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace esphome {
|
||||
namespace custom_component {
|
||||
|
||||
class CustomComponentConstructor {
|
||||
public:
|
||||
CustomComponentConstructor(const std::function<std::vector<Component *>()> &init) {
|
||||
this->components_ = init();
|
||||
|
||||
for (auto *comp : this->components_) {
|
||||
App.register_component(comp);
|
||||
}
|
||||
}
|
||||
|
||||
Component *get_component(int i) const { return this->components_[i]; }
|
||||
|
||||
protected:
|
||||
std::vector<Component *> components_;
|
||||
};
|
||||
|
||||
} // namespace custom_component
|
||||
} // namespace esphome
|
Loading…
Reference in New Issue
Block a user