diff --git a/README.md b/README.md index 0d793bf7..40871442 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,7 @@ Currently the following service providers are supported: - [AbfallNavi.de (RegioIT.de)](./doc/source/abfallnavi_de.md) - [Abfallkalender Würzburg](./doc/source/wuerzburg_de.md) - [Abfallwirtschaft Landkreis Harburg](./doc/source/aw_harburg_de.md) +- [Abfallwirtschaft Landkreis Wolfenbüttel](./doc/source/alw_wf_de.md) - [Abfallwirtschaft Rendsburg](./doc/source/awr_de.md) - [Abfallwirtschaft Stuttgart](./doc/source/stuttgart_de.md) - [Abfallwirtschaft Südholstein](./doc/source/awsh_de.md) diff --git a/custom_components/waste_collection_schedule/waste_collection_schedule/source/alw_wf_de.py b/custom_components/waste_collection_schedule/waste_collection_schedule/source/alw_wf_de.py new file mode 100644 index 00000000..0d7504ce --- /dev/null +++ b/custom_components/waste_collection_schedule/waste_collection_schedule/source/alw_wf_de.py @@ -0,0 +1,98 @@ +import datetime +import json +import pytz +import logging + +import requests +from waste_collection_schedule import Collection # type: ignore[attr-defined] + +TITLE = "ALW Wolfenbüttel" +DESCRIPTION = "Source for ALW Wolfenbüttel." +URL = "https://abfallapp.alw-wf.de" +TEST_CASES = { + "Linden alte Straße": {"ort": "Linden mit Okertalsiedlung", "strasse": "Siedlung"}, + "Linden neuere Straße": {"ort": "Linden mit Okertalsiedlung", "strasse": "Kleingartenweg"}, + "Dettum": {"ort": "Dettum", "strasse": "Egal!"}, +} + +AUTH_DATA = { + "auth": { + "Name": "ALW", + "Version": "2.0", + "AuthKey": "ALW", + "DeviceID": "ALW", + "Username": "ALW", + "Password": "ALW", + }, + "request": {} +} +ALL_STREETS = "Alle Straßen" +BIN_TYPE_NORMAL = "0" + +class Source: + def __init__(self, ort, strasse): + self._ort = ort + self._strasse = strasse + + def fetch(self): + auth_params = json.dumps(AUTH_DATA) + + # ALW WF uses a self-signed certificate so we need to disable certificate verification + r = requests.post(f"{URL}/GetOrte.php", data=auth_params, verify=False) + orte = r.json() + if orte["result"][0]["StatusCode"] != 200: + _LOGGER.error(f"Error getting Orte: {orte['result'][0]['StatusMsg']}") + return [] + orte = orte["result"][0]["result"] + orte = {i["Name"]: i["ID"] for i in orte} + ort_id = orte.get(self._ort, None) + + if ort_id == None: + _LOGGER.error(f"Error finding Ort {self._ort}") + return [] + + r = requests.post(f"{URL}/GetStrassen.php", data=auth_params, verify=False) + strassen = r.json() + if strassen["result"][0]["StatusCode"] != 200: + _LOGGER.error(f"Error getting Straßen: {strassen['result'][0]['StatusMsg']}") + return [] + strassen = strassen["result"][0]["result"] + strasse_id = None + for strasse in strassen: + if strasse["OrtID"] != ort_id: + continue + if strasse["Name"] == ALL_STREETS or strasse["Name"] == self._strasse: + strasse_id = strasse["ID"] + break + continue + + if strasse_id == None: + _LOGGER.error(f"Error finding Straße {self._strasse}") + return [] + + r = requests.post(f"{URL}/GetArten.php", data=auth_params, verify=False) + arten = r.json() + if arten["result"][0]["StatusCode"] != 200: + _LOGGER.error(f"Error getting Arten: {arten['result'][0]['StatusMsg']}") + return [] + arten = arten["result"][0]["result"] + arten = [i for i in arten if i["Art"] == BIN_TYPE_NORMAL] + arten = {int(i["Wertigkeit"]): i["Name"] for i in arten} + + entries = [] + r = requests.post(f"{URL}/GetTermine.php/{strasse_id}", data=auth_params, verify=False) + termine = r.json() + if termine["result"][0]["StatusCode"] != 200: + _LOGGER.error(f"Error getting Termine: {termine['result'][0]['StatusMsg']}") + return [] + termine = termine["result"][0]["result"] + for termin in termine: + ts = int(termin["DatumLong"])/1000 + # Timestamps are unix with milliseconds but not UTC... + date = datetime.datetime.fromtimestamp(ts, tz=pytz.timezone("Europe/Berlin")).date() + types = int(termin["Abfallwert"]) + for art in arten: + if types & art: + entries.append(Collection(date, arten[art], date)) + + return entries diff --git a/doc/source/alw_wf_de.md b/doc/source/alw_wf_de.md new file mode 100644 index 00000000..ef71cb3d --- /dev/null +++ b/doc/source/alw_wf_de.md @@ -0,0 +1,41 @@ +# ALW Wolfenbüttel + +Support for schedules provided by [ALW Wolfenbüttel](https://www.alw-wf.de//), Germany. + +## Configuration via configuration.yaml + +```yaml +waste_collection_schedule: + sources: + - name: alw_wf_de + args: + ort: ORT + strasse: STRASSE +``` + +### Configuration Variables + +**ort**
+*(string) (required)* + +**strasse**
+*(string) (required)* + +## Example + +```yaml +waste_collection_schedule: + sources: + - name: alw_wf_de + args: + ort: "Linden mit Okertalsiedlung" + strasse: "Am Buschkopf" +``` + +## How to get the source arguments + +1. Go to the calendar at https://www.alw-wf.de/index.php/abfallkalender. +2. Select your location in the drop down menus. + - Notice: The page reloads after selecting `Ort`, so wait for that before selecting `Straße`. +3. Copy the **exact** values from the 2 drop down menus as `ort` and `strasse` in the source configuration. + - In case you can only select the street `Alle Straßen`, then the `strasse` option does not matter (it is still required, just set it to something). diff --git a/info.md b/info.md index e2f2f346..b1cfc5fc 100644 --- a/info.md +++ b/info.md @@ -68,6 +68,7 @@ Currently the following service providers are supported: - [AbfallNavi.de (RegioIT.de)](https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/abfallnavi_de.md) - [Abfallkalender Würzburg](https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/wuerzburg_de.md) - [Abfallwirtschaft Landkreis Harburg](https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/aw_harburg_de.md) +- [Abfallwirtschaft Landkreis Wolfenbüttel](https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/alw_wf_de.md) - [Abfallwirtschaft Rendsburg](https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/awr_de.md) - [Abfallwirtschaft Stuttgart](https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/stuttgart_de.md) - [Abfallwirtschaft Südholstein](https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/awsh_de.md)