diff --git a/src/panels/profile/ha-profile-section-general.ts b/src/panels/profile/ha-profile-section-general.ts
index e75b4bdaa3..3f48b4dcea 100644
--- a/src/panels/profile/ha-profile-section-general.ts
+++ b/src/panels/profile/ha-profile-section-general.ts
@@ -12,12 +12,11 @@ import "../../components/ha-svg-icon";
import "../../layouts/hass-tabs-subpage";
import { profileSections } from "./ha-panel-profile";
import { isExternal } from "../../data/external";
-import { SELECTED_THEME_KEY } from "../../data/ws-themes";
import type { CoreFrontendUserData } from "../../data/frontend";
import { getOptimisticFrontendUserDataCollection } from "../../data/frontend";
import { showConfirmationDialog } from "../../dialogs/generic/show-dialog-box";
import { haStyle } from "../../resources/styles";
-import type { HomeAssistant, Route, ThemeSettings } from "../../types";
+import type { HomeAssistant, Route } from "../../types";
import "./ha-advanced-mode-row";
import "./ha-enable-shortcuts-row";
import "./ha-force-narrow-row";
@@ -32,7 +31,6 @@ import "./ha-pick-time-zone-row";
import "./ha-push-notifications-row";
import "./ha-set-suspend-row";
import "./ha-set-vibrate-row";
-import { storage } from "../../common/decorators/storage";
import type { HaSwitch } from "../../components/ha-switch";
@customElement("ha-profile-section-general")
@@ -45,13 +43,6 @@ class HaProfileSectionGeneral extends LitElement {
@property({ attribute: false }) public route!: Route;
- @storage({
- key: SELECTED_THEME_KEY,
- state: true,
- subscribe: true,
- })
- private _browserThemeSettings?: ThemeSettings;
-
@state() private _browserThemeActivated = false;
private _unsubCoreData?: UnsubscribeFunc;
@@ -144,7 +135,7 @@ class HaProfileSectionGeneral extends LitElement {
.narrow=${this.narrow}
.hass=${this.hass}
>
- ${this._browserThemeSettings || this._browserThemeActivated
+ ${this.hass.browserThemeEnabled || this._browserThemeActivated
? html`
@@ -198,12 +189,12 @@ class HaProfileSectionGeneral extends LitElement {
)}
- ${this._browserThemeSettings || this._browserThemeActivated
+ ${this.hass.browserThemeEnabled || this._browserThemeActivated
? html`
>(superClass: T) =>
};
this._updateHass({
selectedTheme,
+ browserThemeEnabled: ev.detail.storageLocation === "browser",
});
this._applyTheme(mql.matches);
@@ -67,6 +68,7 @@ export default >(superClass: T) =>
const selectedTheme = await fetchSelectedTheme(this.hass!);
this._updateHass({
selectedTheme,
+ browserThemeEnabled: false,
});
this._applyTheme(mql.matches);
});
@@ -108,7 +110,10 @@ export default >(superClass: T) =>
selectedTheme
) {
this._themeApplied = true;
- this._updateHass({ selectedTheme });
+ this._updateHass({
+ selectedTheme,
+ browserThemeEnabled: false,
+ });
this._applyTheme(mql.matches);
}
}
diff --git a/src/types.ts b/src/types.ts
index 02d50a82ab..64babb27b8 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -223,6 +223,7 @@ export interface HomeAssistant {
config: HassConfig;
themes: Themes;
selectedTheme: ThemeSettings | null;
+ browserThemeEnabled?: boolean;
panels: Panels;
panelUrl: string;
// i18n
diff --git a/src/util/ha-pref-storage.ts b/src/util/ha-pref-storage.ts
index 73be8f54e4..a3edbf4166 100644
--- a/src/util/ha-pref-storage.ts
+++ b/src/util/ha-pref-storage.ts
@@ -1,8 +1,9 @@
+import { SELECTED_THEME_KEY } from "../data/ws-themes";
import type { HomeAssistant } from "../types";
const STORED_STATE = [
"dockedSidebar",
- "selectedTheme",
+ SELECTED_THEME_KEY,
"selectedLanguage",
"vibrate",
"debugConnection",
@@ -11,11 +12,17 @@ const STORED_STATE = [
"defaultPanel",
];
-const CLEARABLE_STATE = ["selectedTheme"];
+const CLEARABLE_STATE = [SELECTED_THEME_KEY];
export function storeState(hass: HomeAssistant) {
try {
- STORED_STATE.forEach((key) => {
+ const states = [...STORED_STATE];
+
+ if (!hass.browserThemeEnabled) {
+ states.splice(states.indexOf(SELECTED_THEME_KEY), 1);
+ }
+
+ states.forEach((key) => {
const value = hass[key];
window.localStorage.setItem(
key,
@@ -34,15 +41,18 @@ export function storeState(hass: HomeAssistant) {
}
export function getState() {
- const state = {};
+ const state: Partial = {};
STORED_STATE.forEach((key) => {
const storageItem = window.localStorage.getItem(key);
if (storageItem !== null) {
let value = JSON.parse(storageItem);
// selectedTheme went from string to object on 20200718
- if (key === "selectedTheme" && typeof value === "string") {
- value = { theme: value };
+ if (key === SELECTED_THEME_KEY) {
+ if (typeof value === "string") {
+ value = { theme: value };
+ }
+ state.browserThemeEnabled = true;
}
// dockedSidebar went from boolean to enum on 20190720
if (key === "dockedSidebar" && typeof value === "boolean") {