internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: mampfes/hacs_waste_collection_schedule

Issue:
Not using HA supported python version
HA supports the last two minor versions of Python, that is currently 3.10 and 3.9.
[calendar.py](https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/custom_components/waste_collection_schedule/calendar.py#L118) makes use of Python 3.10 only type hinting features for optional arguments via unions:
`def calc_unique_calendar_id(scraper: Scraper, type: str | None = None):`
The union str | None is not supported as type hint by Python 3.9, hence the waste collection schedule fails to load albeit HA runs on a supported installation.


Discussion:

Resolving patch:
diff --git a/custom_components/waste_collection_schedule/calendar.py b/custom_components/waste_collection_schedule/calendar.py
--- a/custom_components/waste_collection_schedule/calendar.py
+++ b/custom_components/waste_collection_schedule/calendar.py
@@ -1,15 +1,12 @@
 """Calendar platform support for Waste Collection Schedule."""
 
 import logging
-from datetime import timedelta, timezone, datetime
+from datetime import datetime, timedelta
 
 from homeassistant.components.calendar import CalendarEntity, CalendarEvent
 from homeassistant.core import HomeAssistant
-from homeassistant.util.dt import DEFAULT_TIME_ZONE
 
-from custom_components.waste_collection_schedule.waste_collection_schedule.scraper import (
-    Scraper,
-)
+from custom_components.waste_collection_schedule.waste_collection_schedule.scraper import Scraper
 
 _LOGGER = logging.getLogger(__name__)
 
@@ -115,5 +112,5 @@ def _convert(self, collection) -> CalendarEvent:
         )
 
 
-def calc_unique_calendar_id(scraper: Scraper, type: str | None = None):
+def calc_unique_calendar_id(scraper: Scraper, type: str = None):
     return scraper.unique_id + ("_" + type if type is not None else "") + "_calendar"


Test patch:
Repository: mampfes/hacs_waste_collection_schedule

Issue:
Request for Oslo Kommune, Norway
https://www.oslo.kommune.no/avfall-og-gjenvinning/nar-hentes-avfallet/


Discussion:

Resolving patch:
diff --git a/custom_components/waste_collection_schedule/waste_collection_schedule/source/oslokommune_no.py b/custom_components/waste_collection_schedule/waste_collection_schedule/source/oslokommune_no.py
new file mode 100644
--- /dev/null
+++ b/custom_components/waste_collection_schedule/waste_collection_schedule/source/oslokommune_no.py
@@ -0,0 +1,75 @@
+import requests
+import urllib.parse
+import json
+import datetime
+import re
+
+from waste_collection_schedule import Collection  # type: ignore[attr-defined]
+from pprint import pprint
+
+TITLE = "Oslo Kommune"
+DESCRIPTION = "Oslo Kommune (Norway)."
+URL = "https://www.oslo.kommune.no/avfall-og-gjenvinning/nar-hentes-avfallet/"
+
+# **street_code:** \
+# **county_id:** \
+# Can be found with this REST-API call.
+# ```
+# https://ws.geonorge.no/adresser/v1/#/default/get_sok
+# https://ws.geonorge.no/adresser/v1/sok?sok=Min%20Gate%2012
+# ```
+# "street_id" equals to "adressekode" and "county_id" equals to "kommunenummer".
+
+TEST_CASES = {
+    "Villa Paradiso": {
+        "street_name": "Olaf Ryes Plass",
+        "house_number": 8,
+        "house_letter": '',
+        "street_id": 15331
+    }
+}
+
+BASE_URL = "https://www.oslo.kommune.no/xmlhttprequest.php"
+
+class Source:
+    def __init__(self, street_name, house_number, house_letter, street_id):
+        self._street_name  = street_name
+        self._house_number = house_number
+        self._house_letter = house_letter
+        self._street_id    = street_id
+        self._icon_map     = {
+            "":           "mdi:trash-can",
+            "restavfall": "mdi:trash-can",
+            "papir":      "mdi:newspaper-variant-multiple"
+        } 
+
+    def fetch(self):
+        headers = {
+            'user-agent': 'Home-Assitant-waste-col-sched/0.1'
+        }
+
+        args = {
+            'service':   'ren.search',
+            'street':    self._street_name,
+            'number':    self._house_number,
+            'letter':    self._house_letter,
+            'street_id': self._street_id,
+        }
+
+        r = requests.get(BASE_URL, params = args, headers = headers)
+
+        entries = []
+        res = json.loads(r.content)['data']['result'][0]['HentePunkts']
+        for f in res:
+            pprint(f['Tjenester'][0])
+            entries.append(
+                Collection(
+                    date = datetime.datetime.strptime(
+                        f['Tjenester'][0]['TommeDato'], "%d.%m.%Y"
+                    ).date(),
+                    t = f['Tjenester'][0]['Fraksjon']['Tekst'],
+                    icon = 'mdi:trash-can'
+                )
+            )
+
+        return entries


Test patch:
Repository: mampfes/hacs_waste_collection_schedule

Issue:
Add source for Germany - Nordwestmecklenburg --> Abfuhrtermine 2022 für den Landkreis 
please, can you add this scource?

https://www.geoport-nwm.de/de/abfuhrtermine-geoportal.html




Discussion:

Resolving patch:
diff --git a/custom_components/waste_collection_schedule/waste_collection_schedule/source/geoport_nwm_de.py b/custom_components/waste_collection_schedule/waste_collection_schedule/source/geoport_nwm_de.py
new file mode 100644
--- /dev/null
+++ b/custom_components/waste_collection_schedule/waste_collection_schedule/source/geoport_nwm_de.py
@@ -0,0 +1,64 @@
+import datetime
+import requests
+import urllib
+from waste_collection_schedule import Collection  # type: ignore[attr-defined]
+from waste_collection_schedule.service.ICS import ICS
+
+TITLE = "Landkreis Nordwestmecklenburg"
+DESCRIPTION = "Source for Landkreis Nordwestmecklenburg"
+URL = "https://www.geoport-nwm.de/de/abfuhrtermine-geoportal.html"
+TEST_CASES = {
+    "Rüting": {"district": "Rüting"},
+    "Grevenstein u. ...": {"district": "Grevenstein u. Ausbau"},
+    "Seefeld": {"district": "Seefeld/ Testorf- Steinfort"},
+    "1100l": {"district": "Groß Stieten (1.100 l Behälter)"},
+    "kl. Bünsdorf": {"district": "Klein Bünsdorf"}
+}
+
+
+class Source:
+    def __init__(self, district):
+        self._district = district
+        self._ics = ICS()
+
+    def fetch(self):
+        today = datetime.date.today()
+        dates = []
+        if today.month == 12:
+            # On Dec 27 2022, the 2022 schedule was no longer available for test case "Seefeld", all others worked
+            try:
+                dates = self.fetch_year(today.year)
+            except Exception:
+                pass
+            try:
+                dates.extend(self.fetch_year(today.year + 1))
+            except Exception:
+                pass
+        else:
+            dates = self.fetch_year(today.year)
+
+        entries = []
+        for d in dates:
+            entries.append(Collection(d[0], d[1]))
+        return entries
+
+    def fetch_year(self, year):
+        arg = convert_to_arg(self._district)
+        r = requests.get(
+            f"https://www.geoport-nwm.de/nwm-download/Abfuhrtermine/ICS/{year}/{arg}.ics")
+        r.raise_for_status()
+        return self._ics.convert(r.text)
+
+
+def convert_to_arg(district):
+    district = district.replace("(1.100 l Behälter)", "1100_l")
+    district = district.replace("ü", "ue")
+    district = district.replace("ö", "oe")
+    district = district.replace("ä", "ae")
+    district = district.replace("ß", "ss")
+    district = district.replace("/", "")
+    district = district.replace("- ", "-")
+    district = district.replace(".", "")
+    district = district.replace(" ", "_")
+    arg = urllib.parse.quote("Ortsteil_" + district)
+    return arg


Test patch:
Repository: mampfes/hacs_waste_collection_schedule

Issue:
Please expose service for manual schedule refresh
As per my understanding current setup  allows refresh of the schedule to happen only once a day at the time configured in `fetch_time`.
This may cause issues if for some reason the source is not available at the given time, there is an issue with connectivity or a schedule change has been announced via different channels and update needs to happen on-demand.

Please expose `waste_collection_schedule.reload` service that would call the same routing that is normally executed at `fetch_time`, but on demand.


Discussion:

Resolving patch:
diff --git a/custom_components/waste_collection_schedule/__init__.py b/custom_components/waste_collection_schedule/__init__.py
--- a/custom_components/waste_collection_schedule/__init__.py
+++ b/custom_components/waste_collection_schedule/__init__.py
@@ -123,6 +123,12 @@ async def async_setup(hass: HomeAssistant, config: dict):
 
     # initial fetch of all data
     hass.add_job(api._fetch)
+    
+    def fetch_data():
+        hass.add_job(api._fetch)
+
+    # Register new Service fetch_data
+    hass.services.async_register(DOMAIN, 'fetch_data', fetch_data)
 
     return True
 


Test patch:
Repository: mampfes/hacs_waste_collection_schedule

Issue:
Add StadtService Brühl
Add Source for StadtService Brühl

Update stadtservice_bruehl_de.md


Discussion:
Thank you very much, hope to get it installed soon.
Thanks for your contribution.
> 

Is it somehow possible to separate the different waste types when using this integration?

Resolving patch:
diff --git a/custom_components/waste_collection_schedule/waste_collection_schedule/source/stadtservice_bruehl_de.py b/custom_components/waste_collection_schedule/waste_collection_schedule/source/stadtservice_bruehl_de.py
--- a/custom_components/waste_collection_schedule/waste_collection_schedule/source/stadtservice_bruehl_de.py
+++ b/custom_components/waste_collection_schedule/waste_collection_schedule/source/stadtservice_bruehl_de.py
@@ -18,7 +18,7 @@ class Source:
     def __init__(self, strasse, hnr):
         self._strasse = strasse
         self._hnr = hnr
-        self._ics = ICS()
+        self._ics = ICS(regex="(.*?) \\- ", split_at=", ")
 
     def fetch(self):
 


Test patch:
Repository: mampfes/hacs_waste_collection_schedule

Issue:
Specify local file path information in docs
Neither
- https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/faq.md

nor
- https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/ics.md#configuration-variables
- https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/ics.md#local-file

specify, where the file has to be stored.

1. Is "calendar.ics" meant to be the share `/config/calendar.ics`?
2. What would the `file:` parameter need to look like when the file is e. g. located in `/config/customfolder/calendar.ics` ?


Discussion:
I've always assumed path references are relative to the `configuration.yaml` as that's where the config info is based and being called from. On the assumption your `configuration.yaml` file is in the `config` folder, this should work for the set-up you've described (and isn't too different to how I've referenced .ics files in the past).

```yaml
waste_collection_schedule:
  sources:
    - name: ics
      args:
        file: "./customfolder/calendar.ics"
```

Update: according to https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/installation.md#configuring-waste-collection-schedules the ICS always needs to be in `/config/www/`.

path then specified as `file: "www/calendar.ics"` following https://youtu.be/aCKLKGYiA7w?t=365.

Please specify this too. Just too many things which could fail.
The problem with local files and relative paths is, that it also depends on the Home Assistant installation type (core vs supervised vs OS vs ...). Therefore it is not easy to give a single answer. But it would be nice if you could help, e.g. by creating a PR which describes your environment and solution.
Running on HA OS I'm using `file: "www/abfall/abfuhrkalender_home.ics"` now. That information basically originates from the linked YT video (you referenced).

Resolving patch:
diff --git a/custom_components/waste_collection_schedule/waste_collection_schedule/source/ics.py b/custom_components/waste_collection_schedule/waste_collection_schedule/source/ics.py
--- a/custom_components/waste_collection_schedule/waste_collection_schedule/source/ics.py
+++ b/custom_components/waste_collection_schedule/waste_collection_schedule/source/ics.py
@@ -1,5 +1,6 @@
 import datetime
 import logging
+from os import getcwd
 from pathlib import Path
 
 import requests
@@ -202,7 +203,11 @@ def fetch_url(self, url, params=None):
         return self._convert(r.text)
 
     def fetch_file(self, file):
-        f = open(file)
+        try:
+            f = open(file)
+        except FileNotFoundError as e:
+            _LOGGER.error(f"Working directory: '{getcwd()}'")
+            raise
         return self._convert(f.read())
 
     def _convert(self, data):


Test patch:
Repository: mampfes/hacs_waste_collection_schedule

Issue:
Error with Service Provider Stadtreinigung Leipzig / stadtreinigung-leipzig.de
Hi everyone,
Since 03.01.2023 (this is where I noticed it), WCS can no longer retrieve data from Stadtwerke Leipzig.
The following error is displayed:

fetch failed for source Stadtreinigung Leipzig: Traceback (most recent call last): File "/config/custom_components/waste_collection_schedule/waste_collection_schedule/source_shell.py", line 134, in fetch entries = self._source.fetch() File "/config/custom_components/waste_collection_schedule/waste_collection_schedule/source/stadtreinigung_leipzig_de.py", line 34, in fetch raise Exception(f"street not found: {self._street}") Exception: street not found: Pflugkstraße

My configuration.yaml:
waste_collection_schedule:
  sources:
    - name: stadtreinigung_leipzig_de
      args:
        street: Pflugkstraße
        house_number: 1
      calendar_title: Abfallkalender

I've been trying around here for a few days, but I can't find a solution to the problem. Is it possible that the API has been changed/defective?
Thanks for your help...


Discussion:

Resolving patch:
diff --git a/custom_components/waste_collection_schedule/waste_collection_schedule/source/stadtreinigung_leipzig_de.py b/custom_components/waste_collection_schedule/waste_collection_schedule/source/stadtreinigung_leipzig_de.py
--- a/custom_components/waste_collection_schedule/waste_collection_schedule/source/stadtreinigung_leipzig_de.py
+++ b/custom_components/waste_collection_schedule/waste_collection_schedule/source/stadtreinigung_leipzig_de.py
@@ -21,12 +21,13 @@ def __init__(self, street, house_number):
 
     def fetch(self):
         params = {
-            "name": self._street,
+            "old_format": 1,
+            "search": self._street,
         }
 
         # get list of streets and house numbers
         r = requests.get(
-            "https://stadtreinigung-leipzig.de/rest/wastecalendarstreets", params=params
+            "https://stadtreinigung-leipzig.de/rest/Navision/Streets", params=params
         )
 
         data = json.loads(r.text)


Test patch:
Repository: mampfes/hacs_waste_collection_schedule

Issue:
Problems with awido_de
Hello,

i have a problem with the awido_de calander :(


Log:
```
2023-01-09 20:43:52.963 ERROR (SyncWorker_4) [waste_collection_schedule.source_shell] fetch failed for source AWIDO Online:
File "/config/custom_components/waste_collection_schedule/waste_collection_schedule/source_shell.py", line 134, in fetch
File "/config/custom_components/waste_collection_schedule/waste_collection_schedule/source/awido_de.py", line 108, in fetch

```

configuration.yaml
```
waste_collection_schedule:
  sources:
    - name: awido_de
      args:
        customer: "bgl"
        city: "Laufen"
        street: "XXX Str."
        housenumber: 1
```

Setup:
```
Home Assistant 2023.1.2
Frontend 20230104.0 - latest
Installation: Docker
Waste Collection Schedule 1.33.0
```

Any ideas?

Regards,
Christian


Discussion:
Could you please try: `housenumber: "1"`
> Could you please try: `housenumber: "1"`

Okay, housenumber: "1"` is working now... :) Thanks!

Resolving patch:
diff --git a/custom_components/waste_collection_schedule/waste_collection_schedule/source/awido_de.py b/custom_components/waste_collection_schedule/waste_collection_schedule/source/awido_de.py
--- a/custom_components/waste_collection_schedule/waste_collection_schedule/source/awido_de.py
+++ b/custom_components/waste_collection_schedule/waste_collection_schedule/source/awido_de.py
@@ -194,6 +194,12 @@ def EXTRA_INFO():
         "street": "Rehgrund",
     },
     "Tübingen, Dettenhausen": {"customer": "tuebingen", "city": "Dettenhausen"},
+    "Berchtesgadener Land": {
+        "customer": "bgl",
+        "city": "Laufen",
+        "street": "Ahornweg",
+        "housenumber": 1,
+    },
 }
 
 _LOGGER = logging.getLogger(__name__)
@@ -204,7 +210,7 @@ def __init__(self, customer, city, street=None, housenumber=None):
         self._customer = customer
         self._city = city
         self._street = street
-        self._housenumber = housenumber
+        self._housenumber = None if housenumber is None else str(housenumber)
 
     def fetch(self):
         # Retrieve list of places


Test patch:
Repository: mampfes/hacs_waste_collection_schedule

Issue:
I miss one with C-Trace.de/WZV
Hello guys,

I just switched from ics to C-Trace.de. Since then, unfortunately, it no longer shows me all the bins. I'm missing the residual waste, everything else is displayed as usual. Can someone help me?




Discussion:
Do you see the missing waste type in the HA calendar? If yes, it is probably an issue of your sensor configuration --> check if the values below `types`are matching exactly (they are also case sensisitive).

If not, do you see the missing waste type if you use the web browers to with your address?
No, it cannot be seen in the calendar or can find in the sensors. I have already checked everything, but unfortunately without success.

Yes, on the WZV website, where I used to load my ics file for HA, everything is in there and it works great.

Resolving patch:
diff --git a/custom_components/waste_collection_schedule/waste_collection_schedule/source/c_trace_de.py b/custom_components/waste_collection_schedule/waste_collection_schedule/source/c_trace_de.py
--- a/custom_components/waste_collection_schedule/waste_collection_schedule/source/c_trace_de.py
+++ b/custom_components/waste_collection_schedule/waste_collection_schedule/source/c_trace_de.py
@@ -27,6 +27,12 @@
         "hausnummer": 7,
         "service": "augsburglandkreis",
     },
+    "WZV": {
+        "ort": "Bark",
+        "strasse": "Birkenweg",
+        "hausnummer": 1,
+        "service": "segebergwzv-abfallkalender",
+    },
 }
 
 
@@ -66,7 +72,7 @@ def fetch(self):
             "Gemeinde": self._ort,
             "Strasse": self._strasse,
             "Hausnr": self._hausnummer,
-            "Abfall": "|".join(str(i) for i in range(1, 99)),  # return all waste types
+            "Abfall": "|".join(str(i) for i in range(0, 99)),  # return all waste types
         }
         r = session.get(
             f"{BASE_URL}/{self._service}/{session_id}/abfallkalender/cal", params=args


Test patch:
Repository: mampfes/hacs_waste_collection_schedule

Issue:
impossible to call fetch_data manual
Because i try to add my own ics http url i need debug it.
Calling fetch_data doesn't work:

```
takes 0 positional arguments but 1 was given
```

just an extra question: Is it possible to use {%y} (small) to get 23 not 2023?


Discussion:

Resolving patch:
diff --git a/custom_components/waste_collection_schedule/__init__.py b/custom_components/waste_collection_schedule/__init__.py
--- a/custom_components/waste_collection_schedule/__init__.py
+++ b/custom_components/waste_collection_schedule/__init__.py
@@ -7,7 +7,7 @@
 import homeassistant.helpers.config_validation as cv
 import homeassistant.util.dt as dt_util
 import voluptuous as vol
-from homeassistant.core import HomeAssistant, callback
+from homeassistant.core import HomeAssistant, ServiceCall, callback
 from homeassistant.helpers.dispatcher import dispatcher_send
 
 from .const import DOMAIN, UPDATE_SENSORS_SIGNAL
@@ -123,12 +123,14 @@ async def async_setup(hass: HomeAssistant, config: dict):
 
     # initial fetch of all data
     hass.add_job(api._fetch)
-    
-    def fetch_data():
+
+    async def async_fetch_data(service: ServiceCall) -> None:
         hass.add_job(api._fetch)
 
     # Register new Service fetch_data
-    hass.services.async_register(DOMAIN, 'fetch_data', fetch_data)
+    hass.services.async_register(
+        DOMAIN, "fetch_data", async_fetch_data, schema=vol.Schema({})
+    )
 
     return True
 


Test patch:
Repository: mampfes/hacs_waste_collection_schedule

Issue:
ZVA-SEK has been added. Thanks, great job. But there is a problem.
First of all: Thanks to 5ila5 for doing the job. Thats awesome.

But all entries are one day ahead.
I created the entries using the "static" configuration, and compared to the import there is one day "shift".
Maybe because there is an alarm in the ICS-file?
Or am i doing something wrong?

![image](https://user-images.githubusercontent.com/115486571/226136239-f3b9384a-4ea7-4dba-8cc4-d01e0585cf56.png)

Greetings, Holger.

PS.: @5ila5: whenever you are in the area of Kassel, send me a note, and i will show you the finest brewery in the area (beers on me).

  sources:
    - name: static
      calendar_title: Papier
      args:
        type: Altpapier
        frequency: WEEKLY
        interval: 4
        start: '2023-01-16'
        until: '2023-12-18'
        excludes:
          - '2023-04-10'
        dates:
          - '2023-04-15'
          - '2023-03-01'
    - name: static
      calendar_title: Bio
      args:
        type: Biomuell
        frequency: WEEKLY
        interval: 2
        start: '2023-01-06'
        until: '2023-12-22'
        excludes:
          - '2023-09-29'
        dates:
          - '2023-09-23'
    - name: static
      calendar_title: Rest
      args:
        type: Restmuell
        frequency: WEEKLY
        interval: 3
        start: '2023-01-17'
        until: '2023-12-19'
        excludes:
          - '2023-09-29'
        dates:
          - '2023-09-23'
    - name: static
      calendar_title: Gelb
      args:
        type: Gelbe
        frequency: WEEKLY
        interval: 4
        start: '2023-01-18'
        until: '2023-12-20'
    - name: zva_sek_de
      calendar_title: "ZVA"
      args:
        bezirk: "Felsberg"
        ortsteil: "Felsberg"



Discussion:

Resolving patch:
diff --git a/custom_components/waste_collection_schedule/waste_collection_schedule/source/zva_sek_de.py b/custom_components/waste_collection_schedule/waste_collection_schedule/source/zva_sek_de.py
--- a/custom_components/waste_collection_schedule/waste_collection_schedule/source/zva_sek_de.py
+++ b/custom_components/waste_collection_schedule/waste_collection_schedule/source/zva_sek_de.py
@@ -109,6 +109,8 @@ def fetch(self):
             "ak_bezirk": bezirk_id,
             "ak_ortsteil": ortsteil_id,
             "alle_arten": "",
+            "iCalEnde": 6,
+            "iCalBeginn": 17,
         }
         if self._street is not None:
             args["ak_strasse"] = street_id


Test patch: