From 4a7402784833ceba64f73f244918e5998b05cdc3 Mon Sep 17 00:00:00 2001 From: Otto Winter Date: Sun, 3 Feb 2019 20:46:18 +0100 Subject: [PATCH] Miscellaneous Fixes --- esphomeyaml/automation.py | 13 ++++++------- esphomeyaml/components/api.py | 8 ++++---- esphomeyaml/components/binary_sensor/__init__.py | 5 +---- esphomeyaml/components/binary_sensor/pn532.py | 6 +++--- .../components/binary_sensor/remote_receiver.py | 7 +++---- esphomeyaml/components/esp32_ble_beacon.py | 4 ++-- esphomeyaml/components/esp32_ble_tracker.py | 5 ++--- esphomeyaml/components/fan/__init__.py | 7 +++++-- esphomeyaml/components/font.py | 6 +++--- esphomeyaml/components/image.py | 4 ++-- esphomeyaml/components/light/__init__.py | 6 +++--- esphomeyaml/components/mqtt.py | 8 ++++---- esphomeyaml/components/output/custom.py | 5 ++--- esphomeyaml/components/sensor/__init__.py | 2 +- esphomeyaml/components/stepper/__init__.py | 2 +- .../components/switch/remote_transmitter.py | 4 ++-- esphomeyaml/components/switch/uart.py | 4 ++-- esphomeyaml/components/time/__init__.py | 12 ++++++------ esphomeyaml/components/wifi.py | 14 ++++++-------- esphomeyaml/cpp_generator.py | 7 +++++-- 20 files changed, 63 insertions(+), 66 deletions(-) diff --git a/esphomeyaml/automation.py b/esphomeyaml/automation.py index fff90e3824..8250008829 100644 --- a/esphomeyaml/automation.py +++ b/esphomeyaml/automation.py @@ -7,10 +7,10 @@ from esphomeyaml.const import CONF_ABOVE, CONF_ACTION_ID, CONF_AND, CONF_AUTOMAT CONF_BELOW, CONF_CONDITION, CONF_CONDITION_ID, CONF_DELAY, CONF_ELSE, CONF_ID, CONF_IF, \ CONF_LAMBDA, CONF_OR, CONF_RANGE, CONF_THEN, CONF_TRIGGER_ID, CONF_WHILE 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, void, bool_ +from esphomeyaml.cpp_generator import Pvariable, TemplateArguments, add, get_variable, \ + process_lambda, templatable +from esphomeyaml.cpp_types import Action, App, Component, PollingComponent, Trigger, bool_, \ + esphomelib_ns, float_, uint32, void from esphomeyaml.util import ServiceRegistry @@ -318,11 +318,10 @@ def build_action(full_config, arg_type): def build_actions(config, arg_type): actions = [] for conf in config: - action = None for action in build_action(conf, arg_type): yield None actions.append(action) - yield ArrayInitializer(*actions, multiline=False) + yield actions def build_condition(full_config, arg_type): @@ -342,7 +341,7 @@ def build_conditions(config, arg_type): for condition in build_condition(conf, arg_type): yield None conditions.append(condition) - yield ArrayInitializer(*conditions, multiline=False) + yield conditions def build_automation_(trigger, arg_type, config): diff --git a/esphomeyaml/components/api.py b/esphomeyaml/components/api.py index 2737ef6d84..5a7cfd9cfc 100644 --- a/esphomeyaml/components/api.py +++ b/esphomeyaml/components/api.py @@ -5,7 +5,7 @@ import esphomeyaml.config_validation as cv from esphomeyaml.const import CONF_DATA, CONF_DATA_TEMPLATE, CONF_ID, CONF_PASSWORD, CONF_PORT, \ CONF_SERVICE, CONF_VARIABLES, CONF_REBOOT_TIMEOUT from esphomeyaml.core import CORE -from esphomeyaml.cpp_generator import ArrayInitializer, Pvariable, add, get_variable, process_lambda +from esphomeyaml.cpp_generator import Pvariable, add, get_variable, process_lambda from esphomeyaml.cpp_helpers import setup_component from esphomeyaml.cpp_types import Action, App, Component, StoringController, esphomelib_ns @@ -74,15 +74,15 @@ def homeassistant_service_to_code(config, action_id, arg_type, template_arg): add(act.set_service(config[CONF_SERVICE])) if CONF_DATA in config: datas = [KeyValuePair(k, v) for k, v in config[CONF_DATA].items()] - add(act.set_data(ArrayInitializer(*datas))) + add(act.set_data(datas)) if CONF_DATA_TEMPLATE in config: datas = [KeyValuePair(k, v) for k, v in config[CONF_DATA_TEMPLATE].items()] - add(act.set_data_template(ArrayInitializer(*datas))) + add(act.set_data_template(datas)) if CONF_VARIABLES in config: datas = [] for key, value in config[CONF_VARIABLES].items(): for value_ in process_lambda(value, []): yield None datas.append(TemplatableKeyValuePair(key, value_)) - add(act.set_variables(ArrayInitializer(*datas))) + add(act.set_variables(datas)) yield act diff --git a/esphomeyaml/components/binary_sensor/__init__.py b/esphomeyaml/components/binary_sensor/__init__.py index 85a276b6e2..21aaa339d0 100644 --- a/esphomeyaml/components/binary_sensor/__init__.py +++ b/esphomeyaml/components/binary_sensor/__init__.py @@ -216,11 +216,10 @@ def setup_filter(config): def setup_filters(config): filters = [] for conf in config: - filter = None for filter in setup_filter(conf): yield None filters.append(filter) - yield ArrayInitializer(*filters) + yield filters def setup_binary_sensor_core_(binary_sensor_var, config): @@ -231,7 +230,6 @@ def setup_binary_sensor_core_(binary_sensor_var, config): if CONF_INVERTED in config: add(binary_sensor_var.set_inverted(config[CONF_INVERTED])) if CONF_FILTERS in config: - filters = None for filters in setup_filters(config[CONF_FILTERS]): yield add(binary_sensor_var.add_filters(filters)) @@ -266,7 +264,6 @@ def setup_binary_sensor_core_(binary_sensor_var, config): ('min_length', tim[CONF_MIN_LENGTH]), ('max_length', tim.get(CONF_MAX_LENGTH, 4294967294)), )) - timings = ArrayInitializer(*timings, multiline=False) rhs = App.register_component(binary_sensor_var.make_multi_click_trigger(timings)) trigger = Pvariable(conf[CONF_TRIGGER_ID], rhs) if CONF_INVALID_COOLDOWN in conf: diff --git a/esphomeyaml/components/binary_sensor/pn532.py b/esphomeyaml/components/binary_sensor/pn532.py index f0681ff6d7..3ee45ce3f4 100644 --- a/esphomeyaml/components/binary_sensor/pn532.py +++ b/esphomeyaml/components/binary_sensor/pn532.py @@ -1,11 +1,11 @@ import voluptuous as vol -import esphomeyaml.config_validation as cv from esphomeyaml.components import binary_sensor from esphomeyaml.components.pn532 import PN532Component +import esphomeyaml.config_validation as cv from esphomeyaml.const import CONF_NAME, CONF_UID from esphomeyaml.core import HexInt -from esphomeyaml.cpp_generator import get_variable, ArrayInitializer +from esphomeyaml.cpp_generator import get_variable DEPENDENCIES = ['pn532'] @@ -41,7 +41,7 @@ def to_code(config): for hub in get_variable(config[CONF_PN532_ID]): yield addr = [HexInt(int(x, 16)) for x in config[CONF_UID].split('-')] - rhs = hub.make_tag(config[CONF_NAME], ArrayInitializer(*addr, multiline=False)) + rhs = hub.make_tag(config[CONF_NAME], addr) binary_sensor.register_binary_sensor(rhs, config) diff --git a/esphomeyaml/components/binary_sensor/remote_receiver.py b/esphomeyaml/components/binary_sensor/remote_receiver.py index f189a2225b..61aeb634be 100644 --- a/esphomeyaml/components/binary_sensor/remote_receiver.py +++ b/esphomeyaml/components/binary_sensor/remote_receiver.py @@ -1,17 +1,17 @@ import voluptuous as vol -import esphomeyaml.config_validation as cv from esphomeyaml.components import binary_sensor from esphomeyaml.components.remote_receiver import RemoteReceiverComponent, remote_ns from esphomeyaml.components.remote_transmitter import RC_SWITCH_RAW_SCHEMA, \ RC_SWITCH_TYPE_A_SCHEMA, RC_SWITCH_TYPE_B_SCHEMA, RC_SWITCH_TYPE_C_SCHEMA, \ RC_SWITCH_TYPE_D_SCHEMA, binary_code, build_rc_switch_protocol +import esphomeyaml.config_validation as cv from esphomeyaml.const import CONF_ADDRESS, CONF_CHANNEL, CONF_CODE, CONF_COMMAND, CONF_DATA, \ CONF_DEVICE, CONF_FAMILY, CONF_GROUP, CONF_LG, CONF_NAME, CONF_NBITS, CONF_NEC, \ CONF_PANASONIC, CONF_PROTOCOL, CONF_RAW, CONF_RC_SWITCH_RAW, CONF_RC_SWITCH_TYPE_A, \ CONF_RC_SWITCH_TYPE_B, CONF_RC_SWITCH_TYPE_C, CONF_RC_SWITCH_TYPE_D, CONF_SAMSUNG, CONF_SONY, \ CONF_STATE -from esphomeyaml.cpp_generator import ArrayInitializer, get_variable, Pvariable +from esphomeyaml.cpp_generator import Pvariable, get_variable DEPENDENCIES = ['remote_receiver'] @@ -82,8 +82,7 @@ def receiver_base(full_config): if key == CONF_SONY: return SonyReceiver.new(name, config[CONF_DATA], config[CONF_NBITS]) if key == CONF_RAW: - data = ArrayInitializer(*config, multiline=False) - return RawReceiver.new(name, data) + return RawReceiver.new(name, *config) if key == CONF_RC_SWITCH_RAW: return RCSwitchRawReceiver.new(name, build_rc_switch_protocol(config[CONF_PROTOCOL]), binary_code(config[CONF_CODE]), len(config[CONF_CODE])) diff --git a/esphomeyaml/components/esp32_ble_beacon.py b/esphomeyaml/components/esp32_ble_beacon.py index 326314756f..6db3211680 100644 --- a/esphomeyaml/components/esp32_ble_beacon.py +++ b/esphomeyaml/components/esp32_ble_beacon.py @@ -2,7 +2,7 @@ import voluptuous as vol from esphomeyaml import config_validation as cv from esphomeyaml.const import CONF_ID, CONF_SCAN_INTERVAL, CONF_TYPE, CONF_UUID, ESP_PLATFORM_ESP32 -from esphomeyaml.cpp_generator import ArrayInitializer, Pvariable, RawExpression, add +from esphomeyaml.cpp_generator import Pvariable, RawExpression, add from esphomeyaml.cpp_helpers import setup_component from esphomeyaml.cpp_types import App, Component, esphomelib_ns @@ -26,7 +26,7 @@ CONFIG_SCHEMA = vol.Schema({ def to_code(config): uuid = config[CONF_UUID].hex uuid_arr = [RawExpression('0x{}'.format(uuid[i:i + 2])) for i in range(0, len(uuid), 2)] - rhs = App.make_esp32_ble_beacon(ArrayInitializer(*uuid_arr, multiline=False)) + rhs = App.make_esp32_ble_beacon(uuid_arr) ble = Pvariable(config[CONF_ID], rhs) if CONF_MAJOR in config: add(ble.set_major(config[CONF_MAJOR])) diff --git a/esphomeyaml/components/esp32_ble_tracker.py b/esphomeyaml/components/esp32_ble_tracker.py index 19030a258c..b758372420 100644 --- a/esphomeyaml/components/esp32_ble_tracker.py +++ b/esphomeyaml/components/esp32_ble_tracker.py @@ -4,7 +4,7 @@ from esphomeyaml import config_validation as cv from esphomeyaml.components import sensor from esphomeyaml.const import CONF_ID, CONF_SCAN_INTERVAL, ESP_PLATFORM_ESP32 from esphomeyaml.core import HexInt -from esphomeyaml.cpp_generator import ArrayInitializer, Pvariable, add +from esphomeyaml.cpp_generator import Pvariable, add from esphomeyaml.cpp_helpers import setup_component from esphomeyaml.cpp_types import App, Component, esphomelib_ns @@ -25,8 +25,7 @@ CONFIG_SCHEMA = vol.Schema({ def make_address_array(address): - addr = [HexInt(i) for i in address.parts] - return ArrayInitializer(*addr, multiline=False) + return [HexInt(i) for i in address.parts] def to_code(config): diff --git a/esphomeyaml/components/fan/__init__.py b/esphomeyaml/components/fan/__init__.py index 3a80a4b0a6..c4a2d60e3d 100644 --- a/esphomeyaml/components/fan/__init__.py +++ b/esphomeyaml/components/fan/__init__.py @@ -8,8 +8,9 @@ from esphomeyaml.const import CONF_ID, CONF_INTERNAL, CONF_MQTT_ID, CONF_NAME, C CONF_OSCILLATION_COMMAND_TOPIC, CONF_OSCILLATION_OUTPUT, CONF_OSCILLATION_STATE_TOPIC, \ CONF_SPEED, CONF_SPEED_COMMAND_TOPIC, CONF_SPEED_STATE_TOPIC from esphomeyaml.core import CORE -from esphomeyaml.cpp_generator import add, Pvariable, get_variable, templatable -from esphomeyaml.cpp_types import Application, Component, Nameable, esphomelib_ns, Action, bool_ +from esphomeyaml.cpp_generator import Pvariable, add, get_variable, templatable +from esphomeyaml.cpp_types import Action, Application, Component, Nameable, bool_, esphomelib_ns +from esphomeyaml.py_compat import string_types PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({ @@ -125,6 +126,8 @@ def fan_turn_on_to_code(config, action_id, arg_type, template_arg): if CONF_SPEED in config: for template_ in templatable(config[CONF_SPEED], arg_type, FanSpeed): yield None + if isinstance(template_, string_types): + template_ = FAN_SPEEDS[template_] add(action.set_speed(template_)) yield action diff --git a/esphomeyaml/components/font.py b/esphomeyaml/components/font.py index c69ffbd46e..290fe3a136 100644 --- a/esphomeyaml/components/font.py +++ b/esphomeyaml/components/font.py @@ -6,7 +6,7 @@ from esphomeyaml.components import display import esphomeyaml.config_validation as cv from esphomeyaml.const import CONF_FILE, CONF_GLYPHS, CONF_ID, CONF_SIZE from esphomeyaml.core import CORE, HexInt -from esphomeyaml.cpp_generator import ArrayInitializer, MockObj, Pvariable, RawExpression, add +from esphomeyaml.cpp_generator import MockObj, Pvariable, RawExpression, add, safe_exp from esphomeyaml.cpp_types import App from esphomeyaml.py_compat import sort_by_cmp @@ -111,11 +111,11 @@ def to_code(config): raw_data = MockObj(config[CONF_RAW_DATA_ID]) add(RawExpression('static const uint8_t {}[{}] PROGMEM = {}'.format( raw_data, len(data), - ArrayInitializer(*[HexInt(x) for x in data], multiline=False)))) + safe_exp([HexInt(x) for x in data])))) glyphs = [] for glyph in config[CONF_GLYPHS]: glyphs.append(Glyph(glyph, raw_data, *glyph_args[glyph])) - rhs = App.make_font(ArrayInitializer(*glyphs), ascent, ascent + descent) + rhs = App.make_font(glyphs, ascent, ascent + descent) Pvariable(config[CONF_ID], rhs) diff --git a/esphomeyaml/components/image.py b/esphomeyaml/components/image.py index adfeffe7d3..ff0afe12bf 100644 --- a/esphomeyaml/components/image.py +++ b/esphomeyaml/components/image.py @@ -8,7 +8,7 @@ from esphomeyaml.components import display, font import esphomeyaml.config_validation as cv from esphomeyaml.const import CONF_FILE, CONF_ID, CONF_RESIZE from esphomeyaml.core import CORE, HexInt -from esphomeyaml.cpp_generator import ArrayInitializer, MockObj, Pvariable, RawExpression, add +from esphomeyaml.cpp_generator import MockObj, Pvariable, RawExpression, add, safe_exp from esphomeyaml.cpp_types import App _LOGGER = logging.getLogger(__name__) @@ -59,7 +59,7 @@ def to_code(config): raw_data = MockObj(config[CONF_RAW_DATA_ID]) add(RawExpression('static const uint8_t {}[{}] PROGMEM = {}'.format( raw_data, len(data), - ArrayInitializer(*[HexInt(x) for x in data], multiline=False)))) + safe_exp([HexInt(x) for x in data])))) rhs = App.make_image(raw_data, width, height) Pvariable(config[CONF_ID], rhs) diff --git a/esphomeyaml/components/light/__init__.py b/esphomeyaml/components/light/__init__.py index 6eb0186171..702656865c 100644 --- a/esphomeyaml/components/light/__init__.py +++ b/esphomeyaml/components/light/__init__.py @@ -279,7 +279,7 @@ def build_effect(full_config): ('duration', color[CONF_DURATION]), )) if colors: - add(effect.set_colors(ArrayInitializer(*colors))) + add(effect.set_colors(colors)) yield effect elif key == CONF_FLICKER: rhs = FlickerLightEffect.new(config[CONF_NAME]) @@ -322,7 +322,7 @@ def build_effect(full_config): ('num_leds', color[CONF_NUM_LEDS]), )) if colors: - add(effect.set_colors(ArrayInitializer(*colors))) + add(effect.set_colors(colors)) yield effect elif key == CONF_ADDRESSABLE_SCAN: rhs = AddressableScanEffect.new(config[CONF_NAME]) @@ -383,7 +383,7 @@ def setup_light_core_(light_var, config): yield effects.append(effect) if effects: - add(light_var.add_effects(ArrayInitializer(*effects))) + add(light_var.add_effects(effects)) setup_mqtt_component(light_var.Pget_mqtt(), config) diff --git a/esphomeyaml/components/mqtt.py b/esphomeyaml/components/mqtt.py index aa132b56ee..8e067f3ada 100644 --- a/esphomeyaml/components/mqtt.py +++ b/esphomeyaml/components/mqtt.py @@ -15,8 +15,8 @@ from esphomeyaml.const import CONF_AVAILABILITY, CONF_BIRTH_MESSAGE, CONF_BROKER CONF_RETAIN, CONF_SHUTDOWN_MESSAGE, CONF_SSL_FINGERPRINTS, CONF_STATE_TOPIC, CONF_TOPIC, \ CONF_TOPIC_PREFIX, CONF_TRIGGER_ID, CONF_USERNAME, CONF_WILL_MESSAGE from esphomeyaml.core import EsphomeyamlError -from esphomeyaml.cpp_generator import ArrayInitializer, Pvariable, RawExpression, \ - StructInitializer, TemplateArguments, add, process_lambda, templatable +from esphomeyaml.cpp_generator import 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, void @@ -169,7 +169,7 @@ def to_code(config): if CONF_SSL_FINGERPRINTS in config: for fingerprint in config[CONF_SSL_FINGERPRINTS]: arr = [RawExpression("0x{}".format(fingerprint[i:i + 2])) for i in range(0, 40, 2)] - add(mqtt.add_ssl_fingerprint(ArrayInitializer(*arr, multiline=False))) + add(mqtt.add_ssl_fingerprint(arr)) if CONF_KEEPALIVE in config: add(mqtt.set_keep_alive(config[CONF_KEEPALIVE])) @@ -340,4 +340,4 @@ def setup_mqtt_component(obj, config): LIB_DEPS = 'AsyncMqttClient@0.8.2' -REQUIRED_BUILD_FLAGS = '-DUSE_MQTT' +BUILD_FLAGS = '-DUSE_MQTT' diff --git a/esphomeyaml/components/output/custom.py b/esphomeyaml/components/output/custom.py index 89319ddaa6..53c4f52935 100644 --- a/esphomeyaml/components/output/custom.py +++ b/esphomeyaml/components/output/custom.py @@ -3,7 +3,7 @@ import voluptuous as vol 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, Pvariable +from esphomeyaml.cpp_generator import process_lambda, variable from esphomeyaml.cpp_types import std_vector CustomBinaryOutputConstructor = output.output_ns.class_('CustomBinaryOutputConstructor') @@ -62,8 +62,7 @@ def to_code(config): rhs = klass(template_) custom = variable(config[CONF_ID], rhs) for i, conf in enumerate(config[CONF_OUTPUTS]): - var = Pvariable(conf[CONF_ID], custom.get_output(i)) - output.register_output(var, conf) + output.register_output(custom.get_output(i), conf) BUILD_FLAGS = '-DUSE_CUSTOM_OUTPUT' diff --git a/esphomeyaml/components/sensor/__init__.py b/esphomeyaml/components/sensor/__init__.py index 6008d01ee8..b064a22bd7 100644 --- a/esphomeyaml/components/sensor/__init__.py +++ b/esphomeyaml/components/sensor/__init__.py @@ -162,7 +162,7 @@ def setup_filters(config): for filter in setup_filter(conf): yield None filters.append(filter) - yield ArrayInitializer(*filters) + yield filters def setup_sensor_core_(sensor_var, config): diff --git a/esphomeyaml/components/stepper/__init__.py b/esphomeyaml/components/stepper/__init__.py index fe9ec064cc..b9a297c87c 100644 --- a/esphomeyaml/components/stepper/__init__.py +++ b/esphomeyaml/components/stepper/__init__.py @@ -120,5 +120,5 @@ def stepper_report_position_to_code(config, action_id, arg_type, template_arg): action = Pvariable(action_id, rhs, type=type) for template_ in templatable(config[CONF_POSITION], arg_type, int32): yield None - add(action.set_target(template_)) + add(action.set_position(template_)) yield action diff --git a/esphomeyaml/components/switch/remote_transmitter.py b/esphomeyaml/components/switch/remote_transmitter.py index 5afc018bda..065b351030 100644 --- a/esphomeyaml/components/switch/remote_transmitter.py +++ b/esphomeyaml/components/switch/remote_transmitter.py @@ -12,7 +12,7 @@ from esphomeyaml.const import CONF_ADDRESS, CONF_CARRIER_FREQUENCY, CONF_CHANNEL CONF_RC_SWITCH_TYPE_A, CONF_RC_SWITCH_TYPE_B, CONF_RC_SWITCH_TYPE_C, CONF_RC_SWITCH_TYPE_D, \ CONF_REPEAT, CONF_SAMSUNG, CONF_SONY, CONF_STATE, CONF_TIMES, \ CONF_WAIT_TIME -from esphomeyaml.cpp_generator import ArrayInitializer, Pvariable, add, get_variable +from esphomeyaml.cpp_generator import Pvariable, add, get_variable DEPENDENCIES = ['remote_transmitter'] @@ -100,7 +100,7 @@ def transmitter_base(full_config): else: data = config carrier_frequency = None - return RawTransmitter.new(name, ArrayInitializer(*data, multiline=False), + return RawTransmitter.new(name, data, carrier_frequency) if key == CONF_RC_SWITCH_RAW: return RCSwitchRawTransmitter.new(name, build_rc_switch_protocol(config[CONF_PROTOCOL]), diff --git a/esphomeyaml/components/switch/uart.py b/esphomeyaml/components/switch/uart.py index d37f2f5bd2..57573c7462 100644 --- a/esphomeyaml/components/switch/uart.py +++ b/esphomeyaml/components/switch/uart.py @@ -5,7 +5,7 @@ from esphomeyaml.components.uart import UARTComponent import esphomeyaml.config_validation as cv from esphomeyaml.const import CONF_DATA, CONF_ID, CONF_INVERTED, CONF_NAME, CONF_UART_ID from esphomeyaml.core import HexInt -from esphomeyaml.cpp_generator import ArrayInitializer, Pvariable, get_variable +from esphomeyaml.cpp_generator import Pvariable, get_variable from esphomeyaml.cpp_types import App from esphomeyaml.py_compat import text_type @@ -38,7 +38,7 @@ def to_code(config): data = config[CONF_DATA] if isinstance(data, str): data = [HexInt(ord(x)) for x in data] - rhs = App.make_uart_switch(uart_, config[CONF_NAME], ArrayInitializer(*data, multiline=False)) + rhs = App.make_uart_switch(uart_, config[CONF_NAME], data) var = Pvariable(config[CONF_ID], rhs) switch.setup_switch(var, config) diff --git a/esphomeyaml/components/time/__init__.py b/esphomeyaml/components/time/__init__.py index 8b78b0dfaa..68011d5d2c 100644 --- a/esphomeyaml/components/time/__init__.py +++ b/esphomeyaml/components/time/__init__.py @@ -278,22 +278,22 @@ def setup_time_core_(time_var, config): trigger = Pvariable(conf[CONF_TRIGGER_ID], rhs) seconds = conf.get(CONF_SECONDS, [x for x in range(0, 61)]) - add(trigger.add_seconds(ArrayInitializer(*seconds, multiline=False))) + add(trigger.add_seconds(seconds)) minutes = conf.get(CONF_MINUTES, [x for x in range(0, 60)]) - add(trigger.add_minutes(ArrayInitializer(*minutes, multiline=False))) + add(trigger.add_minutes(minutes)) hours = conf.get(CONF_HOURS, [x for x in range(0, 24)]) - add(trigger.add_hours(ArrayInitializer(*hours, multiline=False))) + add(trigger.add_hours(hours)) days_of_month = conf.get(CONF_DAYS_OF_MONTH, [x for x in range(1, 32)]) - add(trigger.add_days_of_month(ArrayInitializer(*days_of_month, multiline=False))) + add(trigger.add_days_of_month(days_of_month)) months = conf.get(CONF_MONTHS, [x for x in range(1, 13)]) - add(trigger.add_months(ArrayInitializer(*months, multiline=False))) + add(trigger.add_months(months)) days_of_week = conf.get(CONF_DAYS_OF_WEEK, [x for x in range(1, 8)]) - add(trigger.add_days_of_week(ArrayInitializer(*days_of_week, multiline=False))) + add(trigger.add_days_of_week(days_of_week)) automation.build_automation(trigger, NoArg, conf) diff --git a/esphomeyaml/components/wifi.py b/esphomeyaml/components/wifi.py index 9013c40f51..5067effb84 100644 --- a/esphomeyaml/components/wifi.py +++ b/esphomeyaml/components/wifi.py @@ -1,15 +1,14 @@ import voluptuous as vol import esphomeyaml.config_validation as cv -from esphomeyaml.const import CONF_AP, CONF_CHANNEL, CONF_DNS1, CONF_DNS2, CONF_DOMAIN, \ - CONF_GATEWAY, CONF_HOSTNAME, CONF_ID, CONF_MANUAL_IP, CONF_PASSWORD, CONF_POWER_SAVE_MODE, \ - CONF_REBOOT_TIMEOUT, CONF_SSID, CONF_STATIC_IP, CONF_SUBNET, CONF_NETWORKS, CONF_BSSID, \ - CONF_FAST_CONNECT +from esphomeyaml.const import CONF_AP, CONF_BSSID, CONF_CHANNEL, CONF_DNS1, CONF_DNS2, \ + CONF_DOMAIN, \ + CONF_FAST_CONNECT, CONF_GATEWAY, CONF_HOSTNAME, CONF_ID, CONF_MANUAL_IP, CONF_NETWORKS, \ + CONF_PASSWORD, CONF_POWER_SAVE_MODE, CONF_REBOOT_TIMEOUT, CONF_SSID, CONF_STATIC_IP, CONF_SUBNET from esphomeyaml.core import CORE, HexInt -from esphomeyaml.cpp_generator import Pvariable, StructInitializer, add, variable, ArrayInitializer +from esphomeyaml.cpp_generator import Pvariable, StructInitializer, add, variable from esphomeyaml.cpp_types import App, Component, esphomelib_ns, global_ns - IPAddress = global_ns.class_('IPAddress') ManualIP = esphomelib_ns.struct('ManualIP') WiFiComponent = esphomelib_ns.class_('WiFiComponent', Component) @@ -141,8 +140,7 @@ def wifi_network(config, static_ip): if CONF_PASSWORD in config: add(ap.set_password(config[CONF_PASSWORD])) if CONF_BSSID in config: - bssid = [HexInt(i) for i in config[CONF_BSSID].parts] - add(ap.set_bssid(ArrayInitializer(*bssid, multiline=False))) + add(ap.set_bssid([HexInt(i) for i in config[CONF_BSSID].parts])) if CONF_CHANNEL in config: add(ap.set_channel(config[CONF_CHANNEL])) if static_ip is not None: diff --git a/esphomeyaml/cpp_generator.py b/esphomeyaml/cpp_generator.py index 12844a9153..37af8b82c4 100644 --- a/esphomeyaml/cpp_generator.py +++ b/esphomeyaml/cpp_generator.py @@ -134,7 +134,7 @@ class StructInitializer(Expression): class ArrayInitializer(Expression): def __init__(self, *args, **kwargs): # type: (*Any, **Any) -> None super(ArrayInitializer, self).__init__() - self.multiline = kwargs.get('multiline', True) + self.multiline = kwargs.get('multiline', False) self.args = [] for arg in args: if arg is None: @@ -264,7 +264,8 @@ class FloatLiteral(Literal): # pylint: disable=bad-continuation -def safe_exp(obj # type: Union[Expression, bool, str, unicode, int, long, float, TimePeriod] +def safe_exp( + obj # type: Union[Expression, bool, str, unicode, int, long, float, TimePeriod, list] ): # type: (...) -> Expression if isinstance(obj, Expression): @@ -285,6 +286,8 @@ def safe_exp(obj # type: Union[Expression, bool, str, unicode, int, long, float return IntLiteral(int(obj.total_milliseconds)) if isinstance(obj, TimePeriodSeconds): return IntLiteral(int(obj.total_seconds)) + if isinstance(obj, (tuple, list)): + return ArrayInitializer(*[safe_exp(o) for o in obj]) raise ValueError(u"Object is not an expression", obj)