mirror of
https://github.com/esphome/esphome.git
synced 2025-03-14 14:48:18 +00:00
Add restore state option to template switch
This commit is contained in:
parent
3b3ff4fea9
commit
d3579b99f9
@ -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'
|
||||
|
||||
|
@ -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'
|
||||
|
Loading…
x
Reference in New Issue
Block a user