Public: anyone can read this; the crew can change it.

Migrated from github.com/Trevato/SO-ARM100

Track the light's real day: lightOn/lightOff in the care log, off-due from the actual on-time (today: on 8:30 → off 20:30) #640

opened this in answer to

Merged 37d 22h ago

The care log now records the light's real day with lightOn and lightOff actions. The off-due time follows the actual on-time. I ran bun test on the files this change touches (139 tests, all passing).

Notes

opened this

The care log now records the light's real day with lightOn and lightOff actions. The off-due time follows the actual on-time. I ran bun test on the files this change touches (139 tests, all passing). The forge's full check hasn't run yet, and I didn't look at the grow card on a preview.

  • Actions: lightOn and lightOff are added to the care-log actions in care-log.ts. They also work from the care page's action menu and from the terminal (/care did lightOn).
  • Check-in page (/care/checkin): a Light button reads "Light on" or "Light off" depending on the last light action. An optional "at…" time field logs it late. The time is read in the Pi's zone, and a time still ahead of now is taken as yesterday's.
  • Grow card: src/light-day.ts builds the day's lines from the log, e.g. Light on 08:30 → off due 20:30 (12 h) · started 1 h 30 m late · 1 h 30 m of light so far. Once the light is off it shows the finished day and the hours it ran. The light's hours for the day are summed from the actions, not entered.
  • Off-time: off due is the on-time plus the schedule's hours, held between 10 h and SPINACH_MAX_HOURS (14 h). It adds "light still on?" once there is no lightOff 30 minutes past due. An on-time older than 36 h shows nothing.
  • Night mode: Wake up writes one lightOn and Good night writes one lightOff. Wake up writes only after the light write succeeds, so a refused write logs nothing.
  • Tests: light-day.test.ts covers 8:30 → 20:30, 06:00 → 18:00, the 10 h and 14 h bounds, the 30-minute "still on?" and the check-in button. night-switch.test.ts covers one action per Wake up and Good night, and no log on a refused wake.
  • Not done — the reminder: the due time shows on the card as a label only. I did not add a reminder entry to the reminders list.
  • Late start: it is measured against the Pi's schedule as the relay last read it. Until the Pi answers once, it uses the default 06:00 / 12 h schedule and UTC.

🤖 Generated with Claude Code

Closes #639

2 earlier comments
commented

The care log now records the light's real day with lightOn and lightOff actions. The off-due time follows the actual on-time. I ran bun test on the files this change touches (139 tests, all passing). The forge's full check hasn't run yet, and I didn't look at the grow card on a preview.

  • Actions: lightOn and lightOff are added to the care-log actions in care-log.ts. They also work from the care page's action menu and from the terminal (/care did lightOn).
  • Check-in page (/care/checkin): a Light button reads "Light on" or "Light off" depending on the last light action. An optional "at…" time field logs it late. The time is read in the Pi's zone, and a time still ahead of now is taken as yesterday's.
  • Grow card: src/light-day.ts builds the day's lines from the log, e.g. Light on 08:30 → off due 20:30 (12 h) · started 1 h 30 m late · 1 h 30 m of light so far. Once the light is off it shows the finished day and the hours it ran. The light's hours for the day are summed from the actions, not entered.
  • Off-time: off due is the on-time plus the schedule's hours, held between 10 h and SPINACH_MAX_HOURS (14 h). It adds "light still on?" once there is no lightOff 30 minutes past due. An on-time older than 36 h shows nothing.
  • Night mode: Wake up writes one lightOn and Good night writes one lightOff. Wake up writes only after the light write succeeds, so a refused write logs nothing.
  • Tests: light-day.test.ts covers 8:30 → 20:30, 06:00 → 18:00, the 10 h and 14 h bounds, the 30-minute "still on?" and the check-in button. night-switch.test.ts covers one action per Wake up and Good night, and no log on a refused wake.
  • Not done — the reminder: the due time shows on the card as a label only. I did not add a reminder entry to the reminders list.
  • Late start: it is measured against the Pi's schedule as the relay last read it. Until the Pi answers once, it uses the default 06:00 / 12 h schedule and UTC.

🤖 Generated with Claude Code

commented

I've addressed @juniper's requested changes and pushed them to the branch. The night-switch and care tests pass (56) and the type check is clean on the files I touched. I didn't run the preview, so the grow-card lines and check-in button are untested in a browser.

  • Good night no longer logs lightOff. @juniper is right: it only closes the room, so nothing switches the light off and the log would have been wrong. Wake up still logs one lightOn, and only after the light write succeeds. This goes against the issue's item 4, which asked for Good night to log lightOff. The lightOff entry now comes from the owner's tap on the check-in's Light off button. The night-switch.ts header comment says so.
  • Test change: the old test asserted that Good night writes lightOff, and that was wrong. It now checks that Wake up writes one lightOn, and that Good night writes nothing and leaves the open day open, with lastLight still "on".
  • Dead import removed from care-checkin.ts.
  • Terminal back-dating: /care checkin light <on|off> [HH:MM] now logs a late light from the terminal. It uses the same checkinEntry function as the page's "at…" field, and a test covers it. /care did lightOn still always logs now.
  • README now covers the Light button and "at…" field, the terminal line, lightOn/lightOff in the action list, and the grow-card lines with the 10–14 h bound and the "light still on?" rule.

The reminder entry for the off time is still not added: off due appears only as a label on the grow card.

🤖 Generated with Claude Code

commented

I've addressed all three of @juniper's points and pushed them to the branch. The new and affected tests pass (the 119 in the light, workshop, night-switch and care files, plus the 4 in light-checkin.test.ts), and the type check is clean on the files I touched. I did not run the full forge check or the preview.

  • Zone and schedule (@juniper's first point):
    • lightSeen is now null until the Pi has actually answered, with no UTC default.
    • The at… time on POST /care/checkin (and so /care checkin light on 08:30) asks the Pi for its zone first. If the Pi doesn't answer, it returns 409 with "the Pi's time zone is not known yet… log the light now, or try again". Logging "now" still works.
    • The grow card shows no light line until the zone is known, and it starts a background read so the line appears on the next load.
    • A Pi with a cycle schedule still reports its zone, so the zone is known.
  • Ordering: lastLight and lightDay now pick the latest lightOn by time, and the earliest lightOff after it. A forgotten earlier lightOn logged after a lightOff no longer flips the day or the check-in button.
  • Tests added:
    • light-checkin.test.ts runs a fake Pi in Asia/Tokyo.
    • A guest is refused and writes nothing, a non-owner gets 403, and the owner gets a 303.
    • Tokyo 08:30 at lands at 23:30 UTC the day before.
    • An at is refused with 409 while the Pi is down.
    • The card at / reads "Light on 08:30 → off due 20:30 (12 h)" in the Pi's zone.
    • workshop-phone.test.ts checks the data-light rendering, including escaping.
    • light-day.test.ts checks the ordering.
  • Off-due reminder (third point): the reminder is still only a label on the grow card. I opened #641 for it as a follow-up.

I did not link #641 to #639 with a dependency, since that is the parent's call.

🤖 Generated with Claude Code

Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs