mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-24 09:46:36 +00:00
Fix an infinite loop in automation numeric_state (#22429)
This commit is contained in:
parent
5f6396b187
commit
9fff3adbfb
@ -60,6 +60,18 @@ export default class HaNumericStateCondition extends LitElement {
|
||||
return true;
|
||||
}
|
||||
|
||||
private _data = memoizeOne(
|
||||
(
|
||||
inputAboveIsEntity: boolean,
|
||||
inputBelowIsEntity: boolean,
|
||||
condition: NumericStateCondition
|
||||
) => ({
|
||||
mode_above: inputAboveIsEntity ? "input" : "value",
|
||||
mode_below: inputBelowIsEntity ? "input" : "value",
|
||||
...condition,
|
||||
})
|
||||
);
|
||||
|
||||
private _schema = memoizeOne(
|
||||
(
|
||||
localize: LocalizeFunc,
|
||||
@ -233,31 +245,33 @@ export default class HaNumericStateCondition extends LitElement {
|
||||
] as const
|
||||
);
|
||||
|
||||
public render() {
|
||||
const inputAboveIsEntity =
|
||||
public willUpdate() {
|
||||
this._inputAboveIsEntity =
|
||||
this._inputAboveIsEntity ??
|
||||
(typeof this.condition.above === "string" &&
|
||||
((this.condition.above as string).startsWith("input_number.") ||
|
||||
(this.condition.above as string).startsWith("number.") ||
|
||||
(this.condition.above as string).startsWith("sensor.")));
|
||||
const inputBelowIsEntity =
|
||||
this._inputBelowIsEntity =
|
||||
this._inputBelowIsEntity ??
|
||||
(typeof this.condition.below === "string" &&
|
||||
((this.condition.below as string).startsWith("input_number.") ||
|
||||
(this.condition.below as string).startsWith("number.") ||
|
||||
(this.condition.below as string).startsWith("sensor.")));
|
||||
}
|
||||
|
||||
public render() {
|
||||
const schema = this._schema(
|
||||
this.hass.localize,
|
||||
inputAboveIsEntity,
|
||||
inputBelowIsEntity
|
||||
this._inputAboveIsEntity,
|
||||
this._inputBelowIsEntity
|
||||
);
|
||||
|
||||
const data = {
|
||||
mode_above: inputAboveIsEntity ? "input" : "value",
|
||||
mode_below: inputBelowIsEntity ? "input" : "value",
|
||||
...this.condition,
|
||||
};
|
||||
const data = this._data(
|
||||
this._inputAboveIsEntity!,
|
||||
this._inputBelowIsEntity!,
|
||||
this.condition
|
||||
);
|
||||
|
||||
return html`
|
||||
<ha-form
|
||||
|
@ -224,6 +224,19 @@ export class HaNumericStateTrigger extends LitElement {
|
||||
);
|
||||
|
||||
public willUpdate(changedProperties: PropertyValues) {
|
||||
this._inputAboveIsEntity =
|
||||
this._inputAboveIsEntity ??
|
||||
(typeof this.trigger.above === "string" &&
|
||||
((this.trigger.above as string).startsWith("input_number.") ||
|
||||
(this.trigger.above as string).startsWith("number.") ||
|
||||
(this.trigger.above as string).startsWith("sensor.")));
|
||||
this._inputBelowIsEntity =
|
||||
this._inputBelowIsEntity ??
|
||||
(typeof this.trigger.below === "string" &&
|
||||
((this.trigger.below as string).startsWith("input_number.") ||
|
||||
(this.trigger.below as string).startsWith("number.") ||
|
||||
(this.trigger.below as string).startsWith("sensor.")));
|
||||
|
||||
if (!changedProperties.has("trigger")) {
|
||||
return;
|
||||
}
|
||||
@ -244,36 +257,33 @@ export class HaNumericStateTrigger extends LitElement {
|
||||
};
|
||||
}
|
||||
|
||||
private _data = memoizeOne(
|
||||
(
|
||||
inputAboveIsEntity: boolean,
|
||||
inputBelowIsEntity: boolean,
|
||||
trigger: NumericStateTrigger
|
||||
) => ({
|
||||
mode_above: inputAboveIsEntity ? "input" : "value",
|
||||
mode_below: inputBelowIsEntity ? "input" : "value",
|
||||
...trigger,
|
||||
entity_id: ensureArray(trigger.entity_id),
|
||||
for: createDurationData(trigger.for),
|
||||
})
|
||||
);
|
||||
|
||||
public render() {
|
||||
const trgFor = createDurationData(this.trigger.for);
|
||||
|
||||
const inputAboveIsEntity =
|
||||
this._inputAboveIsEntity ??
|
||||
(typeof this.trigger.above === "string" &&
|
||||
((this.trigger.above as string).startsWith("input_number.") ||
|
||||
(this.trigger.above as string).startsWith("number.") ||
|
||||
(this.trigger.above as string).startsWith("sensor.")));
|
||||
const inputBelowIsEntity =
|
||||
this._inputBelowIsEntity ??
|
||||
(typeof this.trigger.below === "string" &&
|
||||
((this.trigger.below as string).startsWith("input_number.") ||
|
||||
(this.trigger.below as string).startsWith("number.") ||
|
||||
(this.trigger.below as string).startsWith("sensor.")));
|
||||
|
||||
const schema = this._schema(
|
||||
this.hass.localize,
|
||||
this.trigger.entity_id,
|
||||
inputAboveIsEntity,
|
||||
inputBelowIsEntity
|
||||
this._inputAboveIsEntity,
|
||||
this._inputBelowIsEntity
|
||||
);
|
||||
|
||||
const data = {
|
||||
mode_above: inputAboveIsEntity ? "input" : "value",
|
||||
mode_below: inputBelowIsEntity ? "input" : "value",
|
||||
...this.trigger,
|
||||
entity_id: ensureArray(this.trigger.entity_id),
|
||||
for: trgFor,
|
||||
};
|
||||
const data = this._data(
|
||||
this._inputAboveIsEntity!,
|
||||
this._inputBelowIsEntity!,
|
||||
this.trigger
|
||||
);
|
||||
|
||||
return html`
|
||||
<ha-form
|
||||
@ -289,7 +299,7 @@ export class HaNumericStateTrigger extends LitElement {
|
||||
|
||||
private _valueChanged(ev: CustomEvent): void {
|
||||
ev.stopPropagation();
|
||||
const newTrigger = ev.detail.value;
|
||||
const newTrigger = { ...ev.detail.value };
|
||||
|
||||
this._inputAboveIsEntity = newTrigger.mode_above === "input";
|
||||
this._inputBelowIsEntity = newTrigger.mode_below === "input";
|
||||
|
Loading…
x
Reference in New Issue
Block a user