mirror of
https://github.com/sascha-hemi/hacs_waste_collection_schedule.git
synced 2026-03-21 03:04:09 +01:00
add vasyd_se
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
import json
|
||||
from datetime import datetime
|
||||
|
||||
import requests
|
||||
from waste_collection_schedule import Collection # type: ignore[attr-defined]
|
||||
|
||||
TITLE = "VA Syd Sophämntning"
|
||||
DESCRIPTION = "Source for VA Syd waste collection."
|
||||
URL = "https://www.vasyd.se/Artiklar/Avfall-och-soptomning-privat/sopt%C3%B6mning-schema/"
|
||||
TEST_CASES = {
|
||||
"Home": {"street_address": "Industrigatan 13, Malmö"},
|
||||
"Polisen": {"street_address": "Drottninggatan 18, Malmö"},
|
||||
}
|
||||
|
||||
|
||||
class Source:
|
||||
def __init__(self, street_address):
|
||||
self._street_address = street_address
|
||||
|
||||
def fetch(self):
|
||||
data = {"query": self._street_address}
|
||||
response = requests.post(
|
||||
"https://www.vasyd.se/api/sitecore/MyPagesApi/BuildingAddressSearch",
|
||||
data=data,
|
||||
)
|
||||
|
||||
building_data = json.loads(response.text)["items"]
|
||||
building_id = None
|
||||
if building_data and len(building_data) > 0:
|
||||
building_id = building_data[0]["id"]
|
||||
|
||||
if not building_id:
|
||||
return []
|
||||
|
||||
data = {"query": building_id, "street": self._street_address}
|
||||
response = requests.post(
|
||||
"https://www.vasyd.se/api/sitecore/MyPagesApi/WastePickupByAddress",
|
||||
data=data,
|
||||
)
|
||||
|
||||
data = json.loads(response.text)["items"]
|
||||
|
||||
entries = []
|
||||
for item in data:
|
||||
waste_type = item["wasteType"]
|
||||
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
|
||||
51
doc/source/vasyd_se.md
Normal file
51
doc/source/vasyd_se.md
Normal file
@@ -0,0 +1,51 @@
|
||||
# Sysav Sophämtning
|
||||
|
||||
Support for schedules provided by [VA Syd](https://www.vasyd.se/Artiklar/Avfall-och-soptomning-privat/sopt%C3%B6mning-schema/), serving the municipality of Malmö, Lund, Lomma, Eslöv and Burlöv, Sweden.
|
||||
|
||||
## Configuration via configuration.yaml
|
||||
|
||||
```yaml
|
||||
waste_collection_schedule:
|
||||
sources:
|
||||
- name: vasyd_se
|
||||
args:
|
||||
street_address: STREET_ADDRESS
|
||||
```
|
||||
|
||||
### Configuration Variables
|
||||
|
||||
**street_address**<br>
|
||||
*(string) (required)*
|
||||
|
||||
## Example
|
||||
|
||||
```yaml
|
||||
waste_collection_schedule:
|
||||
sources:
|
||||
- name: vasyd_se
|
||||
args:
|
||||
street_address: Industrigatan 13, Malmö
|
||||
customize:
|
||||
- type: Fyrfack1
|
||||
alias: Brännbart, kompost, plast & färgat glas
|
||||
- type: Fyrfack2
|
||||
alias: Pappersförpackningar, tidningar, metall & ofärgat glas
|
||||
|
||||
sensors:
|
||||
- platform: waste_collection_schedule
|
||||
name: next_yard_collection
|
||||
types:
|
||||
- Trädgårdsavfall
|
||||
- platform: waste_collection_schedule
|
||||
name: next_bin1_collection
|
||||
types:
|
||||
- Brännbart, kompost, plast & färgat glas
|
||||
- platform: waste_collection_schedule
|
||||
name: next_bin2_collection
|
||||
types:
|
||||
- Pappersförpackningar, tidningar, metall & ofärgat glas
|
||||
```
|
||||
|
||||
## 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://www.vasyd.se/Artiklar/Avfall-och-soptomning-privat/sopt%C3%B6mning-schema/).
|
||||
1
info.md
1
info.md
@@ -104,6 +104,7 @@ Currently the following service providers are supported:
|
||||
|
||||
- [Lerum.se](https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/lerum_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)
|
||||
|
||||
### Switzerland
|
||||
|
||||
|
||||
Reference in New Issue
Block a user