@@ -111,6 +111,7 @@ class BatteryNotesFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
111
111
VERSION = CONFIG_VERSION
112
112
113
113
data : dict
114
+ model_info : ModelInfo = None
114
115
115
116
@staticmethod
116
117
@callback
@@ -179,8 +180,11 @@ async def async_step_device(
179
180
device_entry .hw_version ,
180
181
)
181
182
182
- model_info = ModelInfo (
183
- device_entry .manufacturer , device_entry .model , get_device_model_id (device_entry ), device_entry .hw_version
183
+ self .model_info = ModelInfo (
184
+ device_entry .manufacturer ,
185
+ device_entry .model ,
186
+ get_device_model_id (device_entry ),
187
+ device_entry .hw_version ,
184
188
)
185
189
186
190
library = await Library .factory (self .hass )
@@ -189,7 +193,7 @@ async def async_step_device(
189
193
self .data [CONF_BATTERY_QUANTITY ] = 1
190
194
191
195
device_battery_details = await library .get_device_battery_details (
192
- model_info
196
+ self . model_info
193
197
)
194
198
195
199
if device_battery_details and not device_battery_details .is_manual :
@@ -268,7 +272,7 @@ async def async_step_entity(
268
272
device_entry .hw_version ,
269
273
)
270
274
271
- model_info = ModelInfo (
275
+ self . model_info = ModelInfo (
272
276
device_entry .manufacturer ,
273
277
device_entry .model ,
274
278
get_device_model_id (device_entry ),
@@ -278,7 +282,7 @@ async def async_step_entity(
278
282
library = await Library .factory (self .hass )
279
283
280
284
device_battery_details = await library .get_device_battery_details (
281
- model_info
285
+ self . model_info
282
286
)
283
287
284
288
if device_battery_details and not device_battery_details .is_manual :
@@ -326,7 +330,6 @@ async def async_step_manual(self, user_input: dict[str, Any] | None = None):
326
330
errors = errors ,
327
331
)
328
332
329
-
330
333
async def async_step_battery (self , user_input : dict [str , Any ] | None = None ):
331
334
"""Second step in config flow to add the battery type."""
332
335
errors : dict [str , str ] = {}
@@ -375,6 +378,12 @@ async def async_step_battery(self, user_input: dict[str, Any] | None = None):
375
378
376
379
return self .async_show_form (
377
380
step_id = "battery" ,
381
+ description_placeholders = {
382
+ "manufacturer" : self .model_info .manufacturer if self .model_info else "" ,
383
+ "model" : self .model_info .model if self .model_info else "" ,
384
+ "model_id" : self .model_info .model_id if self .model_info else "" ,
385
+ "hw_version" : self .model_info .hw_version if self .model_info else "" ,
386
+ },
378
387
data_schema = vol .Schema (
379
388
{
380
389
vol .Required (
@@ -413,6 +422,8 @@ async def async_step_battery(self, user_input: dict[str, Any] | None = None):
413
422
class OptionsFlowHandler (OptionsFlow ):
414
423
"""Handle an option flow for BatteryNotes."""
415
424
425
+ model_info : ModelInfo = None
426
+
416
427
def __init__ (self , config_entry : ConfigEntry ) -> None :
417
428
"""Initialize options flow."""
418
429
self .config_entry = config_entry
@@ -433,6 +444,25 @@ async def async_step_init(
433
444
errors = {}
434
445
self .current_config = dict (self .config_entry .data )
435
446
447
+ if self .source_device_id :
448
+ device_registry = dr .async_get (self .hass )
449
+ device_entry = device_registry .async_get (self .source_device_id )
450
+
451
+ _LOGGER .debug (
452
+ "Looking up device %s %s %s %s" ,
453
+ device_entry .manufacturer ,
454
+ device_entry .model ,
455
+ get_device_model_id (device_entry ) or "" ,
456
+ device_entry .hw_version ,
457
+ )
458
+
459
+ self .model_info = ModelInfo (
460
+ device_entry .manufacturer ,
461
+ device_entry .model ,
462
+ get_device_model_id (device_entry ),
463
+ device_entry .hw_version ,
464
+ )
465
+
436
466
schema = self .build_options_schema ()
437
467
if user_input is not None :
438
468
user_input [CONF_BATTERY_QUANTITY ] = int (user_input [CONF_BATTERY_QUANTITY ])
@@ -446,6 +476,12 @@ async def async_step_init(
446
476
447
477
return self .async_show_form (
448
478
step_id = "init" ,
479
+ description_placeholders = {
480
+ "manufacturer" : self .model_info .manufacturer if self .model_info else "" ,
481
+ "model" : self .model_info .model if self .model_info else "" ,
482
+ "model_id" : self .model_info .model_id if self .model_info else "" ,
483
+ "hw_version" : self .model_info .hw_version if self .model_info else "" ,
484
+ },
449
485
data_schema = schema ,
450
486
errors = errors ,
451
487
)
0 commit comments