1
- const _customElementsDefine = window . customElements . define ;
2
- window . customElements . define = ( name , cl , conf ) => {
3
- if ( ! customElements . get ( name ) ) {
4
- _customElementsDefine . call ( window . customElements , name , cl , conf ) ;
5
- } else {
6
- console . warn ( `${ name } has been defined twice` ) ;
7
- }
8
- } ;
9
-
10
- if ( ! customElements . get ( "paper-input" ) ) {
11
- console . log ( "imported" , "paper-input" ) ;
12
- import ( "https://unpkg.com/@polymer/paper-input/paper-input.js?module" ) ;
13
- }
14
- if ( ! customElements . get ( "paper-toggle-button" ) ) {
15
- console . log ( "imported" , "paper-toggle-button" ) ;
16
- import (
17
- "https://unpkg.com/@polymer/paper-toggle-button/paper-toggle-button.js?module"
18
- ) ;
19
- }
20
- if ( ! customElements . get ( "paper-dropdown-menu" ) ) {
21
- console . log ( "imported" , "paper-dropdown-menu" ) ;
22
- import (
23
- "https://unpkg.com/@polymer/paper-dropdown-menu/paper-dropdown-menu.js?module"
24
- ) ;
25
- }
26
- if ( ! customElements . get ( "paper-listbox" ) ) {
27
- console . log ( "imported" , "paper-listbox" ) ;
28
- import ( "https://unpkg.com/@polymer/paper-listbox/paper-listbox.js?module" ) ;
29
- }
30
- if ( ! customElements . get ( "paper-item" ) ) {
31
- console . log ( "imported" , "paper-item" ) ;
32
- import ( "https://unpkg.com/@polymer/paper-item/paper-item.js?module" ) ;
33
- }
34
-
35
1
const fireEvent = ( node , type , detail , options ) => {
36
2
options = options || { } ;
37
3
detail = detail === null || detail === undefined ? { } : detail ;
38
4
const event = new Event ( type , {
39
5
bubbles : options . bubbles === undefined ? true : options . bubbles ,
40
6
cancelable : Boolean ( options . cancelable ) ,
41
- composed : options . composed === undefined ? true : options . composed
7
+ composed : options . composed === undefined ? true : options . composed ,
42
8
} ) ;
43
9
event . detail = detail ;
44
10
node . dispatchEvent ( event ) ;
@@ -87,7 +53,7 @@ export class WeatherCardEditor extends LitElement {
87
53
}
88
54
89
55
const entities = Object . keys ( this . hass . states ) . filter (
90
- eid => eid . substr ( 0 , eid . indexOf ( "." ) ) === "weather"
56
+ ( eid ) => eid . substr ( 0 , eid . indexOf ( "." ) ) === "weather"
91
57
) ;
92
58
93
59
return html `
@@ -127,32 +93,55 @@ export class WeatherCardEditor extends LitElement {
127
93
slot ="dropdown-content "
128
94
.selected ="${ entities . indexOf ( this . _entity ) } "
129
95
>
130
- ${ entities . map ( entity => {
96
+ ${ entities . map ( ( entity ) => {
131
97
return html `
132
98
< paper-item > ${ entity } </ paper-item >
133
99
` ;
134
100
} ) }
135
101
</ paper-listbox >
136
102
</ paper-dropdown-menu >
137
103
` }
138
- < paper-toggle-button
139
- .checked =${ this . _current }
140
- .configValue ="${ "current" } "
141
- @change="${ this . _valueChanged } "
142
- > Show current</ paper-toggle-button
143
- >
144
- < paper-toggle-button
145
- .checked =${ this . _details }
146
- .configValue ="${ "details" } "
147
- @change="${ this . _valueChanged } "
148
- > Show details</ paper-toggle-button
149
- >
150
- < paper-toggle-button
151
- .checked =${ this . _forecast }
152
- .configValue ="${ "forecast" } "
153
- @change="${ this . _valueChanged } "
154
- > Show forecast</ paper-toggle-button
155
- >
104
+ ${ customElements . get ( "paper-toggle-button" )
105
+ ? html `
106
+ < paper-toggle-button
107
+ .checked =${ this . _current }
108
+ .configValue ="${ "current" } "
109
+ @change="${ this . _valueChanged } "
110
+ > Show current</ paper-toggle-button
111
+ >
112
+ < paper-toggle-button
113
+ .checked =${ this . _details }
114
+ .configValue ="${ "details" } "
115
+ @change="${ this . _valueChanged } "
116
+ > Show details</ paper-toggle-button
117
+ >
118
+ < paper-toggle-button
119
+ .checked =${ this . _forecast }
120
+ .configValue ="${ "forecast" } "
121
+ @change="${ this . _valueChanged } "
122
+ > Show forecast</ paper-toggle-button
123
+ >
124
+ `
125
+ : html `
126
+ < ha-switch
127
+ .checked =${ this . _current }
128
+ .configValue ="${ "current" } "
129
+ @change="${ this . _valueChanged } "
130
+ > Show current</ ha-switch
131
+ >
132
+ < ha-switch
133
+ .checked =${ this . _details }
134
+ .configValue ="${ "details" } "
135
+ @change="${ this . _valueChanged } "
136
+ > Show details</ ha-switch
137
+ >
138
+ < ha-switch
139
+ .checked =${ this . _forecast }
140
+ .configValue ="${ "forecast" } "
141
+ @change="${ this . _valueChanged } "
142
+ > Show forecast</ ha-switch
143
+ >
144
+ ` }
156
145
</ div >
157
146
</ div >
158
147
` ;
@@ -173,7 +162,7 @@ export class WeatherCardEditor extends LitElement {
173
162
this . _config = {
174
163
...this . _config ,
175
164
[ target . configValue ] :
176
- target . checked !== undefined ? target . checked : target . value
165
+ target . checked !== undefined ? target . checked : target . value ,
177
166
} ;
178
167
}
179
168
}
0 commit comments