Skip to content

Commit da4c060

Browse files
committed
Bugfix translations in config flow
1 parent b89b537 commit da4c060

3 files changed

Lines changed: 56 additions & 12 deletions

File tree

custom_components/enpal_webparser/config_flow.py

Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,51 @@ async def process_user_input(hass, user_input: dict[str, Any]) -> tuple[dict[str
143143
}, {}
144144

145145

146+
def get_localized_options(hass, key: str) -> dict[str, str]:
147+
"""Get localized selector options based on user's language.
148+
149+
Args:
150+
hass: Home Assistant instance
151+
key: The option key ('setup_mode' or 'discovered_device_none')
152+
153+
Returns:
154+
Dictionary with option values and localized labels
155+
"""
156+
language = hass.config.language or "en"
157+
158+
translations = {
159+
"setup_mode": {
160+
"en": {
161+
"discover": "Auto-discover Enpal boxes on network",
162+
"manual": "Manual setup (enter URL)",
163+
},
164+
"de": {
165+
"discover": "Automatische Erkennung von Enpal-Geräten im Netzwerk",
166+
"manual": "Manuelle Einrichtung (URL eingeben)",
167+
},
168+
},
169+
"discovered_device_none": {
170+
"en": {
171+
"none": "None of these - Enter URL manually",
172+
},
173+
"de": {
174+
"none": "Keines davon - URL manuell eingeben",
175+
},
176+
},
177+
"no_devices": {
178+
"en": {
179+
"manual": "No devices found - Enter URL manually",
180+
},
181+
"de": {
182+
"manual": "Keine Geräte gefunden - URL manuell eingeben",
183+
},
184+
},
185+
}
186+
187+
# Default to English if language not found
188+
return translations.get(key, {}).get(language, translations[key]["en"])
189+
190+
146191
class EnpalConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
147192
VERSION = 1
148193

@@ -165,10 +210,9 @@ async def async_step_user(self, user_input=None):
165210
return self.async_show_form(
166211
step_id="user",
167212
data_schema=vol.Schema({
168-
vol.Required("setup_mode", default="discover"): vol.In({
169-
"discover": "Auto-discover Enpal boxes on network",
170-
"manual": "Manual setup (enter URL)",
171-
})
213+
vol.Required("setup_mode", default="discover"): vol.In(
214+
get_localized_options(self.hass, "setup_mode")
215+
),
172216
}),
173217
)
174218

@@ -209,9 +253,9 @@ async def async_step_discovery(self, user_input=None):
209253
return self.async_show_form(
210254
step_id="discovery",
211255
data_schema=vol.Schema({
212-
vol.Required("discovered_device"): vol.In({
213-
"manual": "No devices found - Enter URL manually",
214-
})
256+
vol.Required("discovered_device"): vol.In(
257+
get_localized_options(self.hass, "no_devices")
258+
),
215259
}),
216260
errors={"base": "no_devices_found"},
217261
description_placeholders={
@@ -221,7 +265,7 @@ async def async_step_discovery(self, user_input=None):
221265

222266
# Create selection dict from discovered devices
223267
device_options = {url: url for url in self._discovered_devices}
224-
device_options["manual"] = "None of these - Enter URL manually"
268+
device_options.update(get_localized_options(self.hass, "discovered_device_none"))
225269

226270
return self.async_show_form(
227271
step_id="discovery",

custom_components/enpal_webparser/translations/de.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
"step": {
44
"user": {
55
"title": "Enpal Solar Integration einrichten",
6-
"description": "Wählen Sie, wie Sie Ihre Enpal-Solaranlage einrichten möchten",
6+
"description": "Wählen Sie, wie Sie Ihre Enpal-Solaranlage einrichten möchten.\n\nHinweis: Die automatische Erkennung durchsucht Ihr Netzwerk und kann 1-2 Minuten dauern. Bitte haben Sie während des Scans Geduld.",
77
"data": {
88
"setup_mode": "Einrichtungsmethode"
99
}
1010
},
1111
"discovery": {
1212
"title": "Gefundene Enpal-Geräte",
13-
"description": "{discovered_count} Enpal-Gerät(e) in Ihrem Netzwerk gefunden. Wählen Sie Ihr Gerät aus:",
13+
"description": "{discovered_count} Gerät(e) in Ihrem Netzwerk gefunden. Wählen Sie Ihr Gerät aus:",
1414
"data": {
1515
"discovered_device": "Enpal-Gerät auswählen"
1616
}

custom_components/enpal_webparser/translations/en.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
"step": {
44
"user": {
55
"title": "Setup Enpal Solar Integration",
6-
"description": "Choose how you want to set up your Enpal solar system",
6+
"description": "Choose how you want to set up your Enpal solar system.\n\nNote: Auto-discovery will scan your network and may take 1-2 minutes. Please be patient during the scan.",
77
"data": {
88
"setup_mode": "Setup method"
99
}
1010
},
1111
"discovery": {
1212
"title": "Discovered Enpal Devices",
13-
"description": "Found {discovered_count} Enpal device(s) on your network. Select your device:",
13+
"description": "Found {discovered_count} device(s) on your network. Select your device:",
1414
"data": {
1515
"discovered_device": "Select Enpal device"
1616
}

0 commit comments

Comments
 (0)