Fix removing/moving device actions (#6441)

Fixes https://github.com/home-assistant/frontend/issues/6438
This commit is contained in:
Bram Kragten 2020-07-21 18:05:21 +02:00 committed by GitHub
parent 16473c9177
commit e08c10315e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 11 deletions

View File

@ -117,11 +117,7 @@ export abstract class HaDeviceAutomationPicker<
> >
${this.NO_AUTOMATION_TEXT} ${this.NO_AUTOMATION_TEXT}
</paper-item> </paper-item>
<paper-item <paper-item key=${UNKNOWN_AUTOMATION_KEY} hidden>
key=${UNKNOWN_AUTOMATION_KEY}
.automation=${this.value}
hidden
>
${this.UNKNOWN_AUTOMATION_TEXT} ${this.UNKNOWN_AUTOMATION_TEXT}
</paper-item> </paper-item>
${this._automations.map( ${this._automations.map(
@ -175,18 +171,17 @@ export abstract class HaDeviceAutomationPicker<
} }
private _automationChanged(ev) { private _automationChanged(ev) {
this._setValue(ev.detail.item.automation); if (ev.detail.item.automation) {
this._setValue(ev.detail.item.automation);
}
} }
private _setValue(automation: T) { private _setValue(automation: T) {
if (this.value && deviceAutomationsEqual(automation, this.value)) { if (this.value && deviceAutomationsEqual(automation, this.value)) {
return; return;
} }
this.value = automation; fireEvent(this, "change");
setTimeout(() => { fireEvent(this, "value-changed", { value: automation });
fireEvent(this, "change");
fireEvent(this, "value-changed", { value: automation });
}, 0);
} }
static get styles(): CSSResult { static get styles(): CSSResult {

View File

@ -97,6 +97,7 @@ export class HaDeviceAction extends LitElement {
protected updated(changedPros) { protected updated(changedPros) {
const prevAction = changedPros.get("action"); const prevAction = changedPros.get("action");
if (prevAction && !deviceAutomationsEqual(prevAction, this.action)) { if (prevAction && !deviceAutomationsEqual(prevAction, this.action)) {
this._deviceId = undefined;
this._getCapabilities(); this._getCapabilities();
} }
} }