@@ -17,10 +17,10 @@ import "./knx-sync-state-selector-row";
17
17
import { renderConfigureEntityCard } from "./knx-configure-entity-options" ;
18
18
import { KNXLogger } from "../tools/knx-logger" ;
19
19
import { extractValidationErrors } from "../utils/validation" ;
20
- import type { EntityData , ErrorDescription } from "../types/entity_data" ;
20
+ import type { EntityData , ErrorDescription , KnxEntityData } from "../types/entity_data" ;
21
21
import type { KNX } from "../types/knx" ;
22
22
import type { PlatformInfo } from "../utils/common" ;
23
- import type { SettingsGroup , SelectorSchema , GroupSelect } from "../utils/schema" ;
23
+ import type { SettingsGroup , SelectorSchema , GroupSelect , GASchema } from "../utils/schema" ;
24
24
25
25
const logger = new KNXLogger ( "knx-configure-entity" ) ;
26
26
@@ -91,13 +91,53 @@ export class KNXConfigureEntity extends LitElement {
91
91
}
92
92
93
93
_generateSettingsGroup ( group : SettingsGroup , errors ?: ErrorDescription [ ] ) {
94
+ if ( group . collapsible === true ) {
95
+ return html ` <ha- expansion- panel
96
+ outlined
97
+ .header = ${ group . heading }
98
+ .secondary = ${ group . description }
99
+ .expanded = ${ this . _groupHasGroupAddressInConfig ( group ) }
100
+ > ${ this . _generateItems ( group . selectors , errors ) }
101
+ </ ha- expansion- panel> ` ;
102
+ }
94
103
return html ` <ha- settings- row narrow>
95
104
<div slot= "heading" > ${ group . heading } </ div>
96
105
<div slot= "description" > ${ group . description } </ div>
97
106
${ this . _generateItems ( group . selectors , errors ) }
98
107
</ ha- settings- row> ` ;
99
108
}
100
109
110
+ _groupHasGroupAddressInConfig ( group : SettingsGroup ) {
111
+ if ( this . config === undefined ) {
112
+ return false ;
113
+ }
114
+ return group . selectors . some ( ( selector ) => {
115
+ if ( selector . type === "group_address" )
116
+ return this . _hasGroupAddressInConfig ( selector , this . config ! . knx ) ;
117
+ if ( selector . type === "group_select" )
118
+ return selector . options . some ( ( options ) =>
119
+ options . schema . some ( ( schema ) => {
120
+ if ( schema . type === "settings_group" ) return this . _groupHasGroupAddressInConfig ( schema ) ;
121
+ if ( schema . type === "group_address" )
122
+ return this . _hasGroupAddressInConfig ( schema , this . config ! . knx ) ;
123
+ return false ;
124
+ } ) ,
125
+ ) ;
126
+ return false ;
127
+ } ) ;
128
+ }
129
+
130
+ _hasGroupAddressInConfig ( ga_selector : GASchema , knxData : KnxEntityData ) {
131
+ if ( ! ( ga_selector . name in knxData ) ) return false ;
132
+
133
+ const knxEntry = knxData [ ga_selector . name ] ;
134
+ if ( knxEntry . write !== undefined ) return true ;
135
+ if ( knxEntry . state !== undefined ) return true ;
136
+ if ( knxEntry . passive ?. length ) return true ;
137
+
138
+ return false ;
139
+ }
140
+
101
141
_generateItems ( selectors : SelectorSchema [ ] , errors ?: ErrorDescription [ ] ) {
102
142
return html `${ selectors . map ( ( selector : SelectorSchema ) =>
103
143
this . _generateItem ( selector , errors ) ,
@@ -245,7 +285,18 @@ export class KNXConfigureEntity extends LitElement {
245
285
}
246
286
}
247
287
288
+ ha-expansion-panel {
289
+ margin-bottom : 16px ;
290
+ }
291
+ ha-expansion-panel > : first-child {
292
+ margin-top : 16px ;
293
+ }
294
+ ha-expansion-panel > ha-settings-row : first-child {
295
+ border : 0 ;
296
+ }
297
+
248
298
ha-settings-row {
299
+ margin-bottom : 16px ;
249
300
padding : 0 ;
250
301
}
251
302
ha-control-select {
0 commit comments