mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-28 19:56:42 +00:00
Z-WaveJS: stop inclusion subscription while dialog is open and handling it
This commit is contained in:
parent
3ee3cfa6cb
commit
07c2aaa808
@ -78,6 +78,8 @@ class ZWaveJSConfigDashboard extends SubscribeMixin(LitElement) {
|
|||||||
|
|
||||||
private _dialogOpen = false;
|
private _dialogOpen = false;
|
||||||
|
|
||||||
|
private _s2InclusionUnsubscribe?: UnsubscribeFunc;
|
||||||
|
|
||||||
protected async firstUpdated() {
|
protected async firstUpdated() {
|
||||||
if (this.hass) {
|
if (this.hass) {
|
||||||
await this._fetchData();
|
await this._fetchData();
|
||||||
@ -105,19 +107,7 @@ class ZWaveJSConfigDashboard extends SubscribeMixin(LitElement) {
|
|||||||
this._statistics = message;
|
this._statistics = message;
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
subscribeS2Inclusion(this.hass, this.configEntryId, (message) => {
|
this._subscribeS2Inclusion(),
|
||||||
if (!this._dialogOpen) {
|
|
||||||
showZWaveJSAddNodeDialog(this, {
|
|
||||||
entry_id: this.configEntryId,
|
|
||||||
dsk: message.dsk,
|
|
||||||
onStop: () => {
|
|
||||||
setTimeout(() => this._fetchData(), 100);
|
|
||||||
this._dialogOpen = false;
|
|
||||||
},
|
|
||||||
});
|
|
||||||
this._dialogOpen = true;
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -578,17 +568,7 @@ class ZWaveJSConfigDashboard extends SubscribeMixin(LitElement) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async _addNodeClicked() {
|
private async _addNodeClicked() {
|
||||||
if (!this._dialogOpen) {
|
this._openInclusionDialog();
|
||||||
showZWaveJSAddNodeDialog(this, {
|
|
||||||
entry_id: this.configEntryId!,
|
|
||||||
// refresh the data after the dialog is closed. add a small delay for the inclusion state to update
|
|
||||||
onStop: () => {
|
|
||||||
setTimeout(() => this._fetchData(), 100);
|
|
||||||
this._dialogOpen = false;
|
|
||||||
},
|
|
||||||
});
|
|
||||||
this._dialogOpen = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _removeNodeClicked() {
|
private async _removeNodeClicked() {
|
||||||
@ -627,6 +607,41 @@ class ZWaveJSConfigDashboard extends SubscribeMixin(LitElement) {
|
|||||||
showOptionsFlowDialog(this, configEntry!);
|
showOptionsFlowDialog(this, configEntry!);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _openInclusionDialog(dsk?: string) {
|
||||||
|
if (!this._dialogOpen) {
|
||||||
|
// Unsubscribe from S2 inclusion before opening dialog
|
||||||
|
if (this._s2InclusionUnsubscribe) {
|
||||||
|
this._s2InclusionUnsubscribe();
|
||||||
|
this._s2InclusionUnsubscribe = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
showZWaveJSAddNodeDialog(this, {
|
||||||
|
entry_id: this.configEntryId!,
|
||||||
|
dsk,
|
||||||
|
onStop: this._handleInclusionDialogClosed,
|
||||||
|
});
|
||||||
|
this._dialogOpen = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private _handleInclusionDialogClosed = () => {
|
||||||
|
// refresh the data after the dialog is closed. add a small delay for the inclusion state to update
|
||||||
|
setTimeout(() => this._fetchData(), 100);
|
||||||
|
this._dialogOpen = false;
|
||||||
|
this._subscribeS2Inclusion();
|
||||||
|
};
|
||||||
|
|
||||||
|
private async _subscribeS2Inclusion() {
|
||||||
|
this._s2InclusionUnsubscribe = await subscribeS2Inclusion(
|
||||||
|
this.hass,
|
||||||
|
this.configEntryId,
|
||||||
|
(message) => {
|
||||||
|
this._openInclusionDialog(message.dsk);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
return this._s2InclusionUnsubscribe;
|
||||||
|
}
|
||||||
|
|
||||||
static get styles(): CSSResultGroup {
|
static get styles(): CSSResultGroup {
|
||||||
return [
|
return [
|
||||||
haStyle,
|
haStyle,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user