From 74e412a9f87b6dfb6b27c526a5f3ec380f1d6d2a Mon Sep 17 00:00:00 2001 From: bbqandgames Date: Tue, 26 Nov 2024 17:01:12 -0500 Subject: [PATCH] Updated holiday date check to reset after a Sunday is reached --- .../source/republicservices_com.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/custom_components/waste_collection_schedule/waste_collection_schedule/source/republicservices_com.py b/custom_components/waste_collection_schedule/waste_collection_schedule/source/republicservices_com.py index 3834250ab..b6525405d 100644 --- a/custom_components/waste_collection_schedule/waste_collection_schedule/source/republicservices_com.py +++ b/custom_components/waste_collection_schedule/waste_collection_schedule/source/republicservices_com.py @@ -118,6 +118,9 @@ def fetch(self): i += 1 # Cycle through schedule and holidays incorporating delays + # According to Republic Waste "Holidays typically push our residential pickup + # schedules back one day with regular schedules resuming the following week." + # Source: https://www.republicservices.com/customer-support/faq while True: changes = 0 for holiday in holidays: @@ -126,8 +129,10 @@ def fetch(self): d = holidays[holiday]["delay"] for pickup in schedule: p = schedule[pickup]["date"] - date_difference = (p - h).days - if date_difference <= 5 and date_difference >= 0: + # Calculate the next Sunday since Sunday should reset the + # scheduled pickup date + ns = h + timedelta(days=6 - h.weekday()) + if h <= p < ns: revised_date = p + timedelta(days=d) schedule[pickup]["date"] = revised_date holidays[holiday]["incorporated"] = True