Phase 6 follow-up: today-and-future events, one write per school-wide event

Two corrections found while preparing the first live run:

- A scan that runs late in the day still records today's school events; the
  candidate window now starts at the local start of day instead of "now".
- The Compass week calendar is school-wide, so one event is stored against each
  child. Write it once, with no child prefix in the title, and record the same
  Home Assistant event id on every child's item. A per-child event still keeps
  the child's name.

Also report pending events as events, not rows, in `school calendar status`.
Tests cover the window and the de-duplication.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
2026-10-15 18:05:33 +11:00
parent f6be17fe4f
commit f56dbb46ac
5 changed files with 244 additions and 80 deletions

View File

@@ -125,11 +125,14 @@ func calendarStatus(args []string) {
os.Exit(1)
}
now := time.Now().In(cfg.Location)
candidates, err := st.CalendarCandidates(ctx, nil, nil, now, 0)
candidates, err := st.CalendarCandidates(ctx, nil, nil, calendar.StartOfDay(now), 0)
if err != nil {
fmt.Fprintln(os.Stderr, "school calendar:", err)
os.Exit(1)
}
// Count events, not rows: a school-wide event is stored against each
// child but written once.
pendingEvents := len(calendar.GroupDuplicates(candidates))
if asJSON {
out := struct {
@@ -145,7 +148,7 @@ func calendarStatus(args []string) {
BaseURL: haHost(cfg.Calendar.BaseURL),
Entity: cfg.Calendar.EntityID,
TokenSet: cfg.Calendar.Token != "",
Pending: len(candidates),
Pending: pendingEvents,
ReloadedAt: now.Format(time.RFC3339),
PushSummary: summary,
}
@@ -171,7 +174,7 @@ func calendarStatus(args []string) {
} else {
fmt.Printf("reachable yes\n")
}
fmt.Printf("pending events %d (important, not in the calendar yet)\n", len(candidates))
fmt.Printf("pending events %d (important, not in the calendar yet)\n", pendingEvents)
fmt.Printf("pushes %d (%d failed)\n", summary.Total, summary.Failed)
if summary.Last != nil {
state := "ok"