1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-30 06:33:51 +00:00

Allow simpler automation syntax

This commit is contained in:
Otto Winter
2018-06-13 21:27:58 +02:00
parent 9bb06782b2
commit 6c6d21a7ab
10 changed files with 70 additions and 51 deletions

View File

@@ -13,9 +13,9 @@ PLATFORM_SCHEMA = cv.nameable(cover.COVER_PLATFORM_SCHEMA.extend({
cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(MakeTemplateCover),
vol.Optional(CONF_LAMBDA): cv.lambda_,
vol.Optional(CONF_OPTIMISTIC): cv.boolean,
vol.Optional(CONF_OPEN_ACTION): automation.ACTIONS_SCHEMA,
vol.Optional(CONF_CLOSE_ACTION): automation.ACTIONS_SCHEMA,
vol.Optional(CONF_STOP_ACTION): automation.ACTIONS_SCHEMA,
vol.Optional(CONF_OPEN_ACTION): automation.validate_automation(),
vol.Optional(CONF_CLOSE_ACTION): automation.validate_automation(),
vol.Optional(CONF_STOP_ACTION): automation.validate_automation(),
}), cv.has_at_least_one_key(CONF_LAMBDA, CONF_OPTIMISTIC))
@@ -30,20 +30,14 @@ def to_code(config):
yield
add(make.Ptemplate_.set_state_lambda(template_))
if CONF_OPEN_ACTION in config:
actions = None
for actions in automation.build_actions(config[CONF_OPEN_ACTION], NoArg):
yield
add(make.Ptemplate_.add_open_actions(actions))
automation.build_automation(make.Ptemplate_.get_open_trigger(), NoArg,
config[CONF_OPEN_ACTION])
if CONF_CLOSE_ACTION in config:
actions = None
for actions in automation.build_actions(config[CONF_CLOSE_ACTION], NoArg):
yield
add(make.Ptemplate_.add_close_actions(actions))
automation.build_automation(make.Ptemplate_.get_close_trigger(), NoArg,
config[CONF_CLOSE_ACTION])
if CONF_STOP_ACTION in config:
actions = None
for actions in automation.build_actions(config[CONF_STOP_ACTION], NoArg):
yield
add(make.Ptemplate_.add_stop_actions(actions))
automation.build_automation(make.Ptemplate_.get_stop_trigger(), NoArg,
config[CONF_STOP_ACTION])
if CONF_OPTIMISTIC in config:
add(make.Ptemplate_.set_optimistic(config[CONF_OPTIMISTIC]))