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