Handle cast connect different instance better (#19526)

This commit is contained in:
Bram Kragten 2024-01-25 13:00:55 +01:00 committed by GitHub
parent b224ec50e4
commit 59a3a35b19
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 3 deletions

View File

@ -205,7 +205,6 @@ export class HcMain extends HassElement {
expires_in: 0, expires_in: 0,
}), }),
}); });
this._hassUUID = msg.hassUUID;
} catch (err: any) { } catch (err: any) {
const errorMessage = this._getErrorMessage(err); const errorMessage = this._getErrorMessage(err);
this._error = errorMessage; this._error = errorMessage;
@ -225,6 +224,17 @@ export class HcMain extends HassElement {
this.hass.connection.close(); this.hass.connection.close();
} }
this.initializeHass(auth, connection); this.initializeHass(auth, connection);
if (this._hassUUID !== msg.hassUUID) {
this._hassUUID = msg.hassUUID;
this._lovelacePath = null;
this._urlPath = undefined;
this._lovelaceConfig = undefined;
if (this._unsubLovelace) {
this._unsubLovelace();
this._unsubLovelace = undefined;
}
resourcesLoaded = false;
}
this._error = undefined; this._error = undefined;
this._sendStatus(); this._sendStatus();
} }
@ -233,7 +243,7 @@ export class HcMain extends HassElement {
this._showDemo = false; this._showDemo = false;
// We should not get this command before we are connected. // We should not get this command before we are connected.
// Means a client got out of sync. Let's send status to them. // Means a client got out of sync. Let's send status to them.
if (!this.hass) { if (!this.hass?.connected) {
this._sendStatus(msg.senderId!); this._sendStatus(msg.senderId!);
this._error = "Cannot show Lovelace because we're not connected."; this._error = "Cannot show Lovelace because we're not connected.";
this._sendError( this._sendError(
@ -284,6 +294,7 @@ export class HcMain extends HassElement {
this._lovelaceConfig = undefined; this._lovelaceConfig = undefined;
if (this._unsubLovelace) { if (this._unsubLovelace) {
this._unsubLovelace(); this._unsubLovelace();
this._unsubLovelace = undefined;
} }
const llColl = atLeastVersion(this.hass.connection.haVersion, 0, 107) const llColl = atLeastVersion(this.hass.connection.haVersion, 0, 107)
? getLovelaceCollection(this.hass.connection, msg.urlPath) ? getLovelaceCollection(this.hass.connection, msg.urlPath)

View File

@ -41,7 +41,9 @@ export const applyThemesOnElement = (
// If there is no explicitly desired dark mode provided, we automatically // If there is no explicitly desired dark mode provided, we automatically
// use the active one from `themes`. // use the active one from `themes`.
const darkMode = const darkMode =
themeSettings?.dark !== undefined ? themeSettings.dark : themes.darkMode; themeSettings?.dark !== undefined
? themeSettings.dark
: themes?.darkMode || false;
let cacheKey = themeToApply; let cacheKey = themeToApply;
let themeRules: Partial<ThemeVars> = {}; let themeRules: Partial<ThemeVars> = {};