#427: added support for infeo.at and tested with customer bogenschuetz-entsorgung.de

This commit is contained in:
dm82m
2022-11-12 21:23:41 +01:00
parent 85363f969d
commit 151163ff92
4 changed files with 159 additions and 0 deletions

View File

@@ -99,6 +99,7 @@ Currently the following service providers are supported:
- [AWBKoeln.de](./doc/source/awbkoeln_de.md) - [AWBKoeln.de](./doc/source/awbkoeln_de.md)
- [AWIDO-online.de](./doc/source/awido_de.md) - [AWIDO-online.de](./doc/source/awido_de.md)
- [Berlin-Recycling.de](./doc/source/berlin_recycling_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) - [BSR.de / Berliner Stadtreinigungsbetriebe](./doc/source/bsr_de.md)
- [C-Trace.de](./doc/source/c_trace_de.md) - [C-Trace.de](./doc/source/c_trace_de.md)
- [Cochem-Zell](./doc/source/cochem_zell_online_de.md) - [Cochem-Zell](./doc/source/cochem_zell_online_de.md)

View File

@@ -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

54
doc/source/infeo_at.md Normal file
View File

@@ -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**<br>
*(string) (required)*
**zone**<br>
*(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`.

View File

@@ -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) - [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) - [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) - [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) - [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) - [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) - [Cochem-Zell](https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/cochem_zell_online_de.md)