mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-28 11:46:42 +00:00
Improve error handling in automation i18n (#25266)
This commit is contained in:
parent
4624cc609f
commit
d7dd11ba7f
@ -73,16 +73,20 @@ class HaEntityAttributePicker extends LitElement {
|
||||
return nothing;
|
||||
}
|
||||
|
||||
const stateObj = this.hass.states[this.entityId!] as HassEntity | undefined;
|
||||
|
||||
return html`
|
||||
<ha-combo-box
|
||||
.hass=${this.hass}
|
||||
.value=${this.value
|
||||
? stateObj
|
||||
? computeAttributeNameDisplay(
|
||||
this.hass.localize,
|
||||
this.hass.states[this.entityId!],
|
||||
stateObj,
|
||||
this.hass.entities,
|
||||
this.value
|
||||
)
|
||||
: this.value
|
||||
: ""}
|
||||
.autofocus=${this.autofocus}
|
||||
.label=${this.label ??
|
||||
|
@ -1,4 +1,4 @@
|
||||
import type { HassConfig } from "home-assistant-js-websocket";
|
||||
import type { HassConfig, HassEntity } from "home-assistant-js-websocket";
|
||||
import { ensureArray } from "../common/array/ensure-array";
|
||||
import {
|
||||
formatDurationLong,
|
||||
@ -155,7 +155,7 @@ const tryDescribeTrigger = (
|
||||
|
||||
const stateObj = Array.isArray(trigger.entity_id)
|
||||
? hass.states[trigger.entity_id[0]]
|
||||
: hass.states[trigger.entity_id];
|
||||
: (hass.states[trigger.entity_id] as HassEntity | undefined);
|
||||
|
||||
if (Array.isArray(trigger.entity_id)) {
|
||||
for (const entity of trigger.entity_id.values()) {
|
||||
@ -172,12 +172,14 @@ const tryDescribeTrigger = (
|
||||
}
|
||||
|
||||
const attribute = trigger.attribute
|
||||
? stateObj
|
||||
? computeAttributeNameDisplay(
|
||||
hass.localize,
|
||||
stateObj,
|
||||
hass.entities,
|
||||
trigger.attribute
|
||||
)
|
||||
: trigger.attribute
|
||||
: undefined;
|
||||
|
||||
const duration = trigger.for
|
||||
@ -232,13 +234,15 @@ const tryDescribeTrigger = (
|
||||
if (trigger.attribute) {
|
||||
const stateObj = Array.isArray(trigger.entity_id)
|
||||
? hass.states[trigger.entity_id[0]]
|
||||
: hass.states[trigger.entity_id];
|
||||
attribute = computeAttributeNameDisplay(
|
||||
: (hass.states[trigger.entity_id] as HassEntity | undefined);
|
||||
attribute = stateObj
|
||||
? computeAttributeNameDisplay(
|
||||
hass.localize,
|
||||
stateObj,
|
||||
hass.entities,
|
||||
trigger.attribute
|
||||
);
|
||||
)
|
||||
: trigger.attribute;
|
||||
}
|
||||
|
||||
const entityArray: string[] = ensureArray(trigger.entity_id);
|
||||
@ -250,7 +254,7 @@ const tryDescribeTrigger = (
|
||||
}
|
||||
}
|
||||
|
||||
const stateObj = hass.states[entityArray[0]];
|
||||
const stateObj = hass.states[entityArray[0]] as HassEntity | undefined;
|
||||
|
||||
let fromChoice = "other";
|
||||
let fromString = "";
|
||||
@ -266,7 +270,8 @@ const tryDescribeTrigger = (
|
||||
const from: string[] = [];
|
||||
for (const state of fromArray) {
|
||||
from.push(
|
||||
trigger.attribute
|
||||
stateObj
|
||||
? trigger.attribute
|
||||
? hass
|
||||
.formatEntityAttributeValue(
|
||||
stateObj,
|
||||
@ -275,6 +280,7 @@ const tryDescribeTrigger = (
|
||||
)
|
||||
.toString()
|
||||
: hass.formatEntityState(stateObj, state)
|
||||
: state
|
||||
);
|
||||
}
|
||||
if (from.length !== 0) {
|
||||
@ -298,7 +304,8 @@ const tryDescribeTrigger = (
|
||||
const to: string[] = [];
|
||||
for (const state of toArray) {
|
||||
to.push(
|
||||
trigger.attribute
|
||||
stateObj
|
||||
? trigger.attribute
|
||||
? hass
|
||||
.formatEntityAttributeValue(
|
||||
stateObj,
|
||||
@ -307,6 +314,7 @@ const tryDescribeTrigger = (
|
||||
)
|
||||
.toString()
|
||||
: hass.formatEntityState(stateObj, state).toString()
|
||||
: state
|
||||
);
|
||||
}
|
||||
if (to.length !== 0) {
|
||||
@ -725,7 +733,9 @@ const tryDescribeTrigger = (
|
||||
if (localized) {
|
||||
return localized;
|
||||
}
|
||||
const stateObj = hass.states[config.entity_id as string];
|
||||
const stateObj = hass.states[config.entity_id as string] as
|
||||
| HassEntity
|
||||
| undefined;
|
||||
return `${stateObj ? computeStateName(stateObj) : config.entity_id} ${
|
||||
config.type
|
||||
}`;
|
||||
@ -894,13 +904,15 @@ const tryDescribeCondition = (
|
||||
if (condition.attribute) {
|
||||
const stateObj = Array.isArray(condition.entity_id)
|
||||
? hass.states[condition.entity_id[0]]
|
||||
: hass.states[condition.entity_id];
|
||||
attribute = computeAttributeNameDisplay(
|
||||
: (hass.states[condition.entity_id] as HassEntity | undefined);
|
||||
attribute = stateObj
|
||||
? computeAttributeNameDisplay(
|
||||
hass.localize,
|
||||
stateObj,
|
||||
hass.entities,
|
||||
condition.attribute
|
||||
);
|
||||
)
|
||||
: condition.attribute;
|
||||
}
|
||||
|
||||
const entities: string[] = [];
|
||||
@ -919,16 +931,16 @@ const tryDescribeCondition = (
|
||||
}
|
||||
|
||||
const states: string[] = [];
|
||||
const stateObj =
|
||||
hass.states[
|
||||
const stateObj = hass.states[
|
||||
Array.isArray(condition.entity_id)
|
||||
? condition.entity_id[0]
|
||||
: condition.entity_id
|
||||
];
|
||||
] as HassEntity | undefined;
|
||||
if (Array.isArray(condition.state)) {
|
||||
for (const state of condition.state.values()) {
|
||||
states.push(
|
||||
condition.attribute
|
||||
stateObj
|
||||
? condition.attribute
|
||||
? hass
|
||||
.formatEntityAttributeValue(
|
||||
stateObj,
|
||||
@ -937,11 +949,13 @@ const tryDescribeCondition = (
|
||||
)
|
||||
.toString()
|
||||
: hass.formatEntityState(stateObj, state)
|
||||
: state
|
||||
);
|
||||
}
|
||||
} else if (condition.state !== "") {
|
||||
states.push(
|
||||
condition.attribute
|
||||
stateObj
|
||||
? condition.attribute
|
||||
? hass
|
||||
.formatEntityAttributeValue(
|
||||
stateObj,
|
||||
@ -950,6 +964,7 @@ const tryDescribeCondition = (
|
||||
)
|
||||
.toString()
|
||||
: hass.formatEntityState(stateObj, condition.state.toString())
|
||||
: condition.state.toString()
|
||||
);
|
||||
}
|
||||
|
||||
@ -979,7 +994,7 @@ const tryDescribeCondition = (
|
||||
// Numeric State Condition
|
||||
if (condition.condition === "numeric_state" && condition.entity_id) {
|
||||
const entity_ids = ensureArray(condition.entity_id);
|
||||
const stateObj = hass.states[entity_ids[0]];
|
||||
const stateObj = hass.states[entity_ids[0]] as HassEntity | undefined;
|
||||
const entity = formatListWithAnds(
|
||||
hass.locale,
|
||||
entity_ids.map((id) =>
|
||||
@ -988,12 +1003,14 @@ const tryDescribeCondition = (
|
||||
);
|
||||
|
||||
const attribute = condition.attribute
|
||||
? stateObj
|
||||
? computeAttributeNameDisplay(
|
||||
hass.localize,
|
||||
stateObj,
|
||||
hass.entities,
|
||||
condition.attribute
|
||||
)
|
||||
: condition.attribute
|
||||
: undefined;
|
||||
|
||||
if (condition.above !== undefined && condition.below !== undefined) {
|
||||
@ -1187,7 +1204,9 @@ const tryDescribeCondition = (
|
||||
if (localized) {
|
||||
return localized;
|
||||
}
|
||||
const stateObj = hass.states[config.entity_id as string];
|
||||
const stateObj = hass.states[config.entity_id as string] as
|
||||
| HassEntity
|
||||
| undefined;
|
||||
return `${stateObj ? computeStateName(stateObj) : config.entity_id} ${
|
||||
config.type
|
||||
}`;
|
||||
|
Loading…
x
Reference in New Issue
Block a user