Skip to content

Commit

Permalink
attempt to use phone storage
Browse files Browse the repository at this point in the history
  • Loading branch information
daredoes committed Nov 17, 2022
1 parent 16096fe commit 4c9a265
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "default-dashboard",
"version": "1.0.4",
"version": "1.0.5",
"description": "Sets the default dashboard for lovelace automatically",
"keywords": [
"home-assistant",
Expand Down
21 changes: 20 additions & 1 deletion src/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ Object.keys(LOCAL_STORAGE_OPTIONS).forEach((key) => {
LOCAL_STORAGE_OPTIONS[key] = key;
});

export const fireEvent = (defaultPanel: string) => {
const detail = { defaultPanel };
const event = new Event('hass-default-panel', {
bubbles: true,
cancelable: false,
composed: true,
});
(event as any).detail = detail;
// window.dispatchEvent(event);
return event;
};

class DefaultDashboardController {
hass!: HomeAssistant;
constructor(hass: HomeAssistant) {
Expand All @@ -35,7 +47,14 @@ class DefaultDashboardController {
};

setDefaultPanel = async (defaultPanel: string) => {
(this.hass as any).defaultPanel = defaultPanel;
// this.hass['defaultPanel'] = defaultPanel;
window.dispatchEvent(
new StorageEvent('storage', {
key: 'defaultPanel',
newValue: defaultPanel,
}),
);
// console.log(this.hass['defaultPanel']);
localStorage.setItem(LOCAL_STORAGE_OPTIONS.defaultPanel, defaultPanel);
localStorage.setItem(LOCAL_STORAGE_OPTIONS.isDefaultPanelManaged, 'true');
};
Expand Down
1 change: 1 addition & 0 deletions src/default-dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ let controller: Controller;
}
const managedPanel = `"${my_lovelace_url as string}"`;
const settings = await controller.getStorageSettings();
console.log(settings);
const disabled = settings.isDefaultPanelManaged === 'false';
if (!disabled) {
if (settings.defaultManagedPanel !== managedPanel) {
Expand Down

0 comments on commit 4c9a265

Please sign in to comment.