Localize sun condition in automation editor (#19473)

Sun condition
This commit is contained in:
Simon Lamon 2024-01-22 18:17:20 +01:00 committed by GitHub
parent 545d140dcf
commit 9354ed927b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 42 additions and 53 deletions

View File

@ -1016,60 +1016,40 @@ const tryDescribeCondition = (
}
// Sun condition
if (
condition.condition === "sun" &&
("before" in condition || "after" in condition)
) {
let base = "Confirm";
if (!condition.after && !condition.before) {
base += " sun";
return base;
}
base += " sun";
if (condition.after) {
let after_duration = "";
if (condition.after_offset) {
if (typeof condition.after_offset === "number") {
after_duration = ` offset by ${secondsToDuration(
condition.after_offset
)!}`;
} else if (typeof condition.after_offset === "string") {
after_duration = ` offset by ${condition.after_offset}`;
} else {
after_duration = ` offset by ${JSON.stringify(
condition.after_offset
)}`;
}
if (condition.condition === "sun" && (condition.before || condition.after)) {
let afterDuration = "";
if (condition.after && condition.after_offset) {
if (typeof condition.after_offset === "number") {
afterDuration = secondsToDuration(condition.after_offset)!;
} else if (typeof condition.after_offset === "string") {
afterDuration = condition.after_offset;
} else {
afterDuration = JSON.stringify(condition.after_offset);
}
base += ` after ${condition.after}${after_duration}`;
}
if (condition.before) {
let before_duration = "";
if (condition.before_offset) {
if (typeof condition.before_offset === "number") {
before_duration = ` offset by ${secondsToDuration(
condition.before_offset
)!}`;
} else if (typeof condition.before_offset === "string") {
before_duration = ` offset by ${condition.before_offset}`;
} else {
before_duration = ` offset by ${JSON.stringify(
condition.before_offset
)}`;
}
let beforeDuration = "";
if (condition.before && condition.before_offset) {
if (typeof condition.before_offset === "number") {
beforeDuration = secondsToDuration(condition.before_offset)!;
} else if (typeof condition.before_offset === "string") {
beforeDuration = condition.before_offset;
} else {
beforeDuration = JSON.stringify(condition.before_offset);
}
base += ` before ${condition.before}${before_duration}`;
}
return base;
return hass.localize(
`${conditionsTranslationBaseKey}.sun.description.full`,
{
afterChoice: condition.after ?? "other",
afterOffsetChoice: afterDuration !== "" ? "offset" : "other",
afterOffset: afterDuration,
beforeChoice: condition.before ?? "other",
beforeOffsetChoice: beforeDuration !== "" ? "offset" : "other",
beforeOffset: beforeDuration,
}
);
}
// Zone condition

View File

@ -2508,7 +2508,9 @@
"label": "Time and location",
"description": "When someone enters or leaves a zone, or at a specific time."
},
"other": { "label": "Other triggers" }
"other": {
"label": "Other triggers"
}
},
"type": {
"calendar": {
@ -2748,7 +2750,9 @@
"label": "Time and location",
"description": "If someone is in a zone or if the current time is before or after a specified time."
},
"other": { "label": "Other conditions" },
"other": {
"label": "Other conditions"
},
"building_blocks": {
"label": "Building blocks",
"description": "Build more complex conditions."
@ -2828,7 +2832,8 @@
"sunrise": "Sunrise",
"sunset": "Sunset",
"description": {
"picker": "If the sun is above or below the horizon."
"picker": "If the sun is above or below the horizon.",
"full": "Confirm sun{afterChoice, select, \n sunrise { after sunrise}\n sunset { after sunset}\n other {}\n}{afterOffsetChoice, select, \n offset { offset by {afterOffset}}\n other {}\n}{beforeChoice, select, \n sunrise { before sunrise}\n sunset { before sunset}\n other {}\n}{beforeOffsetChoice, select, \n offset { offset by {beforeOffset}}\n other {}\n}"
}
},
"template": {
@ -2912,8 +2917,12 @@
"type_select": "Action type",
"continue_on_error": "Continue on error",
"groups": {
"helpers": { "label": "Helpers" },
"other": { "label": "Other actions" },
"helpers": {
"label": "Helpers"
},
"other": {
"label": "Other actions"
},
"building_blocks": {
"label": "Building blocks",
"description": "Build more complex sequences of actions."