Skip to content

Commit 86a2b08

Browse files
Device summary (#2011)
* Show device summary on battery type config flow * Diagnostics * Diagnostics * Apply automatic changes * Add device summary to options flow * Options flow conditional device lookup * Tidy up --------- Co-authored-by: andrew-codechimp <andrew-codechimp@users.noreply.github.com>
1 parent a3d2835 commit 86a2b08

File tree

22 files changed

+85
-31
lines changed

22 files changed

+85
-31
lines changed

custom_components/battery_notes/common.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ def validate_is_float(num):
1313
return False
1414
return False
1515

16+
1617
def get_device_model_id(device_entry: DeviceEntry) -> str | None:
1718
"""Get the device model if available."""
18-
if hasattr(device_entry, "model_id"):
19-
return device_entry.model_id
20-
else:
21-
return None
19+
return device_entry.model_id if hasattr(device_entry, "model_id") else None

custom_components/battery_notes/config_flow.py

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ class BatteryNotesFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
111111
VERSION = CONFIG_VERSION
112112

113113
data: dict
114+
model_info: ModelInfo = None
114115

115116
@staticmethod
116117
@callback
@@ -179,8 +180,11 @@ async def async_step_device(
179180
device_entry.hw_version,
180181
)
181182

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,
184188
)
185189

186190
library = await Library.factory(self.hass)
@@ -189,7 +193,7 @@ async def async_step_device(
189193
self.data[CONF_BATTERY_QUANTITY] = 1
190194

191195
device_battery_details = await library.get_device_battery_details(
192-
model_info
196+
self.model_info
193197
)
194198

195199
if device_battery_details and not device_battery_details.is_manual:
@@ -268,7 +272,7 @@ async def async_step_entity(
268272
device_entry.hw_version,
269273
)
270274

271-
model_info = ModelInfo(
275+
self.model_info = ModelInfo(
272276
device_entry.manufacturer,
273277
device_entry.model,
274278
get_device_model_id(device_entry),
@@ -278,7 +282,7 @@ async def async_step_entity(
278282
library = await Library.factory(self.hass)
279283

280284
device_battery_details = await library.get_device_battery_details(
281-
model_info
285+
self.model_info
282286
)
283287

284288
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):
326330
errors=errors,
327331
)
328332

329-
330333
async def async_step_battery(self, user_input: dict[str, Any] | None = None):
331334
"""Second step in config flow to add the battery type."""
332335
errors: dict[str, str] = {}
@@ -375,6 +378,12 @@ async def async_step_battery(self, user_input: dict[str, Any] | None = None):
375378

376379
return self.async_show_form(
377380
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+
},
378387
data_schema=vol.Schema(
379388
{
380389
vol.Required(
@@ -413,6 +422,8 @@ async def async_step_battery(self, user_input: dict[str, Any] | None = None):
413422
class OptionsFlowHandler(OptionsFlow):
414423
"""Handle an option flow for BatteryNotes."""
415424

425+
model_info: ModelInfo = None
426+
416427
def __init__(self, config_entry: ConfigEntry) -> None:
417428
"""Initialize options flow."""
418429
self.config_entry = config_entry
@@ -433,6 +444,25 @@ async def async_step_init(
433444
errors = {}
434445
self.current_config = dict(self.config_entry.data)
435446

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+
436466
schema = self.build_options_schema()
437467
if user_input is not None:
438468
user_input[CONF_BATTERY_QUANTITY] = int(user_input[CONF_BATTERY_QUANTITY])
@@ -446,6 +476,12 @@ async def async_step_init(
446476

447477
return self.async_show_form(
448478
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+
},
449485
data_schema=schema,
450486
errors=errors,
451487
)

custom_components/battery_notes/translations/ca.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
}
3232
},
3333
"battery": {
34+
"description": "Manufacturer: {manufacturer}\nModel: {model}\nModel ID: {model_id}\nHardware version: {hw_version}\n",
3435
"data": {
3536
"battery_type": "Tipus de bateria",
3637
"battery_quantity": "Quantitat de bateries",
@@ -58,7 +59,7 @@
5859
"options": {
5960
"step": {
6061
"init": {
61-
"description": "Si necessiteu ajuda amb la configuració, mireu aquí: https://andrew-codechimp.github.io/HA-Battery-Notes/",
62+
"description": "Manufacturer: {manufacturer}\nModel: {model}\nModel ID: {model_id}\nHardware version: {hw_version}\n",
6263
"data": {
6364
"name": "Nom",
6465
"battery_type": "Tipus de bateria",

custom_components/battery_notes/translations/da.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
}
3232
},
3333
"battery": {
34+
"description": "Manufacturer: {manufacturer}\nModel: {model}\nModel ID: {model_id}\nHardware version: {hw_version}\n",
3435
"data": {
3536
"battery_type": "Batteri type",
3637
"battery_quantity": "Antal batterier",
@@ -58,7 +59,7 @@
5859
"options": {
5960
"step": {
6061
"init": {
61-
"description": "Hvis du har brug for hjælp til konfigurationen, så kig her: https://andrew-codechimp.github.io/HA-Battery-Notes/",
62+
"description": "Manufacturer: {manufacturer}\nModel: {model}\nModel ID: {model_id}\nHardware version: {hw_version}\n",
6263
"data": {
6364
"name": "Navn",
6465
"battery_type": "Batteri type",

custom_components/battery_notes/translations/de.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
}
3232
},
3333
"battery": {
34+
"description": "Manufacturer: {manufacturer}\nModel: {model}\nModel ID: {model_id}\nHardware version: {hw_version}\n",
3435
"data": {
3536
"battery_type": "Batterieart",
3637
"battery_quantity": "Batteriemenge",
@@ -58,7 +59,7 @@
5859
"options": {
5960
"step": {
6061
"init": {
61-
"description": "Hilfe zur Konfiguration findest du unter: https://andrew-codechimp.github.io/HA-Battery-Notes/",
62+
"description": "Manufacturer: {manufacturer}\nModel: {model}\nModel ID: {model_id}\nHardware version: {hw_version}\n",
6263
"data": {
6364
"name": "Name",
6465
"battery_type": "Batterieart",

custom_components/battery_notes/translations/el.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
}
3232
},
3333
"battery": {
34+
"description": "Manufacturer: {manufacturer}\nModel: {model}\nModel ID: {model_id}\nHardware version: {hw_version}\n",
3435
"data": {
3536
"battery_type": "Τύπος μπαταρίας",
3637
"battery_quantity": "Αριθμός μπαταριών",
@@ -58,7 +59,7 @@
5859
"options": {
5960
"step": {
6061
"init": {
61-
"description": "Αν χρειάζεστε βοήθεια με τις ρυθμίσεις παραμέτρων ρίξτε μια ματιά εδώ: https://andrew-codechimp.github.io/HA-Battery-Notes/",
62+
"description": "Manufacturer: {manufacturer}\nModel: {model}\nModel ID: {model_id}\nHardware version: {hw_version}\n",
6263
"data": {
6364
"name": "Ονομα",
6465
"battery_type": "Τύπος μπαταρίας",

custom_components/battery_notes/translations/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
}
3232
},
3333
"battery": {
34+
"description": "Manufacturer: {manufacturer}\nModel: {model}\nModel ID: {model_id}\nHardware version: {hw_version}\n",
3435
"data": {
3536
"battery_type": "Battery type",
3637
"battery_quantity": "Battery quantity",
@@ -58,7 +59,7 @@
5859
"options": {
5960
"step": {
6061
"init": {
61-
"description": "If you need help with the configuration have a look here: https://andrew-codechimp.github.io/HA-Battery-Notes/",
62+
"description": "Manufacturer: {manufacturer}\nModel: {model}\nModel ID: {model_id}\nHardware version: {hw_version}\n",
6263
"data": {
6364
"name": "Name",
6465
"battery_type": "Battery type",

custom_components/battery_notes/translations/es-ES.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
}
3232
},
3333
"battery": {
34+
"description": "Manufacturer: {manufacturer}\nModel: {model}\nModel ID: {model_id}\nHardware version: {hw_version}\n",
3435
"data": {
3536
"battery_type": "Tipo de batería",
3637
"battery_quantity": "Cantidad de batería",
@@ -58,7 +59,7 @@
5859
"options": {
5960
"step": {
6061
"init": {
61-
"description": "Si necesitas ayuda con la configuración, echa un vistazo aquí: https://andrew-codechimp.github.io/HA-Battery-Notes/",
62+
"description": "Manufacturer: {manufacturer}\nModel: {model}\nModel ID: {model_id}\nHardware version: {hw_version}\n",
6263
"data": {
6364
"name": "Nombre",
6465
"battery_type": "Tipo de batería",

custom_components/battery_notes/translations/fi.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
}
3232
},
3333
"battery": {
34+
"description": "Manufacturer: {manufacturer}\nModel: {model}\nModel ID: {model_id}\nHardware version: {hw_version}\n",
3435
"data": {
3536
"battery_type": "Akun tyyppi",
3637
"battery_quantity": "Akkujen määrä",
@@ -58,7 +59,7 @@
5859
"options": {
5960
"step": {
6061
"init": {
61-
"description": "Jos tarvitset apua asetuksissa, katso täältä: https://andrew-codechimp.github.io/HA-Battery-Notes/",
62+
"description": "Manufacturer: {manufacturer}\nModel: {model}\nModel ID: {model_id}\nHardware version: {hw_version}\n",
6263
"data": {
6364
"name": "Nimi",
6465
"battery_type": "Akun tyyppi",

custom_components/battery_notes/translations/fr.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
}
3232
},
3333
"battery": {
34+
"description": "Manufacturer: {manufacturer}\nModel: {model}\nModel ID: {model_id}\nHardware version: {hw_version}\n",
3435
"data": {
3536
"battery_type": "Type de batterie",
3637
"battery_quantity": "Nombre de batteries",
@@ -58,7 +59,7 @@
5859
"options": {
5960
"step": {
6061
"init": {
61-
"description": "En cas de demande d'aide, aller à: https://andrew-codechimp.github.io/HA-Battery-Notes/",
62+
"description": "Manufacturer: {manufacturer}\nModel: {model}\nModel ID: {model_id}\nHardware version: {hw_version}\n",
6263
"data": {
6364
"name": "Nom",
6465
"battery_type": "Type de batterie",

custom_components/battery_notes/translations/hu.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
}
3232
},
3333
"battery": {
34+
"description": "Manufacturer: {manufacturer}\nModel: {model}\nModel ID: {model_id}\nHardware version: {hw_version}\n",
3435
"data": {
3536
"battery_type": "Elem típus",
3637
"battery_quantity": "Az akkumulátor mennyisége",
@@ -58,7 +59,7 @@
5859
"options": {
5960
"step": {
6061
"init": {
61-
"description": "Ha segítségre van szükséged a konfigurációhoz: https://andrew-codechimp.github.io/HA-Battery-Notes/",
62+
"description": "Manufacturer: {manufacturer}\nModel: {model}\nModel ID: {model_id}\nHardware version: {hw_version}\n",
6263
"data": {
6364
"name": "Név",
6465
"battery_type": "Elem típus",

custom_components/battery_notes/translations/it.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
}
3232
},
3333
"battery": {
34+
"description": "Manufacturer: {manufacturer}\nModel: {model}\nModel ID: {model_id}\nHardware version: {hw_version}\n",
3435
"data": {
3536
"battery_type": "Tipo di batteria",
3637
"battery_quantity": "Quantità batteria",
@@ -58,7 +59,7 @@
5859
"options": {
5960
"step": {
6061
"init": {
61-
"description": "Se hai bisogno di aiuto per la configurazione, dai un'occhiata qui: https://andrew-codechimp.github.io/HA-Battery-Notes/",
62+
"description": "Manufacturer: {manufacturer}\nModel: {model}\nModel ID: {model_id}\nHardware version: {hw_version}\n",
6263
"data": {
6364
"name": "Nome",
6465
"battery_type": "Tipo di batteria",

custom_components/battery_notes/translations/lt.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
}
3232
},
3333
"battery": {
34+
"description": "Manufacturer: {manufacturer}\nModel: {model}\nModel ID: {model_id}\nHardware version: {hw_version}\n",
3435
"data": {
3536
"battery_type": "Baterijos tipas",
3637
"battery_quantity": "Baterijų kiekis",
@@ -58,7 +59,7 @@
5859
"options": {
5960
"step": {
6061
"init": {
61-
"description": "Daugiau pagalbos apie konfigūraciją rasite čia: https://andrew-codechimp.github.io/HA-Battery-Notes/",
62+
"description": "Manufacturer: {manufacturer}\nModel: {model}\nModel ID: {model_id}\nHardware version: {hw_version}\n",
6263
"data": {
6364
"name": "Pavadinimas",
6465
"battery_type": "Baterijos tipas",

custom_components/battery_notes/translations/nl.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
}
3232
},
3333
"battery": {
34+
"description": "Manufacturer: {manufacturer}\nModel: {model}\nModel ID: {model_id}\nHardware version: {hw_version}\n",
3435
"data": {
3536
"battery_type": "Batterij type",
3637
"battery_quantity": "Aantal batterijen",
@@ -58,7 +59,7 @@
5859
"options": {
5960
"step": {
6061
"init": {
61-
"description": "Als u hulp nodig heeft bij de configuratie kunt u hier een kijkje nemen: https://andrew-codechimp.github.io/HA-Battery-Notes/",
62+
"description": "Manufacturer: {manufacturer}\nModel: {model}\nModel ID: {model_id}\nHardware version: {hw_version}\n",
6263
"data": {
6364
"name": "Naam",
6465
"battery_type": "Batterij type",

custom_components/battery_notes/translations/no.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
}
3232
},
3333
"battery": {
34+
"description": "Manufacturer: {manufacturer}\nModel: {model}\nModel ID: {model_id}\nHardware version: {hw_version}\n",
3435
"data": {
3536
"battery_type": "Battery type",
3637
"battery_quantity": "Battery quantity",
@@ -58,7 +59,7 @@
5859
"options": {
5960
"step": {
6061
"init": {
61-
"description": "If you need help with the configuration have a look here: https://andrew-codechimp.github.io/HA-Battery-Notes/",
62+
"description": "Manufacturer: {manufacturer}\nModel: {model}\nModel ID: {model_id}\nHardware version: {hw_version}\n",
6263
"data": {
6364
"name": "Navn",
6465
"battery_type": "Battery type",

custom_components/battery_notes/translations/pl.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
}
3232
},
3333
"battery": {
34+
"description": "Manufacturer: {manufacturer}\nModel: {model}\nModel ID: {model_id}\nHardware version: {hw_version}\n",
3435
"data": {
3536
"battery_type": "Typ baterii",
3637
"battery_quantity": "Liczba baterii",
@@ -58,7 +59,7 @@
5859
"options": {
5960
"step": {
6061
"init": {
61-
"description": "Jeśli potrzebujesz pomocy w konfiguracji, zajrzyj tutaj: https://andrew-codechimp.github.io/HA-Battery-Notes/",
62+
"description": "Manufacturer: {manufacturer}\nModel: {model}\nModel ID: {model_id}\nHardware version: {hw_version}\n",
6263
"data": {
6364
"name": "Nazwa",
6465
"battery_type": "Typ baterii",

custom_components/battery_notes/translations/pt.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
}
3232
},
3333
"battery": {
34+
"description": "Manufacturer: {manufacturer}\nModel: {model}\nModel ID: {model_id}\nHardware version: {hw_version}\n",
3435
"data": {
3536
"battery_type": "Tipo de bateria",
3637
"battery_quantity": "Quantidade de baterias",
@@ -58,7 +59,7 @@
5859
"options": {
5960
"step": {
6061
"init": {
61-
"description": "Caso precise se ajude na configuração pode verificar em: https://github.com/andrew-codechimp/ha-battery-notes",
62+
"description": "Manufacturer: {manufacturer}\nModel: {model}\nModel ID: {model_id}\nHardware version: {hw_version}\n",
6263
"data": {
6364
"name": "Nome",
6465
"battery_type": "Tipo de bateria",
@@ -182,4 +183,4 @@
182183
"name": "Verificar bateria com carga baixa"
183184
}
184185
}
185-
}
186+
}

0 commit comments

Comments
 (0)