mampfes / hacs_waste_collection_schedule

Home Assistant integration framework for (garbage collection) schedules
MIT License
997 stars 634 forks source link

[Feature]: Add Garden Waste option to Waverley UK source #1940

Open mjdyson opened 5 months ago

mjdyson commented 5 months ago

I propose a feature for:

Sources

Describe your wanted feature

Garden Waste collection day is not currently provided by the website API, however it can be inferred.

The Waverley website states that garden waste is collected on the same week as as the domestic waste https://www.waverley.gov.uk/Services/Bins-and-recycling/Rubbish-and-recycling-collections/Check-bin-collection-day

See excerpt:

image

I have a working prototype code that may be useful for other users - i'm happy to PR or discuss alternatives:

for u1 in u1s:
    lis = u1.find_all("li", recursive=False)
    entries.append(
        Collection(
            date=datetime.strptime(
                lis[1].text.replace("\n", ""), "%d/%m/%Y"
            ).date(),
            t=lis[2].text.replace("\n", ""),
            icon=ICON_MAP.get(
                lis[2].text.replace("\n", "").replace(" Collection Service", "")
            ),
        )
    )
    if self._garden_waste:
        if "Domestic" in lis[2].text:
            date = datetime.strptime(
                        lis[1].text.replace("\n", ""), "%d/%m/%Y"
                    ).date()
            entries.append(
                Collection(
                    date - timedelta(datetime.weekday(date) - self._garden_waste),
                    t="Garden Waste Collection Service",
                    icon=ICON_MAP.get("Garden Waste")
                ),
            )
kalmatthew commented 5 months ago

This used to work and I can't quite work out when it failed. Also despite that text if you use their online checker it does display the dates for the brown garden waste bins SmartSelect_20240417_180042_Vivaldi

mjdyson commented 5 months ago

Interesting... My garden bin doesn't come out in the checker.

Screenshot_20240417-193804.png

kalmatthew commented 5 months ago

That is odd, the really obvious thing to ask is if you renewed it for this year? Assuming you did, what day does it get collected (mine is Wednesday with domestic waste being Friday). When I have a chance to get to a proper computer I'm also going to look at the source for the page I get to try and understand why the parse doesn't work for me, when I can see the detials.

mjdyson commented 5 months ago

Well this may be the most obscure debugging exercise I've ever done. My garden waste "subscription" fee has expired, hence why I think it wasn't working for me.

I've now renewed and hopefully it will come back. I'll update this as required when things change.

Edit. I just got your reply. Thanks for the nudge on this. I checked my neighbours address and it was working for them. Hopefully a silly oversight on my part 😂

kalmatthew commented 5 months ago

It doesn't fix the underlying issue though!

This was irritating me so I turned on a proper PC, I'll admit that I haven't done any proper development in about 12 years and never in Python. However, the code for Garden Waste seems to be the same both by eye and with simple diff, so I had another look and discovered an oversight of my own, due to the instructions on the Waverly site I hadn't added a house number so I suspect this only worked when the house that came first for my postcode had a garden waste collection. I'm going to see if I can improve the docs for Waverly. (Now done in #1987)