From e976f9c1195de1d21babce2a87273e33ac3fdd2a Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Wed, 31 Aug 2022 14:48:28 +0200 Subject: [PATCH] Simplify action descriptions (#13529) --- .../src/pages/automation/describe-action.ts | 9 +++ src/data/script_i18n.ts | 57 +++++-------------- 2 files changed, 24 insertions(+), 42 deletions(-) diff --git a/gallery/src/pages/automation/describe-action.ts b/gallery/src/pages/automation/describe-action.ts index cf8249901f..1a32ac0829 100644 --- a/gallery/src/pages/automation/describe-action.ts +++ b/gallery/src/pages/automation/describe-action.ts @@ -90,6 +90,15 @@ const ACTIONS = [ then: [{ delay: "00:00:01" }], else: [{ delay: "00:00:05" }], }, + { + if: [{ condition: "state" }], + then: [{ delay: "00:00:01" }], + }, + { + if: [{ condition: "state" }, { condition: "state" }], + then: [{ delay: "00:00:01" }], + else: [{ delay: "00:00:05" }], + }, { choose: [ { diff --git a/src/data/script_i18n.ts b/src/data/script_i18n.ts index f6e0aba008..c3b9c70246 100644 --- a/src/data/script_i18n.ts +++ b/src/data/script_i18n.ts @@ -154,9 +154,9 @@ export const describeAction = ( if (actionType === "fire_event") { const config = action as EventAction; if (isTemplate(config.event)) { - return "Event based on a template"; + return "Fire event based on a template"; } - return `Event ${config.event}`; + return `Fire event ${config.event}`; } if (actionType === "wait_template") { @@ -174,54 +174,29 @@ export const describeAction = ( if (actionType === "if") { const config = action as IfAction; - return `If ${ + return `Perform an action if: ${ typeof config.if === "string" ? config.if - : ensureArray(config.if) - .map((condition) => describeCondition(condition, hass)) - .join(", ") - } then ${ensureArray(config.then).map((thenAction) => - describeAction(hass, thenAction) - )}${ - config.else - ? ` else ${ensureArray(config.else).map((elseAction) => - describeAction(hass, elseAction) - )}` - : "" - }`; + : ensureArray(config.if).length > 1 + ? `${ensureArray(config.if).length} conditions` + : describeCondition(ensureArray(config.if)[0], hass) + }${config.else ? " (or else!)" : ""}`; } if (actionType === "choose") { const config = action as ChooseAction; return config.choose - ? `If ${ensureArray(config.choose) - .map( - (chooseAction) => - `${ - typeof chooseAction.conditions === "string" - ? chooseAction.conditions - : ensureArray(chooseAction.conditions) - .map((condition) => describeCondition(condition, hass)) - .join(", ") - } then ${ensureArray(chooseAction.sequence) - .map((chooseSeq) => describeAction(hass, chooseSeq)) - .join(", ")}` - ) - .join(", else if ")}${ - config.default - ? `. If none match: ${ensureArray(config.default) - .map((dAction) => describeAction(hass, dAction)) - .join(", ")}` - : "" - }` - : "Choose"; + ? `Choose between ${ + ensureArray(config.choose).length + (config.default ? 1 : 0) + } actions` + : "Choose an action"; } if (actionType === "repeat") { const config = action as RepeatAction; - return `Repeat ${ensureArray(config.repeat.sequence).map((repeatAction) => - describeAction(hass, repeatAction) - )} ${"count" in config.repeat ? `${config.repeat.count} times` : ""}${ + return `Repeat an action ${ + "count" in config.repeat ? `${config.repeat.count} times` : "" + }${ "while" in config.repeat ? `while ${ensureArray(config.repeat.while) .map((condition) => describeCondition(condition, hass)) @@ -252,9 +227,7 @@ export const describeAction = ( if (actionType === "parallel") { const config = action as ParallelAction; - return `Run in parallel: ${ensureArray(config.parallel) - .map((pAction) => describeAction(hass, pAction)) - .join(", ")}`; + return `Run ${ensureArray(config.parallel).length} actions in parallel`; } return actionType;