From 110ae36f1548e31b01037bc6c04d9e7076754ca8 Mon Sep 17 00:00:00 2001 From: Maurice Makaay Date: Thu, 27 May 2021 15:32:07 +0200 Subject: [PATCH] Make the preset.activate action work with lambdas. --- components/xiaomi_bslamp2/light/__init__.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/components/xiaomi_bslamp2/light/__init__.py b/components/xiaomi_bslamp2/light/__init__.py index c10035b..327bf16 100644 --- a/components/xiaomi_bslamp2/light/__init__.py +++ b/components/xiaomi_bslamp2/light/__init__.py @@ -180,8 +180,8 @@ def disco_action_off_to_code(config, action_id, template_arg, args): maybe_simple_preset_action(cv.Any( cv.Schema({ 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.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]}")) elif CONF_PRESET in config: 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: 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 @coroutine