1
+ import type {
2
+ LovelaceSectionConfig ,
3
+ LovelaceStrategySectionConfig ,
4
+ } from "../../../data/lovelace/config/section" ;
5
+ import type { LovelaceStrategyConfig } from "../../../data/lovelace/config/strategy" ;
1
6
import type {
2
7
LovelaceConfig ,
8
+ LovelaceDashboardStrategyConfig ,
3
9
LovelaceRawConfig ,
4
10
} from "../../../data/lovelace/config/types" ;
5
11
import { isStrategyDashboard } from "../../../data/lovelace/config/types" ;
6
- import type { LovelaceStrategyConfig } from "../../../data/lovelace/config/strategy" ;
7
- import type { LovelaceViewConfig } from "../../../data/lovelace/config/view" ;
12
+ import type {
13
+ LovelaceStrategyViewConfig ,
14
+ LovelaceViewConfig ,
15
+ } from "../../../data/lovelace/config/view" ;
8
16
import { isStrategyView } from "../../../data/lovelace/config/view" ;
9
17
import type { AsyncReturnType , HomeAssistant } from "../../../types" ;
10
18
import { cleanLegacyStrategyConfig , isLegacyStrategy } from "./legacy-strategy" ;
@@ -133,10 +141,11 @@ const generateStrategy = async <T extends LovelaceStrategyConfigType>(
133
141
} ;
134
142
135
143
export const generateLovelaceDashboardStrategy = async (
136
- strategyConfig : LovelaceStrategyConfig ,
144
+ config : LovelaceDashboardStrategyConfig ,
137
145
hass : HomeAssistant
138
- ) : Promise < LovelaceConfig > =>
139
- generateStrategy (
146
+ ) : Promise < LovelaceConfig > => {
147
+ const { strategy, ...base } = config ;
148
+ const generated = generateStrategy (
140
149
"dashboard" ,
141
150
( err ) => ( {
142
151
views : [
@@ -151,15 +160,21 @@ export const generateLovelaceDashboardStrategy = async (
151
160
} ,
152
161
] ,
153
162
} ) ,
154
- strategyConfig ,
163
+ strategy ,
155
164
hass
156
165
) ;
166
+ return {
167
+ ...base ,
168
+ ...generated ,
169
+ } ;
170
+ } ;
157
171
158
172
export const generateLovelaceViewStrategy = async (
159
- strategyConfig : LovelaceStrategyConfig ,
173
+ config : LovelaceStrategyViewConfig ,
160
174
hass : HomeAssistant
161
- ) : Promise < LovelaceViewConfig > =>
162
- generateStrategy (
175
+ ) : Promise < LovelaceViewConfig > => {
176
+ const { strategy, ...base } = config ;
177
+ const generated = await generateStrategy (
163
178
"view" ,
164
179
( err ) => ( {
165
180
cards : [
@@ -169,15 +184,21 @@ export const generateLovelaceViewStrategy = async (
169
184
} ,
170
185
] ,
171
186
} ) ,
172
- strategyConfig ,
187
+ strategy ,
173
188
hass
174
189
) ;
190
+ return {
191
+ ...base ,
192
+ ...generated ,
193
+ } ;
194
+ } ;
175
195
176
196
export const generateLovelaceSectionStrategy = async (
177
- strategyConfig : LovelaceStrategyConfig ,
197
+ config : LovelaceStrategySectionConfig ,
178
198
hass : HomeAssistant
179
- ) : Promise < LovelaceViewConfig > =>
180
- generateStrategy (
199
+ ) : Promise < LovelaceSectionConfig > => {
200
+ const { strategy, ...base } = config ;
201
+ const generated = await generateStrategy (
181
202
"section" ,
182
203
( err ) => ( {
183
204
cards : [
@@ -187,9 +208,14 @@ export const generateLovelaceSectionStrategy = async (
187
208
} ,
188
209
] ,
189
210
} ) ,
190
- strategyConfig ,
211
+ strategy ,
191
212
hass
192
213
) ;
214
+ return {
215
+ ...base ,
216
+ ...generated ,
217
+ } ;
218
+ } ;
193
219
194
220
/**
195
221
* Find all references to strategies and replaces them with the generated output
@@ -199,20 +225,20 @@ export const expandLovelaceConfigStrategies = async (
199
225
hass : HomeAssistant
200
226
) : Promise < LovelaceConfig > => {
201
227
const newConfig = isStrategyDashboard ( config )
202
- ? await generateLovelaceDashboardStrategy ( config . strategy , hass )
228
+ ? await generateLovelaceDashboardStrategy ( config , hass )
203
229
: { ...config } ;
204
230
205
231
newConfig . views = await Promise . all (
206
232
newConfig . views . map ( async ( view ) => {
207
233
const newView = isStrategyView ( view )
208
- ? await generateLovelaceViewStrategy ( view . strategy , hass )
234
+ ? await generateLovelaceViewStrategy ( view , hass )
209
235
: { ...view } ;
210
236
211
237
if ( newView . sections ) {
212
238
newView . sections = await Promise . all (
213
239
newView . sections . map ( async ( section ) => {
214
240
const newSection = isStrategyView ( section )
215
- ? await generateLovelaceSectionStrategy ( section . strategy , hass )
241
+ ? await generateLovelaceSectionStrategy ( section , hass )
216
242
: { ...section } ;
217
243
return newSection ;
218
244
} )
0 commit comments