diff --git a/custom_components/waste_collection_schedule/waste_collection_schedule/source/renoweb_dk.py b/custom_components/waste_collection_schedule/waste_collection_schedule/source/renoweb_dk.py index 55e23cbd..eb4df4bf 100644 --- a/custom_components/waste_collection_schedule/waste_collection_schedule/source/renoweb_dk.py +++ b/custom_components/waste_collection_schedule/waste_collection_schedule/source/renoweb_dk.py @@ -91,7 +91,7 @@ class Source: @property def _address_id(self) -> int: """Return the address id.""" - if not hasattr(self, "__address_id"): + if not hasattr(self, f"_{self.__class__.__name__}__address_id"): self._get_address_id() return self.__address_id @@ -110,7 +110,12 @@ class Source: response.raise_for_status() # For some reason the response is a JSON structure inside a JSON string - for entry in json.loads(response.json()["d"])["list"]: + waste_schemes = json.loads(response.json()["d"])["list"] + + if not waste_schemes: + raise ValueError("No waste schemes found, check address or address_id") + + for entry in waste_schemes: if not entry["afhentningsbestillingmateriel"] and re.search( r"dag den \d{2}-\d{2}-\d{4}", entry["toemningsdato"] ): diff --git a/doc/source/renoweb_dk.md b/doc/source/renoweb_dk.md index e9447a57..227d22ba 100644 --- a/doc/source/renoweb_dk.md +++ b/doc/source/renoweb_dk.md @@ -22,7 +22,7 @@ _(String) (required)_ The name of the municipality as it appears in the URL. E.g. https://htk.renoweb.dk/Legacy/selvbetjening/mit_affald.aspx where "htk" is for Høje-Taastrup municipality. **address** -_(String) (required)_ +_(String) (optional)_ The address to look up. It should be exactly as it is on the website until the comma between the street address and the postal code. @@ -31,6 +31,8 @@ _(Int) (optional)_ Use address_id if the address lookup fails. +_Note that while both **address** and **address_id** are optional, one of them must be supplied and if both are used, **address_id** will take precedence._ + ## Example ```yaml