Skip to content

Commit eac22bb

Browse files
authored
Merge pull request #3011 from bramstroker/feat/config-flow-source-entity
Add entity_it to first pane of discovery flow
2 parents 6f58fa0 + 45673d4 commit eac22bb

File tree

17 files changed

+72
-18
lines changed

17 files changed

+72
-18
lines changed

custom_components/powercalc/common.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,14 @@ def get_wrapped_entity_name(
9595
) -> str:
9696
"""Construct entity name based on the wrapped entity"""
9797
if entity_entry:
98-
if entity_entry.name is None and entity_entry.has_entity_name and device_entry:
99-
return device_entry.name_by_user or device_entry.name or object_id
100-
101-
return entity_entry.name or entity_entry.original_name or object_id
98+
if entity_entry.name:
99+
return entity_entry.name
100+
if entity_entry.has_entity_name and device_entry:
101+
device_name = device_entry.name_by_user or device_entry.name
102+
if device_name:
103+
return f"{device_name} {entity_entry.original_name}" if entity_entry.original_name else device_name
104+
105+
return entity_entry.original_name or object_id
102106

103107
entity_state = hass.states.get(entity_id)
104108
if entity_state:

custom_components/powercalc/config_flow.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
from homeassistant.core import callback
3838
from homeassistant.data_entry_flow import FlowResult
3939
from homeassistant.helpers import entity_registry as er
40-
from homeassistant.helpers import selector
40+
from homeassistant.helpers import selector, translation
4141
from homeassistant.helpers.schema_config_entry_flow import SchemaFlowError
4242
from homeassistant.helpers.selector import TextSelector
4343
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
@@ -1730,12 +1730,20 @@ async def async_step_library(
17301730
remarks = self.selected_profile.config_flow_discovery_remarks
17311731
if remarks:
17321732
remarks = "\n\n" + remarks
1733+
1734+
translations = translation.async_get_cached_translations(self.hass, self.hass.config.language, "common", DOMAIN)
1735+
if self.selected_profile.discovery_by == DiscoveryBy.DEVICE and self.source_entity and self.source_entity.device_entry:
1736+
source = f"{translations.get(f'component.{DOMAIN}.common.source_device')}: {self.source_entity.device_entry.name}"
1737+
else:
1738+
source = f"{translations.get(f'component.{DOMAIN}.common.source_entity')}: {self.source_entity_id}"
1739+
17331740
return self.async_show_form(
17341741
step_id=Step.LIBRARY,
17351742
description_placeholders={
17361743
"remarks": remarks, # type: ignore
17371744
"manufacturer": self.selected_profile.manufacturer,
17381745
"model": self.selected_profile.model,
1746+
"source": source,
17391747
},
17401748
data_schema=SCHEMA_POWER_AUTODISCOVERED,
17411749
errors={},

custom_components/powercalc/translations/cz.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
22
"common": {
3+
"source_entity": "Source entity",
4+
"source_device": "Source device",
35
"remarks_smart_switch": "This profile only provides standby power values. \n When you have an appliance which consumes a fixed amount of power when turned on, you can provide that value in next step of the config flow",
46
"remarks_smart_dimmer": "This profile only provides standby power values. \n In the next step you can optionally provide the values of the connected light"
57
},
@@ -204,7 +206,7 @@
204206
"data_description": {
205207
"confirm_autodisovered_model": "Pokud se rozhodnete nepotvrzovat, pak můžete zadat výrobce a model manuálně"
206208
},
207-
"description": "Výrobce \"{manufacturer}\" a model \"{model}\" byl automaticky detekován pro vaše zařízení.{remarks}",
209+
"description": "{source}\n\nVýrobce \"{manufacturer}\" a model \"{model}\" byl automaticky detekován pro vaše zařízení.{remarks}",
208210
"title": "Knihovna"
209211
},
210212
"library_multi_profile": {

custom_components/powercalc/translations/de.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
22
"common": {
3+
"source_entity": "Source entity",
4+
"source_device": "Source device",
35
"remarks_smart_switch": "Dieses Profil liefert nur Werte für die Standby-Leistung. \n Wenn Sie ein Gerät haben, das beim Einschalten eine bestimmte Menge an Strom verbraucht, können Sie diesen Wert im nächsten Schritt des Konfigurationsablaufs angeben",
46
"remarks_smart_dimmer": "Dieses Profil bietet nur Standby-Leistungswerte. \n Im nächsten Schritt können Sie optional die Werte der angeschlossenen Lampe angeben"
57
},
@@ -204,7 +206,7 @@
204206
"data_description": {
205207
"confirm_autodisovered_model": "Wenn Sie nicht bestätigen möchten, können Sie den Hersteller und das Modell selbst eingeben"
206208
},
207-
"description": "Hersteller \"{manufacturer}\" und Modell \"{model}\" wurden für Ihre Gerät automatisch erkannt.{remarks}",
209+
"description": "{source}\n\nHersteller \"{manufacturer}\" und Modell \"{model}\" wurden für Ihre Gerät automatisch erkannt.{remarks}",
208210
"title": "Bibliothek"
209211
},
210212
"library_multi_profile": {

custom_components/powercalc/translations/en.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
22
"common": {
3+
"source_entity": "Source entity",
4+
"source_device": "Source device",
35
"remarks_smart_switch": "This profile only provides standby power values. \n When you have an appliance which consumes a fixed amount of power when turned on, you can provide that value in next step of the config flow",
46
"remarks_smart_dimmer": "This profile only provides standby power values. \n In the next step you can optionally provide the values of the connected light"
57
},
@@ -204,7 +206,7 @@
204206
"data_description": {
205207
"confirm_autodisovered_model": "If you choose not to confirm, you can input the manufacturer and model yourself"
206208
},
207-
"description": "Manufacturer \"{manufacturer}\" and model \"{model}\" were automatically detected for your device.{remarks}",
209+
"description": "{source}\n\nManufacturer \"{manufacturer}\" and model \"{model}\" were automatically detected for your device.{remarks}",
208210
"title": "Library"
209211
},
210212
"library_multi_profile": {

custom_components/powercalc/translations/es.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
22
"common": {
3+
"source_entity": "Source entity",
4+
"source_device": "Source device",
35
"remarks_smart_switch": "Este perfil solo provee valores de potencia en espera (standby). \nCuando tienes un aparato que encendido consume una cantidad fija de potencia, puedes proveer ese valor en el siguiente paso de la configuración",
46
"remarks_smart_dimmer": "Este perfil solo proporciona valores de energía en Standby. \n En el siguiente paso puedes proporcionar opcionalmente los valores de la luz conectada"
57
},
@@ -204,7 +206,7 @@
204206
"data_description": {
205207
"confirm_autodisovered_model": "Si eliges no confirmar, puedes introducir el fabricante y el modelo tú mismo"
206208
},
207-
"description": "El fabricante \"{manufacturer}\" y el modelo \"{model}\" fueron detectados automáticamente en su dispositivo.{remarks}",
209+
"description": "{source}\n\nEl fabricante \"{manufacturer}\" y el modelo \"{model}\" fueron detectados automáticamente en su dispositivo.{remarks}",
208210
"title": "Biblioteca"
209211
},
210212
"library_multi_profile": {

custom_components/powercalc/translations/fr.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
22
"common": {
3+
"source_entity": "Source entity",
4+
"source_device": "Source device",
35
"remarks_smart_switch": "This profile only provides standby power values. \n When you have an appliance which consumes a fixed amount of power when turned on, you can provide that value in next step of the config flow",
46
"remarks_smart_dimmer": "This profile only provides standby power values. \n In the next step you can optionally provide the values of the connected light"
57
},
@@ -204,7 +206,7 @@
204206
"data_description": {
205207
"confirm_autodisovered_model": "Si vous choisissez de ne pas confirmer, vous pouvez entrer vous-même le fabricant et le modèle"
206208
},
207-
"description": "Le fabricant \"{manufacturer}\" et le modèle \"{model}\" ont été automatiquement détectés pour votre appareil.{remarks}",
209+
"description": "{source}\n\nLe fabricant \"{manufacturer}\" et le modèle \"{model}\" ont été automatiquement détectés pour votre appareil.{remarks}",
208210
"title": "Bibliothèque"
209211
},
210212
"library_multi_profile": {

custom_components/powercalc/translations/it.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
22
"common": {
3+
"source_entity": "Source entity",
4+
"source_device": "Source device",
35
"remarks_smart_switch": "Questo profilo fornisce solo valori di potenza in standby. Quando hai un dispositivo che consuma una quantità fissa di potenza quando è acceso, puoi fornire quel valore nel passaggio successivo del flusso di configurazione",
46
"remarks_smart_dimmer": "This profile only provides standby power values. \n In the next step you can optionally provide the values of the connected light"
57
},
@@ -204,7 +206,7 @@
204206
"data_description": {
205207
"confirm_autodisovered_model": "Se si sceglie di non confermare, è possibile immettere il produttore e modellare da soli"
206208
},
207-
"description": "Produttore \"{manufacturer}\" e modello \"{model}\" sono stati rilevati automaticamente per il tuo dispositivo.{remarks}",
209+
"description": "Source entity: {source_entity}\n\nProduttore \"{manufacturer}\" e modello \"{model}\" sono stati rilevati automaticamente per il tuo dispositivo.{remarks}",
208210
"title": "Libreria"
209211
},
210212
"library_multi_profile": {

custom_components/powercalc/translations/nl.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
22
"common": {
3+
"source_entity": "Bron entiteit",
4+
"source_device": "Bron apparaat",
35
"remarks_smart_switch": "Dit profiel biedt alleen stand-by stroomwaarden. \n Wanneer je een apparaat hebt dat een vaste hoeveelheid stroom verbruikt wanneer het is ingeschakeld, kunt u die waarde opgeven in de volgende stap van de configuratie flow",
46
"remarks_smart_dimmer": "Dit profiel biedt alleen stand-by-stroomwaarden. \n In de volgende stap kunt u optioneel de waarden van het aangesloten licht opgeven."
57
},
@@ -204,7 +206,7 @@
204206
"data_description": {
205207
"confirm_autodisovered_model": "Wanneer je niet bevestigd kan je in het volgende scherm zelf de fabrikant en het model kiezen."
206208
},
207-
"description": "Fabrikant \"{manufacturer}\" en model \"{model}\" zijn automatisch gedecteerd voor het apparaat.{remarks}",
209+
"description": "{source}\n\nFabrikant \"{manufacturer}\" en model \"{model}\" zijn automatisch gedecteerd voor het apparaat.{remarks}",
208210
"title": "Bibliotheek"
209211
},
210212
"library_multi_profile": {

custom_components/powercalc/translations/pl.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
22
"common": {
3+
"source_entity": "Source entity",
4+
"source_device": "Source device",
35
"remarks_smart_switch": "Ten profil dostarcza tylko wartości poboru mocy w trybie czuwania. \n Gdy masz urządzenie, które zużywa stałą ilość energii po włączeniu, możesz podać tę wartość w następnym kroku przepływu konfiguracji",
46
"remarks_smart_dimmer": "This profile only provides standby power values. \n In the next step you can optionally provide the values of the connected light"
57
},
@@ -204,7 +206,7 @@
204206
"data_description": {
205207
"confirm_autodisovered_model": "Jeśli zdecydujesz się nie potwierdzać, możesz samodzielnie wprowadzić producenta i model"
206208
},
207-
"description": "Producent \"{manufacturer}\" i model \"{model}\" zostały automatycznie wykryte dla twojego światła.{remarks}",
209+
"description": "{source}\n\nProducent \"{manufacturer}\" i model \"{model}\" zostały automatycznie wykryte dla twojego światła.{remarks}",
208210
"title": "Biblioteka"
209211
},
210212
"library_multi_profile": {

0 commit comments

Comments
 (0)