Skip to content

Commit 405834f

Browse files
committed
2 parents ce12c1d + 292067c commit 405834f

File tree

4 files changed

+81
-56
lines changed

4 files changed

+81
-56
lines changed

custom_components/waste_collection_schedule/manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
"dependencies": [],
77
"codeowners": ["@mampfes"],
88
"iot_class": "cloud_polling",
9-
"version": "1.34.0",
9+
"version": "1.35.0",
1010
"integration_type": "hub"
1111
}
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
from datetime import datetime
2-
from waste_collection_schedule import Collection # type: ignore[attr-defined]
3-
import json
2+
43
import requests
54
from bs4 import BeautifulSoup
5+
from waste_collection_schedule import Collection # type: ignore[attr-defined]
66

7-
TITLE = "Stavanger"
7+
TITLE = "Stavanger Kommune"
88
DESCRIPTION = "Source for Stavanger Kommune, Norway"
99
URL = "https://www.stavanger.kommune.no/"
1010
TEST_CASES = {
11-
"TestcaseI": {"id": "57bf9d36-722e-400b-ae93-d80f8e354724", "municipality": "Stavanger", "gnumber": "57", "bnumber": "922", "snumber": "0"},
11+
"TestcaseI": {
12+
"id": "57bf9d36-722e-400b-ae93-d80f8e354724",
13+
"municipality": "Stavanger",
14+
"gnumber": "57",
15+
"bnumber": "922",
16+
"snumber": "0",
17+
},
1218
}
1319

1420
ICON_MAP = {
@@ -18,6 +24,7 @@
1824
"Juletre": "mdi:pine-tree",
1925
}
2026

27+
2128
class Source:
2229
def __init__(self, id, municipality, gnumber, bnumber, snumber):
2330
self._id = id
@@ -27,43 +34,38 @@ def __init__(self, id, municipality, gnumber, bnumber, snumber):
2734
self._snumber = snumber
2835

2936
def fetch(self):
30-
url = 'https://www.stavanger.kommune.no/renovasjon-og-miljo/tommekalender/finn-kalender/show'
31-
headers = {
32-
'referer': 'https://www.stavanger.kommune.no'
33-
}
34-
35-
params = {
36-
'id' : self._id,
37-
'municipality' : self._municipality,
38-
'gnumber' : self._gnumber,
39-
'bnumber' : self._bnumber,
40-
'snumber' : self._snumber
41-
}
37+
url = "https://www.stavanger.kommune.no/renovasjon-og-miljo/tommekalender/finn-kalender/show"
38+
headers = {"referer": "https://www.stavanger.kommune.no"}
4239

43-
r = requests.get(url, params=params, headers=headers)
40+
params = {
41+
"id": self._id,
42+
"municipality": self._municipality,
43+
"gnumber": self._gnumber,
44+
"bnumber": self._bnumber,
45+
"snumber": self._snumber,
46+
}
4447

45-
print(r.text)
48+
r = requests.get(url, params=params, headers=headers)
49+
r.raise_for_status()
4650

47-
soup = BeautifulSoup(r.text, "html.parser")
51+
soup = BeautifulSoup(r.text, "html.parser")
4852

49-
tag = soup.find_all("option")
50-
year = tag[0].get('value').split('-')
51-
year = year[1]
53+
tag = soup.find_all("option")
54+
year = tag[0].get("value").split("-")
55+
year = year[1]
5256

53-
entries = []
54-
for tag in soup.find_all("tr", {"class":"waste-calendar__item"}):
55-
if tag.text.strip() == 'Dato og dag\nAvfallstype':
56-
continue
57+
entries = []
58+
for tag in soup.find_all("tr", {"class": "waste-calendar__item"}):
59+
if tag.text.strip() == "Dato og dag\nAvfallstype":
60+
continue
5761

58-
date = tag.text.strip().split(' - ')
59-
date = datetime.strptime(date[0]+'.'+year, '%d.%m.%Y').date()
60-
#print (date)
62+
date = tag.text.strip().split(" - ")
63+
date = datetime.strptime(date[0] + "." + year, "%d.%m.%Y").date()
6164

62-
for img in tag.find_all("img"):
63-
print (date,img.get('title'))
64-
icon = ICON_MAP.get(img.get('title'))
65-
entries.append(
66-
Collection(date, img.get('title'), icon=icon)
67-
)
65+
for img in tag.find_all("img"):
66+
waste_type = img.get("title")
67+
entries.append(
68+
Collection(date, waste_type, icon=ICON_MAP.get(waste_type))
69+
)
6870

69-
return entries
71+
return entries

doc/installation.md

+36-17
Original file line numberDiff line numberDiff line change
@@ -71,23 +71,34 @@ waste_collection_schedule:
7171
7272
| Parameter | Type | Requirement | Description |
7373
|-----|-----|-----|-----|
74-
| sources: | | required | Contains information for the service provider being used |
75-
| name: | string | required | name of the service provider source to use. Should be the same as the source filename, but without the `.py` extension. See the [README](/README.md#supported-service-providers) for supported service providers |
76-
| args: | various | required | source-specific arguments provided to service provider to unambiguously identify the collection schedule to return. Depending on the service provider, some arguments may be mandatory, and some may be optional. See individual sources for more details |
77-
| customize: | | optional | Can be used to customise data retrieved from a source |
78-
| type: | string | required | The identity of the waste type as returned from the source |
79-
| alias: | string | optional | A more readable, or user-friendly, name for the type of waste being collected. Default is `None` |
80-
| show: | boolean | optional | Show (`True`) or hide (`False`) collections of this specific waste type. Default is `True` |
81-
| icon: | string | optional | Icon to use for this specific waste type. Icons from the Home Assistant mdi icon set can be used. Default is `None`. |
82-
| picture: | string | optional | string representation of the path to a picture used to represent this specific waste type. Default is `None` |
83-
| use_dedicated_calendar: | boolean | optional | Creates a calendar dedicated to this specific waste type. Default is `False` |
84-
| dedicated_calendar_title: | string | optional | A more readable, or user-friendly, name for this specific waste calendar object. If nothing is provided, the name returned by the source will be used |
85-
| fetch_time: | time | optional | representation of the time of day in "HH:MM" that Home Assistant polls service provider for latest collection schedule. If no time is provided, the default of "01:00" is used |
86-
| random_fetch_time_offset: | int | optional | randomly offsets the `fetch_time` by up to _int_ minutes. Can be used to distribute Home Assistant fetch commands over a longer time frame to avoid peak loads at service providers |
87-
| day_switch_time: | time | optional | time of the day in "HH:MM" that Home Assistant dismisses the current entry and moves to the next entry. If no time if provided, the default of "10:00" is used. |
88-
| separator: | string | optional | Used to join entries if the multiple values for a single day are returned by the source. If no value is entered, the default of ", " is used |
89-
90-
## Configuring source sensor(s)
74+
| sources | list | required | Contains information for the service provider being used. For details see [Attributes for sources](#attributes-for-sources) |
75+
| fetch_time | time | optional | representation of the time of day in "HH:MM" that Home Assistant polls service provider for latest collection schedule. If no time is provided, the default of "01:00" is used |
76+
| random_fetch_time_offset | int | optional | randomly offsets the `fetch_time` by up to _int_ minutes. Can be used to distribute Home Assistant fetch commands over a longer time frame to avoid peak loads at service providers |
77+
| day_switch_time | time | optional | time of the day in "HH:MM" that Home Assistant dismisses the current entry and moves to the next entry. If no time if provided, the default of "10:00" is used. |
78+
| separator | string | optional | Used to join entries if the multiple values for a single day are returned by the source. If no value is entered, the default of ", " is used |
79+
80+
## Attributes for _sources_
81+
82+
| Parameter | Type | Requirement | Description |
83+
|-----|-----|-----|-----|
84+
| name | string | required | name of the service provider source to use. Should be the same as the source filename, but without the `.py` extension. See the [README](/README.md#supported-service-providers) for supported service providers |
85+
| args | various | required | source-specific arguments provided to service provider to unambiguously identify the collection schedule to return. Depending on the service provider, some arguments may be mandatory, and some may be optional. See individual sources for more details |
86+
| customize | list | optional | Can be used to customise data retrieved from a source. For details see [Attributes for customize](#attributes-for-customize) |
87+
| use_dedicated_calendar | boolean | optional | Creates a calendar dedicated to this specific waste type. Default is `False` |
88+
| dedicated_calendar_title | string | optional | A more readable, or user-friendly, name for this specific waste calendar object. If nothing is provided, the name returned by the source will be used |
89+
90+
91+
## Attributes for _customize_
92+
93+
| Parameter | Type | Requirement | Description |
94+
|-----|-----|-----|-----|
95+
| type | string | required | The identity of the waste type as returned from the source |
96+
| alias | string | optional | A more readable, or user-friendly, name for the type of waste being collected. Default is `None` |
97+
| show | boolean | optional | Show (`True`) or hide (`False`) collections of this specific waste type. Default is `True` |
98+
| icon | string | optional | Icon to use for this specific waste type. Icons from the Home Assistant mdi icon set can be used. Default is `None`. |
99+
| picture | string | optional | string representation of the path to a picture used to represent this specific waste type. Default is `None` |
100+
101+
## Configuring Sensor(s)
91102

92103
Add the following lines to your `configuration.yaml` file:
93104

@@ -139,6 +150,14 @@ The following variables can be used within `value_template` and `date_template`:
139150
| `value.daysTo` | Days to collection | int | 0 = today, 1 = tomorrow, etc |
140151
| `value.types` | Waste types | list of strings | Use `join` filter to join types |
141152

153+
Examples:
154+
155+
```yaml
156+
value_template: '{{value.types|join(", ")}}'
157+
value_template: 'in {{value.daysTo}} days'
158+
value_template: 'on {{value.date.strftime("%a")}}, {{value.date.strftime("%d.%m.%Y")}}'
159+
```
160+
142161
## Combine Data from multiple Sources
143162

144163
To combine data from multiple sources into one sensor, just add the source indexes like that:

doc/source/stavanger_no.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,19 @@ waste_collection_schedule:
2020
2121
**id**
2222
*(string) (required)*
23+
2324
**municipality**
2425
*(string) (required)*
26+
2527
**gnumber**
2628
*(string) (required)*
29+
2730
**bnumber**
2831
*(string) (required)*
32+
2933
**snumber**
3034
*(string) (required)*
35+
3136
## Example
3237
3338
```yaml
@@ -47,7 +52,7 @@ waste_collection_schedule:
4752
Visit the [Stavanger Kommune, Norway](https://www.stavanger.kommune.no/renovasjon-og-miljo/tommekalender/finn-kalender/) page and search for your address.
4853
use the parameters for url
4954
50-
##Example URL
55+
## Example URL
5156
5257
https://www.stavanger.kommune.no/renovasjon-og-miljo/tommekalender/finn-kalender/show?id=afe76cc0-19a9-4345-99bc-920bd16ab7cc&municipality=Stavanger&gnumber=58&bnumber=968&snumber=0
5358
@@ -58,4 +63,3 @@ extract the arguments from this url you get. in this example
5863
**gnumber**=58
5964
**bnumber**=968
6065
**snumber**=0
61-

0 commit comments

Comments
 (0)