mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +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;
|
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(
|
private _schema = memoizeOne(
|
||||||
(
|
(
|
||||||
localize: LocalizeFunc,
|
localize: LocalizeFunc,
|
||||||
@ -233,31 +245,33 @@ export default class HaNumericStateCondition extends LitElement {
|
|||||||
] as const
|
] as const
|
||||||
);
|
);
|
||||||
|
|
||||||
public render() {
|
public willUpdate() {
|
||||||
const inputAboveIsEntity =
|
this._inputAboveIsEntity =
|
||||||
this._inputAboveIsEntity ??
|
this._inputAboveIsEntity ??
|
||||||
(typeof this.condition.above === "string" &&
|
(typeof this.condition.above === "string" &&
|
||||||
((this.condition.above as string).startsWith("input_number.") ||
|
((this.condition.above as string).startsWith("input_number.") ||
|
||||||
(this.condition.above as string).startsWith("number.") ||
|
(this.condition.above as string).startsWith("number.") ||
|
||||||
(this.condition.above as string).startsWith("sensor.")));
|
(this.condition.above as string).startsWith("sensor.")));
|
||||||
const inputBelowIsEntity =
|
this._inputBelowIsEntity =
|
||||||
this._inputBelowIsEntity ??
|
this._inputBelowIsEntity ??
|
||||||
(typeof this.condition.below === "string" &&
|
(typeof this.condition.below === "string" &&
|
||||||
((this.condition.below as string).startsWith("input_number.") ||
|
((this.condition.below as string).startsWith("input_number.") ||
|
||||||
(this.condition.below as string).startsWith("number.") ||
|
(this.condition.below as string).startsWith("number.") ||
|
||||||
(this.condition.below as string).startsWith("sensor.")));
|
(this.condition.below as string).startsWith("sensor.")));
|
||||||
|
}
|
||||||
|
|
||||||
|
public render() {
|
||||||
const schema = this._schema(
|
const schema = this._schema(
|
||||||
this.hass.localize,
|
this.hass.localize,
|
||||||
inputAboveIsEntity,
|
this._inputAboveIsEntity,
|
||||||
inputBelowIsEntity
|
this._inputBelowIsEntity
|
||||||
);
|
);
|
||||||
|
|
||||||
const data = {
|
const data = this._data(
|
||||||
mode_above: inputAboveIsEntity ? "input" : "value",
|
this._inputAboveIsEntity!,
|
||||||
mode_below: inputBelowIsEntity ? "input" : "value",
|
this._inputBelowIsEntity!,
|
||||||
...this.condition,
|
this.condition
|
||||||
};
|
);
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<ha-form
|
<ha-form
|
||||||
|
@ -224,6 +224,19 @@ export class HaNumericStateTrigger extends LitElement {
|
|||||||
);
|
);
|
||||||
|
|
||||||
public willUpdate(changedProperties: PropertyValues) {
|
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")) {
|
if (!changedProperties.has("trigger")) {
|
||||||
return;
|
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() {
|
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(
|
const schema = this._schema(
|
||||||
this.hass.localize,
|
this.hass.localize,
|
||||||
this.trigger.entity_id,
|
this.trigger.entity_id,
|
||||||
inputAboveIsEntity,
|
this._inputAboveIsEntity,
|
||||||
inputBelowIsEntity
|
this._inputBelowIsEntity
|
||||||
);
|
);
|
||||||
|
|
||||||
const data = {
|
const data = this._data(
|
||||||
mode_above: inputAboveIsEntity ? "input" : "value",
|
this._inputAboveIsEntity!,
|
||||||
mode_below: inputBelowIsEntity ? "input" : "value",
|
this._inputBelowIsEntity!,
|
||||||
...this.trigger,
|
this.trigger
|
||||||
entity_id: ensureArray(this.trigger.entity_id),
|
);
|
||||||
for: trgFor,
|
|
||||||
};
|
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<ha-form
|
<ha-form
|
||||||
@ -289,7 +299,7 @@ export class HaNumericStateTrigger extends LitElement {
|
|||||||
|
|
||||||
private _valueChanged(ev: CustomEvent): void {
|
private _valueChanged(ev: CustomEvent): void {
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
const newTrigger = ev.detail.value;
|
const newTrigger = { ...ev.detail.value };
|
||||||
|
|
||||||
this._inputAboveIsEntity = newTrigger.mode_above === "input";
|
this._inputAboveIsEntity = newTrigger.mode_above === "input";
|
||||||
this._inputBelowIsEntity = newTrigger.mode_below === "input";
|
this._inputBelowIsEntity = newTrigger.mode_below === "input";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user