Skip to content

Commit e66ca9b

Browse files
committed
HealthStatsSync: refresh today's weekday _sleepData typicals
The existing daily 6-day loop deliberately skips today (incomplete current-day daily fields shouldn't overwrite the watch's accelerometer-tracked values), but the firmware reads `<today's weekday>_sleepData` typicals on the sleep summary card. Without this extra write the typicals for today's weekday stay stale for a day after the new typical-sleep code starts running. After the daily loop, add a typicals-only blob for today's weekday with last_processed_timestamp=0. Firmware's prv_notify_health_listeners gates the in-memory daily-metric update on a valid timestamp and bails out, so daily fields=0 don't corrupt today's tracked values, but health_db_insert still stores the blob — making the typicals readable via health_db_get_typical_value. This brings sleep typicals in line with the step typicals, which already cover all 7 weekdays via their separate per-weekday loop.
1 parent 18e6496 commit e66ca9b

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

libpebble3/src/commonMain/kotlin/io/rebble/libpebblecommon/services/HealthStatsSync.kt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,29 @@ internal suspend fun updateHealthStatsInDatabase(
129129
))
130130
}
131131

132+
// The loop above skips today's weekday by design (incomplete current-day daily fields
133+
// shouldn't overwrite the watch's accelerometer-tracked values). But today's weekday's
134+
// _sleepData blob is exactly what the firmware reads for "today's typical sleep" on the
135+
// sleep summary card, so without this extra write its typicals stay stale for a day.
136+
// Send a typicals-only blob with last_processed_timestamp=0; firmware's
137+
// prv_notify_health_listeners gates the in-memory daily-metric update on a valid
138+
// timestamp and bails out, so the daily fields=0 don't corrupt today's tracked values.
139+
// health_db_insert still stores the blob, so the typicals are readable.
140+
SLEEP_KEYS[today.dayOfWeek]?.let { todaySleepKey ->
141+
val todaySleepPayloadData = sleepPayload(
142+
dayStartEpochSec = 0L,
143+
sleepDuration = 0,
144+
deepSleepDuration = 0,
145+
fallAsleepTime = 0,
146+
wakeupTime = 0,
147+
typicals = sleepTypicals[today.dayOfWeek],
148+
)
149+
stats.add(HealthStat(
150+
key = todaySleepKey,
151+
payload = todaySleepPayloadData.toByteArray()
152+
))
153+
}
154+
132155
// Per-weekday typical-step blobs (consumed by firmware activity_insights for the
133156
// "X% above/below typical" comparison in the end-of-day activity summary notification).
134157
val typicalsByWeekday = computeAllWeekdayTypicalSteps(healthDao, today, timeZone)

0 commit comments

Comments
 (0)