Browse Source

Make the preset.activate action work with lambdas. (#31)

Co-authored-by: Maurice Makaay <mmakaay1@xs4all.net>
pull/35/head
Maurice Makaay 3 years ago
committed by GitHub
parent
commit
67abbf19ed
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 5 deletions
  1. +8
    -5
      components/xiaomi_bslamp2/light/__init__.py

+ 8
- 5
components/xiaomi_bslamp2/light/__init__.py View File

@ -180,8 +180,8 @@ def disco_action_off_to_code(config, action_id, template_arg, args):
maybe_simple_preset_action(cv.Any( maybe_simple_preset_action(cv.Any(
cv.Schema({ cv.Schema({
cv.GenerateID(CONF_PRESETS_ID): cv.use_id(PresetsContainer), cv.GenerateID(CONF_PRESETS_ID): cv.use_id(PresetsContainer),
cv.Required(CONF_GROUP): is_preset_group,
cv.Optional(CONF_PRESET): is_preset
cv.Required(CONF_GROUP): cv.templatable(cv.string),
cv.Optional(CONF_PRESET): cv.templatable(cv.string)
}), }),
cv.Schema({ cv.Schema({
cv.GenerateID(CONF_PRESETS_ID): cv.use_id(PresetsContainer), cv.GenerateID(CONF_PRESETS_ID): cv.use_id(PresetsContainer),
@ -197,11 +197,14 @@ def preset_activate_to_code(config, action_id, template_arg, args):
cg.add(action_var.set_operation(f"next_{config[CONF_NEXT]}")) cg.add(action_var.set_operation(f"next_{config[CONF_NEXT]}"))
elif CONF_PRESET in config: elif CONF_PRESET in config:
cg.add(action_var.set_operation("activate_preset")) cg.add(action_var.set_operation("activate_preset"))
cg.add(action_var.set_group(config[CONF_GROUP]))
cg.add(action_var.set_preset(config[CONF_PRESET]))
group_template_ = yield cg.templatable(config[CONF_GROUP], args, cg.std_string)
cg.add(action_var.set_group(group_template_))
preset_template_ = yield cg.templatable(config[CONF_PRESET], args, cg.std_string)
cg.add(action_var.set_preset(preset_template_))
else: else:
cg.add(action_var.set_operation("activate_group")) cg.add(action_var.set_operation("activate_group"))
cg.add(action_var.set_group(config[CONF_GROUP]))
group_template_ = yield cg.templatable(config[CONF_GROUP], args, cg.std_string)
cg.add(action_var.set_group(group_template_))
yield action_var yield action_var
@coroutine @coroutine


Loading…
Cancel
Save