mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Z-WaveJS: stop inclusion subscription while dialog is open (#24294)
* Z-WaveJS: stop inclusion subscription while dialog is open and handling it * Don't pass dsk to core * PR comments
This commit is contained in:
parent
d47e5c847b
commit
4fa915c869
@ -116,10 +116,8 @@ class DialogZWaveJSAddNode extends LitElement {
|
|||||||
if (params.dsk) {
|
if (params.dsk) {
|
||||||
this._status = "validate_dsk_enter_pin";
|
this._status = "validate_dsk_enter_pin";
|
||||||
this._dsk = params.dsk;
|
this._dsk = params.dsk;
|
||||||
this._startInclusion(undefined, params.dsk);
|
|
||||||
} else {
|
|
||||||
this._startInclusion();
|
|
||||||
}
|
}
|
||||||
|
this._startInclusion();
|
||||||
}
|
}
|
||||||
|
|
||||||
@query("#pin-input") private _pinInput?: HaTextField;
|
@query("#pin-input") private _pinInput?: HaTextField;
|
||||||
|
@ -78,6 +78,8 @@ class ZWaveJSConfigDashboard extends SubscribeMixin(LitElement) {
|
|||||||
|
|
||||||
private _dialogOpen = false;
|
private _dialogOpen = false;
|
||||||
|
|
||||||
|
private _s2InclusionUnsubscribe?: Promise<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.then((unsubscribe) => unsubscribe());
|
||||||
|
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 _subscribeS2Inclusion() {
|
||||||
|
this._s2InclusionUnsubscribe = 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