feat(clock): timezone, NTP, set-time and clocktower sync in the device Clock tab

Console side of the firmware 3.x TimeKeeper overhaul (project-vesper
F-079/F-081/F-083). The Clock tab's "Network & Time" card was read-only and
showed fields the firmware no longer reports, and both analog clocks drew
the browser's own time.

- Time & Timezone card: device local time, zone, mode, UTC offset, DST state
  (incl. expired manual dates), next change, RTC synced. Read live from the
  device (system.get_time, clock.get_timezone) - the device is the source of
  truth for time settings; nothing about them is mirrored to Firestore.
- EditTimezoneModal: Automatic (country -> zone from the backend timezone
  table, or a custom yearly rule built into a POSIX string), Manual DST (std
  offset, amount, this season's start/end), Fixed, Local only.
- SetDeviceTimeModal: this computer's UTC time, or a typed local time.
- NTP Sync card + NtpSettingsModal: automatic on/off, nightly time, servers,
  last result/drift; Sync Now queues clock.sync_ntp and polls clock.get_ntp.
- SyncClockModal (was a placeholder): pause, enter what the face shows,
  clock.set_face + resume.
- EditClockSettingsModal: face sync policy force/smart + max wait; mirrored
  as clockSettings.faceSyncMode / smartMaxWaitMin (added to the backend model,
  which silently dropped unknown keys - the old gmtOffsetSec/ntpServer mirror
  never persisted, so those dead drift checks are removed).
- Device Time / Clocktower clocks now show the device's wall clock and the
  real face position (refreshed every 30 s while the clock runs).

Live reads are chained after the existing clock.get_config drift check and
face polling pauses while a modal or Sync Now is sending, because device
replies are matched FIFO without a request id.

Stage 5 of project-vesper docs/features/timekeeper-overhaul.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-28 21:10:02 +02:00
co-authored by Claude Opus 5.5
parent e4ea43a079
commit cdf5fc79a0
9 changed files with 1072 additions and 101 deletions
@@ -1,10 +1,13 @@
// frontend/src/modals/bellcloud/devices/EditClockSettingsModal.jsx
// Edits: master switch, ODD/EVEN outputs, pulse and pause durations (sliders).
// Edits: master switch, ODD/EVEN outputs, pulse and pause durations (sliders), and the
// face sync policy (firmware 3.2.0+: force = run a full lap when the face is ahead,
// smart = wait if it is at most N minutes ahead).
import { useState } from 'react'
import Modal from '@/components/ui/Modal'
import Button from '@/components/ui/Button'
import FormField from '@/components/ui/FormField'
import SegmentedControl from '@/components/ui/SegmentedControl'
import api from '@/lib/api'
// Pulse options in milliseconds — shown as sliders with labelled steps
@@ -68,6 +71,8 @@ export default function EditClockSettingsModal({ open, onClose, onSaved, attr, s
const [clockOut2, setClockOut2] = useState(String(existingClockOutputs[1] ?? 0))
const [runPulse, setRunPulse] = useState(existingTimings[0] || PULSE_STEPS[3]) // default 500ms
const [pauseMs, setPauseMs] = useState(existingTimings[1] || PAUSE_STEPS[1]) // default 1000ms
const [faceSync, setFaceSync] = useState(clock.faceSyncMode || 'force')
const [maxWait, setMaxWait] = useState(String(clock.smartMaxWaitMin ?? 61))
const [saving, setSaving] = useState(false)
const [error, setError] = useState('')
@@ -78,7 +83,11 @@ export default function EditClockSettingsModal({ open, onClose, onSaved, attr, s
const validationMsg = hasClock && (out1 === 0 || out2 === 0)
? 'Both outputs must be assigned when the clock is enabled.'
: null
const canSave = !conflictMsg && !validationMsg
const maxWaitNum = Number(maxWait)
const maxWaitMsg = faceSync === 'smart' && (!Number.isInteger(maxWaitNum) || maxWaitNum < 1 || maxWaitNum > 359)
? 'Maximum wait must be 1–359 minutes.'
: null
const canSave = !conflictMsg && !validationMsg && !maxWaitMsg
const handleSave = async () => {
if (!canSave) return
@@ -93,6 +102,8 @@ export default function EditClockSettingsModal({ open, onClose, onSaved, attr, s
c2: out2,
pulse_duration: runPulse,
pause_duration: pauseMs,
face_sync_mode: faceSync,
...(faceSync === 'smart' ? { smart_max_wait_min: maxWaitNum } : {}),
})
await api.put(`/devices/${id}`, {
@@ -102,6 +113,8 @@ export default function EditClockSettingsModal({ open, onClose, onSaved, attr, s
...clock,
clockOutputs: [out1, out2].filter(o => o > 0),
clockTimings: [runPulse, pauseMs],
faceSyncMode: faceSync,
...(faceSync === 'smart' ? { smartMaxWaitMin: maxWaitNum } : {}),
},
},
})
@@ -228,10 +241,42 @@ export default function EditClockSettingsModal({ open, onClose, onSaved, attr, s
onChange={setPauseMs}
/>
<div style={{ height: 1, backgroundColor: 'var(--color-border)' }} />
{/* Face sync policy */}
<div style={{ display: 'flex', flexDirection: 'column', gap: 'var(--space-3)' }}>
<div>
<p style={{ fontSize: 'var(--font-size-base)', fontWeight: 'var(--font-weight-semibold)', color: 'var(--color-text-primary)' }}>
Face Ahead of Real Time
</p>
<p style={{ fontSize: 'var(--font-size-sm)', color: 'var(--color-text-muted)', marginTop: 2 }}>
The hands only move forward. When they are ahead (e.g. after DST ends), Force runs a full
lap to catch up; Smart stops them until real time catches up.
</p>
</div>
<SegmentedControl
options={[{ value: 'force', label: 'Force (full lap)' }, { value: 'smart', label: 'Smart (wait)' }]}
value={faceSync}
onChange={setFaceSync}
size="sm"
/>
{faceSync === 'smart' && (
<FormField
label="Wait if ahead by at most (minutes)"
name="smartMaxWait"
type="number"
value={maxWait}
onChange={e => setMaxWait(e.target.value)}
inputProps={{ min: 1, max: 359, step: 1 }}
hint="Default 61 covers the DST change. Further ahead than this, the face runs the lap."
/>
)}
</div>
{/* Errors / warnings */}
{(conflictMsg || validationMsg) && (
{(conflictMsg || validationMsg || maxWaitMsg) && (
<p style={{ fontSize: 'var(--font-size-sm)', color: 'var(--color-warning)', backgroundColor: 'var(--color-warning-bg)', padding: 'var(--space-2) var(--space-3)', borderRadius: 'var(--radius-sm)' }}>
{conflictMsg || validationMsg}
{conflictMsg || validationMsg || maxWaitMsg}
</p>
)}
{error && (