Skip to content

Commit

Permalink
Device trigger - sync value with initialHaFormData (#20810)
Browse files Browse the repository at this point in the history
Device trigger - sync yaml with initialHaFormData
  • Loading branch information
karwosts authored May 24, 2024
1 parent 80c7fd2 commit d52641b
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { css, html, LitElement } from "lit";
import { customElement, property, state } from "lit/decorators";
import memoizeOne from "memoize-one";
import { fireEvent } from "../../../../../common/dom/fire_event";
import { deepEqual } from "../../../../../common/util/deep-equal";
import "../../../../../components/device/ha-device-picker";
import "../../../../../components/device/ha-device-trigger-picker";
import "../../../../../components/ha-form/ha-form";
Expand Down Expand Up @@ -125,6 +126,20 @@ export class HaDeviceTrigger extends LitElement {
this._capabilities = trigger.domain
? await fetchDeviceTriggerCapabilities(this.hass, trigger)
: undefined;

if (this._capabilities) {
// Match yaml to what is displayed in the form from computeInitialHaFormData
const newTrigger = {
...this.trigger,
...this._extraFieldsData(this.trigger, this._capabilities),
};

if (!deepEqual(this.trigger, newTrigger)) {
fireEvent(this, "value-changed", {
value: newTrigger,
});
}
}
}

private _devicePicked(ev) {
Expand Down

0 comments on commit d52641b

Please sign in to comment.