mirror of
https://github.com/sascha-hemi/hacs_waste_collection_schedule.git
synced 2026-03-21 03:04:09 +01:00
Add support for hygea.be (#90)
* feat: add support for hygea * chore: renamaed hygea to follow the rule * fix: impossible to import and added icons * fix: datetime instead of date * fix: range instead of data * fix: data instead of day * fix: handling bad response * fix: 'Déchets residuels' not working properly * fix: 'Déchets residuels' not working properly * disabled 'Dechets residuels' because it is not returned by the api * doc: add documentation Co-authored-by: Tim Simon <tim@mirahi.io>
This commit is contained in:
@@ -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
|
||||
31
doc/source/hygea_be.md
Normal file
31
doc/source/hygea_be.md
Normal file
@@ -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**<br>
|
||||
*(string) (required)*
|
||||
|
||||
## Example
|
||||
|
||||
```yaml
|
||||
waste_collection_schedule:
|
||||
sources:
|
||||
- name: hygea_id
|
||||
args:
|
||||
street_id: 3758
|
||||
```
|
||||
Reference in New Issue
Block a user