@@ -39,11 +39,16 @@ class DeclutteringCard extends LitElement {
3939 throw new Error ( "The object decluttering_templates doesn't exist in your main lovelace config." ) ;
4040 }
4141 const templateConfig = ll . config . decluttering_templates [ config . template ] as TemplateConfig ;
42- if ( ! templateConfig || ! templateConfig . card ) {
42+ if ( ! templateConfig ) {
4343 throw new Error ( `The template "${ config . template } " doesn't exist in decluttering_templates` ) ;
44+ } else if ( ! ( templateConfig . card || templateConfig . element ) ) {
45+ throw new Error ( 'You shoud define either a card or an element in the template' ) ;
46+ } else if ( templateConfig . card && templateConfig . element ) {
47+ throw new Error ( 'You can define a card and an element in the template' ) ;
4448 }
4549 this . _config = deepReplace ( config . variables , templateConfig ) ;
46- this . _createCard ( this . _config ) . then ( card => {
50+ const type = templateConfig . card ? 'card' : 'element' ;
51+ this . _createCard ( this . _config , type ) . then ( card => {
4752 this . _card = card ;
4853 return this . _card ;
4954 } ) ;
@@ -57,12 +62,21 @@ class DeclutteringCard extends LitElement {
5762 ` ;
5863 }
5964
60- private async _createCard ( config : LovelaceCardConfig ) : Promise < LovelaceCard > {
65+ private async _createCard ( config : LovelaceCardConfig , type : 'element' | 'card' ) : Promise < LovelaceCard > {
6166 let element : LovelaceCard ;
6267 if ( HELPERS ) {
63- if ( config . type === 'divider' ) element = ( await HELPERS ) . createRowElement ( config ) ;
64- else element = ( await HELPERS ) . createCardElement ( config ) ;
65- // fireEvent(element, 'll-rebuild');
68+ if ( type === 'card' ) {
69+ if ( config . type === 'divider' ) element = ( await HELPERS ) . createRowElement ( config ) ;
70+ else element = ( await HELPERS ) . createCardElement ( config ) ;
71+ // fireEvent(element, 'll-rebuild');
72+ } else {
73+ element = ( await HELPERS ) . createHuiElement ( config ) ;
74+ if ( config . style ) {
75+ Object . keys ( config . style ) . forEach ( prop => {
76+ this . style . setProperty ( prop , config . style [ prop ] ) ;
77+ } ) ;
78+ }
79+ }
6680 } else {
6781 element = createThing ( config ) ;
6882 }
@@ -73,15 +87,19 @@ class DeclutteringCard extends LitElement {
7387 'll-rebuild' ,
7488 ev => {
7589 ev . stopPropagation ( ) ;
76- this . _rebuildCard ( element , config ) ;
90+ this . _rebuildCard ( element , config , type ) ;
7791 } ,
7892 { once : true } ,
7993 ) ;
8094 return element ;
8195 }
8296
83- private async _rebuildCard ( element : LovelaceCard , config : LovelaceCardConfig ) : Promise < void > {
84- const newCard = await this . _createCard ( config ) ;
97+ private async _rebuildCard (
98+ element : LovelaceCard ,
99+ config : LovelaceCardConfig ,
100+ type : 'element' | 'card' ,
101+ ) : Promise < void > {
102+ const newCard = await this . _createCard ( config , type ) ;
85103 element . replaceWith ( newCard ) ;
86104 return ;
87105 }
0 commit comments