-
-
Notifications
You must be signed in to change notification settings - Fork 695
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #297 from vasaru/add-ssam_se
Added source for SSAM.se
- Loading branch information
Showing
4 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
custom_components/waste_collection_schedule/waste_collection_schedule/source/ssam_se.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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**<br> | ||
*(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). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters