Skip to content

Commit 21235d9

Browse files
committed
auto-create helper entities
1 parent 9fd5c93 commit 21235d9

2 files changed

Lines changed: 37 additions & 7 deletions

File tree

src/controller.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,34 @@ class DefaultDashboardController {
1414
});
1515
};
1616

17+
createInputBoolean = async (): Promise<any> => {
18+
const res = await this.hass.callWS({
19+
type: 'input_boolean/create',
20+
name: 'Default Dashboard',
21+
initial: true,
22+
});
23+
console.log(res);
24+
return res;
25+
};
26+
27+
createInputSelect = async (): Promise<any> => {
28+
const dashboards = await this.getDashboards().then((boards) => {
29+
return boards
30+
.filter((d) => !d.require_admin)
31+
.flatMap((d) => {
32+
return d.url_path;
33+
});
34+
});
35+
const res = await this.hass.callWS({
36+
type: 'input_select/create',
37+
name: 'Default Dashboard',
38+
options: ['lovelace', ...dashboards, 'refresh'],
39+
initial: 'lovelace',
40+
});
41+
console.log(res);
42+
return res;
43+
};
44+
1745
getStorageSettings = async (): Promise<{ defaultPanel: string | null; isDefaultPanelManaged: string | null }> => {
1846
const defaultPanel: string | null = localStorage.getItem(LOCAL_STORAGE_OPTIONS.defaultPanel);
1947
const isDefaultPanelManaged: string | null = localStorage.getItem(LOCAL_STORAGE_OPTIONS.isDefaultPanelManaged);

src/default-dashboard.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,18 @@ const enableIfNull = async () => {
7474
// Gets the helper entities needed for Default Dashboard, and throws log messages if they are missing
7575
const getUrlAndToggle = (hass: HomeAssistant) => {
7676
const url = hass.states[DEFAULT_DASHBOARD_DROPDOWN]?.state;
77-
const enabled = hass.states[DEFAULT_DASHBOARD_TOGGLE]?.state === 'on';
78-
if (url === null || enabled === null) {
79-
if (url === null) {
80-
log(`Please create a Dropdown helper with the id \`${DEFAULT_DASHBOARD_DROPDOWN}\``);
77+
const enabled = hass.states[DEFAULT_DASHBOARD_TOGGLE]?.state;
78+
if (url === undefined || enabled === undefined) {
79+
if (url === undefined) {
80+
controller.createInputSelect();
81+
log(`Created a Dropdown helper with the id \`${DEFAULT_DASHBOARD_DROPDOWN}\``);
8182
}
82-
if (enabled === null) {
83-
log(`Please create a Toggle helper with the id \`${DEFAULT_DASHBOARD_TOGGLE}\``);
83+
if (enabled === undefined) {
84+
controller.createInputBoolean();
85+
log(`Created a Toggle helper with the id \`${DEFAULT_DASHBOARD_TOGGLE}\``);
8486
}
8587
}
86-
return { url, enabled };
88+
return { url, enabled: enabled === 'on' };
8789
};
8890

8991
// Try to enable Default Dashboard, if that is current setting

0 commit comments

Comments
 (0)