mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-08 12:32:43 +00:00
New `syncUserSleep` routine pulls per-segment sleep data from POST /v2/sleep?action=get and writes one Measurement row per stage segment, tagged with the appropriate SleepStage enum: state 0 (awake) → AWAKE state 1 (light sleep) → CORE (HealthKit-aligned NREM 1+2) state 2 (deep sleep) → DEEP state 3 (REM) → REM state 4 (synthetic) → ignored The legacy ASLEEP and IN_BED enum slots stay reserved for HealthKit ingest (pre-iOS-16 `asleepUnspecified` and iOS-16+ `inBed`). ScanWatch nights with no REM segment simply omit the row rather than synthesising an all-zeros entry — Withings drops the field, the writer never sees it. Idempotency rides on Migration 0055's five-column composite — a re-sync of the same night UPDATEs every segment row in place rather than inserting duplicates, even when Withings re-aggregates the night with adjusted segment boundaries. Sleep durations stored as canonical minutes (seconds ÷ 60, rounded) so re-syncs don't flip values on floating-point noise.