1
+ import { computeDomain } from "../../../../../common/entity/compute_domain" ;
2
+ import { computeStateName } from "../../../../../common/entity/compute_state_name" ;
1
3
import type { EntityFilterFunc } from "../../../../../common/entity/entity_filter" ;
2
4
import { generateEntityFilter } from "../../../../../common/entity/entity_filter" ;
5
+ import { stripPrefixFromEntityName } from "../../../../../common/entity/strip_prefix_from_entity_name" ;
3
6
import { orderCompare } from "../../../../../common/string/compare" ;
7
+ import type { LovelaceCardConfig } from "../../../../../data/lovelace/config/card" ;
4
8
import type { HomeAssistant } from "../../../../../types" ;
9
+ import { supportsAlarmModesCardFeature } from "../../../card-features/hui-alarm-modes-card-feature" ;
10
+ import { supportsCoverOpenCloseCardFeature } from "../../../card-features/hui-cover-open-close-card-feature" ;
11
+ import { supportsLightBrightnessCardFeature } from "../../../card-features/hui-light-brightness-card-feature" ;
12
+ import { supportsLockCommandsCardFeature } from "../../../card-features/hui-lock-commands-card-feature" ;
13
+ import { supportsTargetTemperatureCardFeature } from "../../../card-features/hui-target-temperature-card-feature" ;
14
+ import type { LovelaceCardFeatureConfig } from "../../../card-features/types" ;
15
+ import type { TileCardConfig } from "../../../cards/types" ;
5
16
6
17
export const AREA_STRATEGY_GROUPS = [
7
18
"lights" ,
8
19
"climate" ,
9
20
"media_players" ,
10
21
"security" ,
22
+ "others" ,
11
23
] as const ;
12
24
13
25
export const AREA_STRATEGY_GROUP_ICONS = {
14
26
lights : "mdi:lightbulb" ,
15
27
climate : "mdi:home-thermometer" ,
16
28
media_players : "mdi:multimedia" ,
17
29
security : "mdi:security" ,
30
+ others : "mdi:shape" ,
18
31
} ;
19
32
20
33
// Todo be replace by translation when validated
@@ -23,6 +36,7 @@ export const AREA_STRATEGY_GROUP_LABELS = {
23
36
climate : "Climate" ,
24
37
media_players : "Entertainment" ,
25
38
security : "Security" ,
39
+ others : "Others" ,
26
40
} ;
27
41
28
42
export type AreaStrategyGroup = ( typeof AREA_STRATEGY_GROUPS ) [ number ] ;
@@ -75,9 +89,15 @@ export const getAreaGroupedEntities = (
75
89
"shade" ,
76
90
"shutter" ,
77
91
"window" ,
92
+ "none" ,
78
93
] ,
79
94
entity_category : "none" ,
80
95
} ) ,
96
+ generateEntityFilter ( hass , {
97
+ domain : "fan" ,
98
+ area : area ,
99
+ entity_category : "none" ,
100
+ } ) ,
81
101
generateEntityFilter ( hass , {
82
102
domain : "binary_sensor" ,
83
103
area : area ,
@@ -109,13 +129,40 @@ export const getAreaGroupedEntities = (
109
129
area : area ,
110
130
entity_category : "none" ,
111
131
} ) ,
132
+ generateEntityFilter ( hass , {
133
+ domain : "camera" ,
134
+ area : area ,
135
+ entity_category : "none" ,
136
+ } ) ,
112
137
generateEntityFilter ( hass , {
113
138
domain : "binary_sensor" ,
114
139
device_class : [ "door" , "garage_door" ] ,
115
140
area : area ,
116
141
entity_category : "none" ,
117
142
} ) ,
118
143
] ,
144
+ others : [
145
+ generateEntityFilter ( hass , {
146
+ domain : "vacuum" ,
147
+ area : area ,
148
+ entity_category : "none" ,
149
+ } ) ,
150
+ generateEntityFilter ( hass , {
151
+ domain : "lawn_mower" ,
152
+ area : area ,
153
+ entity_category : "none" ,
154
+ } ) ,
155
+ generateEntityFilter ( hass , {
156
+ domain : "valve" ,
157
+ area : area ,
158
+ entity_category : "none" ,
159
+ } ) ,
160
+ generateEntityFilter ( hass , {
161
+ domain : "switch" ,
162
+ area : area ,
163
+ entity_category : "none" ,
164
+ } ) ,
165
+ ] ,
119
166
} ;
120
167
121
168
return Object . fromEntries (
@@ -147,3 +194,55 @@ export const getAreaGroupedEntities = (
147
194
} )
148
195
) as AreaEntitiesByGroup ;
149
196
} ;
197
+
198
+ export const computeAreaTileCardConfig =
199
+ ( hass : HomeAssistant , prefix : string , includeFeature ?: boolean ) =>
200
+ ( entity : string ) : LovelaceCardConfig => {
201
+ const stateObj = hass . states [ entity ] ;
202
+
203
+ const additionalCardConfig : Partial < TileCardConfig > = { } ;
204
+
205
+ const domain = computeDomain ( entity ) ;
206
+ if ( domain === "camera" ) {
207
+ additionalCardConfig . show_entity_picture = true ;
208
+ }
209
+
210
+ let feature : LovelaceCardFeatureConfig | undefined ;
211
+ if ( includeFeature ) {
212
+ if ( supportsLightBrightnessCardFeature ( stateObj ) ) {
213
+ feature = {
214
+ type : "light-brightness" ,
215
+ } ;
216
+ } else if ( supportsCoverOpenCloseCardFeature ( stateObj ) ) {
217
+ feature = {
218
+ type : "cover-open-close" ,
219
+ } ;
220
+ } else if ( supportsTargetTemperatureCardFeature ( stateObj ) ) {
221
+ feature = {
222
+ type : "target-temperature" ,
223
+ } ;
224
+ } else if ( supportsAlarmModesCardFeature ( stateObj ) ) {
225
+ feature = {
226
+ type : "alarm-modes" ,
227
+ } ;
228
+ } else if ( supportsLockCommandsCardFeature ( stateObj ) ) {
229
+ feature = {
230
+ type : "lock-commands" ,
231
+ } ;
232
+ }
233
+ }
234
+
235
+ if ( feature ) {
236
+ additionalCardConfig . features = [ feature ] ;
237
+ }
238
+
239
+ const name = computeStateName ( stateObj ) ;
240
+ const stripedName = stripPrefixFromEntityName ( name , prefix . toLowerCase ( ) ) ;
241
+
242
+ return {
243
+ type : "tile" ,
244
+ entity : entity ,
245
+ name : stripedName ,
246
+ ...additionalCardConfig ,
247
+ } ;
248
+ } ;
0 commit comments