mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Make numeric_state trigger and condition translatable (#18017)
This commit is contained in:
parent
4f3dc82fd9
commit
44748df3ac
@ -138,41 +138,54 @@ const tryDescribeTrigger = (
|
|||||||
|
|
||||||
// Numeric State Trigger
|
// Numeric State Trigger
|
||||||
if (trigger.platform === "numeric_state" && trigger.entity_id) {
|
if (trigger.platform === "numeric_state" && trigger.entity_id) {
|
||||||
let base = "When";
|
|
||||||
const stateObj = hass.states[trigger.entity_id];
|
const stateObj = hass.states[trigger.entity_id];
|
||||||
const entity = stateObj ? computeStateName(stateObj) : trigger.entity_id;
|
const entity = stateObj ? computeStateName(stateObj) : trigger.entity_id;
|
||||||
|
|
||||||
if (trigger.attribute) {
|
const attribute = trigger.attribute
|
||||||
base += ` ${computeAttributeNameDisplay(
|
? computeAttributeNameDisplay(
|
||||||
hass.localize,
|
hass.localize,
|
||||||
stateObj,
|
stateObj,
|
||||||
hass.entities,
|
hass.entities,
|
||||||
trigger.attribute
|
trigger.attribute
|
||||||
)} from`;
|
)
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
const duration = trigger.for ? describeDuration(trigger.for) : undefined;
|
||||||
|
|
||||||
|
if (trigger.above && trigger.below) {
|
||||||
|
return hass.localize(
|
||||||
|
`${triggerTranslationBaseKey}.numeric_state.description.above-below`,
|
||||||
|
{
|
||||||
|
attribute: attribute,
|
||||||
|
entity: entity,
|
||||||
|
above: trigger.above,
|
||||||
|
below: trigger.below,
|
||||||
|
duration: duration,
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
if (trigger.above) {
|
||||||
base += ` ${entity} is`;
|
return hass.localize(
|
||||||
|
`${triggerTranslationBaseKey}.numeric_state.description.above`,
|
||||||
if (trigger.above !== undefined) {
|
{
|
||||||
base += ` above ${trigger.above}`;
|
attribute: attribute,
|
||||||
|
entity: entity,
|
||||||
|
above: trigger.above,
|
||||||
|
duration: duration,
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
if (trigger.below) {
|
||||||
if (trigger.below !== undefined && trigger.above !== undefined) {
|
return hass.localize(
|
||||||
base += " and";
|
`${triggerTranslationBaseKey}.numeric_state.description.below`,
|
||||||
|
{
|
||||||
|
attribute: attribute,
|
||||||
|
entity: entity,
|
||||||
|
below: trigger.below,
|
||||||
|
duration: duration,
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (trigger.below !== undefined) {
|
|
||||||
base += ` below ${trigger.below}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (trigger.for) {
|
|
||||||
const duration = describeDuration(trigger.for);
|
|
||||||
if (duration) {
|
|
||||||
base += ` for ${duration}`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return base;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// State Trigger
|
// State Trigger
|
||||||
@ -825,29 +838,49 @@ const tryDescribeCondition = (
|
|||||||
|
|
||||||
// Numeric State Condition
|
// Numeric State Condition
|
||||||
if (condition.condition === "numeric_state" && condition.entity_id) {
|
if (condition.condition === "numeric_state" && condition.entity_id) {
|
||||||
let base = "Confirm";
|
|
||||||
const stateObj = hass.states[condition.entity_id];
|
const stateObj = hass.states[condition.entity_id];
|
||||||
const entity = stateObj ? computeStateName(stateObj) : condition.entity_id;
|
const entity = stateObj ? computeStateName(stateObj) : condition.entity_id;
|
||||||
|
|
||||||
if ("attribute" in condition) {
|
const attribute = condition.attribute
|
||||||
base += ` ${condition.attribute} from`;
|
? computeAttributeNameDisplay(
|
||||||
|
hass.localize,
|
||||||
|
stateObj,
|
||||||
|
hass.entities,
|
||||||
|
condition.attribute
|
||||||
|
)
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
if (condition.above && condition.below) {
|
||||||
|
return hass.localize(
|
||||||
|
`${conditionsTranslationBaseKey}.numeric_state.description.above-below`,
|
||||||
|
{
|
||||||
|
attribute: attribute,
|
||||||
|
entity: entity,
|
||||||
|
above: condition.above,
|
||||||
|
below: condition.below,
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
if (condition.above) {
|
||||||
base += ` ${entity} is`;
|
return hass.localize(
|
||||||
|
`${conditionsTranslationBaseKey}.numeric_state.description.above`,
|
||||||
if ("above" in condition) {
|
{
|
||||||
base += ` above ${condition.above}`;
|
attribute: attribute,
|
||||||
|
entity: entity,
|
||||||
|
above: condition.above,
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
if (condition.below) {
|
||||||
if ("below" in condition && "above" in condition) {
|
return hass.localize(
|
||||||
base += " and";
|
`${conditionsTranslationBaseKey}.numeric_state.description.below`,
|
||||||
|
{
|
||||||
|
attribute: attribute,
|
||||||
|
entity: entity,
|
||||||
|
below: condition.below,
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ("below" in condition) {
|
|
||||||
base += ` below ${condition.below}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
return base;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Time condition
|
// Time condition
|
||||||
|
@ -2446,7 +2446,12 @@
|
|||||||
"mode_below": "Below mode",
|
"mode_below": "Below mode",
|
||||||
"value_template": "Value template",
|
"value_template": "Value template",
|
||||||
"type_value": "Fixed number",
|
"type_value": "Fixed number",
|
||||||
"type_input": "Numeric value of another entity"
|
"type_input": "Numeric value of another entity",
|
||||||
|
"description": {
|
||||||
|
"above": "When {attribute, select, \n undefined {} \n other {{attribute} from }\n }{entity} is above {above}{duration, select, \n undefined {} \n other { for {duration}}\n }",
|
||||||
|
"below": "When {attribute, select, \n undefined {} \n other {{attribute} from }\n }{entity} is below {below}{duration, select, \n undefined {} \n other { for {duration}}\n }",
|
||||||
|
"above-below": "When {attribute, select, \n undefined {} \n other {{attribute} from }\n }{entity} is above {above} and below {below}{duration, select, \n undefined {} \n other { for {duration}}\n }"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"persistent_notification": {
|
"persistent_notification": {
|
||||||
"label": "Persistent notification",
|
"label": "Persistent notification",
|
||||||
@ -2595,7 +2600,12 @@
|
|||||||
"below": "[%key:ui::panel::config::automation::editor::triggers::type::numeric_state::below%]",
|
"below": "[%key:ui::panel::config::automation::editor::triggers::type::numeric_state::below%]",
|
||||||
"mode_above": "[%key:ui::panel::config::automation::editor::triggers::type::numeric_state::mode_above%]",
|
"mode_above": "[%key:ui::panel::config::automation::editor::triggers::type::numeric_state::mode_above%]",
|
||||||
"mode_below": "[%key:ui::panel::config::automation::editor::triggers::type::numeric_state::mode_below%]",
|
"mode_below": "[%key:ui::panel::config::automation::editor::triggers::type::numeric_state::mode_below%]",
|
||||||
"value_template": "[%key:ui::panel::config::automation::editor::triggers::type::numeric_state::value_template%]"
|
"value_template": "[%key:ui::panel::config::automation::editor::triggers::type::numeric_state::value_template%]",
|
||||||
|
"description": {
|
||||||
|
"above": "When {attribute, select, \n undefined {} \n other {{attribute} from }\n }{entity} is above {above}",
|
||||||
|
"below": "When {attribute, select, \n undefined {} \n other {{attribute} from }\n }{entity} is below {below}",
|
||||||
|
"above-below": "When {attribute, select, \n undefined {} \n other {{attribute} from }\n }{entity} is above {above} and below {below}"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"or": {
|
"or": {
|
||||||
"label": "Or",
|
"label": "Or",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user