File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ) ;
Original file line number Diff line number Diff 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
7575const 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
You can’t perform that action at this time.
0 commit comments