improve hvcgroep source to support other dutch services

This commit is contained in:
mampfes
2022-12-24 09:32:13 +01:00
parent 1db8badf72
commit d419c273d9
4 changed files with 99 additions and 21 deletions

View File

@@ -146,8 +146,8 @@ Currently the following service providers are supported:
### Netherlands
- [HVCGroep and others](./doc/source/hvcgroep_nl.md)
- [Ximmio](./doc/source/ximmio_nl.md)
- [HVCGroep](./doc/source/hvcgroep_nl.md)
### New Zealand

View File

@@ -1,4 +1,3 @@
import json
import logging
from datetime import datetime
@@ -8,13 +7,52 @@ from waste_collection_schedule import Collection # type: ignore[attr-defined]
TITLE = "HVCGroep"
DESCRIPTION = "Source for the Dutch HVCGroep waste management."
URL = "https://www.hvcgroep.nl/zelf-regelen/afvalkalender"
TEST_CASES = {"Tollebeek": {"postal_code": "8309AV", "house_number": "1"}}
TEST_CASES = {
"Tollebeek": {"postal_code": "8309AV", "house_number": "1"},
"Hvgroep: Tollebeek": {
"postal_code": "8309AV",
"house_number": "1",
"service": "hvcgroep",
},
"Cyclus": {"postal_code": "2841ML", "house_number": "1090", "service": "cyclusnv"},
"Mjinblink": {
"postal_code": "5741BV",
"house_number": "76",
"service": "mjinblink",
},
}
_LOGGER = logging.getLogger(__name__)
SERVICE_MAP = {
"alphenaandenrijn": "https://afvalkalender.alphenaandenrijn.nl",
"cranendonck": "https://afvalkalender.cranendonck.nl",
"cyclusnv": "https://afvalkalender.cyclusnv.nl",
"dar": "https://afvalkalender.dar.nl",
"denhaag": "https://huisvuilkalender.denhaag.nl",
"gad": "https://inzamelkalender.gad.nl",
"gemeenteberkelland": "https://afvalkalender.gemeenteberkelland.nl",
"hvcgroep": "https://inzamelkalender.hvcgroep.nl",
"lingewaard": "https://afvalwijzer.lingewaard.nl",
"middelburgvlissingen": "https://afvalwijzer.middelburgvlissingen.nl",
"mijnblink": "https://mijnblink.nl",
"peelenmaas": "https://afvalkalender.peelenmaas.nl",
"prezero": "https://inzamelwijzer.prezero.nl",
"purmerend": "https://afvalkalender.purmerend.nl",
"rmn": "https://inzamelschema.rmn.nl",
"schouwen-duiveland": "https://afvalkalender.schouwen-duiveland.nl",
"spaarnelanden": "https://afvalwijzer.spaarnelanden.nl",
"stadswerk072": "https://www.stadswerk072.nl",
"sudwestfryslan": "https://afvalkalender.sudwestfryslan.nl",
"venray": "https://afvalkalender.venray.nl",
"voorschoten": "https://afvalkalender.voorschoten.nl",
"waalre": "https://afvalkalender.waalre.nl",
"zrd": "https://afvalkalender.zrd.nl",
}
class Source:
def __init__(self, postal_code, house_number):
def __init__(self, postal_code, house_number, service="hvcgroep"):
self.postal_code = postal_code
self.house_number = house_number
self.icons = {
@@ -23,15 +61,14 @@ class Source:
"papier-en-karton": "mdi:archive",
"restafval": "mdi:trash-can",
}
self._url = SERVICE_MAP[service]
def fetch(self):
bag_id = 0
# Retrieve bagid (unique waste management identifier)
r = requests.get(
f"https://inzamelkalender.hvcgroep.nl/adressen/{self.postal_code}:{self.house_number}"
)
data = json.loads(r.text)
r = requests.get(f"{self._url}/adressen/{self.postal_code}:{self.house_number}")
r.raise_for_status()
data = r.json()
# Something must be wrong, maybe the address isn't valid? No need to do the extra requests so just return here.
if len(data) == 0:
@@ -41,16 +78,14 @@ class Source:
bag_id = data[0]["bagid"]
# Retrieve the details about different waste management flows (for example, paper, plastic etc.)
r = requests.get(
f"https://inzamelkalender.hvcgroep.nl/rest/adressen/{bag_id}/afvalstromen"
)
waste_flows = json.loads(r.text)
r = requests.get(f"{self._url}/rest/adressen/{bag_id}/afvalstromen")
r.raise_for_status()
waste_flows = r.json()
# Retrieve the coming pickup dates for waste.
r = requests.get(
f"https://inzamelkalender.hvcgroep.nl/rest/adressen/{bag_id}/ophaaldata"
)
data = json.loads(r.text)
r = requests.get(f"{self._url}/rest/adressen/{bag_id}/ophaaldata")
r.raise_for_status()
data = r.json()
entries = []

View File

@@ -1,6 +1,6 @@
# HVCGroep
Support for schedules provided by [hvcgroep.nl](https://www.hvcgroep.nl/).
Support for schedules provided by [hvcgroep.nl](https://www.hvcgroep.nl/) and other Dutch municipalities.
## Configuration via configuration.yaml
@@ -11,23 +11,66 @@ waste_collection_schedule:
args:
postal_code: POSTAL_CODE
house_number: HOUSE_NUMBER
service: SERVICE
```
### Configuration Variables
**postal_code**<br>
**postal_code**
*(string) (required)*
**house_number**<br>
**house_number**
*(string) (required)*
**service**
*(string) (optional, default="hvcgroep")*
Use one of the following codes as service code:
- alphenaandenrijn
- cranendonck
- cyclusnv
- dar
- denhaag
- gad
- gemeenteberkelland
- hvcgroep
- lingewaard
- middelburgvlissingen
- mijnblink
- peelenmaas
- prezero
- purmerend
- rmn
- schouwen-duiveland
- spaarnelanden
- stadswerk072
- sudwestfryslan
- venray
- voorschoten
- waalre
- zrd
## Example
```yaml
# hvgroep
waste_collection_schedule:
sources:
- name: hvcgroep_nl
args:
postal_code: 1713VM
house_number: 1
service: hvxgroep
```
```yaml
# cyclusnv
waste_collection_schedule:
sources:
- name: hvcgroep_nl
args:
postal_code: 2841ML
house_number: 1090
service: cyclusnv
```

View File

@@ -131,8 +131,8 @@ Currently the following service providers are supported:
### Netherlands
- [HVCGroep and others](https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/hvcgroep_nl.md)
- [Ximmio](https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/ximmio_nl.md)
- [HVCGroep](https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/hvcgroep_nl.md)
### New Zealand