Attempt to fix script parameters (#4627)

This commit is contained in:
Jesse Hills 2023-06-28 11:34:08 +12:00 committed by GitHub
parent c82be2cd60
commit 68119ddcd4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 1 deletions

View File

@ -33,6 +33,7 @@ SCRIPT_MODES = {
PARAMETER_TYPE_TRANSLATIONS = {
"string": "std::string",
"boolean": "bool",
}
@ -149,6 +150,16 @@ async def to_code(config):
),
)
async def script_execute_action_to_code(config, action_id, template_arg, args):
def convert(type: str):
def converter(value):
if type == "std::string":
return value
if type == "bool":
return cg.RawExpression(str(value).lower())
return cg.RawExpression(str(value))
return converter
async def get_ordered_args(config, script_params):
config_args = config.copy()
config_args.pop(CONF_ID)
@ -160,7 +171,9 @@ async def script_execute_action_to_code(config, action_id, template_arg, args):
raise EsphomeError(
f"Missing parameter: '{name}' in script.execute {config[CONF_ID]}"
)
arg = await cg.templatable(config_args[name], args, type)
arg = await cg.templatable(
config_args[name], args, type, convert(str(type))
)
script_args.append(arg)
return script_args