Skip to content

Fix reading the display on a SKY - #1168

Draft
joostlek wants to merge 1 commit into
frenck:mainfrom
joostlek:fix-sky-screensaver-modes
Draft

Fix reading the display on a SKY#1168
joostlek wants to merge 1 commit into
frenck:mainfrom
joostlek:fix-sky-screensaver-modes

Conversation

@joostlek

Copy link
Copy Markdown
Collaborator

Proposed Changes

(Describe the changes and rationale behind them)

A regression in #1162, released in v1.4.0. Reading the display on a SKY raises:

mashumaro.exceptions.MissingField: Field "when_dark" of type
DisplayScreensaverWhenDark is missing in DisplayScreensaverModes instance

That propagates out of device() and display(), so a SKY cannot be set up at all on v1.4.0.

The cause is that I modelled screensaver.modes from a TIME, which reports time_based and when_dark, and made both fields required. A SKY reports time_based and screen_off:

"screensaver": {
    "enabled": true,
    "modes": {
        "screen_off": { "enabled": false },
        "time_based": { "enabled": false }
    },
    "widget": ""
}

Which modes a device reports depends on the hardware, so every mode is now optional rather than the model asserting any particular set. screen_off is modelled, and added to ScreensaverMode so it can be selected on a SKY.

Why it was missed

Every device fixture in the repo is a TIME — device.json and device2.json are an LM 37X8, device3.json is an sa8 — so there was no SKY payload to contradict the assumption. This adds device_sky.json, taken from a real SKY, to the parametrized test_get_device, plus a test covering the mode difference explicitly. The snapshot changes are purely additive: the existing TIME snapshots gain 'screen_off': None, with no values altered.

Compatibility

time_based and when_dark are now | None and so need a None check. This is visible to type checkers, and updating this repo's own tests surfaced 12 such errors, which is a fair preview of what a consumer will see.

It is not a behavioural break, though: previously a missing mode raised MissingField rather than yielding None, so any code path that worked before still works. Only code that already had to handle the exception now gets a None instead.

Verified both ways: a live LaMetric TIME (sa8, OS 3.2.7) still reads correctly with when_dark populated and screen_off as None, and the SKY payload now parses with the reverse.

Related Issues

(Github link to related issues or pull requests)

Regression from #1162.

🤖 Generated with Claude Code

The screensaver modes were modelled from a TIME, which reports
time_based and when_dark, and both were required. A SKY reports
time_based and screen_off, so reading its display raised

  MissingField: Field "when_dark" of type DisplayScreensaverWhenDark
  is missing in DisplayScreensaverModes instance

which fails device() outright and so breaks setting up a SKY at all.

Every mode is now optional, and screen_off is modelled and selectable
through ScreensaverMode. Which modes a device reports depends on the
hardware, so this stops being an assumption about any one model.

The device fixtures were all TIMEs, which is why this was missed. Adds a
SKY fixture, taken from a real device, to the device test and covers the
mode difference explicitly.

Note that time_based and when_dark are now optional and so need a None
check; mashumaro raised on the missing field before, rather than
returning None, so nothing that worked before stops working.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@joostlek
joostlek marked this pull request as draft September 10, 2026 18:18
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