mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 07:03:55 +00:00 
			
		
		
		
	Updates
This commit is contained in:
		
							
								
								
									
										25
									
								
								esphomeyaml/components/custom_component.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								esphomeyaml/components/custom_component.py
									
									
									
									
									
										Normal 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' | ||||||
| @@ -1,15 +1,13 @@ | |||||||
| import voluptuous as vol | import voluptuous as vol | ||||||
|  |  | ||||||
| from esphomeyaml.components import binary_sensor, output | from esphomeyaml.components import output | ||||||
| import esphomeyaml.config_validation as cv | import esphomeyaml.config_validation as cv | ||||||
| from esphomeyaml.const import CONF_ID, CONF_LAMBDA, CONF_OUTPUTS, CONF_TYPE | from esphomeyaml.const import CONF_ID, CONF_LAMBDA, CONF_OUTPUTS, CONF_TYPE | ||||||
| from esphomeyaml.cpp_generator import process_lambda, variable | from esphomeyaml.cpp_generator import process_lambda, variable | ||||||
| from esphomeyaml.cpp_types import std_vector | from esphomeyaml.cpp_types import std_vector | ||||||
|  |  | ||||||
| CustomBinaryOutputConstructor = binary_sensor.binary_sensor_ns.class_( | CustomBinaryOutputConstructor = output.output_ns.class_('CustomBinaryOutputConstructor') | ||||||
|     'CustomBinaryOutputConstructor') | CustomFloatOutputConstructor = output.output_ns.class_('CustomFloatOutputConstructor') | ||||||
| CustomFloatOutputConstructor = binary_sensor.binary_sensor_ns.class_( |  | ||||||
|     'CustomFloatOutputConstructor') |  | ||||||
|  |  | ||||||
| BINARY_SCHEMA = output.PLATFORM_SCHEMA.extend({ | BINARY_SCHEMA = output.PLATFORM_SCHEMA.extend({ | ||||||
|     cv.GenerateID(): cv.declare_variable_id(CustomBinaryOutputConstructor), |     cv.GenerateID(): cv.declare_variable_id(CustomBinaryOutputConstructor), | ||||||
|   | |||||||
| @@ -464,7 +464,7 @@ class MockObj(Expression): | |||||||
|         return obj |         return obj | ||||||
|  |  | ||||||
|     def class_(self, name, *parents):  # type: (str, *MockObjClass) -> MockObjClass |     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) |         obj.requires.append(self) | ||||||
|         return obj |         return obj | ||||||
|  |  | ||||||
|   | |||||||
| @@ -4,8 +4,8 @@ global_ns = MockObj('', '') | |||||||
| float_ = global_ns.namespace('float') | float_ = global_ns.namespace('float') | ||||||
| bool_ = global_ns.namespace('bool') | bool_ = global_ns.namespace('bool') | ||||||
| std_ns = global_ns.namespace('std') | std_ns = global_ns.namespace('std') | ||||||
| std_string = std_ns.string | std_string = std_ns.class_('string') | ||||||
| std_vector = std_ns.vector | std_vector = std_ns.class_('vector') | ||||||
| uint8 = global_ns.namespace('uint8_t') | uint8 = global_ns.namespace('uint8_t') | ||||||
| uint16 = global_ns.namespace('uint16_t') | uint16 = global_ns.namespace('uint16_t') | ||||||
| uint32 = global_ns.namespace('uint32_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 *') | const_char_ptr = global_ns.namespace('const char *') | ||||||
| NAN = global_ns.namespace('NAN') | NAN = global_ns.namespace('NAN') | ||||||
| esphomelib_ns = global_ns  # using namespace esphomelib; | esphomelib_ns = global_ns  # using namespace esphomelib; | ||||||
| NoArg = esphomelib_ns.NoArg | NoArg = esphomelib_ns.class_('NoArg') | ||||||
| App = esphomelib_ns.App | App = esphomelib_ns.App | ||||||
| io_ns = esphomelib_ns.namespace('io') | io_ns = esphomelib_ns.namespace('io') | ||||||
| Nameable = esphomelib_ns.class_('Nameable') | Nameable = esphomelib_ns.class_('Nameable') | ||||||
| Trigger = esphomelib_ns.class_('Trigger') | Trigger = esphomelib_ns.class_('Trigger') | ||||||
| Action = esphomelib_ns.class_('Action') | Action = esphomelib_ns.class_('Action') | ||||||
| Component = esphomelib_ns.class_('Component') | Component = esphomelib_ns.class_('Component') | ||||||
|  | ComponentPtr = Component.operator('ptr') | ||||||
| PollingComponent = esphomelib_ns.class_('PollingComponent', Component) | PollingComponent = esphomelib_ns.class_('PollingComponent', Component) | ||||||
| Application = esphomelib_ns.class_('Application') | Application = esphomelib_ns.class_('Application') | ||||||
| optional = esphomelib_ns.class_('optional') | optional = esphomelib_ns.class_('optional') | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user