fix(slots): handle cross-midnight demand windows (#896)#896
Open
jackmcintyre wants to merge 1 commit into
Open
fix(slots): handle cross-midnight demand windows (#896)#896jackmcintyre wants to merge 1 commit into
jackmcintyre wants to merge 1 commit into
Conversation
The DW membership test `dw_start_time <= slot_time < dw_end_time` is false for every slot of the day when end <= start (e.g. 22:00 -> 06:00 overnight peak). The feature silently disabled itself — no slot flagged, no DW entry detected, no pre-charge — with no error or warning. Now detects the cross-midnight case (end <= start) and applies the wrap: a slot is in the DW if its time is >= start OR < end. TDD: 5 new tests in TestDemandWindowCrossMidnight — slots at 23:00, 02:00, 12:00 (outside), 22:00 (entry boundary), 06:00 (exit, exclusive). 3 failed red (23:00, 02:00, 22:00 all wrongly False), all green after fix. 3219 pass, coverage 95%.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The DW membership test
dw_start_time <= slot_time < dw_end_timeis false for every slot of the day whenend <= start(e.g.22:00→06:00overnight peak). The feature silently disabled itself — no slot flagged, no DW entry detected, no pre-charge — with no error or warning._parse_time_option(slots.py:473) does no cross-midnight handling, and there's no validation inconfig_flow. The default15:00–21:00doesn't cross midnight, so this is latent for most users but bites anyone on an overnight-peak tariff.Changes
engine/slots.py:_process_single_slotdetects the cross-midnight case (end <= start) and applies the wrap:Validation
TestDemandWindowCrossMidnight— slots at 23:00 (in), 02:00 (in), 12:00 (out), 22:00 (entry boundary), 06:00 (exit, exclusive). 3 failed red (23:00, 02:00, 22:00 all wronglyFalse), all green after fix.uv run ruff checkclean onslots.py(pre-existing import-sort warnings in test file are unrelated).Out of scope
Config-flow validation (warning the user when end <= start) is intentionally not added — overnight windows are legitimate, so the fix is to handle them correctly rather than block them.