Repository: mampfes/hacs_waste_collection_schedule

Issue:
provide custom HEADERS in ical source
Hello, 

I'm trying to download an ics schedule from my providers homepage. It only works when a "Referer":"<url>" Header is set. Otherwise a 403 Error occure. I manually changed the fixed Header (currently the user-agent) in the ics.py, but that will be overridden in future updates, i guess.

My question (or feature request, i suppose) is, is there a way to provide such a custom Header in the source configuration for ics?


Discussion:
@mampfes 
Could we just add a new argument headers and extend the existing HEADERS variable?

```python
class Source:
    def __init__(
        self,
        url=None,
        file=None,
        offset=None,
        params=None,
        year_field=None,
        method="GET",
        regex=None,
        split_at=None,
        version=2,
        verify_ssl=True,
---     headers=None,   #add this line
    ):
        self._url = url
        self._file = file
        if bool(self._url is not None) == bool(self._file is not None):
            raise RuntimeError("Specify either url or file")
        if version == 1:
            self._ics = ICS_v1(offset=offset, split_at=split_at, regex=regex)
        else:
            self._ics = ICS(offset=offset, split_at=split_at, regex=regex)
        self._params = params
        self._year_field = year_field  # replace this field in params with current year
        self._method = method  # The method to send the params
        self._verify_ssl = verify_ssl
---     if headers is not None:  #add this line
---         HEADERS.update(headers)  #add this line
```

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
@@ -19,7 +19,7 @@
         "url": "https://stadtreinigung-leipzig.de/wir-kommen-zu-ihnen/abfallkalender/ical.ics?position_nos=38296&name=Sandgrubenweg%2027"
     },
     "Ludwigsburg": {
-        "url": "https://www.avl-ludwigsburg.de/fileadmin/Files/Abfallkalender/ICS/Privat/Privat_{%Y}_Ossweil.ics"
+        "url": "https://kundenportal.avl-lb.de/WasteManagementLudwigsburg/WasteManagementServiceServlet?ApplicationName=Calendar&SubmitAction=sync&StandortID=950230001&AboID=8188&Fra=BT;RT;PT;LT;GT"
     },
     "Esslingen, Bahnhof": {
         "url": "https://api.abfall.io/?kh=DaA02103019b46345f1998698563DaAd&t=ics&s=1a862df26f6943997cef90233877a4fe"
@@ -135,6 +135,7 @@ def __init__(
         split_at=None,
         version=2,
         verify_ssl=True,
+        headers={},
     ):
         self._url = url
         self._file = file
@@ -148,6 +149,8 @@ def __init__(
         self._year_field = year_field  # replace this field in params with current year
         self._method = method  # The method to send the params
         self._verify_ssl = verify_ssl
+        self._headers = HEADERS
+        self._headers.update(headers)
 
     def fetch(self):
         if self._url is not None:
@@ -187,11 +190,11 @@ def fetch_url(self, url, params=None):
         # get ics file
         if self._method == "GET":
             r = requests.get(
-                url, params=params, headers=HEADERS, verify=self._verify_ssl
+                url, params=params, headers=self._headers, verify=self._verify_ssl
             )
         elif self._method == "POST":
             r = requests.post(
-                url, data=params, headers=HEADERS, verify=self._verify_ssl
+                url, data=params, headers=self._headers, verify=self._verify_ssl
             )
         else:
             raise RuntimeError(


Test patch: