Skip to content

Add missing fields and correct sleep docs in Huawei schemas - #451

Open
yatharthranjan wants to merge 6 commits into
devfrom
huawei-activity-device-type
Open

yatharthranjan wants to merge 6 commits into
devfrom
huawei-activity-device-type

Conversation

@yatharthranjan

@yatharthranjan yatharthranjan commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Summary

  • huawei_activity_record.avsc:
    • Adds an optional deviceTypeName string for Huawei's deviceInfo.devType (for example "Smart watch").
    • Updates the deviceType doc: the int field holds deviceInfo.deviceCode.
  • huawei_continuous_exercise_intensity_v2_statistics.avsc: adds an optional totalIntensity int.
  • huawei_health_record_sleep.avsc: the stage durations are documented in minutes rather than ms.
  • huawei_continuous_sleep_fragment.avsc: corrects the sleepState codes to 1 = light, 2 = REM, 3 = deep, 4 = awake.
  • huawei_sleep_on_off_bed_record.avsc: documents the onOffBedState codes, 1 = getting in bed and 2 = getting out of bed, per Huawei's data type reference.
  • New huawei_heart_rate.avsc (HuaweiHeartRate) and huawei_spo2.avsc (HuaweiSpo2), with topics connect_huawei_instantaneous_heart_rate and connect_huawei_instantaneous_spo2 in the spec, for individual readings. The spec only had their daily statistics.

All of these were found by probing the live Health Kit API.

v2/activityRecords describes the device as:

"deviceInfo": {"uniqueId": "...", "devType": "Smart watch", "modelNum": "...", "manufacturer": "HUAWEI", "deviceCode": 308517120}

The existing int deviceType field can't hold devType, which is a string.

sampleSet:dailyPolymerize for com.huawei.continuous.exercise_intensity.v2.statistics returns:

[{"fieldName": "totalIntensity", "integerValue": 32},
 {"fieldName": "intensity_map", "mapValue": [{"key": "1", "value": {"integerValue": 11}}, ...]}]

In that response totalIntensity (32) differs from the sum of the map (30), so it has to be stored separately.

One night of live sleep data confirms the units and codes:

  • In the health.record.sleep record, light 161 + deep 77 + REM 58 equals all_sleep_time 296. Adding awake_time 52 gives 348, the number of minutes between fall_asleep_time and wakeup_time.
  • The same night's one-minute continuous.sleep.fragment points add up to 1: 161, 2: 58, 3: 77 and 4: 58 minutes. That matches light, REM, deep and awake (52, plus the 6 minutes between going to bed and falling asleep).

sampleSet:polymerize returns individual readings all day, including during sleep (two days: 567 heart rate and 26 SpO2 points):

{"dataTypeName": "com.huawei.instantaneous.heart_rate", "value": [{"fieldName": "bpm", "floatValue": 82.0}]}
{"dataTypeName": "com.huawei.instantaneous.spo2", "value": [{"fieldName": "saturation", "floatValue": 98.0}, {"fieldName": "oxygen_supply_flow_rate", "floatValue": 0.0}]}

Compatibility

Both new fields are optional with a null default, so the existing schemas stay backward compatible. The sleep changes only touch docs. The heart rate and SpO2 schemas are new.

Test plan

  • ./gradlew check in java-sdk

Related: RADAR-base/RADAR-REST-Connector#204 (the Huawei connector) and #450 (blood pressure last values).

Huawei's activityRecords response describes the recording device as
deviceInfo {devType: "Smart watch", deviceCode: 308517120, ...}. The
existing int deviceType field can only hold the code, so add an optional
deviceTypeName string for devType and document deviceType as the
deviceCode. The new field defaults to null, keeping the schema
backward compatible.

Claude-Session: https://claude.ai/code/session_01PeNFs67cbLTGQ6xKiyDHdC
Huawei's continuous.exercise_intensity.v2.statistics sample points carry
a totalIntensity integer next to intensity_map. In the live response it
was 32 while the map's entries summed to 30, so it can't be derived
from the map. Add it as an optional int with a null default, keeping
the schema backward compatible.

Claude-Session: https://claude.ai/code/session_01PeNFs67cbLTGQ6xKiyDHdC
@yatharthranjan yatharthranjan changed the title Add device type name to Huawei activity records Add device type name and total intensity to Huawei schemas Nov 18, 2026
A live night of Huawei sleep data shows the health.record.sleep
durations are minutes, not milliseconds: light 161 + deep 77 + REM 58
equals all_sleep_time 296, and adding awake_time 52 gives the 348
minutes between fall_asleep_time and wakeup_time.

Summing the same night's one-minute continuous.sleep.fragment points per
sleep_state gives 1: 161, 2: 58, 3: 77 and 4: 58 minutes, matching
light, REM, deep and awake (52 plus the 6 minutes between going to bed
and falling asleep). Fix the stage codes, which had 1, 3 and 4 swapped.

Documentation only; no field types change.
@yatharthranjan yatharthranjan changed the title Add device type name and total intensity to Huawei schemas Add missing fields and correct sleep docs in Huawei schemas Nov 19, 2026
The Health Kit polymerize API returns individual instantaneous.heart_rate
(bpm, one-minute points) and instantaneous.spo2 (saturation and
oxygen_supply_flow_rate) readings all day, including during sleep, but
the spec only covered their daily statistics. Add a schema and topic for
each.
Per the Health Kit sleep.on_off_bed_record reference, onOffBedState is 1 when getting in bed and 2 when getting out of bed. A live night returned two 2 events, the second at the sleep record's wakeup_time.
"int"
],
"doc": "Sleep stage: 1=awake, 2=REM, 3=light sleep, 4=deep sleep.",
"doc": "Sleep stage: 1=light sleep, 2=REM, 3=deep sleep, 4=awake.",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think we should have another key like sleepStateString or something just for values?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you mean like an enum?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah like in addition to. the int sleepState so we have the value as well?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants