From fcf5da66c0c2a6d8027c3e763e5913eedc8982d7 Mon Sep 17 00:00:00 2001 From: Otto Winter Date: Sun, 10 Feb 2019 16:47:39 +0100 Subject: [PATCH] Add Switch Interlocking (#411) --- esphomeyaml/components/switch/gpio.py | 13 +++++++++++-- esphomeyaml/const.py | 1 + 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/esphomeyaml/components/switch/gpio.py b/esphomeyaml/components/switch/gpio.py index 8018569d20..8a2f76d06e 100644 --- a/esphomeyaml/components/switch/gpio.py +++ b/esphomeyaml/components/switch/gpio.py @@ -3,8 +3,8 @@ import voluptuous as vol from esphomeyaml import pins from esphomeyaml.components import switch import esphomeyaml.config_validation as cv -from esphomeyaml.const import CONF_ID, CONF_NAME, CONF_PIN, CONF_RESTORE_MODE -from esphomeyaml.cpp_generator import Pvariable, add +from esphomeyaml.const import CONF_ID, CONF_NAME, CONF_PIN, CONF_RESTORE_MODE, CONF_INTERLOCK +from esphomeyaml.cpp_generator import Pvariable, add, get_variable from esphomeyaml.cpp_helpers import gpio_output_pin_expression, setup_component from esphomeyaml.cpp_types import App, Component @@ -22,6 +22,7 @@ PLATFORM_SCHEMA = cv.nameable(switch.SWITCH_PLATFORM_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(GPIOSwitch), vol.Required(CONF_PIN): pins.gpio_output_pin_schema, vol.Optional(CONF_RESTORE_MODE): cv.one_of(*RESTORE_MODES, upper=True, space='_'), + vol.Optional(CONF_INTERLOCK): cv.ensure_list(cv.use_variable_id(switch.Switch)), }).extend(cv.COMPONENT_SCHEMA.schema)) @@ -34,6 +35,14 @@ def to_code(config): if CONF_RESTORE_MODE in config: add(gpio.set_restore_mode(RESTORE_MODES[config[CONF_RESTORE_MODE]])) + if CONF_INTERLOCK in config: + interlock = [] + for it in config[CONF_INTERLOCK]: + for lock in get_variable(it): + yield + interlock.append(lock) + add(gpio.set_interlock(interlock)) + switch.setup_switch(gpio, config) setup_component(gpio, config) diff --git a/esphomeyaml/const.py b/esphomeyaml/const.py index dd54df83c8..c0d9325476 100644 --- a/esphomeyaml/const.py +++ b/esphomeyaml/const.py @@ -399,6 +399,7 @@ CONF_DIRECTION = 'direction' CONF_VARIANT = 'variant' CONF_METHOD = 'method' CONF_FAST_CONNECT = 'fast_connect' +CONF_INTERLOCK = 'interlock' ALLOWED_NAME_CHARS = u'abcdefghijklmnopqrstuvwxyz0123456789_' ARDUINO_VERSION_ESP32_DEV = 'https://github.com/platformio/platform-espressif32.git#feature/stage'