From 361cb4ec19a3bb4217340edf18587b16c1b5b69e Mon Sep 17 00:00:00 2001 From: r-poulsen <2556678+r-poulsen@users.noreply.github.com> Date: Wed, 21 Feb 2024 17:19:34 +0100 Subject: [PATCH] renoweb dk (#1817) * Added renoweb.dk * README.md updated * info.md updated * requested modifications * requested modifications * reformatting * Better error handling, issue with using address_id fixed --------- Co-authored-by: Rune <{ID}+{username}@users.noreply.github.com> Co-authored-by: 5ila5 <5ila5@users.noreply.github.com> --- .../waste_collection_schedule/source/renoweb_dk.py | 9 +++++++-- doc/source/renoweb_dk.md | 4 +++- 2 files changed, 10 insertions(+), 3 deletions(-) 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