Skip to content

Night engine fixes: Start now, Off after I'm up, switched-off nights, empty cutoff - #115

Merged
ncbudd merged 3 commits into
mainfrom
engine-fixes
Nov 27, 2026
Merged

ncbudd merged 3 commits into
mainfrom
engine-fixes

Conversation

@ncbudd

@ncbudd ncbudd commented Nov 27, 2026

Copy link
Copy Markdown
Owner

Root cause

A bug pass over the night engine (controller, night, presence, summary, away) turned up these, each checked in the code
and reproduced with a test that fails before the fix:

  1. "Start now" didn't always start. After "Wait an hour", an earlier "I'm up", or a long enough time out of bed,
    the pause, the ended flag or the stale out-of-bed time kept the side off.
  2. "Off tonight" pressed after "I'm up", but before the planned end, marked the finished night as skipped instead
    of the coming one, so tonight's night still ran.
  3. A night switched off after it started stayed "skipped" past its end. No "night done" was recorded, the morning
    summary waited, and the noon rollover was held back.
  4. The empty-side safety cutoff outlived its afternoon. A by-hand session left on an empty bed tripped it, and it
    then also blocked the evening's pre-conditioning (and "Start now" or "Resume") until someone lay down.
  5. A temperature set right after "Off tonight" (before the evening's pre-cool) didn't turn the side on: the engine
    still saw the side as "off by the person", so the change wasn't treated as "turn my side on".
  6. The morning "Were you away?" check ignored away periods that had already ended, so after coming back it could
    ask about a night the person was marked away.
  7. A wearable night record with no length divided by zero in that same check.

Fix

  • tonight("start_now") clears the pause, the ended / lie-in-over flags, the out-of-bed times and the empty cutoff;
    resume and any night start (_began) clear the empty cutoff, and so does entering pre-conditioning ("waiting").
  • tonight("skip") sets skip_next once the night has ended by hand, as it already did after the planned end.
  • A started night that's switched off becomes "done" at its end (unless lying in).
  • adjust() counts a side it has just resumed as idle, so a temperature turns it on by hand.
  • away.morning_check also treats a night as away when an ended away period covered at least half of it, and
    night_verdict returns "can't tell" when there are no rows.

Noted and not changed here (each needs a decision, or is intentional):

  • Heavy movement on one side keeps the other side "in bed" (a commented design choice: someone may be on the other side).
  • The lie-in can run 4 h past the planned end while the summary window stops at wake + 3 h.
  • Swapping sides in the middle of a night leaves "I'm up" on the person, not the side.
  • An alarm set for tomorrow, seen during a lie-in after noon, can move the old night's wake time.
  • A watch or pet check holding presence as unknown for over 10 min can trigger the schedule fallback.
  • Guest mode reads the regular sleeper's phone for the pet check.
  • An adjust with a different "until" replaces a whole-night override instead of adding to it.
  • The morning summary keys nights by the bedtime's calendar date (looks wrong for bedtimes after midnight, but real
    mornings with a midnight bedtime work, so it needs a test against real data first).

Verification

  • New tests/test_engine_fixes.py (6 scenario tests); all 6 fail on the old engine and pass now.
  • The 43 test files that exercise nights, "tonight" actions, away, morning, notifications and pets: 942 passed
    (the soak test is left to CI).

Release note

Fixes: "Start now" starts even after a pause or getting up; "Off tonight" pressed after "I'm up" is for the coming
night; a night switched off still finishes properly (night summary and morning notification); an empty-bed cutoff in
the afternoon no longer stops the evening's pre-cooling; and the morning "Were you away?" question doesn't ask about
nights you were already marked away.

@ncbudd
ncbudd merged commit a5f2d8c into main Nov 27, 2026
15 checks passed
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.

1 participant