Skip to content

fix: reset S400 stabilized on idle packet and add stabilized support for Scale v1/v2#322

Merged
Ernst79 merged 12 commits into
Bluetooth-Devices:mainfrom
dckiller51:fix-scales-stabilization-binary-sensor
Jun 7, 2026
Merged

fix: reset S400 stabilized on idle packet and add stabilized support for Scale v1/v2#322
Ernst79 merged 12 commits into
Bluetooth-Devices:mainfrom
dckiller51:fix-scales-stabilization-binary-sensor

Conversation

@dckiller51

Copy link
Copy Markdown
Contributor

Summary

Follow-up to the merged PR adding stabilized binary sensor for S400. This PR fixes a bug where the S400 stabilized sensor was not reset when the user stepped off the scale, and extends stabilized support to Mi Smart Scale v1 and Mi Body Composition Scale v2.

Changes

_parse_xiaomi — S400 idle packet fix

  • Added _S400_MODELS class attribute (MJTZC01YM, MJTZC03YM)
  • When an S400 idle packet is received (frctrl_object_include == 0), the stabilized sensor is now reset to OFF — previously it was silently ignored, leaving the sensor stuck on ON after a barefoot weighing

_parse_scale_v1 — Mi Smart Scale (XMTZC01HM/XMTZC04HM)

  • Added stabilized binary sensor: ON when mass_stabilized=True and mass > 0, OFF otherwise
  • Reset to OFF on mass == 0 (person stepped off)

_parse_scale_v2 — Mi Body Composition Scale (XMTZC02HM/XMTZC05HM/NUN4049CN)

  • Added stabilized binary sensor with the same logic as v1
  • Impedance is only published when impedance_stabilized=True

Tests added

  • test_Xiaomi_Scale1_reset — v1 reset when person steps off (mass=0, stabilized=False)
  • test_Xiaomi_Scale2_reset — v2 reset when person steps off (mass=0, stabilized=False)

@codecov

codecov Bot commented Jun 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.50000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 55.19%. Comparing base (a5f55ec) to head (3c2859b).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/xiaomi_ble/parser.py 86.66% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #322      +/-   ##
==========================================
+ Coverage   54.91%   55.19%   +0.27%     
==========================================
  Files           7        7              
  Lines        1393     1406      +13     
  Branches      271      276       +5     
==========================================
+ Hits          765      776      +11     
- Misses        513      514       +1     
- Partials      115      116       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dckiller51 dckiller51 force-pushed the fix-scales-stabilization-binary-sensor branch from 8ba42b1 to 08b5c40 Compare June 7, 2026 10:36
@dckiller51 dckiller51 force-pushed the fix-scales-stabilization-binary-sensor branch from 08b5c40 to a54f0c4 Compare June 7, 2026 10:37
@dckiller51

Copy link
Copy Markdown
Contributor Author

@Ernst79 Great, thank you! As soon as you merge these changes, I'll handle the next step and open a PR to add these modifications to Home Assistant's native xiaomi_ble component.

Comment thread src/xiaomi_ble/parser.py Outdated

@Ernst79 Ernst79 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM thanks

@Ernst79 Ernst79 merged commit c8dcd31 into Bluetooth-Devices:main Jun 7, 2026
10 checks passed
@dckiller51 dckiller51 deleted the fix-scales-stabilization-binary-sensor branch June 7, 2026 20:24
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