diff --git a/src/data/automation_i18n.ts b/src/data/automation_i18n.ts index d7f186a0dc..e01c04de14 100644 --- a/src/data/automation_i18n.ts +++ b/src/data/automation_i18n.ts @@ -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 diff --git a/src/translations/en.json b/src/translations/en.json index 1142a89d23..0bb3f0844d 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -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."