Add Switch Interlocking (#411)

This commit is contained in:
Otto Winter 2019-02-10 16:47:39 +01:00 committed by GitHub
parent b6edbf9d0b
commit fcf5da66c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View File

@ -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)

View File

@ -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'