Skip to content

Commit d29f0b2

Browse files
committed
Bugfix translations and hassfest
1 parent a238235 commit d29f0b2

3 files changed

Lines changed: 8 additions & 40 deletions

File tree

custom_components/enpal_webparser/config_flow.py

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
from homeassistant.core import callback
2828
from homeassistant.helpers import config_validation as cv
2929
from homeassistant.helpers.aiohttp_client import async_get_clientsession
30-
from homeassistant.helpers import translation
3130

3231
from .discovery import discover_enpal_devices, quick_discover_enpal_devices
3332
from .wallbox_api import WallboxApiClient
@@ -152,17 +151,6 @@ def __init__(self):
152151
super().__init__()
153152
self._discovered_devices = []
154153
self._discovery_running = False
155-
self._translations = None
156-
157-
async def _get_translation(self, key: str, default: str) -> str:
158-
"""Get translation for a key with fallback to default."""
159-
if self._translations is None:
160-
self._translations = await translation.async_get_translations(
161-
self.hass, self.hass.config.language, "config", {DOMAIN}
162-
)
163-
164-
full_key = f"component.{DOMAIN}.config.step.discovery_options.{key}"
165-
return self._translations.get(full_key, default)
166154

167155
async def async_step_user(self, user_input=None):
168156
"""Handle the initial step - choose between manual and auto-discovery."""
@@ -174,16 +162,12 @@ async def async_step_user(self, user_input=None):
174162
elif user_input.get("setup_mode") == "discover":
175163
return await self.async_step_discovery()
176164

177-
# Get translated strings for options
178-
discover_text = await self._get_translation("discover", "Auto-discover Enpal boxes on network")
179-
manual_text = await self._get_translation("manual", "Manual setup (enter URL)")
180-
181165
return self.async_show_form(
182166
step_id="user",
183167
data_schema=vol.Schema({
184168
vol.Required("setup_mode", default="discover"): vol.In({
185-
"discover": discover_text,
186-
"manual": manual_text,
169+
"discover": "Auto-discover Enpal boxes on network",
170+
"manual": "Manual setup (enter URL)",
187171
})
188172
}),
189173
)
@@ -221,13 +205,12 @@ async def async_step_discovery(self, user_input=None):
221205
# Show discovery results
222206
if not self._discovered_devices:
223207
_LOGGER.warning("[Enpal] No Enpal devices discovered")
224-
no_devices_text = await self._get_translation("no_devices", "No devices found - Enter URL manually")
225208

226209
return self.async_show_form(
227210
step_id="discovery",
228211
data_schema=vol.Schema({
229212
vol.Required("discovered_device"): vol.In({
230-
"manual": no_devices_text,
213+
"manual": "No devices found - Enter URL manually",
231214
})
232215
}),
233216
errors={"base": "no_devices_found"},
@@ -238,8 +221,7 @@ async def async_step_discovery(self, user_input=None):
238221

239222
# Create selection dict from discovered devices
240223
device_options = {url: url for url in self._discovered_devices}
241-
none_of_these_text = await self._get_translation("none_of_these", "None of these - Enter URL manually")
242-
device_options["manual"] = none_of_these_text
224+
device_options["manual"] = "None of these - Enter URL manually"
243225

244226
return self.async_show_form(
245227
step_id="discovery",
@@ -303,6 +285,10 @@ async def async_step_configure(self, user_input=None):
303285
errors["use_wallbox_addon"] = "wallbox_unreachable"
304286

305287
if not errors:
288+
# Set unique_id based on URL to prevent duplicate entries
289+
await self.async_set_unique_id(self._url)
290+
self._abort_if_unique_id_configured()
291+
306292
return self.async_create_entry(
307293
title="Enpal Webparser",
308294
data={"use_options_flow": True},

custom_components/enpal_webparser/translations/de.json

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
"description": "Wählen Sie, wie Sie Ihre Enpal-Solaranlage einrichten möchten",
77
"data": {
88
"setup_mode": "Einrichtungsmethode"
9-
},
10-
"data_description": {
11-
"setup_mode": "Wählen Sie zwischen automatischer Erkennung oder manueller Eingabe"
129
}
1310
},
1411
"discovery": {
@@ -18,12 +15,6 @@
1815
"discovered_device": "Enpal-Gerät auswählen"
1916
}
2017
},
21-
"discovery_options": {
22-
"discover": "Automatische Erkennung im Netzwerk",
23-
"manual": "Manuelle Einrichtung (URL eingeben)",
24-
"none_of_these": "Keines davon - URL manuell eingeben",
25-
"no_devices": "Keine Geräte gefunden - URL manuell eingeben"
26-
},
2718
"manual": {
2819
"title": "Manuelle Einrichtung",
2920
"description": "Geben Sie die URL der Web-Oberfläche Ihres Enpal-Geräts ein",

custom_components/enpal_webparser/translations/en.json

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
"description": "Choose how you want to set up your Enpal solar system",
77
"data": {
88
"setup_mode": "Setup method"
9-
},
10-
"data_description": {
11-
"setup_mode": "Choose between automatic discovery or manual entry"
129
}
1310
},
1411
"discovery": {
@@ -18,12 +15,6 @@
1815
"discovered_device": "Select Enpal device"
1916
}
2017
},
21-
"discovery_options": {
22-
"discover": "Auto-discover Enpal boxes on network",
23-
"manual": "Manual setup (enter URL)",
24-
"none_of_these": "None of these - Enter URL manually",
25-
"no_devices": "No devices found - Enter URL manually"
26-
},
2718
"manual": {
2819
"title": "Manual Setup",
2920
"description": "Enter the URL of your Enpal device's web interface",

0 commit comments

Comments
 (0)