Repository: mampfes/hacs_waste_collection_schedule

Issue:
[Bug]:  Basingstoke and Deane is broken since the 8th of Feb
### I Have A Problem With:

A specific source

### What's Your Problem

The service no longer downloads the waste updates. I tried 1.46 and the master.

### Source (if relevant)

_No response_

### Logs

```Shell
Logger: waste_collection_schedule.source_shell
Source: custom_components/waste_collection_schedule/waste_collection_schedule/source_shell.py:136
integration: waste_collection_schedule (documentation)
First occurred: 11:26:41 (1 occurrences)
Last logged: 11:26:41

fetch failed for source Basingstoke and Deane Borough Council: 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/basingstoke_gov_uk.py", line 65, in fetch date=datetime.strptime(date_str, "%A, %d %B %Y").date(), ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/_strptime.py", line 554, in _strptime_datetime tt, fraction, gmtoff_fraction = _strptime(data_string, format) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/_strptime.py", line 333, in _strptime raise ValueError("time data %r does not match format %r" % ValueError: time data 'none / unknown' does not match format '%A, %d %B %Y'
```


### Relevant Configuration

```YAML
waste_collection_schedule:
  sources:
    - name: basingstoke_gov_uk
      args:
        uprn: "1000809XXXX"
      customize:
        - type: Garden
          show: True
        - type: Waste
          show: True
        - type: Recycling
          show: True
        - type: Glass
          show: True
```


### 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:
Our tests UPRNs (`100060234732`, `100060218986`, `100060235836`, `100060224194`) seem to work fine. Could you please enter your address in https://www.basingstoke.gov.uk/bincollections and check weather collection dates are actually shown. If not, could you please provide an HTML snippet starting with the `Waste collection dates` Headline or at least a screenshot of the section where you see `none / unknown` instead of the actual date.
Hi @5ila5, I have double-checked the uprn, which is correct. It was working ok until Friday.
Looking at the Basingstoke website, the Waste collection dates show "none / unknown", while Recycling, Glass and Garden are showing ok even if in HA I see "Unknown".

<div id="rteelem_ctl03_pnlCollections_Refuse" class="service">
		
                <h2>Waste collection dates</h2>
                <div class="image">
                    <img src="Images/when-are-my-bins-collected/bin-waste.gif" alt="Waste/refuse bin" />
                </div>
                <div class="text">
                    <p>Your waste is collected <strong>fortnightly</strong>, normally on <strong>Tuesday</strong>.</p>
                    <p>Your next scheduled collection dates are:</p>
                    <ul><li>none / unknown</li></ul>
                </div>
            
	</div>

Basingstoke website
![Screenshot 2024-03-10 at 12 49 15](https://github.com/mampfes/hacs_waste_collection_schedule/assets/48698293/e7b18c0c-d73c-4a8a-ae90-41400aab35e5)

Home Assistant
![Screenshot 2024-03-10 at 12 50 02](https://github.com/mampfes/hacs_waste_collection_schedule/assets/48698293/1bc14a0a-bf03-4e4d-a0eb-14ac09042b8c)


Resolving patch:
diff --git a/custom_components/waste_collection_schedule/waste_collection_schedule/source/basingstoke_gov_uk.py b/custom_components/waste_collection_schedule/waste_collection_schedule/source/basingstoke_gov_uk.py
--- a/custom_components/waste_collection_schedule/waste_collection_schedule/source/basingstoke_gov_uk.py
+++ b/custom_components/waste_collection_schedule/waste_collection_schedule/source/basingstoke_gov_uk.py
@@ -1,3 +1,4 @@
+import logging
 from datetime import datetime
 
 import requests
@@ -30,6 +31,7 @@
     "GARDEN": "mdi:leaf",
     "GLASS": "mdi:glass-fragile",
 }
+LOGGER = logging.getLogger(__name__)
 
 
 class Source:
@@ -60,9 +62,17 @@ def fetch(self):
             schedule_dates = service.findAll("li")
             for schedule in schedule_dates:
                 date_str = schedule.text.split("(")[0].strip()
+                try:
+                    date = datetime.strptime(date_str, "%A, %d %B %Y").date()
+                except ValueError as e:
+                    LOGGER.warning(
+                        f"Failed to parse date '{date_str}' for wastetype {waste_type}: {e}"
+                    )
+                    continue
+
                 entries.append(
                     Collection(
-                        date=datetime.strptime(date_str, "%A, %d %B %Y").date(),
+                        date=date,
                         t=waste_type,
                         icon=ICON_MAP.get(waste_type.upper()),
                     )


Test patch: