diff --git a/custom_components/waste_collection_schedule/waste_collection_schedule/source/hygea_be.py b/custom_components/waste_collection_schedule/waste_collection_schedule/source/hygea_be.py new file mode 100644 index 00000000..786de44e --- /dev/null +++ b/custom_components/waste_collection_schedule/waste_collection_schedule/source/hygea_be.py @@ -0,0 +1,59 @@ +from typing import Dict +import math +import time +import json +import datetime + +from waste_collection_schedule import Collection # type: ignore[attr-defined] +import requests + +TITLE = "Hygea" +DESCRIPTION = "Source for Hygea garbage collection" +URL = "https://www.hygea.be/" +TEST_CASES = { + "Soignies": { + "street_index": "3758", + }, + "Frameries": { + "street_index": "4203", + }, + "Erquelinnes": { + "street_index": "6560", + }, +} + + +class Source: + def __init__(self, street_index): + self.street_index = street_index + + def fetch(self): + response = requests.get(f"https://www.hygea.be/displaycal.html?street={self.street_index}&start={math.trunc(time.time())}&end={math.trunc(time.time()) + 2678400}") + if not response.ok: + return [] + data = json.loads(response.text) + entries = [] + + for day in data: + if "sacvert" in day["className"]: + entries.append( + Collection( + date=datetime.datetime.strptime(day["start"], "%Y-%m-%dT%H:%M:%S%z").date(), + t="Déchets Organiques", icon="mdi:trash-can" + ) + ) + if "pmc" in day["className"]: + entries.append( + Collection( + date=datetime.datetime.strptime(day["start"], "%Y-%m-%dT%H:%M:%S%z").date(), t="PMC", + icon="mdi:recycle" + ) + ) + if "fourth" in day["className"]: + entries.append( + Collection( + date=datetime.datetime.strptime(day["start"], "%Y-%m-%dT%H:%M:%S%z").date(), + t="Papier & cartons", icon="mdi:leaf" + ) + ) + return entries diff --git a/doc/source/hygea_be.md b/doc/source/hygea_be.md new file mode 100644 index 00000000..23b2a82e --- /dev/null +++ b/doc/source/hygea_be.md @@ -0,0 +1,31 @@ +# Hygea + +Support for schedules provided by [hygea.be](https://www.hygea.be/). + +## Configuration via configuration.yaml + +```yaml +waste_collection_schedule: + sources: + - name: hygea_id + args: + street_id: ID +``` + +You id can be found in the url when visiting the [the calendar](https://www.hygea.be/votre-calendrier-de-collecte.html) for your street. +It may also work by giving it your post code, but this "api" is a mess so only do that if you have no other choice + +### Configuration Variables + +**street_id**
+*(string) (required)* + +## Example + +```yaml +waste_collection_schedule: + sources: + - name: hygea_id + args: + street_id: 3758 +``` \ No newline at end of file