This commit is contained in:
Otto Winter 2018-11-26 20:43:02 +01:00
parent a7653e9efb
commit b54ab3d623
No known key found for this signature in database
GPG Key ID: DB66C0BE6013F97E
4 changed files with 33 additions and 9 deletions

View File

@ -0,0 +1,25 @@
import voluptuous as vol
import esphomeyaml.config_validation as cv
from esphomeyaml.const import CONF_ID, CONF_LAMBDA
from esphomeyaml.cpp_generator import process_lambda, variable
from esphomeyaml.cpp_types import Component, ComponentPtr, esphomelib_ns, std_vector
CustomComponentConstructor = esphomelib_ns.class_('CustomComponentConstructor')
CUSTOM_COMPONENT_SCHEMA = vol.Schema({
cv.GenerateID(): cv.declare_variable_id(Component),
vol.Required(CONF_LAMBDA): cv.lambda_,
})
def to_code(config):
for template_ in process_lambda(config[CONF_LAMBDA], [],
return_type=std_vector.template(ComponentPtr)):
yield
rhs = CustomComponentConstructor(template_)
variable(config[CONF_ID], rhs)
BUILD_FLAGS = '-DUSE_CUSTOM_COMPONENT'

View File

@ -1,15 +1,13 @@
import voluptuous as vol
from esphomeyaml.components import binary_sensor, output
from esphomeyaml.components import output
import esphomeyaml.config_validation as cv
from esphomeyaml.const import CONF_ID, CONF_LAMBDA, CONF_OUTPUTS, CONF_TYPE
from esphomeyaml.cpp_generator import process_lambda, variable
from esphomeyaml.cpp_types import std_vector
CustomBinaryOutputConstructor = binary_sensor.binary_sensor_ns.class_(
'CustomBinaryOutputConstructor')
CustomFloatOutputConstructor = binary_sensor.binary_sensor_ns.class_(
'CustomFloatOutputConstructor')
CustomBinaryOutputConstructor = output.output_ns.class_('CustomBinaryOutputConstructor')
CustomFloatOutputConstructor = output.output_ns.class_('CustomFloatOutputConstructor')
BINARY_SCHEMA = output.PLATFORM_SCHEMA.extend({
cv.GenerateID(): cv.declare_variable_id(CustomBinaryOutputConstructor),

View File

@ -464,7 +464,7 @@ class MockObj(Expression):
return obj
def class_(self, name, *parents): # type: (str, *MockObjClass) -> MockObjClass
obj = MockObjClass(u'{}::{}'.format(self.base, name), u'.', parents=parents)
obj = MockObjClass(u'{}{}{}'.format(self.base, self.op, name), u'.', parents=parents)
obj.requires.append(self)
return obj

View File

@ -4,8 +4,8 @@ global_ns = MockObj('', '')
float_ = global_ns.namespace('float')
bool_ = global_ns.namespace('bool')
std_ns = global_ns.namespace('std')
std_string = std_ns.string
std_vector = std_ns.vector
std_string = std_ns.class_('string')
std_vector = std_ns.class_('vector')
uint8 = global_ns.namespace('uint8_t')
uint16 = global_ns.namespace('uint16_t')
uint32 = global_ns.namespace('uint32_t')
@ -13,13 +13,14 @@ int32 = global_ns.namespace('int32_t')
const_char_ptr = global_ns.namespace('const char *')
NAN = global_ns.namespace('NAN')
esphomelib_ns = global_ns # using namespace esphomelib;
NoArg = esphomelib_ns.NoArg
NoArg = esphomelib_ns.class_('NoArg')
App = esphomelib_ns.App
io_ns = esphomelib_ns.namespace('io')
Nameable = esphomelib_ns.class_('Nameable')
Trigger = esphomelib_ns.class_('Trigger')
Action = esphomelib_ns.class_('Action')
Component = esphomelib_ns.class_('Component')
ComponentPtr = Component.operator('ptr')
PollingComponent = esphomelib_ns.class_('PollingComponent', Component)
Application = esphomelib_ns.class_('Application')
optional = esphomelib_ns.class_('optional')