Repository: mampfes/hacs_waste_collection_schedule

Issue:
[Bug]: BSR_DE seems not to work anymore
### I Have A Problem With:

A specific source

### What's Your Problem

Source BSR_DE is not importing anything.

This is the Path to the Calendar
https://www.bsr.de/abfuhrkalender_ajax.php?script=dynamic_iCal_ajax&abf_strasse=Chaukenstr.,%2012524%20Berlin%20(Treptow-K%C3%B6penick)&abf_hausnr=3X&tab_control=Liste&abf_config_weihnachtsbaeume=&abf_config_restmuell=on&abf_config_biogut=on&abf_config_wertstoffe=on&abf_config_laubtonne=on

this is the Ical it should get.

BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//www.bsr.de//NONSGML kigkonsult.se iCalcreator 2.41.71//
CALSCALE:GREGORIAN
UID:65616338-3738-4064-a633-326437643934
BEGIN:VEVENT
UID:32386261-6536-4130-a166-356138626438
DTSTAMP:20231228T151659Z
DESCRIPTION:Abholung Hausmüll
DTSTART;TZID=Europe/Berlin:20231228T000000
LOCATION:Chaukenstr. 3X\,
SUMMARY:Abholung Hausmüll
END:VEVENT
BEGIN:VEVENT
UID:37383565-6638-4232-a331-633133633061
DTSTAMP:20231228T151659Z
DESCRIPTION:Abholung Biogut
DTSTART;TZID=Europe/Berlin:20240102T000000
LOCATION:Chaukenstr. 3X\,
SUMMARY:Abholung Biogut
END:VEVENT
BEGIN:VEVENT
UID:30626662-3731-4963-b836-653262613233
DTSTAMP:20231228T151659Z
DESCRIPTION:Abholung Wertstoffe (Abholung durch ALBA)
DTSTART;TZID=Europe/Berlin:20240109T000000
LOCATION:Chaukenstr. 3X\,
SUMMARY:Abholung Wertstoffe (Abholung durch ALBA)
END:VEVENT
BEGIN:VEVENT
UID:64356336-6132-4464-a339-646533373961
DTSTAMP:20231228T151659Z
DESCRIPTION:Abholung Hausmüll
DTSTART;TZID=Europe/Berlin:20240110T000000
LOCATION:Chaukenstr. 3X\,
SUMMARY:Abholung Hausmüll
END:VEVENT
BEGIN:VEVENT
UID:61636636-6661-4834-b063-653566636636
DTSTAMP:20231228T151659Z
DESCRIPTION:Abholung Biogut
DTSTART;TZID=Europe/Berlin:20240115T000000
LOCATION:Chaukenstr. 3X\,
SUMMARY:Abholung Biogut
END:VEVENT
BEGIN:VEVENT
UID:32326238-3862-4533-b361-353033303935
DTSTAMP:20231228T151659Z
DESCRIPTION:Abholung Wertstoffe (Abholung durch ALBA)
DTSTART;TZID=Europe/Berlin:20240123T000000
LOCATION:Chaukenstr. 3X\,
SUMMARY:Abholung Wertstoffe (Abholung durch ALBA)
END:VEVENT
BEGIN:VEVENT
UID:30396632-3239-4764-b439-336132306661
DTSTAMP:20231228T151659Z
DESCRIPTION:Abholung Hausmüll
DTSTART;TZID=Europe/Berlin:20240124T000000
LOCATION:Chaukenstr. 3X\,
SUMMARY:Abholung Hausmüll
END:VEVENT
END:VCALENDAR

### Source (if relevant)

BSR_DE

### Logs

```Shell
no relevant logs
```


### Relevant Configuration

```YAML
- name: bsr_de
      args:
        abf_strasse: Chaukenstr., 12524 Berlin (Treptow-Köpenick)
        abf_hausnr: 3*
```


### Checklist Source Error

- [X] Use the example parameters for your source (often available in the documentation) (don't forget to restart Home Assistant after changing the configuration)
- [X] Checked that the website of your service provider is still working
- [X] Tested my attributes on the service provider website (if possible)
- [X] I have tested with the latest version of the integration (master) (for HACS in the 3 dot menu of the integration click on "Redownload" and choose master as version)

### Checklist Sensor Error

- [x] Checked in the Home Assistant Calendar tab if the event names match the types names (if types argument is used)

### Required

- [X] I have searched past (closed AND opened) issues to see if this bug has already been reported, and it hasn't been.
- [X] I understand that people give their precious time for free, and thus I've done my very best to make this problem as easy as possible to investigate.


Discussion:
Same here. 29.12.2023 was the last entry (Wertstoffe). All following in 2024 are not shown.
Same here. Seems that dates for 2024 are not downloaded
Similar issue for Belgium, I guess we need to wait for 2024 
> Same here. 29.12.2023 was the last entry (Wertstoffe). All following in 2024 are not shown.

I dont have that. Can you share your Config ?
did some investigating on their website but I can't get a ICS file (which the source uses to get the dates) containing any collections for 2024 Even though there are some listed in the html table in List view. This could fix itself in 2024 but currently there is nothing I can do about it.

edit:
@Detmud how did you get this ical file containing events for 2024? I only got empty ICAL files or one with only 2023 events when testing
@1aranzant which source for Belgium do you mean? I might have a look at it (may prevent this for next year) 
@5ila5   Recycle! 
@1aranzant 3 out of 4 test cases return collections for 2024 I guess some municipalities have not yet added their collection dates.
Do you see any dates entering your address on their website (https://www.recycleapp.be)?
@5ila5 I do see the 2024 collection dates on the recycle website, but my HA calendar is empty :/ 

EDIT: just solved my issue... I changed the French streetname to the Dutch one on my config yaml. They must have deleted the French name recently (because it used to work! lol)
thx :)
Seems you can only get a yearly ics calendar for the current year but if you select monthly you can already download ics files with dates for next year

Resolving patch:
diff --git a/custom_components/waste_collection_schedule/waste_collection_schedule/source/bsr_de.py b/custom_components/waste_collection_schedule/waste_collection_schedule/source/bsr_de.py
--- a/custom_components/waste_collection_schedule/waste_collection_schedule/source/bsr_de.py
+++ b/custom_components/waste_collection_schedule/waste_collection_schedule/source/bsr_de.py
@@ -1,4 +1,5 @@
 import urllib.parse
+import datetime
 
 import requests
 from waste_collection_schedule import Collection  # type: ignore[attr-defined]
@@ -91,6 +92,22 @@ def fetch(self):
         # parse ics file
         dates = self._ics.convert(r.text)
 
+
+        now = datetime.datetime.now()
+        # in nov/dec already fetch a monthly ics for january
+        # as yearly ics isn't available until the 1. of january.
+        if now.month in [11, 12]:
+            args["tab_control"] = "Monat"
+            args["abf_selectmonth"] = "1 " + str(now.year + 1)
+
+            # create url using private url encoding
+            encoded = map(lambda key: f"{key}={myquote(str(args[key]))}", args.keys())
+            url = "https://www.bsr.de/abfuhrkalender_ajax.php?" + "&".join(encoded)
+            r = requests.get(url, cookies=cookies)
+
+            # parse ics file
+            dates.extend (self._ics.convert(r.text) )
+
         entries = []
         for d in dates:
             entries.append(Collection(d[0], d[1]))


Test patch: