diff --git a/esphomeyaml/components/switch/gpio.py b/esphomeyaml/components/switch/gpio.py index 58700c67e9..3ee198ec05 100644 --- a/esphomeyaml/components/switch/gpio.py +++ b/esphomeyaml/components/switch/gpio.py @@ -3,14 +3,15 @@ import voluptuous as vol import esphomeyaml.config_validation as cv from esphomeyaml import pins from esphomeyaml.components import switch -from esphomeyaml.const import CONF_MAKE_ID, CONF_NAME, CONF_PIN -from esphomeyaml.helpers import App, Application, gpio_output_pin_expression, variable +from esphomeyaml.const import CONF_MAKE_ID, CONF_NAME, CONF_PIN, CONF_POWER_ON_VALUE +from esphomeyaml.helpers import App, Application, gpio_output_pin_expression, variable, add MakeGPIOSwitch = Application.MakeGPIOSwitch PLATFORM_SCHEMA = cv.nameable(switch.SWITCH_PLATFORM_SCHEMA.extend({ cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(MakeGPIOSwitch), vol.Required(CONF_PIN): pins.gpio_output_pin_schema, + vol.Optional(CONF_POWER_ON_VALUE): cv.boolean, })) @@ -20,6 +21,10 @@ def to_code(config): yield rhs = App.make_gpio_switch(config[CONF_NAME], pin) gpio = variable(config[CONF_MAKE_ID], rhs) + + if CONF_POWER_ON_VALUE in config: + add(gpio.Pswitch_.set_power_on_value(config[CONF_POWER_ON_VALUE])) + switch.setup_switch(gpio.Pswitch_, gpio.Pmqtt, config) diff --git a/esphomeyaml/components/switch/output.py b/esphomeyaml/components/switch/output.py index 6c47b750b4..818225f74f 100644 --- a/esphomeyaml/components/switch/output.py +++ b/esphomeyaml/components/switch/output.py @@ -5,10 +5,10 @@ from esphomeyaml.components import switch from esphomeyaml.const import CONF_MAKE_ID, CONF_NAME, CONF_OUTPUT from esphomeyaml.helpers import App, Application, get_variable, variable -MakeSimpleSwitch = Application.MakeSimpleSwitch +MakeOutputSwitch = Application.MakeOutputSwitch PLATFORM_SCHEMA = cv.nameable(switch.SWITCH_PLATFORM_SCHEMA.extend({ - cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(MakeSimpleSwitch), + cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(MakeOutputSwitch), vol.Required(CONF_OUTPUT): cv.use_variable_id(None), })) @@ -17,9 +17,9 @@ def to_code(config): output = None for output in get_variable(config[CONF_OUTPUT]): yield - rhs = App.make_simple_switch(config[CONF_NAME], output) + rhs = App.make_output_switch(config[CONF_NAME], output) gpio = variable(config[CONF_MAKE_ID], rhs) switch.setup_switch(gpio.Pswitch_, gpio.Pmqtt, config) -BUILD_FLAGS = '-DUSE_SIMPLE_SWITCH' +BUILD_FLAGS = '-DUSE_OUTPUT_SWITCH' diff --git a/esphomeyaml/const.py b/esphomeyaml/const.py index 20e80af34c..23dc55cd2a 100644 --- a/esphomeyaml/const.py +++ b/esphomeyaml/const.py @@ -340,6 +340,7 @@ CONF_MONTHS = 'months' CONF_DAYS_OF_WEEK = 'days_of_week' CONF_CRON = 'cron' CONF_POWER_SAVE_MODE = 'power_save_mode' +CONF_POWER_ON_VALUE = 'power_on_value' ALLOWED_NAME_CHARS = u'abcdefghijklmnopqrstuvwxyz0123456789_' ARDUINO_VERSION_ESP32_DEV = 'https://github.com/platformio/platform-espressif32.git#feature/stage' diff --git a/tests/test1.yaml b/tests/test1.yaml index 6c1d6371b8..27050e3892 100644 --- a/tests/test1.yaml +++ b/tests/test1.yaml @@ -690,6 +690,7 @@ switch: icon: "mdi:restart" inverted: True command_topic: custom_command_topic + power_on_value: True - platform: remote_transmitter name: "Panasonic TV Off" nec: