mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +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
|
// State Condition
|
||||||
if (condition.condition === "state") {
|
if (condition.condition === "state") {
|
||||||
let base = "Confirm";
|
|
||||||
if (!condition.entity_id) {
|
if (!condition.entity_id) {
|
||||||
return `${base} state`;
|
return hass.localize(
|
||||||
|
`${conditionsTranslationBaseKey}.state.description.no_entity`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let attribute = "";
|
||||||
if (condition.attribute) {
|
if (condition.attribute) {
|
||||||
const stateObj = Array.isArray(condition.entity_id)
|
const stateObj = Array.isArray(condition.entity_id)
|
||||||
? hass.states[condition.entity_id[0]]
|
? hass.states[condition.entity_id[0]]
|
||||||
: hass.states[condition.entity_id];
|
: hass.states[condition.entity_id];
|
||||||
base += ` ${computeAttributeNameDisplay(
|
attribute = computeAttributeNameDisplay(
|
||||||
hass.localize,
|
hass.localize,
|
||||||
stateObj,
|
stateObj,
|
||||||
hass.entities,
|
hass.entities,
|
||||||
condition.attribute
|
condition.attribute
|
||||||
)} of`;
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const entities: string[] = [];
|
||||||
if (Array.isArray(condition.entity_id)) {
|
if (Array.isArray(condition.entity_id)) {
|
||||||
const entities: string[] = [];
|
|
||||||
for (const entity of condition.entity_id.values()) {
|
for (const entity of condition.entity_id.values()) {
|
||||||
if (hass.states[entity]) {
|
if (hass.states[entity]) {
|
||||||
entities.push(computeStateName(hass.states[entity]) || 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) {
|
} else if (condition.entity_id) {
|
||||||
base += ` ${
|
entities.push(
|
||||||
hass.states[condition.entity_id]
|
hass.states[condition.entity_id]
|
||||||
? computeStateName(hass.states[condition.entity_id])
|
? computeStateName(hass.states[condition.entity_id])
|
||||||
: condition.entity_id
|
: condition.entity_id
|
||||||
} is`;
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const states: string[] = [];
|
const states: string[] = [];
|
||||||
@ -845,21 +835,27 @@ const tryDescribeCondition = (
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (states.length === 0) {
|
let duration = "";
|
||||||
states.push("a state");
|
|
||||||
}
|
|
||||||
|
|
||||||
const statesString = formatListWithOrs(hass.locale, states);
|
|
||||||
base += ` ${statesString}`;
|
|
||||||
|
|
||||||
if (condition.for) {
|
if (condition.for) {
|
||||||
const duration = describeDuration(hass.locale, condition.for);
|
duration = describeDuration(hass.locale, condition.for) || "";
|
||||||
if (duration) {
|
|
||||||
base += ` for ${duration}`;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
// Numeric State Condition
|
||||||
|
@ -2694,7 +2694,11 @@
|
|||||||
},
|
},
|
||||||
"state": {
|
"state": {
|
||||||
"label": "[%key:ui::panel::config::automation::editor::triggers::type::state::label%]",
|
"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": {
|
"sun": {
|
||||||
"label": "[%key:ui::panel::config::automation::editor::triggers::type::sun::label%]",
|
"label": "[%key:ui::panel::config::automation::editor::triggers::type::sun::label%]",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user