From 151163ff924306eed077f33a4aaad82149e53b7c Mon Sep 17 00:00:00 2001 From: dm82m Date: Sat, 12 Nov 2022 21:23:41 +0100 Subject: [PATCH] #427: added support for infeo.at and tested with customer bogenschuetz-entsorgung.de --- README.md | 1 + .../source/infeo_at.py | 103 ++++++++++++++++++ doc/source/infeo_at.md | 54 +++++++++ info.md | 1 + 4 files changed, 159 insertions(+) create mode 100644 custom_components/waste_collection_schedule/waste_collection_schedule/source/infeo_at.py create mode 100644 doc/source/infeo_at.md diff --git a/README.md b/README.md index 8bf478ac..83f8812e 100644 --- a/README.md +++ b/README.md @@ -99,6 +99,7 @@ Currently the following service providers are supported: - [AWBKoeln.de](./doc/source/awbkoeln_de.md) - [AWIDO-online.de](./doc/source/awido_de.md) - [Berlin-Recycling.de](./doc/source/berlin_recycling_de.md) +- [Bogenschuetz-Entsorgung.de](./doc/source/infeo_at.md) - [BSR.de / Berliner Stadtreinigungsbetriebe](./doc/source/bsr_de.md) - [C-Trace.de](./doc/source/c_trace_de.md) - [Cochem-Zell](./doc/source/cochem_zell_online_de.md) diff --git a/custom_components/waste_collection_schedule/waste_collection_schedule/source/infeo_at.py b/custom_components/waste_collection_schedule/waste_collection_schedule/source/infeo_at.py new file mode 100644 index 00000000..b9201e8f --- /dev/null +++ b/custom_components/waste_collection_schedule/waste_collection_schedule/source/infeo_at.py @@ -0,0 +1,103 @@ +import json +import logging +import requests +from waste_collection_schedule import Collection # type: ignore[attr-defined] +from waste_collection_schedule.service.ICS import ICS + +_LOGGER = logging.getLogger(__name__) + +TITLE = "INFEO" +DESCRIPTION = "Source for INFEO waste collection." +URL = "https://www.infeo.at/" +TEST_CASES = {"Bogenschütz": {"customer": "bogenschütz", "zone": "Dettenhausen"}} + + +class Source: + def __init__(self, customer, zone): + self._customer = customer + self._zone = zone + self._ics = ICS() + + def fetch(self): + baseUrl = f"https://services.infeo.at/awm/api/{self._customer}/wastecalendar" + issueUrl = "https://github.com/mampfes/hacs_waste_collection_schedule/issues/new" + + params = { + "showUnpublishedCalendars": "false", + } + + # get the available published calendar years + url = f"{baseUrl}/calendars" + response = requests.get(url, params=params) + + # data validation + if(response.status_code != 200): + _LOGGER.error(f"problems during api calendar year access, please file an issue at {issueUrl} and mention @dm82m and add this: {response.text}") + return [] + + response = response.json() + if len(response) <= 0: + _LOGGER.error(f"no calendars found, please file an issue at {issueUrl} and mention @dm82m") + return [] + + entries = [] + + # loop over each calendar year entry and extract data + for calendarYear in response: + calendarYearId = calendarYear["id"] + calendarYearName = calendarYear["name"] + + params = { + "calendarId": calendarYearId, + } + + # get available zones for calendar year + url = f"{baseUrl}/zones" + response = requests.get(url, params=params) + + # data validation + if(response.status_code != 200): + _LOGGER.error(f"problems during api zones for calendar year access, please file an issue at {issueUrl} and mention @dm82m and add this: {response.text}") + return [] + + response = response.json() + if len(response) <= 0: + _LOGGER.warning(f"no zones found for calendar year {calendarYearName}, continuing with next calendar year ...") + continue + + zoneId = 0 + + # try to find the configured and matching zone + for zone in response: + if self._zone in zone["name"]: + zoneId = zone["id"] + + if zoneId == 0: + _LOGGER.warning(f"zone '{self._zone}' not found in calendar year {calendarYearName}, continuing with next calendar year ...") + continue + + params = { + "calendarId": calendarYearId, + "zoneId": zoneId, + "outputType": "ical", + } + + # get ical data for year and zone + url = f"{baseUrl}/v2/export" + response = requests.get(url, params=params) + + # data validation + if(response.status_code != 200): + _LOGGER.error(f"problems during api ical data for zone in calendar year, please file an issue at {issueUrl} and mention @dm82m and add this: {response.text}") + return [] + + dates = self._ics.convert(response.text) + + for d in dates: + entries.append(Collection(d[0], d[1])) + + # validate that we processed some data and show an error if not + if len(entries) <= 0: + _LOGGER.error(f"we were not able to get any waste entries for you! please file an issue at {issueUrl} and mention @dm82m and add this zone: '{self._zone}'") + + return entries diff --git a/doc/source/infeo_at.md b/doc/source/infeo_at.md new file mode 100644 index 00000000..d79958f4 --- /dev/null +++ b/doc/source/infeo_at.md @@ -0,0 +1,54 @@ +# INFEO based services + +INFEO is a platform for waste schedules, which has several German, Austrian and Swiss cities and districts as customers. The homepage of the company is https://www.infeo.at/. + +## Configuration via configuration.yaml + +```yaml +waste_collection_schedule: + sources: + - name: infeo_at + args: + customer: CUSTOMER + zone: ZONE +``` + +### Configuration Variables + +**customer**
+*(string) (required)* + +**zone**
+*(string) (required)* + +## Example + +```yaml +waste_collection_schedule: + sources: + - name: infeo_at + args: + customer: bogenschütz + zone: "Rottenburg (Bezirk 2; Baisingen; Ergenzingen)" +``` + +## How to get the source arguments + +### customer + +Approved list of customers (2022-11-13): + +- `bogenschütz`: Bogenschuetz-Entsorgung.de + +If your provider is also using infeo.at you can just try to use the name of your provider as customer. If you have any troubles please file an issue [here](https://github.com/mampfes/hacs_waste_collection_schedule/issues/new) and mention `@dm82m`. + +### zone + +#### Bogenschuetz-Entsorgung.de +- Go to your calendar at `https://www.bogenschuetz-entsorgung.de/images/wastecal/index-zone.html`. +- Leave the year as it is and select the zone of your choice. +- Copy the whole zone name and put it into `zone` of your configuration. + +### city, street, house number + +This is currently not implemented, as it is not needed for customer `bogenschütz`. If you need it, don't hesitate to file an issue [here](https://github.com/mampfes/hacs_waste_collection_schedule/issues/new) and mention `@dm82m`. diff --git a/info.md b/info.md index e77f724c..72797a79 100644 --- a/info.md +++ b/info.md @@ -85,6 +85,7 @@ Currently the following service providers are supported: - [AWBKoeln.de](https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/awbkoeln_de.md) - [AWIDO-online.de](https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/awido_de.md) - [Berlin-Recycling.de](https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/berlin_recycling_de.md) +- [Bogenschuetz-Entsorgung.de](https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/infeo_at.md) - [BSR.de / Berliner Stadtreinigungsbetriebe](https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/bsr_de.md) - [C-Trace.de](https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/c_trace_de.md) - [Cochem-Zell](https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/cochem_zell_online_de.md)