From 0673dd822f475f3edc93d9676e849ee3676e61fa Mon Sep 17 00:00:00 2001 From: Anthony Merlo Date: Sat, 22 Aug 2026 23:08:53 +0100 Subject: [PATCH] fix: remove type annotations, use HealthUnitPrefix + millimeterOfMercury MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Remove all TS type annotations (HealthQuantityType, HealthUnit etc.) to avoid 'string not assignable' errors — let the app infer types - HealthMetricPrefix → HealthUnitPrefix (correct enum name per docs) - HealthUnit.fromString('mmHg') → HealthUnit.millimeterOfMercury() (confirmed in docs: line 35229) --- scripts/health-sync.tsx | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/scripts/health-sync.tsx b/scripts/health-sync.tsx index 23626cb..f4dad7c 100644 --- a/scripts/health-sync.tsx +++ b/scripts/health-sync.tsx @@ -3,18 +3,17 @@ // Server: http://chronos:9432/ingest // // Uses Scripting app APIs: -// Health.queryQuantitySamples(type, options) — global API, no import needed +// Health.queryQuantitySamples(type, options) — global API // sample.quantityValue(unit) — extracts numeric value -// HealthUnit / HealthMetricPrefix — unit construction (global) +// HealthUnit / HealthUnitPrefix — unit construction (global) // fetch() — standard Fetch API (with allowInsecureRequest for HTTP) -// Notification.schedule({ title, body }) — global API +// Notification — imported from "scripting" // Script — imported from "scripting" for Script.exit() // // Docs: https://scriptingapp.github.io/guide/Device%20Capabilities/Health/ import { Script, Notification } from "scripting" -// Variables used by Scripting app. These must be at the very top of the file. // icon-color: deep-blue; icon-glyph: heart; const SERVER_URL = "http://chronos:9432/ingest" @@ -22,15 +21,15 @@ const API_KEY = "333f09ce904e9cbbe3b578fda393be92869122c7222dbccd" // --- Units for each quantity type --- const U = { - kg: HealthUnit.gramUnit(HealthMetricPrefix.kilo), - mmHg: HealthUnit.fromString("mmHg"), + kg: HealthUnit.gramUnit(HealthUnitPrefix.kilo), + mmHg: HealthUnit.millimeterOfMercury(), bpm: HealthUnit.count().divided(HealthUnit.minute()), count: HealthUnit.count(), percent: HealthUnit.percent() } // Read the most recent sample of a type. Returns { value, startDate } or null. -async function readLatest(type: HealthQuantityType, unit: HealthUnit): Promise<{ value: number; startDate: Date } | null> { +async function readLatest(type, unit) { try { const samples = await Health.queryQuantitySamples(type, { limit: 1, @@ -51,7 +50,7 @@ async function readLatest(type: HealthQuantityType, unit: HealthUnit): Promise<{ } // Sum all samples of a type since midnight. Returns a number or null. -async function readTodaySum(type: HealthQuantityType, unit: HealthUnit): Promise { +async function readTodaySum(type, unit) { try { const start = new Date() start.setHours(0, 0, 0, 0) @@ -75,11 +74,11 @@ async function readTodaySum(type: HealthQuantityType, unit: HealthUnit): Promise } } -function todayDate(): string { +function todayDate() { return new Date().toISOString().slice(0, 10) } -async function notify(body: string) { +async function notify(body) { console.log(`notify: ${body}`) await Notification.schedule({ title: "Health Sync", @@ -101,7 +100,7 @@ const spo2 = await readLatest("oxygenSaturation", U.percent) console.log(`Results: weight=${weight?.value} bpSys=${bpSys?.value} bpDia=${bpDia?.value} hr=${hr?.value} rhr=${restingHr?.value} steps=${steps} spo2=${spo2?.value}`) // --- Build samples array — only include metrics that have data --- -const samples: any[] = [] +const samples = [] if (weight) { samples.push({ @@ -113,7 +112,7 @@ if (weight) { } if (bpSys && bpDia) { - const bpValue: any = { systolic: bpSys.value, diastolic: bpDia.value } + const bpValue = { systolic: bpSys.value, diastolic: bpDia.value } if (hr) bpValue.pulse = hr.value samples.push({ type: "blood_pressure", @@ -179,7 +178,7 @@ if (samples.length === 0) { const res = await response.json() console.log(`Server response: ${JSON.stringify(res)}`) await notify(`Sent ${res.ingested || samples.length} samples`) - } catch (e: any) { + } catch (e) { console.log(`POST error: ${e}`) await notify(`Error: ${e.message || e}`) }