Let sleep tracking be switched off
Settings gets a Track sleep switch, stored on the synced profile as sleepOff (negative, so a profile from before it, or an old client that doesn't send it, means tracking). Off hides everything marked data-sleep-only (the sleep log buttons, the Sleep tab, the Sleep/Awake tiles, Last sleep and the Sleep & wake list) plus the bar timer. The sleep state also reads as unknown, so a leftover sleep-start can't dim the log buttons or run a sleep rail through every day's history. The reminder scheduler treats the state as unknown too. Otherwise a leftover sleep-start would mute every other rule for good, or a leftover sleep-end would fire the sleep rule every interval. Nothing logged is deleted.
This commit is contained in:
1 parent
f98137097c
commit
a01d74e9d5
7 files changed
+176
-32
No files matched your search
@@ -188,6 +188,46 @@ func TestSleepStateMatchesLatestBoundary(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSleepStateIgnoredWhenTrackingIsOff(t *testing.T) {
|
||||
sch := testScheduler(t)
|
||||
now := int64(1_700_000_000_000)
|
||||
configs := newConfigStore(sch.db)
|
||||
|
||||
// Tracking stopped while the log still says asleep.
|
||||
addEvent(t, sch, "u1", "pee", now-90*minute)
|
||||
addEvent(t, sch, "u1", "sleep-start", now-600*minute)
|
||||
if _, err := configs.merge("u1", Config{Name: "Rex", SleepOff: true, UpdatedAt: now}); err != nil {
|
||||
t.Fatalf("merge: %v", err)
|
||||
}
|
||||
if got := configs.get("u1"); !got.SleepOff {
|
||||
t.Fatal("sleepOff did not round-trip through the config store")
|
||||
}
|
||||
s, err := sch.sleepStateFor("u1")
|
||||
if err != nil {
|
||||
t.Fatalf("sleepStateFor: %v", err)
|
||||
}
|
||||
if s.state != "" {
|
||||
t.Errorf("state = %q, want none while tracking is off", s.state)
|
||||
}
|
||||
|
||||
// So an overdue pee rule fires rather than waiting for a wake-up that will
|
||||
// never be logged, and the sleep rule stays quiet.
|
||||
if _, ok, err := sch.due("u1", Reminder{Kind: "pee", Enabled: true, IntervalMin: 60}, 0, now, s); err != nil || !ok {
|
||||
t.Errorf("pee: fired = %v (err %v), want a fire", ok, err)
|
||||
}
|
||||
if _, ok, err := sch.due("u1", Reminder{Kind: "sleep", Enabled: true, IntervalMin: 45}, 0, now, s); err != nil || ok {
|
||||
t.Errorf("sleep: fired = %v (err %v), want no fire", ok, err)
|
||||
}
|
||||
|
||||
// Switching it back on reads the log again.
|
||||
if _, err := configs.merge("u1", Config{Name: "Rex", UpdatedAt: now + 1}); err != nil {
|
||||
t.Fatalf("merge: %v", err)
|
||||
}
|
||||
if s, err := sch.sleepStateFor("u1"); err != nil || s.state != "asleep" {
|
||||
t.Errorf("tracking back on: state = %q (err %v), want asleep", s.state, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemindersStoreDefaultsAndClamping(t *testing.T) {
|
||||
sch := testScheduler(t)
|
||||
|
||||
|
||||
Reference in new issue
Block a user