Skip to content

feat: away mode brings the old targets back on its own - #28

Merged
subpathdev merged 1 commit into
feat/save-airingfrom
feat/away-mode
Dec 1, 2026
Merged

subpathdev merged 1 commit into
feat/save-airingfrom
feat/away-mode

Conversation

@subpathdev

Copy link
Copy Markdown
Owner

Stacked on #27 (airing in SQLite). Merge that first; GitHub then retargets this PR to main.

Why

When leaving for a few days, every room had to be lowered by hand, and nothing raised the targets again. Away mode does both. Its state is saved, so a restart or release during the trip doesn't lose the return.

What changes

  • Controller:
    • StartAway(until, target) gives every room whose target is known the away target and remembers its old one. EndAway() ends away now.
    • At the end, a room still at the away target gets its old target back. A room changed during away is left alone.
    • The old target is resent until the thermostat confirms it. It never gives up, like the end of airing, and commandFailed shows on the page after about 5 minutes.
    • A thermostat that is off gets the target once it heats again. A room airing at the end gets it when airing ends.
    • Starting away again during away sets a new end and target and keeps the old targets.
    • The end must be in the future and within 30 days.
  • Saving:
    • A new AwayStore port, combined with AiringStore into Store, holds an Away value created through RestoreAway.
    • A change to several rooms is made together. If one room can't be saved, no room changes, and the next tick writes back anything already saved.
    • At startup, an old target outside the allowed range is clamped to the nearest allowed value.
  • SQLite: migration 0002_away.sql adds an away table. A database created by feat: keep airing in SQLite so it survives a restart #27 is migrated in place.
  • API (the contract changed first, then the code was regenerated):
    • PUT /api/away answers 400 for an invalid end or target, 409 if no room's target is known yet, and 500 if the change couldn't be saved.
    • DELETE /api/away ends away now.
    • The room list gains away; each room gains awayState and awayRestoreTarget.
    • oapi-codegen renamed the AiringState constants (for example api.Active is now api.AiringStateActive) because the new enum shares values with it.
  • Page:
    • An "Away…" button opens a native <dialog> with a datetime-local field for the end and a number field for the away target. It suggests 17 °C and the next day.
    • While away, a banner says when it ends and what each room gets back, with "Back now".
    • Each room has a note while away and while its old target is being restored.
  • README: a new "Away" section, and "Saved state" now covers away.

Verification

  • go build ./..., go vet ./... and go test -race ./... pass. golangci-lint v2.15.0 (through podman) reports 0 issues.

  • Controller tests (12):

    • lower, then bring back;
    • a room changed during away is left alone;
    • the restore never gives up and slow retries go on;
    • validation;
    • starting again keeps the old targets;
    • ending now;
    • a change that can't be saved changes nothing;
    • away during airing;
    • carrying on after a restart, both during away and while restoring;
    • a room without a known target is skipped.

    As a check, I removed the never-give-up rule, and its test failed.

  • SQLite tests: round trip, migrating a database at schema version 1, and a reopen test: away that ends while the service is down still sends the old target after it starts.

  • Local run against a throwaway Mosquitto (podman) with two fake thermostats:

    • started with feat: keep airing in SQLite so it survives a restart #27's binary, then this one: the schema migrated from 1 to 2;
    • started away from the dialog in the browser at phone width: 17 °C was sent to both rooms;
    • restarted during away: it carried on;
    • at the end time it sent 21 and 19 °C, and the page showed "Away is over: raising the target to …";
    • after the fake thermostats confirmed, the rows were deleted.
  • Not verified: real thermostats, the cluster.

🤖 Generated with Claude Code

"Away…" lowers every room with a known target to one target until a date
and time, then raises each room back to the target it had before. Rooms
whose target was changed during away are left alone. Raising the target
back follows the rules for the end of airing: it repeats until the
thermostat confirms it, never gives up, and the page shows a problem.

Away is saved through a new AwayStore port in the SQLite database
(migration 0002), so it survives a restart, and an end that passed while
the service was down is applied as soon as it runs again. Changes to
several rooms are made together: if one room can't be saved, none
changes.

API: PUT and DELETE /api/away, RoomList.away, and Room.awayState and
awayRestoreTarget. The page gets a banner with "Back now" and a native
dialog that suggests 17 °C and the next day.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@subpathdev
subpathdev merged commit 82aef17 into feat/save-airing Dec 1, 2026
6 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