Add restore state option to template switch (#222)

* Add restore state option to template switch

* Add test
This commit is contained in:
Otto Winter 2018-11-09 20:05:50 +01:00 committed by GitHub
parent e3094d9689
commit 3ec931ffa4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 1 deletions

View File

@ -4,18 +4,21 @@ import esphomeyaml.config_validation as cv
from esphomeyaml import automation
from esphomeyaml.components import switch
from esphomeyaml.const import CONF_LAMBDA, CONF_MAKE_ID, CONF_NAME, CONF_TURN_OFF_ACTION, \
CONF_TURN_ON_ACTION, CONF_OPTIMISTIC
CONF_TURN_ON_ACTION, CONF_OPTIMISTIC, CONF_RESTORE_STATE
from esphomeyaml.helpers import App, Application, process_lambda, variable, NoArg, add, bool_, \
optional
MakeTemplateSwitch = Application.MakeTemplateSwitch
TemplateSwitch = switch.switch_ns.TemplateSwitch
PLATFORM_SCHEMA = cv.nameable(switch.SWITCH_PLATFORM_SCHEMA.extend({
cv.GenerateID(): cv.declare_variable_id(TemplateSwitch),
cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(MakeTemplateSwitch),
vol.Optional(CONF_LAMBDA): cv.lambda_,
vol.Optional(CONF_OPTIMISTIC): cv.boolean,
vol.Optional(CONF_TURN_OFF_ACTION): automation.validate_automation(single=True),
vol.Optional(CONF_TURN_ON_ACTION): automation.validate_automation(single=True),
vol.Optional(CONF_RESTORE_STATE): cv.boolean,
}), cv.has_at_least_one_key(CONF_LAMBDA, CONF_OPTIMISTIC))
@ -40,6 +43,9 @@ def to_code(config):
if CONF_OPTIMISTIC in config:
add(make.Ptemplate_.set_optimistic(config[CONF_OPTIMISTIC]))
if CONF_RESTORE_STATE in config:
add(make.Ptemplate_.set_restore_state(config[CONF_RESTORE_STATE]))
BUILD_FLAGS = '-DUSE_TEMPLATE_SWITCH'

View File

@ -359,6 +359,7 @@ CONF_STEP_PIN = 'step_pin'
CONF_DIR_PIN = 'dir_pin'
CONF_SLEEP_PIN = 'sleep_pin'
CONF_SEND_FIRST_AT = 'send_first_at'
CONF_RESTORE_STATE = 'restore_state'
ALLOWED_NAME_CHARS = u'abcdefghijklmnopqrstuvwxyz0123456789_'
ARDUINO_VERSION_ESP32_DEV = 'https://github.com/platformio/platform-espressif32.git#feature/stage'

View File

@ -806,6 +806,7 @@ switch:
level: !lambda 'return 0.5;'
turn_off_action:
- switch.turn_on: living_room_lights_off
restore_state: False
- platform: restart
name: "Living Room Restart"
- platform: shutdown
@ -832,6 +833,7 @@ switch:
// Switch is OFF, do something else here
}
optimistic: true
restore_state: True
- platform: uart
name: "UART String Output"
data: 'DataToSend'