mirror of
https://github.com/sascha-hemi/hacs_waste_collection_schedule.git
synced 2026-03-21 02:04:22 +01:00
Add ALW Wolfenbüttel as source
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
41
doc/source/alw_wf_de.md
Normal file
41
doc/source/alw_wf_de.md
Normal file
@@ -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**<br>
|
||||
*(string) (required)*
|
||||
|
||||
**strasse**<br>
|
||||
*(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).
|
||||
1
info.md
1
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)
|
||||
|
||||
Reference in New Issue
Block a user