Skip to content

Reject a time based screensaver without both times - #1171

Merged
frenck merged 1 commit into
frenck:mainfrom
joostlek:screensaver-time-validation
Sep 11, 2026
Merged

frenck merged 1 commit into
frenck:mainfrom
joostlek:screensaver-time-validation

Conversation

@joostlek

Copy link
Copy Markdown
Collaborator

Proposed Changes

(Describe the changes and rationale behind them)

Setting the screensaver time did not work. The device wants both start_time and end_time on every time_based write, even one that only toggles enabled, and it fails three different ways without them:

mode_params Device response
start_time alone 200, and quietly ignored
end_time alone 400 Bad end time params
enabled alone, no times 400 Bad end time params

The first row is the damaging one, and the likely cause of the report. Changing only the start time — the obvious way to use this — reported success, and the returned Display still held the old times, so nothing indicated the write had been dropped:

# before: reported success, changed nothing
await lametric.display(
    screensaver_mode=ScreensaverMode.TIME_BASED,
    screensaver_start_time=time(21, 0),
)

display() now raises ValueError for the time based mode unless both times are given, so the mismatch surfaces at the call rather than looking like it worked. The other modes take no times and are unaffected, which a test covers.

Requiring both times even to disable the mode is the device's rule, not a choice made here. Callers that only want to toggle it can pass the times they read back from display(), or switch modes instead, since enabling one mode disables the other.

Verified against a LaMetric TIME (model sa8, OS 3.2.7): all three shapes above now raise before any request is sent, and a write with both times applies and reads back correctly.

Follow-up worth considering

The 400 cases surfaced as LaMetricError: Error occurred while connecting to the LaMetric device at <host>, which is actively misleading, since nothing was wrong with the connection. _request() discards the response body on ClientResponseError, so the device's own Bad end time params never reaches the caller. Including it would have made this far easier to diagnose, but it changes exception messages across every endpoint, so it belongs in its own change.

Related Issues

(Github link to related issues or pull requests)

None.

🤖 Generated with Claude Code

Setting the screensaver time did not work. The device wants both times
on every time based write, even one that only toggles the mode, and it
fails in three different ways without them:

  start_time alone  200, and quietly ignored
  end_time alone    400 Bad end time params
  neither           400 Bad end time params

The first is the bad one. Changing only the start time, which is the
obvious way to use this, reported success and returned a Display still
holding the old times.

display() now raises ValueError for the time based mode unless both
times are given, so the mismatch surfaces at the call instead of looking
like it worked. The other modes take no times and are unaffected.

Verified against a LaMetric TIME (sa8, OS 3.2.7).

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@frenck frenck added the bugfix Inconsistencies or issues which will cause a problem for users or implementers. label Sep 11, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The focused validation matches documented device behavior and is adequately tested.

Pull request overview

Adds early validation for device-required time-based screensaver parameters.

Changes:

  • Requires both start and end times for time-based writes.
  • Tests invalid combinations and unaffected modes.
File summaries
File Description
src/demetriek/device.py Validates time-based screensaver writes.
tests/test_display.py Covers validation and other modes.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@frenck
frenck merged commit 71c9d9d into frenck:main Sep 11, 2026
13 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Inconsistencies or issues which will cause a problem for users or implementers.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants