mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-24 09:46:36 +00:00
Localize state condition in automation editor (#18864)
Co-authored-by: Bram Kragten <mail@bramkragten.nl>
This commit is contained in:
parent
f2745747ba
commit
ddf6945190
@ -766,48 +766,38 @@ const tryDescribeCondition = (
|
||||
|
||||
// State Condition
|
||||
if (condition.condition === "state") {
|
||||
let base = "Confirm";
|
||||
if (!condition.entity_id) {
|
||||
return `${base} state`;
|
||||
return hass.localize(
|
||||
`${conditionsTranslationBaseKey}.state.description.no_entity`
|
||||
);
|
||||
}
|
||||
|
||||
let attribute = "";
|
||||
if (condition.attribute) {
|
||||
const stateObj = Array.isArray(condition.entity_id)
|
||||
? hass.states[condition.entity_id[0]]
|
||||
: hass.states[condition.entity_id];
|
||||
base += ` ${computeAttributeNameDisplay(
|
||||
attribute = computeAttributeNameDisplay(
|
||||
hass.localize,
|
||||
stateObj,
|
||||
hass.entities,
|
||||
condition.attribute
|
||||
)} of`;
|
||||
);
|
||||
}
|
||||
|
||||
const entities: string[] = [];
|
||||
if (Array.isArray(condition.entity_id)) {
|
||||
const entities: string[] = [];
|
||||
for (const entity of condition.entity_id.values()) {
|
||||
if (hass.states[entity]) {
|
||||
entities.push(computeStateName(hass.states[entity]) || entity);
|
||||
}
|
||||
}
|
||||
if (entities.length !== 0) {
|
||||
const entitiesString =
|
||||
condition.match === "any"
|
||||
? formatListWithOrs(hass.locale, entities)
|
||||
: formatListWithAnds(hass.locale, entities);
|
||||
base += ` ${entitiesString} ${
|
||||
condition.entity_id.length > 1 ? "are" : "is"
|
||||
}`;
|
||||
} else {
|
||||
// no entity_id or empty array
|
||||
base += " an entity";
|
||||
}
|
||||
} else if (condition.entity_id) {
|
||||
base += ` ${
|
||||
entities.push(
|
||||
hass.states[condition.entity_id]
|
||||
? computeStateName(hass.states[condition.entity_id])
|
||||
: condition.entity_id
|
||||
} is`;
|
||||
);
|
||||
}
|
||||
|
||||
const states: string[] = [];
|
||||
@ -845,21 +835,27 @@ const tryDescribeCondition = (
|
||||
);
|
||||
}
|
||||
|
||||
if (states.length === 0) {
|
||||
states.push("a state");
|
||||
}
|
||||
|
||||
const statesString = formatListWithOrs(hass.locale, states);
|
||||
base += ` ${statesString}`;
|
||||
|
||||
let duration = "";
|
||||
if (condition.for) {
|
||||
const duration = describeDuration(hass.locale, condition.for);
|
||||
if (duration) {
|
||||
base += ` for ${duration}`;
|
||||
}
|
||||
duration = describeDuration(hass.locale, condition.for) || "";
|
||||
}
|
||||
|
||||
return base;
|
||||
return hass.localize(
|
||||
`${conditionsTranslationBaseKey}.state.description.full`,
|
||||
{
|
||||
hasAttribute: attribute !== "" ? "true" : "false",
|
||||
attribute: attribute,
|
||||
numberOfEntities: entities.length,
|
||||
entities:
|
||||
condition.match === "any"
|
||||
? formatListWithOrs(hass.locale, entities)
|
||||
: formatListWithAnds(hass.locale, entities),
|
||||
numberOfStates: states.length,
|
||||
states: formatListWithOrs(hass.locale, states),
|
||||
hasDuration: duration !== "" ? "true" : "false",
|
||||
duration: duration,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// Numeric State Condition
|
||||
|
@ -2694,7 +2694,11 @@
|
||||
},
|
||||
"state": {
|
||||
"label": "[%key:ui::panel::config::automation::editor::triggers::type::state::label%]",
|
||||
"state": "[%key:ui::panel::config::automation::editor::triggers::type::state::label%]"
|
||||
"state": "[%key:ui::panel::config::automation::editor::triggers::type::state::label%]",
|
||||
"description": {
|
||||
"no_entity": "Confirm state",
|
||||
"full": "Confirm{hasAttribute, select, \n true { {attribute} of}\n other {}\n} {numberOfEntities, plural,\n zero {an entity is}\n one {{entities} is}\n other {{entities} are}\n} {numberOfStates, plural,\n zero {a state}\n other {{states}}\n}{hasDuration, select, \n true { for {duration}} \n other {}\n }"
|
||||
}
|
||||
},
|
||||
"sun": {
|
||||
"label": "[%key:ui::panel::config::automation::editor::triggers::type::sun::label%]",
|
||||
|
Loading…
x
Reference in New Issue
Block a user