Skip to content

fix: Pass the user's weight unit to scale handlers (#1562) - #1564

Open
daniel-walker wants to merge 1 commit into
oliexdev:masterfrom
daniel-walker:fix/scale-user-unit
Open

daniel-walker wants to merge 1 commit into
oliexdev:masterfrom
daniel-walker:fix/scale-user-unit

Conversation

@daniel-walker

Copy link
Copy Markdown

Closes #1562.

ScaleUser.scaleUnit was never set: BluetoothFacade.toScaleUser() copied id, name, birthday, height and gender only, so every scale handler saw the default KG. Handlers that push a unit to the scale (MGB, Etekcity, Yunmai, QN, Mi Scale, Runstar R5 and others) switched it to kg even for users who chose lb or st.

Change

The app keeps the weight unit on the Weight measurement type, not on the user. BluetoothFacadeImpl now combines the selected user with measurementFacade.getAllMeasurementTypes() and sets scaleUnit from the Weight type's unit, refreshing it whenever either changes. A new scaleUnitFor() helper does the lookup and falls back to KG while the types aren't loaded or have no weight unit, so users on kg see no change.

Handlers that convert weights with scaleUnit

Five handlers also convert incoming weights with scaleUnit: Mi Scale, Hume Dara 2, Excelvan CF36x, FitTrack Dara and Hoffen BBS-8107. Each one configures the scale with the same unit it later reads weights in. So for lb/st users they now read the unit they configured, instead of applying kg to a scale they just set to kg. They weren't tested on hardware for this change, so reports from owners would be welcome.

Testing

  • Unit tests: new ScaleUnitForTest (kg/lb/st mapping, other mass types such as LBM and bone ignored, KG fallback). Full suite: ./gradlew :app:testDebugUnitTest, 930 tests, 0 failures.

  • On hardware: a debug build of this branch merged with feat: Add support for the Lescale F4P (Runstar R6 protocol) #1563 (Lescale F4P support), on a Pixel (Android 13). Two weigh-ins, before and after saving the Weight type's unit as lb:

    17:08:17 BluetoothFacade: User context updated -> daniel (scale unit kg)
    17:10:07 RunstarR6Handler: Runstar R6 final result payload=[23 08 00 A3 00 01 22 3C 56 01 F6 … 00 0F]
    17:11:15 BluetoothFacade: User context updated -> daniel (scale unit lb)
    17:12:21 RunstarR6Handler: Runstar R6 final result payload=[26 08 00 A3 00 01 22 3C 4C 01 EF … 00 3E]
    

    The unit change reached the handler as soon as it was saved. The F4P switched its display from kg to lb, and its frames came back with the pounds flag (0x0F → 0x3E = 0x20 | 0x1E). Both measurements were stored as 74.3 kg with all 9 values.

This removes the known limitation noted in #1563. The two PRs are independent and can be merged in either order.

🤖 Generated with Claude Code

ScaleUser.scaleUnit was never set: BluetoothFacade.toScaleUser() copied
id, name, birthday, height and gender only, so every handler saw the
default KG. Handlers that push a unit to the scale (MGB, Etekcity,
Yunmai, QN, Mi Scale, Runstar R5 and others) switched it to
kg even for users who chose lb or st.

The app keeps the weight unit on the Weight measurement type, not on
the user. The facade now combines the selected user with the measurement
types and sets scaleUnit from the Weight type's unit, refreshing it when
either changes. It falls back to KG while the types are not loaded, so
users on kg see no change.

Five handlers also convert incoming weights with scaleUnit (Mi Scale,
Hume Dara 2, Excelvan CF36x, FitTrack Dara, Hoffen BBS-8107). Each one
configures the scale with the same unit it later reads weights in, so
for lb/st users they now read the unit they configured instead of
assuming kg. None of these were tested on hardware for this change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Daniel Walker <dwalker@fifo99.com>
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.

Scale handlers never see the user's weight unit (ScaleUser.scaleUnit is always KG)

1 participant