diff --git a/custom_components/waste_collection_schedule/waste_collection_schedule/source/awido_de.py b/custom_components/waste_collection_schedule/waste_collection_schedule/source/awido_de.py index f99c8c910..8ec97389d 100644 --- a/custom_components/waste_collection_schedule/waste_collection_schedule/source/awido_de.py +++ b/custom_components/waste_collection_schedule/waste_collection_schedule/source/awido_de.py @@ -223,6 +223,12 @@ def EXTRA_INFO(): ] TEST_CASES = { + "coburg rödental krötenleite 4": { + "customer": "coburg", + "city": "rödental", + "street": "krötenleite", + "housenumber": 4, + }, "Schorndorf, Miedelsbacher Straße 30 /1": { "customer": "rmk", "city": "Schorndorf", @@ -276,14 +282,20 @@ class JSONNotSupported(Exception): class Source: - def __init__(self, customer, city, street=None, housenumber=None): - self._customer = customer - self._city = city - self._street = street - self._housenumber = None if housenumber is None else str(housenumber) + def __init__( + self, + customer: str, + city: str, + street: str | None = None, + housenumber: str | int | None = None, + ): + self._customer = customer.lower() + self._city = city.lower() + self._street = street.lower() if street else None + self._housenumber = None if housenumber is None else str(housenumber).lower() self._ics = ICS() - def fetch(self): + def fetch(self) -> list[Collection]: # Retrieve list of places r = requests.get( f"https://awido.cubefour.de/WebServices/Awido.Service.svc/secure/getPlaces/client={self._customer}" @@ -292,10 +304,14 @@ def fetch(self): places = r.json() # create city to key map from retrieved places - city_to_oid = {place["value"].strip(): place["key"] for (place) in places} + city_to_oid = { + place["value"].strip().lower(): place["key"] for (place) in places + } if self._city not in city_to_oid: - raise Exception(f"city not found: {self._city}") + raise Exception( + f"city not found: {self._city}, use one of: {list(city_to_oid.keys())}" + ) oid = city_to_oid[self._city] @@ -323,11 +339,13 @@ def fetch(self): # create street to key map from retrieved places street_to_oid = { - street["value"].strip(): street["key"] for (street) in streets + street["value"].strip().lower(): street["key"] for (street) in streets } if self._street not in street_to_oid: - raise Exception(f"street not found: {self._street}") + raise Exception( + f"street not found: {self._street}, use one of {list(street_to_oid.keys())}" + ) oid = street_to_oid[self._street] @@ -341,13 +359,22 @@ def fetch(self): # create housenumber to key map from retrieved places hsnbr_to_oid = { - hsnbr["value"].strip(): hsnbr["key"] for (hsnbr) in hsnbrs + hsnbr["value"].strip().lower(): hsnbr["key"] for (hsnbr) in hsnbrs } - - if self._housenumber not in hsnbr_to_oid: - raise Exception(f"housenumber not found: {self._housenumber}") - - oid = hsnbr_to_oid[self._housenumber] + if ( + len(hsnbr_to_oid) == 0 + or len(hsnbr_to_oid) == 1 + and "" in hsnbr_to_oid + ): + _LOGGER.warning( + "No housenumbers found for street, using street only" + ) + else: + if self._housenumber not in hsnbr_to_oid: + raise Exception( + f"housenumber not found: {self._housenumber}, use one of {list(hsnbr_to_oid.keys())}" + ) + oid = hsnbr_to_oid[self._housenumber] try: return self.get_json_data(oid)