Simplify action descriptions (#13529)
This commit is contained in:
parent
be4dcbe405
commit
e976f9c119
|
@ -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: [
|
||||
{
|
||||
|
|
|
@ -154,9 +154,9 @@ export const describeAction = <T extends ActionType>(
|
|||
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 = <T extends ActionType>(
|
|||
|
||||
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 = <T extends ActionType>(
|
|||
|
||||
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;
|
||||
|
|
Loading…
Reference in New Issue