From 907be3025ce6d53209883324f37990f365b5bef7 Mon Sep 17 00:00:00 2001 From: Otto Winter Date: Thu, 3 Jan 2019 20:39:54 +0100 Subject: [PATCH] Supply return_type for more lambdas --- esphomeyaml/automation.py | 6 +++--- esphomeyaml/components/binary_sensor/__init__.py | 7 ++++--- esphomeyaml/components/display/lcd_gpio.py | 5 +++-- esphomeyaml/components/display/lcd_pcf8574.py | 5 +++-- esphomeyaml/components/display/max7219.py | 5 +++-- esphomeyaml/components/display/nextion.py | 5 +++-- esphomeyaml/components/display/ssd1306_i2c.py | 4 ++-- esphomeyaml/components/display/ssd1306_spi.py | 4 ++-- esphomeyaml/components/display/waveshare_epaper.py | 5 +++-- esphomeyaml/components/light/__init__.py | 6 +++--- esphomeyaml/components/logger.py | 4 ++-- esphomeyaml/components/mqtt.py | 5 +++-- esphomeyaml/components/sensor/__init__.py | 5 +++-- esphomeyaml/cpp_types.py | 1 + 14 files changed, 38 insertions(+), 29 deletions(-) diff --git a/esphomeyaml/automation.py b/esphomeyaml/automation.py index a3cb8e3a57..8e73a314ca 100644 --- a/esphomeyaml/automation.py +++ b/esphomeyaml/automation.py @@ -10,7 +10,7 @@ from esphomeyaml.core import CORE from esphomeyaml.cpp_generator import ArrayInitializer, Pvariable, TemplateArguments, add, \ get_variable, process_lambda, templatable from esphomeyaml.cpp_types import Action, App, Component, PollingComponent, Trigger, \ - esphomelib_ns, float_, uint32 + esphomelib_ns, float_, uint32, void, bool_ from esphomeyaml.util import ServiceRegistry @@ -266,7 +266,7 @@ LAMBDA_ACTION_SCHEMA = cv.lambda_ @ACTION_REGISTRY.register(CONF_LAMBDA, LAMBDA_ACTION_SCHEMA) def lambda_action_to_code(config, action_id, arg_type, template_arg): - for lambda_ in process_lambda(config, [(arg_type, 'x')]): + for lambda_ in process_lambda(config, [(arg_type, 'x')], return_type=void): yield None rhs = LambdaAction.new(template_arg, lambda_) type = LambdaAction.template(template_arg) @@ -278,7 +278,7 @@ LAMBDA_CONDITION_SCHEMA = cv.lambda_ @CONDITION_REGISTRY.register(CONF_LAMBDA, LAMBDA_CONDITION_SCHEMA) def lambda_condition_to_code(config, condition_id, arg_type, template_arg): - for lambda_ in process_lambda(config, [(arg_type, 'x')]): + for lambda_ in process_lambda(config, [(arg_type, 'x')], return_type=bool_): yield rhs = LambdaCondition.new(template_arg, lambda_) type = LambdaCondition.template(template_arg) diff --git a/esphomeyaml/components/binary_sensor/__init__.py b/esphomeyaml/components/binary_sensor/__init__.py index 2a3c909c20..6e08acd9d6 100644 --- a/esphomeyaml/components/binary_sensor/__init__.py +++ b/esphomeyaml/components/binary_sensor/__init__.py @@ -13,7 +13,8 @@ from esphomeyaml.const import CONF_DELAYED_OFF, CONF_DELAYED_ON, CONF_DEVICE_CLA from esphomeyaml.core import CORE from esphomeyaml.cpp_generator import process_lambda, ArrayInitializer, add, Pvariable, \ StructInitializer, get_variable -from esphomeyaml.cpp_types import esphomelib_ns, Nameable, Trigger, NoArg, Component, App, bool_ +from esphomeyaml.cpp_types import esphomelib_ns, Nameable, Trigger, NoArg, Component, App, bool_, \ + optional from esphomeyaml.py_compat import string_types DEVICE_CLASSES = [ @@ -207,8 +208,8 @@ def setup_filter(config): elif CONF_HEARTBEAT in config: yield App.register_component(HeartbeatFilter.new(config[CONF_HEARTBEAT])) elif CONF_LAMBDA in config: - lambda_ = None - for lambda_ in process_lambda(config[CONF_LAMBDA], [(bool_, 'x')]): + for lambda_ in process_lambda(config[CONF_LAMBDA], [(bool_, 'x')], + return_type=optional.template(bool_)): yield None yield LambdaFilter.new(lambda_) diff --git a/esphomeyaml/components/display/lcd_gpio.py b/esphomeyaml/components/display/lcd_gpio.py index c0264618ff..c796ed3f28 100644 --- a/esphomeyaml/components/display/lcd_gpio.py +++ b/esphomeyaml/components/display/lcd_gpio.py @@ -7,7 +7,7 @@ from esphomeyaml.const import CONF_DATA_PINS, CONF_DIMENSIONS, CONF_ENABLE_PIN, CONF_LAMBDA, CONF_RS_PIN, CONF_RW_PIN from esphomeyaml.cpp_generator import Pvariable, add, process_lambda from esphomeyaml.cpp_helpers import gpio_output_pin_expression, setup_component -from esphomeyaml.cpp_types import App, PollingComponent +from esphomeyaml.cpp_types import App, PollingComponent, void LCDDisplay = display.display_ns.class_('LCDDisplay', PollingComponent) LCDDisplayRef = LCDDisplay.operator('ref') @@ -64,7 +64,8 @@ def to_code(config): add(lcd.set_rw_pin(rw)) if CONF_LAMBDA in config: - for lambda_ in process_lambda(config[CONF_LAMBDA], [(LCDDisplayRef, 'it')]): + for lambda_ in process_lambda(config[CONF_LAMBDA], [(LCDDisplayRef, 'it')], + return_type=void): yield add(lcd.set_writer(lambda_)) diff --git a/esphomeyaml/components/display/lcd_pcf8574.py b/esphomeyaml/components/display/lcd_pcf8574.py index f967f259d1..cc3792f992 100644 --- a/esphomeyaml/components/display/lcd_pcf8574.py +++ b/esphomeyaml/components/display/lcd_pcf8574.py @@ -7,7 +7,7 @@ import esphomeyaml.config_validation as cv from esphomeyaml.const import CONF_ADDRESS, CONF_DIMENSIONS, CONF_ID, CONF_LAMBDA from esphomeyaml.cpp_generator import Pvariable, add, process_lambda from esphomeyaml.cpp_helpers import setup_component -from esphomeyaml.cpp_types import App +from esphomeyaml.cpp_types import App, void DEPENDENCIES = ['i2c'] @@ -28,7 +28,8 @@ def to_code(config): add(lcd.set_address(config[CONF_ADDRESS])) if CONF_LAMBDA in config: - for lambda_ in process_lambda(config[CONF_LAMBDA], [(LCDDisplayRef, 'it')]): + for lambda_ in process_lambda(config[CONF_LAMBDA], [(LCDDisplayRef, 'it')], + return_type=void): yield add(lcd.set_writer(lambda_)) diff --git a/esphomeyaml/components/display/max7219.py b/esphomeyaml/components/display/max7219.py index 7283d5932e..fcca07154b 100644 --- a/esphomeyaml/components/display/max7219.py +++ b/esphomeyaml/components/display/max7219.py @@ -8,7 +8,7 @@ from esphomeyaml.const import CONF_CS_PIN, CONF_ID, CONF_INTENSITY, CONF_LAMBDA, CONF_SPI_ID from esphomeyaml.cpp_generator import Pvariable, add, get_variable, process_lambda from esphomeyaml.cpp_helpers import gpio_output_pin_expression, setup_component -from esphomeyaml.cpp_types import App, PollingComponent +from esphomeyaml.cpp_types import App, PollingComponent, void DEPENDENCIES = ['spi'] @@ -39,7 +39,8 @@ def to_code(config): add(max7219.set_intensity(config[CONF_INTENSITY])) if CONF_LAMBDA in config: - for lambda_ in process_lambda(config[CONF_LAMBDA], [(MAX7219ComponentRef, 'it')]): + for lambda_ in process_lambda(config[CONF_LAMBDA], [(MAX7219ComponentRef, 'it')], + return_type=void): yield add(max7219.set_writer(lambda_)) diff --git a/esphomeyaml/components/display/nextion.py b/esphomeyaml/components/display/nextion.py index 254a76eddf..4d051c39b6 100644 --- a/esphomeyaml/components/display/nextion.py +++ b/esphomeyaml/components/display/nextion.py @@ -4,7 +4,7 @@ import esphomeyaml.config_validation as cv from esphomeyaml.const import CONF_ID, CONF_LAMBDA, CONF_UART_ID from esphomeyaml.cpp_generator import Pvariable, add, get_variable, process_lambda from esphomeyaml.cpp_helpers import setup_component -from esphomeyaml.cpp_types import App, PollingComponent +from esphomeyaml.cpp_types import App, PollingComponent, void DEPENDENCIES = ['uart'] @@ -24,7 +24,8 @@ def to_code(config): nextion = Pvariable(config[CONF_ID], rhs) if CONF_LAMBDA in config: - for lambda_ in process_lambda(config[CONF_LAMBDA], [(NextionRef, 'it')]): + for lambda_ in process_lambda(config[CONF_LAMBDA], [(NextionRef, 'it')], + return_type=void): yield add(nextion.set_writer(lambda_)) diff --git a/esphomeyaml/components/display/ssd1306_i2c.py b/esphomeyaml/components/display/ssd1306_i2c.py index 27a77018b5..966ecdc844 100644 --- a/esphomeyaml/components/display/ssd1306_i2c.py +++ b/esphomeyaml/components/display/ssd1306_i2c.py @@ -8,7 +8,7 @@ from esphomeyaml.const import CONF_ADDRESS, CONF_EXTERNAL_VCC, CONF_ID, CONF_LAM CONF_RESET_PIN from esphomeyaml.cpp_generator import Pvariable, add, process_lambda from esphomeyaml.cpp_helpers import gpio_output_pin_expression, setup_component -from esphomeyaml.cpp_types import App +from esphomeyaml.cpp_types import App, void DEPENDENCIES = ['i2c'] @@ -37,7 +37,7 @@ def to_code(config): add(ssd.set_address(config[CONF_ADDRESS])) if CONF_LAMBDA in config: for lambda_ in process_lambda(config[CONF_LAMBDA], - [(display.DisplayBufferRef, 'it')]): + [(display.DisplayBufferRef, 'it')], return_type=void): yield add(ssd.set_writer(lambda_)) diff --git a/esphomeyaml/components/display/ssd1306_spi.py b/esphomeyaml/components/display/ssd1306_spi.py index 34e24ba8b2..54cd05995b 100644 --- a/esphomeyaml/components/display/ssd1306_spi.py +++ b/esphomeyaml/components/display/ssd1306_spi.py @@ -8,7 +8,7 @@ from esphomeyaml.const import CONF_CS_PIN, CONF_DC_PIN, CONF_EXTERNAL_VCC, CONF_ CONF_MODEL, CONF_RESET_PIN, CONF_SPI_ID from esphomeyaml.cpp_generator import Pvariable, add, get_variable, process_lambda from esphomeyaml.cpp_helpers import gpio_output_pin_expression, setup_component -from esphomeyaml.cpp_types import App, PollingComponent +from esphomeyaml.cpp_types import App, PollingComponent, void DEPENDENCIES = ['spi'] @@ -60,7 +60,7 @@ def to_code(config): add(ssd.set_external_vcc(config[CONF_EXTERNAL_VCC])) if CONF_LAMBDA in config: for lambda_ in process_lambda(config[CONF_LAMBDA], - [(display.DisplayBufferRef, 'it')]): + [(display.DisplayBufferRef, 'it')], return_type=void): yield add(ssd.set_writer(lambda_)) diff --git a/esphomeyaml/components/display/waveshare_epaper.py b/esphomeyaml/components/display/waveshare_epaper.py index 2c0a7ccc79..bfca5bb3fd 100644 --- a/esphomeyaml/components/display/waveshare_epaper.py +++ b/esphomeyaml/components/display/waveshare_epaper.py @@ -9,7 +9,7 @@ from esphomeyaml.const import CONF_BUSY_PIN, CONF_CS_PIN, CONF_DC_PIN, CONF_FULL from esphomeyaml.cpp_generator import get_variable, Pvariable, process_lambda, add from esphomeyaml.cpp_helpers import gpio_output_pin_expression, gpio_input_pin_expression, \ setup_component -from esphomeyaml.cpp_types import PollingComponent, App +from esphomeyaml.cpp_types import PollingComponent, App, void DEPENDENCIES = ['spi'] @@ -71,7 +71,8 @@ def to_code(config): raise NotImplementedError() if CONF_LAMBDA in config: - for lambda_ in process_lambda(config[CONF_LAMBDA], [(display.DisplayBufferRef, 'it')]): + for lambda_ in process_lambda(config[CONF_LAMBDA], [(display.DisplayBufferRef, 'it')], + return_type=void): yield add(epaper.set_writer(lambda_)) if CONF_RESET_PIN in config: diff --git a/esphomeyaml/components/light/__init__.py b/esphomeyaml/components/light/__init__.py index 79cbfdd177..0997d1fd5b 100644 --- a/esphomeyaml/components/light/__init__.py +++ b/esphomeyaml/components/light/__init__.py @@ -14,7 +14,7 @@ from esphomeyaml.core import CORE from esphomeyaml.cpp_generator import process_lambda, Pvariable, add, StructInitializer, \ ArrayInitializer, get_variable, templatable from esphomeyaml.cpp_types import esphomelib_ns, Application, Component, Nameable, Action, uint32, \ - float_, std_string + float_, std_string, void PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({ @@ -255,7 +255,7 @@ def build_effect(full_config): key, config = next(iter(full_config.items())) if key == CONF_LAMBDA: lambda_ = None - for lambda_ in process_lambda(config[CONF_LAMBDA], []): + for lambda_ in process_lambda(config[CONF_LAMBDA], [], return_type=void): yield None yield LambdaLightEffect.new(config[CONF_NAME], lambda_, config[CONF_UPDATE_INTERVAL]) elif key == CONF_RANDOM: @@ -291,7 +291,7 @@ def build_effect(full_config): yield effect elif key == CONF_ADDRESSABLE_LAMBDA: args = [(AddressableLightRef, 'it')] - for lambda_ in process_lambda(config[CONF_LAMBDA], args): + for lambda_ in process_lambda(config[CONF_LAMBDA], args, return_type=void): yield None yield AddressableLambdaLightEffect.new(config[CONF_NAME], lambda_, config[CONF_UPDATE_INTERVAL]) diff --git a/esphomeyaml/components/logger.py b/esphomeyaml/components/logger.py index 59a86807af..ad713a4c2d 100644 --- a/esphomeyaml/components/logger.py +++ b/esphomeyaml/components/logger.py @@ -8,7 +8,7 @@ from esphomeyaml.const import CONF_ARGS, CONF_BAUD_RATE, CONF_FORMAT, CONF_ID, C CONF_LOGS, CONF_TAG, CONF_TX_BUFFER_SIZE from esphomeyaml.core import EsphomeyamlError, Lambda, CORE from esphomeyaml.cpp_generator import Pvariable, RawExpression, add, process_lambda, statement -from esphomeyaml.cpp_types import App, Component, esphomelib_ns, global_ns +from esphomeyaml.cpp_types import App, Component, esphomelib_ns, global_ns, void from esphomeyaml.py_compat import text_type @@ -146,7 +146,7 @@ def logger_log_action_to_code(config, action_id, arg_type, template_arg): text = text_type(statement(esp_log(config[CONF_TAG], config[CONF_FORMAT], *args))) - for lambda_ in process_lambda(Lambda(text), [(arg_type, 'x')]): + for lambda_ in process_lambda(Lambda(text), [(arg_type, 'x')], return_type=void): yield None rhs = LambdaAction.new(template_arg, lambda_) type = LambdaAction.template(template_arg) diff --git a/esphomeyaml/components/mqtt.py b/esphomeyaml/components/mqtt.py index 4276cadcab..36afaa9f62 100644 --- a/esphomeyaml/components/mqtt.py +++ b/esphomeyaml/components/mqtt.py @@ -18,7 +18,7 @@ from esphomeyaml.core import EsphomeyamlError from esphomeyaml.cpp_generator import ArrayInitializer, Pvariable, RawExpression, \ StructInitializer, TemplateArguments, add, process_lambda, templatable from esphomeyaml.cpp_types import Action, App, Component, JsonObjectConstRef, JsonObjectRef, \ - Trigger, bool_, esphomelib_ns, optional, std_string, uint8 + Trigger, bool_, esphomelib_ns, optional, std_string, uint8, void def validate_message_just_topic(value): @@ -237,7 +237,8 @@ def mqtt_publish_json_action_to_code(config, action_id, arg_type, template_arg): yield None add(action.set_topic(template_)) - for lambda_ in process_lambda(config[CONF_PAYLOAD], [(arg_type, 'x'), (JsonObjectRef, 'root')]): + for lambda_ in process_lambda(config[CONF_PAYLOAD], [(arg_type, 'x'), (JsonObjectRef, 'root')], + return_type=void): yield None add(action.set_payload(lambda_)) if CONF_QOS in config: diff --git a/esphomeyaml/components/sensor/__init__.py b/esphomeyaml/components/sensor/__init__.py index 4e72835c96..5f8f52152f 100644 --- a/esphomeyaml/components/sensor/__init__.py +++ b/esphomeyaml/components/sensor/__init__.py @@ -16,7 +16,7 @@ from esphomeyaml.core import CORE from esphomeyaml.cpp_generator import ArrayInitializer, Pvariable, add, process_lambda, \ templatable, get_variable from esphomeyaml.cpp_types import App, Component, Nameable, PollingComponent, Trigger, \ - esphomelib_ns, float_ + esphomelib_ns, float_, optional PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({ @@ -136,7 +136,8 @@ def setup_filter(config): yield ExponentialMovingAverageFilter.new(conf[CONF_ALPHA], conf[CONF_SEND_EVERY]) elif CONF_LAMBDA in config: lambda_ = None - for lambda_ in process_lambda(config[CONF_LAMBDA], [(float_, 'x')]): + for lambda_ in process_lambda(config[CONF_LAMBDA], [(float_, 'x')], + return_type=optional.template(float_)): yield None yield LambdaFilter.new(lambda_) elif CONF_THROTTLE in config: diff --git a/esphomeyaml/cpp_types.py b/esphomeyaml/cpp_types.py index d441094657..c07e0c6436 100644 --- a/esphomeyaml/cpp_types.py +++ b/esphomeyaml/cpp_types.py @@ -1,6 +1,7 @@ from esphomeyaml.cpp_generator import MockObj global_ns = MockObj('', '') +void = global_ns.namespace('void') float_ = global_ns.namespace('float') bool_ = global_ns.namespace('bool') std_ns = global_ns.namespace('std')