Skip to content

fix: handle undated Lichfield collection cards - #2179

Closed
JasSmiths wants to merge 1 commit into
robbrad:masterfrom
JasSmiths:agent/fix-lichfield-food-waste-parser
Closed

fix: handle undated Lichfield collection cards#2179
JasSmiths wants to merge 1 commit into
robbrad:masterfrom
JasSmiths:agent/fix-lichfield-food-waste-parser

Conversation

@JasSmiths

@JasSmiths JasSmiths commented Jul 19, 2026

Copy link
Copy Markdown

Summary

  • parse each Lichfield collection card as a self-contained unit instead of pairing global heading and date lists by index
  • derive the next food-waste collection from the weekly weekday shown by the council when no explicit date is present
  • preserve the existing Food Waste bin type used by Home Assistant entities
  • roll explicit collection dates into the next year when their month and day have already passed
  • add regression coverage for the undated food-waste card, the Purple Bin date, the calendar download card, and year rollover

Root cause

Lichfield added a Food Waste Caddy card that contains a weekly collection weekday but no bin-collection-tasks__date element. The scraper collected all headings and all dates into separate lists and paired them by position. The undated card shifted every subsequent date onto the wrong bin and omitted the final dated bin.

Impact

Collection dates remain attached to their own cards, so Brown, Blue, Black, and Purple Bin data is returned correctly. The weekly Food Waste collection is also exposed without changing its existing entity identity.

Validation

  • Python 3.12 targeted regression tests: 2 passed
  • Black formatting check passed
  • live Lichfield scraper invocation using the repository's existing test UPRN returned correctly paired collection data

Summary by CodeRabbit

  • Bug Fixes

    • Corrected Lichfield bin collection dates so each collection is paired with its corresponding date.
    • Improved handling of collection dates that fall in the following calendar year.
    • Preserved the expected “Food Waste” bin label for consistent integrations.
  • Tests

    • Added coverage for date pairing, explicit collection dates, and year transitions.

@coderabbitai

coderabbitai Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Lichfield’s parser now processes each collection card independently, calculates explicit and weekday-based dates relative to the current date, preserves the Food Waste bin identity, and adds deterministic tests for card dates and year rollover.

Changes

Lichfield parser behavior

Layer / File(s) Summary
Card-based date parsing and bin normalization
uk_bin_collection/.../LichfieldDistrictCouncil.py
Collection cards are parsed independently, dates are calculated from explicit or weekday data, and Food Waste Caddy is normalized to Food Waste.
Deterministic parser regression coverage
uk_bin_collection/tests/test_lichfield_district_council.py
A fixed HTML fixture and mocked time and HTTP responses verify card-specific dates and explicit dates rolling into the next year.

Estimated code review effort: 3 (Moderate) | ~20 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and accurately summarizes the main change: handling undated Lichfield collection cards.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@JasSmiths

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@JasSmiths
JasSmiths marked this pull request as ready for review July 24, 2026 14:44
@JasSmiths

Copy link
Copy Markdown
Author

Hi @robbrad, this is ready for review. The fix has been validated against the live Lichfield site and in Home Assistant, including the Food Waste and Purple Bin collection dates. The fork workflows are currently awaiting maintainer approval. When you have a chance, could you please approve the workflows and review the PR? Thanks.

@robbrad

robbrad commented Jul 24, 2026

Copy link
Copy Markdown
Owner

@JasSmiths thanks mate I'll get to it this weekend

robbrad commented Jul 25, 2026

Copy link
Copy Markdown
Owner

Thanks for the detailed writeup and tests on this — the synthetic-weekday-date approach for the dateless Food Waste card and the year-rollover fix were both good catches. #2187 fixed the same underlying bug independently (card-scoped heading/date pairing), so rather than pick one over the other I synthesized both into a single fix in the consolidated "July Part 2" release: #2189. It keeps your weekly-frequency fallback and year-rollover fix, combined with #2187's cleaner heading-text extraction (stripping the visually-hidden spans instead of slicing words). Your regression tests are included too. Closing this one out — credited in the PR.


Generated by Claude Code

@robbrad robbrad closed this Jul 25, 2026
pull Bot pushed a commit to mrw298/UKBinCollectionData that referenced this pull request Jul 25, 2026
LichfieldDistrictCouncil zipped a page-wide heading list and a
page-wide date list together by index. Two things on the current page
break that: the calendar-download link reuses the heading class but
has no date, and a bin with no scheduled collection (Food Waste Caddy)
renders a "Collected every <day>" frequency instead of a date. Either
one shifts every later bin onto the wrong date and drops the last bin.

Iterate each card and read its own date instead of pairing by
position. When a card has no date but does have a weekly frequency,
derive the next occurrence of that weekday so the entity keeps
reporting (previously it silently inherited a neighboring bin's date).
Extract the bin name by removing the visually-hidden heading spans
rather than slicing words, so three-word names like "Food Waste Caddy"
survive; that value is then mapped back to "Food Waste" to preserve
the existing Home Assistant entity identity. Also fix year rollover to
compare against today's date directly instead of a month heuristic.

Synthesizes PR robbrad#2179 by JasSmiths and PR robbrad#2187 by alec-pinson, which
independently reported and fixed this bug.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants