Skip to content

Commit

Permalink
Merge pull request #297 from vasaru/add-ssam_se
Browse files Browse the repository at this point in the history
Added source for SSAM.se
  • Loading branch information
mampfes authored Jul 31, 2022
2 parents 94c3acc + 690fc5b commit 34322c6
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,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)

Expand Down
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
32 changes: 32 additions & 0 deletions doc/source/ssam_se.md
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).
1 change: 1 addition & 0 deletions info.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,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)

Expand Down

0 comments on commit 34322c6

Please sign in to comment.