From b95419c553bb22d4e390f4a1ce5e873d82ed79cd Mon Sep 17 00:00:00 2001 From: Henrik Kjellsson Date: Thu, 14 Jul 2022 16:56:09 +0200 Subject: [PATCH 1/2] Added source for SSAM.se --- .../source/ssam_se.py | 62 +++++++++++++++++++ doc/source/ssam_se.md | 32 ++++++++++ 2 files changed, 94 insertions(+) create mode 100644 custom_components/waste_collection_schedule/waste_collection_schedule/source/ssam_se.py create mode 100644 doc/source/ssam_se.md diff --git a/custom_components/waste_collection_schedule/waste_collection_schedule/source/ssam_se.py b/custom_components/waste_collection_schedule/waste_collection_schedule/source/ssam_se.py new file mode 100644 index 000000000..00f195787 --- /dev/null +++ b/custom_components/waste_collection_schedule/waste_collection_schedule/source/ssam_se.py @@ -0,0 +1,62 @@ +import json +from datetime import datetime + +import requests +from waste_collection_schedule import Collection # type: ignore[attr-defined] + +TITLE = "SSAM Sophämntning" +DESCRIPTION = "Source for SSAM waste collection." +URL = "https://edpfuture.ssam.se/FutureWeb/SimpleWastePickup/GetWastePickupSchedule" +TEST_CASES = { + "Home": {"street_address": "Saturnusvägen 12, Växjö"}, + "Other": {"street_address": "Andvägen 3, Växjö"}, +} + + +class Source: + def __init__(self, street_address): + self._street_address = street_address + + def fetch(self): + params = {"searchText": self._street_address} + print(self._street_address) + response = requests.post( + "https://edpfuture.ssam.se/FutureWeb/SimpleWastePickup/SearchAdress", + params=params, + ) + + address_data = json.loads(response.text) +# print(json.dumps(address_data, indent=4, sort_keys=True)) + address = None + + if address_data and len(address_data) > 0: + address = address_data["Buildings"][0] + + if not address: + return [] + + params = {"address": address} + response = requests.get( + "https://edpfuture.ssam.se/FutureWeb/SimpleWastePickup/GetWastePickupSchedule", + params=params, + ) + + data = json.loads(response.text) +# print(json.dumps(data, indent=4, sort_keys=True)) + + entries = [] + for item in data["RhServices"]: +# print(json.dumps(item, indent=4, sort_keys=True)) + if item["WasteType"] == "FNI1": + waste_type = "Kärl 1" + icon = "mdi:trash-can" + elif item["WasteType"] == "FNI2": + waste_type = "Kärl 2" + icon = "mdi:trash-can" + if waste_type == "Trädgårdsavfall": + icon = "mdi:leaf" + next_pickup = item["NextWastePickup"] + next_pickup_date = datetime.fromisoformat(next_pickup).date() + entries.append(Collection(date=next_pickup_date, t=waste_type, icon=icon)) + + return entries diff --git a/doc/source/ssam_se.md b/doc/source/ssam_se.md new file mode 100644 index 000000000..a3f1e88f8 --- /dev/null +++ b/doc/source/ssam_se.md @@ -0,0 +1,32 @@ +# Sysav Sophämtning + +Support for schedules provided by [SSAM](https://ssam.se/mitt-ssam/hamtdagar.html), serving the municipality of Lessebo, Tingsryd, Älmhult, Markaryd and Växjö Sweden. + +## Configuration via configuration.yaml + +```yaml +waste_collection_schedule: + sources: + - name: ssam_se + args: + street_address: STREET_ADDRESS +``` + +### Configuration Variables + +**street_address**
+*(string) (required)* + +## Example + +```yaml +waste_collection_schedule: + sources: + - name: ssam_se + args: + street_address: Andvägen 3, Växjö +``` + +## How to get the source argument + +The source argument is the address to the house with waste collection. The address can be tested [here](https://ssam.se/mitt-ssam/hamtdagar.html). From 690fc5baa4d7ce913f65b6b1d7bddbdd1dde105a Mon Sep 17 00:00:00 2001 From: Henrik Kjellsson Date: Sun, 24 Jul 2022 18:47:50 +0200 Subject: [PATCH 2/2] Added info about source for SSAM.se --- README.md | 1 + info.md | 1 + 2 files changed, 2 insertions(+) diff --git a/README.md b/README.md index d36dbf557..808e271f0 100644 --- a/README.md +++ b/README.md @@ -129,6 +129,7 @@ Currently the following service providers are supported: ### Sweden - [Lerum.se](./doc/source/lerum_se.md) +- [SSAM.se](./doc/source/ssam_se.md) - [Sysav.se](./doc/source/sysav_se.md) - [Vasyd.se](./doc/source/vasyd_se.md) diff --git a/info.md b/info.md index 51acb533c..6726013a1 100644 --- a/info.md +++ b/info.md @@ -115,6 +115,7 @@ Currently the following service providers are supported: ### Sweden - [Lerum.se](https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/lerum_se.md) +- [SSAM.se](https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/ssam_se.md) - [Sysav.se](https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/sysav_se.md) - [Vasyd.se](https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/vasyd_se.md)