Skip to content

Commit

Permalink
fix: handle parcel lockers without air quality data (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
ceski23 authored Feb 3, 2024
1 parent c725364 commit 295e214
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
16 changes: 13 additions & 3 deletions custom_components/inpost_air/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,17 @@ async def validate_input(hass: HomeAssistant, data: dict[str, Any]) -> dict[str,
Data has the keys from STEP_USER_DATA_SCHEMA with values provided by the user.
"""
parcel_locker = await InPostApi(hass).search_parcel_locker(
data[CONF_PARCEL_LOCKER_ID]
)
api_client = InPostApi(hass)
parcel_locker = await api_client.search_parcel_locker(data[CONF_PARCEL_LOCKER_ID])

if parcel_locker is None:
raise UnknownParcelLocker

try:
await api_client.find_parcel_locker_id(parcel_locker)
except Exception:
raise ParcelLockerWithoutAirData

return parcel_locker


Expand All @@ -56,6 +60,8 @@ async def async_step_user(
self._abort_if_unique_id_configured()
except UnknownParcelLocker:
errors["base"] = "unknown_parcel_locker"
except ParcelLockerWithoutAirData:
errors["base"] = "parcel_locker_no_data"
else:
return self.async_create_entry(
title=f"Parcel locker {parcel_locker['n']}", data=parcel_locker
Expand All @@ -70,3 +76,7 @@ async def async_step_user(

class UnknownParcelLocker(HomeAssistantError):
"""Parcel locker with that ID doesn't exist."""


class ParcelLockerWithoutAirData(HomeAssistantError):
"""Parcel locker with that ID doesn't have air data."""
3 changes: 2 additions & 1 deletion custom_components/inpost_air/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
}
},
"error": {
"unknown_parcel_locker": "Couldn't find parcel locker with this ID"
"unknown_parcel_locker": "Couldn't find parcel locker with this ID",
"parcel_locker_no_data": "This parcel locker doesn't have air quality data"
},
"abort": {
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]"
Expand Down
1 change: 1 addition & 0 deletions custom_components/inpost_air/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"already_configured": "Device is already configured"
},
"error": {
"parcel_locker_no_data": "This parcel locker doesn't have air quality data",
"unknown_parcel_locker": "Couldn't find parcel locker with this ID"
},
"step": {
Expand Down
3 changes: 2 additions & 1 deletion custom_components/inpost_air/translations/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"already_configured": "Urządzenie jest już skonfigurowane"
},
"error": {
"unknown_parcel_locker": "Nie udało się znaleźć paczkomatu z tym kodem"
"unknown_parcel_locker": "Nie udało się znaleźć paczkomatu z tym kodem",
"parcel_locker_no_data": "Ten paczkomat nie udostępnia danych o jakości powietrza"
},
"step": {
"user": {
Expand Down

0 comments on commit 295e214

Please sign in to comment.