mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-18 23:06:40 +00:00
Simplify action descriptions (#13529)
This commit is contained in:
parent
be4dcbe405
commit
e976f9c119
@ -90,6 +90,15 @@ const ACTIONS = [
|
|||||||
then: [{ delay: "00:00:01" }],
|
then: [{ delay: "00:00:01" }],
|
||||||
else: [{ delay: "00:00:05" }],
|
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: [
|
choose: [
|
||||||
{
|
{
|
||||||
|
@ -154,9 +154,9 @@ export const describeAction = <T extends ActionType>(
|
|||||||
if (actionType === "fire_event") {
|
if (actionType === "fire_event") {
|
||||||
const config = action as EventAction;
|
const config = action as EventAction;
|
||||||
if (isTemplate(config.event)) {
|
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") {
|
if (actionType === "wait_template") {
|
||||||
@ -174,54 +174,29 @@ export const describeAction = <T extends ActionType>(
|
|||||||
|
|
||||||
if (actionType === "if") {
|
if (actionType === "if") {
|
||||||
const config = action as IfAction;
|
const config = action as IfAction;
|
||||||
return `If ${
|
return `Perform an action if: ${
|
||||||
typeof config.if === "string"
|
typeof config.if === "string"
|
||||||
? config.if
|
? config.if
|
||||||
: ensureArray(config.if)
|
: ensureArray(config.if).length > 1
|
||||||
.map((condition) => describeCondition(condition, hass))
|
? `${ensureArray(config.if).length} conditions`
|
||||||
.join(", ")
|
: describeCondition(ensureArray(config.if)[0], hass)
|
||||||
} then ${ensureArray(config.then).map((thenAction) =>
|
}${config.else ? " (or else!)" : ""}`;
|
||||||
describeAction(hass, thenAction)
|
|
||||||
)}${
|
|
||||||
config.else
|
|
||||||
? ` else ${ensureArray(config.else).map((elseAction) =>
|
|
||||||
describeAction(hass, elseAction)
|
|
||||||
)}`
|
|
||||||
: ""
|
|
||||||
}`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (actionType === "choose") {
|
if (actionType === "choose") {
|
||||||
const config = action as ChooseAction;
|
const config = action as ChooseAction;
|
||||||
return config.choose
|
return config.choose
|
||||||
? `If ${ensureArray(config.choose)
|
? `Choose between ${
|
||||||
.map(
|
ensureArray(config.choose).length + (config.default ? 1 : 0)
|
||||||
(chooseAction) =>
|
} actions`
|
||||||
`${
|
: "Choose an action";
|
||||||
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";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (actionType === "repeat") {
|
if (actionType === "repeat") {
|
||||||
const config = action as RepeatAction;
|
const config = action as RepeatAction;
|
||||||
return `Repeat ${ensureArray(config.repeat.sequence).map((repeatAction) =>
|
return `Repeat an action ${
|
||||||
describeAction(hass, repeatAction)
|
"count" in config.repeat ? `${config.repeat.count} times` : ""
|
||||||
)} ${"count" in config.repeat ? `${config.repeat.count} times` : ""}${
|
}${
|
||||||
"while" in config.repeat
|
"while" in config.repeat
|
||||||
? `while ${ensureArray(config.repeat.while)
|
? `while ${ensureArray(config.repeat.while)
|
||||||
.map((condition) => describeCondition(condition, hass))
|
.map((condition) => describeCondition(condition, hass))
|
||||||
@ -252,9 +227,7 @@ export const describeAction = <T extends ActionType>(
|
|||||||
|
|
||||||
if (actionType === "parallel") {
|
if (actionType === "parallel") {
|
||||||
const config = action as ParallelAction;
|
const config = action as ParallelAction;
|
||||||
return `Run in parallel: ${ensureArray(config.parallel)
|
return `Run ${ensureArray(config.parallel).length} actions in parallel`;
|
||||||
.map((pAction) => describeAction(hass, pAction))
|
|
||||||
.join(", ")}`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return actionType;
|
return actionType;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user