Add a description for time condition (#16499)

This commit is contained in:
karwosts 2023-05-27 09:27:24 -07:00 committed by GitHub
parent 83570f2419
commit fd0c0a95ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 61 additions and 0 deletions

View File

@ -784,6 +784,67 @@ export const describeCondition = (
return base;
}
// Time condition
if (condition.condition === "time") {
const weekdaysArray = ensureArray(condition.weekday);
const validWeekdays =
weekdaysArray && weekdaysArray.length > 0 && weekdaysArray.length < 7;
if (condition.before || condition.after || validWeekdays) {
const before = condition.before?.toString().includes(".")
? `entity ${
hass.states[condition.before]
? computeStateName(hass.states[condition.before])
: condition.before
}`
: condition.before;
const after = condition.after?.toString().includes(".")
? `entity ${
hass.states[condition.after]
? computeStateName(hass.states[condition.after])
: condition.after
}`
: condition.after;
let result = "Confirm the ";
if (after || before) {
result += "time is ";
}
if (after) {
result += "after " + after;
}
if (before && after) {
result += " and ";
}
if (before) {
result += "before " + before;
}
if ((after || before) && validWeekdays) {
result += " and the ";
}
if (validWeekdays) {
const localizedDays = weekdaysArray.map((d) =>
hass.localize(
`ui.panel.config.automation.editor.conditions.type.time.weekdays.${d}`
)
);
const last = localizedDays.pop();
result += " day is " + localizedDays.join(", ");
if (localizedDays.length) {
if (localizedDays.length > 1) {
result += ",";
}
result += " or ";
}
result += last;
}
return result;
}
}
// Sun condition
if (
condition.condition === "sun" &&