wearOS.ts

Sends core body temperature and history to a paired WearOS watch

Purpose

This module delivers the current core body temperature prediction and the full 24-hour history to a paired WearOS device via react-native-wear-connectivity. Unlike the WatchOS module, it includes the full history payload so the watch can render a history graph without its own database access.

Its responsibilities include:

  • Loading the core temperature history from sensorHistoryDb
  • Converting history records to a time-labelled format for the watch’s HistoryCBTScreen
  • Constructing a single cbt_update message payload with both the current value and history
  • Sending the payload via sendMessage and resolving in both success and failure cases
  • Treating delivery failure as non-fatal so the prediction pipeline is never blocked

Invariants

Non-Fatal Delivery

Both the success and failure callbacks of sendMessage call resolve().

The returned Promise always resolves (never rejects), ensuring that a watch out of range or unpaired does not throw in the calling prediction pipeline.


History Timestamp Formatting

Each history record’s timestamp is formatted as "H:MM" (local time, no leading zero on the hour) using the device’s local clock.


Watch Payload Shape

{
	event: "cbt_update",
	currentCBT: number,
	history: Array<{ time: string; value: number }>
}

The watch’s HistoryCBTScreen expects exactly this shape.


Exports

sendCBTToWearOS(...)

async function sendCBTToWearOS(currentCBT: number): Promise<void>

Loads the sensor history, builds the cbt_update payload, and sends it to the paired WearOS device. Always resolves; logs a warning on delivery failure.

Parameters

ParameterDescription
currentCBTPredicted core temperature in °C