fix: add rotation fallback for south kesteven calendar lookup#2119
fix: add rotation fallback for south kesteven calendar lookup#2119InertiaUK wants to merge 1 commit into
Conversation
when ocr is unavailable and the fallback calendar table does not cover the requested date, calculate the bin type using a 3-week rotation anchored to a known collection (oct 2025 week 2 = silver). verified against the published 2026/27 calendar png.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2119 +/- ##
=======================================
Coverage 86.67% 86.67%
=======================================
Files 9 9
Lines 1141 1141
=======================================
Hits 989 989
Misses 152 152 ☔ View full report in Codecov by Harness. |
📝 WalkthroughWalkthroughThe PR modifies South Kesteven District Council's bin collection logic to handle missing calendar data gracefully. When a bin type cannot be found in the parsed calendar for a specific year/month/week, the code now computes a bin type deterministically using a 3-item rotation anchored to 2025-10-13 instead of raising an error. ChangesBin Type Fallback
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
uk_bin_collection/uk_bin_collection/councils/SouthKestevenDistrictCouncil.py (1)
1126-1137: ⚡ Quick winLog when the rotation fallback path is taken.
This branch currently hides calendar coverage/OCR gaps silently. Add a warning with
collection_dateand computed week context so parser drift remains visible while preserving graceful degradation.Proposed patch
else: # Fallback: 3-week rotation derived from known anchor # Oct 2025 week 2 (day 8-14) = Silver, week 3 = Black, week 4 = Purple # Anchor: 2025-10-13 (start of week 2) = Silver (index 0) + print( + f"Calendar lookup miss for {collection_date} " + f"(Week {week_of_month} of {month}/{year}); using rotation fallback." + ) ROTATION = [ "Silver bin (Recycling)", "Black bin (General waste)", "Purple-lidded bin (Paper & Card)", ] anchor = datetime(2025, 10, 13) days_diff = (date_obj - anchor).days weeks_diff = days_diff // 7 - return ROTATION[weeks_diff % 3] + rotation_index = weeks_diff % 3 + return ROTATION[rotation_index]Based on learnings: In
uk_bin_collection/**/*.pyparsers consumed by Home Assistant, prefer defensive fallbacks with warning logs instead of raising exceptions.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@uk_bin_collection/uk_bin_collection/councils/SouthKestevenDistrictCouncil.py` around lines 1126 - 1137, Add a warning log in the fallback 3-week rotation branch so parser drift is visible: when using ROTATION with anchor, log that the fallback was used and include the collection date (date_obj / collection_date), the anchor value, and the computed days_diff and weeks_diff before returning ROTATION[weeks_diff % 3]. Use the module/class logger (e.g., _LOGGER.warning or self.logger.warning depending on this class’s logging convention) to emit a concise warning containing those values and a short message like "using fallback rotation due to missing calendar/OCR coverage".
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In
`@uk_bin_collection/uk_bin_collection/councils/SouthKestevenDistrictCouncil.py`:
- Around line 1126-1137: Add a warning log in the fallback 3-week rotation
branch so parser drift is visible: when using ROTATION with anchor, log that the
fallback was used and include the collection date (date_obj / collection_date),
the anchor value, and the computed days_diff and weeks_diff before returning
ROTATION[weeks_diff % 3]. Use the module/class logger (e.g., _LOGGER.warning or
self.logger.warning depending on this class’s logging convention) to emit a
concise warning containing those values and a short message like "using fallback
rotation due to missing calendar/OCR coverage".
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: f2f4cd44-ad0e-444b-b854-54e3578958fb
📒 Files selected for processing (1)
uk_bin_collection/uk_bin_collection/councils/SouthKestevenDistrictCouncil.py
Summary
ValueErrorinstead of returning bin dataTesting
ValueError: No bin type found for 08/06/2026 (Week 2 of 6/2026), now returns correct bin typesSummary by CodeRabbit