MiScaleHandler: derive the v1/v2 variant from the GATT table instead of trusting the scan-time name heuristic - #1490
Open
l9i wants to merge 2 commits into
Open
MiScaleHandler: derive the v1/v2 variant from the GATT table instead of trusting the scan-time name heuristic#1490l9i wants to merge 2 commits into
l9i wants to merge 2 commits into
Conversation
Re-detect the Mi scale variant on connect by probing for the history characteristic under 0x181B (V2) / 0x181D (V1), correcting the ambiguous scan-time name heuristic. The weight-only Mi Smart Scale 2 (XMTZC04HM) advertises "MI SCALE2" and carries the 0x1530 vendor service but serves only 0x181D, so V2 mode subscribed/wrote against a non-existent service and hung in "waiting for measurement" forever. Fail fast with a user-visible error + disconnect when the history characteristic exists under neither service. Adds MiScaleHandlerVariantTest. Fixes oliexdev#1489 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Follow-up to e77aa89, fixing the issues found in review: - supportFor() no longer mutates the session variant field. The handler is a shared singleton and the UI re-queries device support at any time (savedDeviceSupport, scan results), which could silently reset a GATT-corrected variant mid-session and drop live v1 frames. - detectVariantFromGatt() no longer hard-rejects clones that serve a standard service without the vendor history characteristic (live weight via 0x2A9D worked for them before the fail-fast). Service presence acts as a fallback tier; only a device exposing neither 0x181B nor 0x181D aborts, which is also exactly what the user-facing error string claims. - The GATT-detected variant is persisted per device address so later scan-time support queries stop promising v2 capabilities (body composition, unit config) a downgraded device cannot deliver. - Variant tests now run on runTest virtual time instead of racing the real 1-second history-fallback timer, and cancel it via handleDisconnected(); new regression tests cover the clone fallback, the mid-session supportFor() query, and the persisted override. All changes stay within MiScaleHandler and its test, per the how-to-support-a-new-scale ground rules (no shared infrastructure changes). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HkiN1TxugYUaxWx2HbzhbD
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.
The weight-only Mi Smart Scale 2 (XMTZC04HM) advertises "MI SCALE2" and even carries the 0x1530 vendor service, so the scan-time heuristic classifies it as v2. Its GATT table, however, only serves the Weight Scale service (0x181D) — there is no Body Composition service (0x181B). The v2 init sequence then subscribes/writes against a non-existent service and the app hangs forever in "waiting for measurement".
Changes:
supportFor()is now side-effect-free. The handler is a shared singleton and the UI re-queries device support while a session is live; previously such a query could reset the GATT-corrected variant mid-session and silently drop live v1 frames.MiScaleHandlerVariantTestcovers scan-time classification, the XMTZC04HM downgrade, genuine v2, the clone fallback (a live 10-byte weight frame is parsed end-to-end), a mid-sessionsupportFor()query not clobbering the session variant, the persisted-variant override, and the neither-service abort. Timer-dependent tests run onrunTestvirtual time instead of racing the real 1-second history-fallback timer.Fixes #1489.