Delay showing connection message (#17595)

This commit is contained in:
Bram Kragten 2023-08-16 14:56:44 +02:00 committed by GitHub
parent 12b61aea2f
commit 613cf932b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -17,6 +17,8 @@ export default <T extends Constructor<HassBaseEl>>(superClass: T) =>
class extends superClass { class extends superClass {
private _subscribedBootstrapIntegrations?: Promise<UnsubscribeFunc>; private _subscribedBootstrapIntegrations?: Promise<UnsubscribeFunc>;
private _disconnectedTimeout?: number;
protected firstUpdated(changedProps) { protected firstUpdated(changedProps) {
super.firstUpdated(changedProps); super.firstUpdated(changedProps);
// Need to load in advance because when disconnected, can't dynamically load code. // Need to load in advance because when disconnected, can't dynamically load code.
@ -65,6 +67,11 @@ export default <T extends Constructor<HassBaseEl>>(superClass: T) =>
protected hassReconnected() { protected hassReconnected() {
super.hassReconnected(); super.hassReconnected();
if (this._disconnectedTimeout) {
clearTimeout(this._disconnectedTimeout);
this._disconnectedTimeout = undefined;
return;
}
showToast(this, { showToast(this, {
message: "", message: "",
duration: 1, duration: 1,
@ -74,11 +81,14 @@ export default <T extends Constructor<HassBaseEl>>(superClass: T) =>
protected hassDisconnected() { protected hassDisconnected() {
super.hassDisconnected(); super.hassDisconnected();
showToast(this, { this._disconnectedTimeout = window.setTimeout(() => {
message: this.hass!.localize("ui.notification_toast.connection_lost"), this._disconnectedTimeout = undefined;
duration: 0, showToast(this, {
dismissable: false, message: this.hass!.localize("ui.notification_toast.connection_lost"),
}); duration: 0,
dismissable: false,
});
}, 1000);
} }
private _handleMessage(message: BootstrapIntegrationsTimings): void { private _handleMessage(message: BootstrapIntegrationsTimings): void {