Skip to content

Commit 7af913c

Browse files
authored
Merge pull request #3101 from bramstroker/feat/config-flow-sub-profile-remarks
Add sub profile remarks to config flow
2 parents 8f9925b + 0bf5214 commit 7af913c

File tree

18 files changed

+45
-24
lines changed

18 files changed

+45
-24
lines changed

custom_components/powercalc/config_flow.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,11 +1154,9 @@ async def _validate(user_input: dict[str, Any]) -> dict[str, str]:
11541154
return {CONF_MODEL: f"{self.sensor_config.get(CONF_MODEL)}/{user_input.get(CONF_SUB_PROFILE)}"}
11551155

11561156
async def _create_schema(
1157-
model_info: ModelInfo,
1157+
profile: PowerProfile,
11581158
) -> vol.Schema:
11591159
"""Create sub profile schema."""
1160-
library = await ProfileLibrary.factory(self.hass)
1161-
profile = await library.get_profile(model_info, process_variables=False)
11621160
sub_profiles = [
11631161
selector.SelectOptionDict(
11641162
value=sub_profile[0],
@@ -1177,18 +1175,30 @@ async def _create_schema(
11771175
},
11781176
)
11791177

1178+
library = await ProfileLibrary.factory(self.hass)
1179+
profile = await library.get_profile(
1180+
ModelInfo(
1181+
str(self.sensor_config.get(CONF_MANUFACTURER)),
1182+
str(self.sensor_config.get(CONF_MODEL)),
1183+
),
1184+
process_variables=False,
1185+
)
1186+
remarks = profile.config_flow_sub_profile_remarks
1187+
if remarks:
1188+
remarks = "\n\n" + remarks
1189+
11801190
return await self.handle_form_step(
11811191
PowercalcFormStep(
11821192
step=Step.SUB_PROFILE,
1183-
schema=await _create_schema(
1184-
ModelInfo(
1185-
str(self.sensor_config.get(CONF_MANUFACTURER)),
1186-
str(self.sensor_config.get(CONF_MODEL)),
1187-
),
1188-
),
1193+
schema=await _create_schema(profile),
11891194
next_step=Step.POWER_ADVANCED,
11901195
validate_user_input=_validate,
1191-
form_kwarg={"description_placeholders": {"entity_id": self.source_entity_id}},
1196+
form_kwarg={
1197+
"description_placeholders": {
1198+
"entity_id": self.source_entity_id,
1199+
"remarks": remarks,
1200+
},
1201+
},
11921202
),
11931203
user_input,
11941204
)

custom_components/powercalc/power_profile/power_profile.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,11 @@ def config_flow_discovery_remarks(self) -> str | None:
302302

303303
return remarks
304304

305+
@property
306+
def config_flow_sub_profile_remarks(self) -> str | None:
307+
"""Get extra remarks to show at the config flow sub profile step."""
308+
return self._json_data.get("config_flow_sub_profile_remarks")
309+
305310
def get_default_discovery_remarks_translation_key(self) -> str | None:
306311
"""When no remarks are provided in the profile, see if we need to show a default remark."""
307312
if self.device_type == DeviceType.SMART_SWITCH and self.needs_fixed_config:

custom_components/powercalc/translations/cz.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@
325325
"data": {
326326
"sub_profile": "Sub profile"
327327
},
328-
"description": "This model has multiple sub profiles. Select one that suites your device\n\n\"{entity_id}\"",
328+
"description": "This model has multiple sub profiles. Select one that suites your device\n\n\"{entity_id}\"{remarks}",
329329
"title": "Sub profile config"
330330
},
331331
"smart_switch": {

custom_components/powercalc/translations/de.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@
325325
"data": {
326326
"sub_profile": "Unterprofil"
327327
},
328-
"description": "Dieses Gerät besitzt ein Modell mit mehreren Unterprofilen. Wählen Sie das Unterprofil aus, welches zu der folgenden Entität gehört:\n\n\"{entity_id}\"",
328+
"description": "Dieses Gerät besitzt ein Modell mit mehreren Unterprofilen. Wählen Sie das Unterprofil aus, welches zu der folgenden Entität gehört:\n\n\"{entity_id}\"{remarks}",
329329
"title": "Unterprofil Konfiguration"
330330
},
331331
"smart_switch": {

custom_components/powercalc/translations/en.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@
325325
"data": {
326326
"sub_profile": "Sub profile"
327327
},
328-
"description": "This device has a model with multiple sub profiles. Select one that corresponds to the following entity of this device:\n\n\"{entity_id}\"",
328+
"description": "This device has a model with multiple sub profiles. Select one that corresponds to the following entity of this device:\n\n\"{entity_id}\"{remarks}",
329329
"title": "Sub profile config"
330330
},
331331
"smart_switch": {

custom_components/powercalc/translations/es.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@
325325
"data": {
326326
"sub_profile": "Subperfil"
327327
},
328-
"description": "Este modelo tiene múltiples subperfiles. Seleccione uno que se adapte a su dispositivo\n\n\"{entity_id}\"",
328+
"description": "Este modelo tiene múltiples subperfiles. Seleccione uno que se adapte a su dispositivo\n\n\"{entity_id}\"{remarks}",
329329
"title": "Configuración del subperfil"
330330
},
331331
"smart_switch": {

custom_components/powercalc/translations/fr.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@
325325
"data": {
326326
"sub_profile": "Sous-profil"
327327
},
328-
"description": "Ce modèle a plusieurs sous-profils. Sélectionnez celui qui convient à votre appareil",
328+
"description": "Ce modèle a plusieurs sous-profils. Sélectionnez celui qui convient à votre appareil{remarks}",
329329
"title": "Configuration du sous-profil"
330330
},
331331
"smart_switch": {

custom_components/powercalc/translations/it.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@
325325
"data": {
326326
"sub_profile": "Sub profile"
327327
},
328-
"description": "This model has multiple sub profiles. Select one that suites your device\n\n\"{entity_id}\"",
328+
"description": "This model has multiple sub profiles. Select one that suites your device\n\n\"{entity_id}\"{remarks}",
329329
"title": "Sub profile config"
330330
},
331331
"smart_switch": {

custom_components/powercalc/translations/nl.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@
325325
"data": {
326326
"sub_profile": "Sub profiel"
327327
},
328-
"description": "Dit model heeft meerdere profielen. Selecteer de juiste voor je apparaat\n\n\"{entity_id}\"",
328+
"description": "Dit model heeft meerdere profielen. Selecteer de juiste voor je apparaat\n\n\"{entity_id}\"{remarks}",
329329
"title": "Sub profiel configuratie"
330330
},
331331
"smart_switch": {

custom_components/powercalc/translations/pl.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@
325325
"data": {
326326
"sub_profile": "Podprofile"
327327
},
328-
"description": "Ten model ma wiele podprofili. Wybierz taki, który pasuje do Twojego urządzenia\n\n\"{entity_id}\"",
328+
"description": "Ten model ma wiele podprofili. Wybierz taki, który pasuje do Twojego urządzenia\n\n\"{entity_id}\"{remarks}",
329329
"title": "Konfiguracja podprofili"
330330
},
331331
"smart_switch": {

0 commit comments

Comments
 (0)