From b54ab3d6230bc37fdabff381cf3b030c15eaf4ec Mon Sep 17 00:00:00 2001 From: Otto Winter Date: Mon, 26 Nov 2018 20:43:02 +0100 Subject: [PATCH] Updates --- esphomeyaml/components/custom_component.py | 25 ++++++++++++++++++++++ esphomeyaml/components/output/custom.py | 8 +++---- esphomeyaml/cpp_generator.py | 2 +- esphomeyaml/cpp_types.py | 7 +++--- 4 files changed, 33 insertions(+), 9 deletions(-) create mode 100644 esphomeyaml/components/custom_component.py diff --git a/esphomeyaml/components/custom_component.py b/esphomeyaml/components/custom_component.py new file mode 100644 index 0000000000..b351dc436a --- /dev/null +++ b/esphomeyaml/components/custom_component.py @@ -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' diff --git a/esphomeyaml/components/output/custom.py b/esphomeyaml/components/output/custom.py index 621b9d878c..369df66b72 100644 --- a/esphomeyaml/components/output/custom.py +++ b/esphomeyaml/components/output/custom.py @@ -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), diff --git a/esphomeyaml/cpp_generator.py b/esphomeyaml/cpp_generator.py index 816f3ae3b8..4a0a465d27 100644 --- a/esphomeyaml/cpp_generator.py +++ b/esphomeyaml/cpp_generator.py @@ -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 diff --git a/esphomeyaml/cpp_types.py b/esphomeyaml/cpp_types.py index 493933a1cf..d441094657 100644 --- a/esphomeyaml/cpp_types.py +++ b/esphomeyaml/cpp_types.py @@ -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')