Add support for Dr. Trust Smart 505 Scale (India) - #1445
Open
joshferns wants to merge 2 commits into
Open
Conversation
MGBHandler previously assumed every notification was a 20-byte composite frame and dropped anything else, so scales like the Dr Trust Smart 505 (same SWAN name / 0xFFB0 service, but 8-byte streaming frames) connected and never produced a measurement. onNotification now dispatches on frame size: the existing 20-byte composite path is unchanged (only moved into onCompositeFrame), and a new 8-byte streaming path parses live/final weight and impedance frames via pure, unit-tested companion functions, latching both values before publishing one measurement and deriving body composition with StandardImpedanceLib (same approach as VitafitVT701Handler).
It had a single call site; folding it into the 8-byte branch matches VitafitVT701Handler's flatter onNotification style. No logic change.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add 8-byte streaming protocol support to MGBHandler (Dr Trust Smart 505)
MGBHandler matches by name (swan/icomon/yg) or service 0xFFB0. The Dr Trust Smart 505 matches but sends 8-byte frames, while the handler only accepted 20-byte composite frames (if (data.size != 20) return) — so it connected, ran its init writes, and silently saved nothing.
This makes onNotification() dispatch on frame size and adds a path for the 8-byte variant. The 20-byte path is unchanged (extracted verbatim into a private method).
Protocol (8-byte variant)
Frame: AC 02 [b2] [b3] [b4] [b5] [flag] [chk], chk = (b2+b3+b4+b5+flag) & 0xFF. Flag byte: CE live weight, CA settled weight (u16 in b2:b3, 0.01 kg), CB impedance (FD 01 [hi] [lo], ohms), CC status. Completion is the CE→CA flag change, not a separate frame.
Implementation
Pure companion-object parsers (isValidStreamingFrame, parseFinalWeightRaw, parseLiveWeightRaw, parseImpedanceOhm), following VitafitVT701Handler's pattern.
Latches weight + impedance, publishes once both arrive, resets in a new onDisconnected().
Composition via StandardImpedanceLib — same library and sanity guard VitafitVT701Handler uses; raw impedance also stored. No new formulas.
Tests
New MGBHandlerStreamingTest.kt covering weight/impedance parsing, the flag distinctions, the FD-config-vs-impedance collision, and checksum/size rejection. Passes; existing VitafitVT701HandlerTest still passes.
Tested on a physical Dr Trust Smart 505: weigh-in saves correctly, and weight/BMI/bone match the vendor app. Composition is derived from raw impedance via StandardImpedanceLib, so it differs from the vendor's proprietary values (as with other impedance scales here) — happy to swap the estimator if preferred. I don't own the 20-byte variant, so only the 8-byte path is hardware-verified.