Skip to content

Commit 7af1681

Browse files
committed
API Key checks: #20
1 parent 0314131 commit 7af1681

18 files changed

Lines changed: 28 additions & 289 deletions

File tree

custom_components/liebherr/config_flow.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Config flow for Liebherr Integration."""
22

33
from collections.abc import Mapping
4+
import re
45
from typing import Any
56

67
from pyliebherr import LiebherrAPI, LiebherrDevice
@@ -145,13 +146,16 @@ async def async_step_user(
145146

146147
if user_input is not None:
147148
# check the API key
148-
api: LiebherrAPI = LiebherrAPI(user_input[CONF_API_KEY])
149-
devices: list[LiebherrDevice] = []
150-
try:
151-
devices = await api.async_get_appliances()
152-
except LiebherrAuthException:
153-
errors["base"] = "auth_error"
154-
await api.async_close()
149+
if not re.fullmatch("^\\S.*\\S$", user_input[CONF_API_KEY]):
150+
errors[CONF_API_KEY] = "whitespace_api_key"
151+
else:
152+
api: LiebherrAPI = LiebherrAPI(user_input[CONF_API_KEY])
153+
devices: list[LiebherrDevice] = []
154+
try:
155+
devices = await api.async_get_appliances()
156+
except LiebherrAuthException:
157+
errors["base"] = "auth_error"
158+
await api.async_close()
155159
if not errors:
156160
await self.async_set_unique_id(f"{DOMAIN}_{user_input[CONF_API_KEY]}")
157161
self._abort_if_unique_id_configured()
@@ -181,9 +185,7 @@ async def async_step_user(
181185
return self.async_abort(reason="invalid_source")
182186

183187
data_schema: vol.Schema = vol.Schema(
184-
{
185-
vol.Required(CONF_API_KEY): TextSelector(),
186-
}
188+
{vol.Required(CONF_API_KEY): vol.All(TextSelector())}
187189
)
188190
return self.async_show_form(
189191
step_id="user", data_schema=data_schema, errors=errors

custom_components/liebherr/entity.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import logging
44

5-
from pyliebherr import LiebherrControl, LiebherrDevice
6-
from pyliebherr.models import ControlType, LiebherrMappedControls
5+
from pyliebherr import ControlType, LiebherrControl, LiebherrDevice
6+
from pyliebherr.models import LiebherrMappedControls
77

88
from homeassistant.helpers.device_registry import DeviceInfo
99
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback

custom_components/liebherr/strings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
}
1616
},
1717
"error": {
18-
"auth_error": "[%key:common::config_flow::error::invalid_api_key%]"
18+
"auth_error": "[%key:common::config_flow::error::invalid_api_key%]",
19+
"whitespace_api_key": "There is whitespace before or after the api key."
1920
},
2021
"abort": {
2122
"already_configured": "API Key already configured.",

custom_components/liebherr/translations/ar.json

Lines changed: 0 additions & 30 deletions
This file was deleted.

custom_components/liebherr/translations/de.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
}
1616
},
1717
"error": {
18-
"auth_error": "API-Schlüssel ist nicht autorisiert oder ungültig."
18+
"auth_error": "API-Schlüssel ist nicht autorisiert oder ungültig.",
19+
"whitespace_api_key": "There is whitespace before or after the api key."
1920
},
2021
"abort": {
2122
"already_configured": "HomeAPI-Schlüssel bereits konfiguriert.",

custom_components/liebherr/translations/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
}
1616
},
1717
"error": {
18-
"auth_error": "API Key is unauthorized or invalid."
18+
"auth_error": "API Key is unauthorized or invalid.",
19+
"whitespace_api_key": "There is whitespace before or after the api key."
1920
},
2021
"abort": {
2122
"already_configured": "API Key already configured.",

custom_components/liebherr/translations/es.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
}
1111
},
1212
"error": {
13-
"auth_error": "Clavo API no autorizado o inválido."
13+
"auth_error": "Clavo API no autorizado o inválido.",
14+
"whitespace_api_key": "Hay espacio en blanco antes o detras del Clavo API."
1415
},
1516
"abort": {
1617
"already_configured": "Clavo API ya configurada.",

custom_components/liebherr/translations/fr.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
}
1616
},
1717
"error": {
18-
"auth_error": "Clé API non autorisée ou invalide."
18+
"auth_error": "Clé API non autorisée ou invalide.",
19+
"whitespace_api_key": "There is whitespace before or after the api key."
1920
},
2021

2122
"abort": {

custom_components/liebherr/translations/hu.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
}
1616
},
1717
"error": {
18-
"auth_error": "API Key nincs engedélyezve vagy érvénytelen."
18+
"auth_error": "API Key nincs engedélyezve vagy érvénytelen.",
19+
"whitespace_api_key": "There is whitespace before or after the api key."
1920
},
2021
"abort": {
2122
"already_configured": "API Key már konfigurálva.",

custom_components/liebherr/translations/it.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
}
1616
},
1717
"error": {
18-
"auth_error": "API Key non autorizzata o invalida."
18+
"auth_error": "API Key non autorizzata o invalida.",
19+
"whitespace_api_key": "There is whitespace before or after the api key."
1920
},
2021
"abort": {
2122
"already_configured": "API Key già configurata.",

0 commit comments

Comments
 (0)