From 94f4f3e239ef17ba900b8933aa44d16ff6a1d83c Mon Sep 17 00:00:00 2001 From: Otto Winter Date: Sat, 13 Oct 2018 19:38:44 +0200 Subject: [PATCH] Add Switch power_on_value option --- esphomeyaml/components/output/gpio.py | 7 +++++-- esphomeyaml/components/switch/gpio.py | 7 +++++-- esphomeyaml/const.py | 1 + tests/test1.yaml | 2 ++ 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/esphomeyaml/components/output/gpio.py b/esphomeyaml/components/output/gpio.py index 3f471e74b5..5cc19329c8 100644 --- a/esphomeyaml/components/output/gpio.py +++ b/esphomeyaml/components/output/gpio.py @@ -3,14 +3,15 @@ import voluptuous as vol from esphomeyaml import pins import esphomeyaml.config_validation as cv from esphomeyaml.components import output -from esphomeyaml.const import CONF_ID, CONF_PIN -from esphomeyaml.helpers import App, Pvariable, gpio_output_pin_expression +from esphomeyaml.const import CONF_ID, CONF_PIN, CONF_POWER_ON_VALUE +from esphomeyaml.helpers import App, Pvariable, gpio_output_pin_expression, add GPIOBinaryOutputComponent = output.output_ns.GPIOBinaryOutputComponent PLATFORM_SCHEMA = output.BINARY_OUTPUT_PLATFORM_SCHEMA.extend({ vol.Required(CONF_ID): cv.declare_variable_id(GPIOBinaryOutputComponent), vol.Required(CONF_PIN): pins.gpio_output_pin_schema, + vol.Optional(CONF_POWER_ON_VALUE): cv.boolean, }) @@ -20,6 +21,8 @@ def to_code(config): yield rhs = App.make_gpio_output(pin) gpio = Pvariable(config[CONF_ID], rhs) + if CONF_POWER_ON_VALUE in config: + add(gpio.set_power_on_value(config[CONF_POWER_ON_VALUE])) output.setup_output_platform(gpio, config) diff --git a/esphomeyaml/components/switch/gpio.py b/esphomeyaml/components/switch/gpio.py index 58700c67e9..bf978504bf 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,8 @@ 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.Pgpio.set_power_on_value(config[CONF_POWER_ON_VALUE])) switch.setup_switch(gpio.Pswitch_, gpio.Pmqtt, config) 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 d6135207cc..5abc2f8be7 100644 --- a/tests/test1.yaml +++ b/tests/test1.yaml @@ -522,6 +522,7 @@ output: id: gpio_26 power_supply: atx_power_supply inverted: False + power_on_value: True - platform: ledc pin: 19 id: gpio_19 @@ -688,6 +689,7 @@ switch: icon: "mdi:restart" inverted: True command_topic: custom_command_topic + power_on_value: True - platform: remote_transmitter name: "Panasonic TV Off" nec: