mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-30 22:53:59 +00:00 
			
		
		
		
	Add Switch Interlocking (#411)
This commit is contained in:
		| @@ -3,8 +3,8 @@ import voluptuous as vol | |||||||
| from esphomeyaml import pins | from esphomeyaml import pins | ||||||
| from esphomeyaml.components import switch | from esphomeyaml.components import switch | ||||||
| import esphomeyaml.config_validation as cv | import esphomeyaml.config_validation as cv | ||||||
| from esphomeyaml.const import CONF_ID, CONF_NAME, CONF_PIN, CONF_RESTORE_MODE | from esphomeyaml.const import CONF_ID, CONF_NAME, CONF_PIN, CONF_RESTORE_MODE, CONF_INTERLOCK | ||||||
| from esphomeyaml.cpp_generator import Pvariable, add | from esphomeyaml.cpp_generator import Pvariable, add, get_variable | ||||||
| from esphomeyaml.cpp_helpers import gpio_output_pin_expression, setup_component | from esphomeyaml.cpp_helpers import gpio_output_pin_expression, setup_component | ||||||
| from esphomeyaml.cpp_types import App, 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), |     cv.GenerateID(): cv.declare_variable_id(GPIOSwitch), | ||||||
|     vol.Required(CONF_PIN): pins.gpio_output_pin_schema, |     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_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)) | }).extend(cv.COMPONENT_SCHEMA.schema)) | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -34,6 +35,14 @@ def to_code(config): | |||||||
|     if CONF_RESTORE_MODE in config: |     if CONF_RESTORE_MODE in config: | ||||||
|         add(gpio.set_restore_mode(RESTORE_MODES[config[CONF_RESTORE_MODE]])) |         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) |     switch.setup_switch(gpio, config) | ||||||
|     setup_component(gpio, config) |     setup_component(gpio, config) | ||||||
|  |  | ||||||
|   | |||||||
| @@ -399,6 +399,7 @@ CONF_DIRECTION = 'direction' | |||||||
| CONF_VARIANT = 'variant' | CONF_VARIANT = 'variant' | ||||||
| CONF_METHOD = 'method' | CONF_METHOD = 'method' | ||||||
| CONF_FAST_CONNECT = 'fast_connect' | CONF_FAST_CONNECT = 'fast_connect' | ||||||
|  | CONF_INTERLOCK = 'interlock' | ||||||
|  |  | ||||||
| ALLOWED_NAME_CHARS = u'abcdefghijklmnopqrstuvwxyz0123456789_' | ALLOWED_NAME_CHARS = u'abcdefghijklmnopqrstuvwxyz0123456789_' | ||||||
| ARDUINO_VERSION_ESP32_DEV = 'https://github.com/platformio/platform-espressif32.git#feature/stage' | ARDUINO_VERSION_ESP32_DEV = 'https://github.com/platformio/platform-espressif32.git#feature/stage' | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user