Repository: mampfes/hacs_waste_collection_schedule

Issue:
Add Garden waste type to Cornwall, UK source
### I propose a feature for:

Sources

### Describe your wanted feature

Can you please add Garden to the cornwall_gov_uk.py source?

Change - COLLECTIONS = {"Rubbish", "Recycling"}
to COLLECTIONS = {"Rubbish", "Recycling", "Garden"}

For my house I'm getting the following html snip so I think it should work. 

<div id="my-waste-collection">
        <h3 class="font-weight-bolder">Current collections</h3>
        <div class="row text-center">
                <div class="col-12 col-md-4">
                    <div id="recycling" class="collection text-center service">
                            <span>Recycling</span>
                            <span>SAT</span>
                            <span>30 Dec</span>
                    </div>
                </div>
                <div class="col-12 col-md-4">
                    <div id="rubbish" class="collection text-center service">
                            <span>Rubbish</span>
                            <span>TUE</span>
                            <span>2 Jan</span>
                    </div>
                </div>
                <div class="col-12 col-md-4">
                    <div id="gardenhassubscription" class="collection text-cente              r service">
                            <span>Garden</span>
                            <span>FRI</span>
                            <span>22 Dec</span>
                    </div>
                </div>
        </div>


Discussion:

Resolving patch:
diff --git a/custom_components/waste_collection_schedule/waste_collection_schedule/source/cornwall_gov_uk.py b/custom_components/waste_collection_schedule/waste_collection_schedule/source/cornwall_gov_uk.py
--- a/custom_components/waste_collection_schedule/waste_collection_schedule/source/cornwall_gov_uk.py
+++ b/custom_components/waste_collection_schedule/waste_collection_schedule/source/cornwall_gov_uk.py
@@ -2,7 +2,7 @@
 
 import requests
 from bs4 import BeautifulSoup
-from waste_collection_schedule import Collection
+from waste_collection_schedule import Collection  # type: ignore[attr-defined]
 
 TITLE = "Cornwall Council"
 DESCRIPTION = "Source for cornwall.gov.uk services for Cornwall Council"
@@ -10,13 +10,18 @@
 TEST_CASES = {
     "known_uprn": {"uprn": "100040118005"},
     "unknown_uprn": {"postcode": "TR261SP", "housenumberorname": "7"},
+    "uprn_with_garden": {"uprn": "100040080721"},
 }
 
 SEARCH_URLS = {
     "uprn_search": "https://www.cornwall.gov.uk/my-area/",
     "collection_search": "https://www.cornwall.gov.uk/umbraco/Surface/Waste/MyCollectionDays?subscribe=False",
 }
-COLLECTIONS = {"Rubbish", "Recycling"}
+ICON_MAP = {
+    "Rubbish": "mdi:delete",
+    "Recycling": "mdi:recycle",
+    "Garden": "mdi:flower",
+}
 
 
 class Source:
@@ -41,25 +46,29 @@ def fetch(self):
             for match in propertyUprns:
                 if match.text.startswith(self._housenumberorname):
                     self._uprn = match["value"]
+            if self._uprn is None:
+                raise Exception(
+                    f"No UPRN found for {self._postcode} {self._housenumberorname}"
+                )
 
         # Get the collection days based on the UPRN (either supplied through arguments or searched for above)
-        if self._uprn is not None:
-            args = {"uprn": self._uprn}
-            r = session.get(SEARCH_URLS["collection_search"], params=args)
-            r.raise_for_status()
-            soup = BeautifulSoup(r.text, features="html.parser")
-            for collection in COLLECTIONS:
-                d = (
-                    soup.find(id=collection.lower()).find_all("span")[-1].text
-                    + " "
-                    + str(date.today().year)
-                )
+        args = {"uprn": self._uprn}
+        r = session.get(SEARCH_URLS["collection_search"], params=args)
+        r.raise_for_status()
+        soup = BeautifulSoup(r.text, features="html.parser")
+        for collection_div in soup.find_all("div", class_="collection"):
+            spans = collection_div.find_all("span")
+            if not spans:
+                continue
+            collection = spans[0].text
+            d = spans[-1].text + " " + str(date.today().year)
 
-                entries.append(
-                    Collection(
-                        datetime.strptime(d, "%d %b %Y").date(),
-                        collection,
-                    )
+            entries.append(
+                Collection(
+                    datetime.strptime(d, "%d %b %Y").date(),
+                    collection,
+                    icon=ICON_MAP.get(collection),
                 )
+            )
 
         return entries


Test patch: