Automation description small fixes (#14055)

This commit is contained in:
Brandon Rothweiler 2022-10-10 10:43:32 -04:00 committed by GitHub
parent 0c800344d2
commit 391cc95883
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 10 deletions

View File

@ -60,18 +60,32 @@ export const describeTrigger = (
base += ` ${entity} is`;
if ("above" in trigger) {
if (trigger.above !== undefined) {
base += ` above ${trigger.above}`;
}
if ("below" in trigger && "above" in trigger) {
if (trigger.below !== undefined && trigger.above !== undefined) {
base += " and";
}
if ("below" in trigger) {
if (trigger.below !== undefined) {
base += ` below ${trigger.below}`;
}
if (trigger.for) {
let duration: string | null;
if (typeof trigger.for === "number") {
duration = secondsToDuration(trigger.for);
} else if (typeof trigger.for === "string") {
duration = trigger.for;
} else {
duration = formatDuration(trigger.for);
}
if (duration) {
base += ` for ${duration}`;
}
}
return base;
}
@ -424,16 +438,18 @@ export const describeCondition = (
base += ` ${entity} is ${states}`;
if ("for" in condition) {
let duration: string;
if (condition.for) {
let duration: string | null;
if (typeof condition.for === "number") {
duration = `for ${secondsToDuration(condition.for)!}`;
duration = secondsToDuration(condition.for);
} else if (typeof condition.for === "string") {
duration = `for ${condition.for}`;
duration = condition.for;
} else {
duration = `for ${JSON.stringify(condition.for)}`;
duration = formatDuration(condition.for);
}
if (duration) {
base += ` for ${duration}`;
}
base += ` for ${duration}`;
}
return base;

View File

@ -159,7 +159,7 @@ export const describeAction = <T extends ActionType>(
return "Activate a scene";
}
const sceneStateObj = entityId ? hass.states[entityId] : undefined;
return `Active scene ${
return `Activate scene ${
sceneStateObj ? computeStateName(sceneStateObj) : entityId
}`;
}