Skip to content

feat(xiaomi_ble): Add stabilized binary sensor and update impedance for MiScale S400#173260

Draft
dckiller51 wants to merge 9 commits into
home-assistant:devfrom
dckiller51:xiaomi_ble_miscale_s400_stabilized
Draft

feat(xiaomi_ble): Add stabilized binary sensor and update impedance for MiScale S400#173260
dckiller51 wants to merge 9 commits into
home-assistant:devfrom
dckiller51:xiaomi_ble_miscale_s400_stabilized

Conversation

@dckiller51

Copy link
Copy Markdown
Contributor

Breaking change

The impedance sensor entity names for the Xiaomi MiScale S400 have been corrected to align with the library definitions.

  • The old impedance_low sensor is now impedance_high.
  • The old impedance sensor is now impedance_low.

Users tracking these specific impedance metrics on a MiScale S400 will need to update their dashboards and automations to reference the new entity IDs.

Proposed change

This PR enhances the xiaomi_ble integration by bringing unified functionality to Xiaomi body composition scales and correcting technical descriptions for the MiScale S400:

  1. Stabilized Binary Sensor: Added the ExtendedBinarySensorDeviceClass.STABILIZED binary sensor to MiScale V1, V2, and S400 models to explicitly expose weight stabilization status.
  2. S400 Impedance Fix: Fixed an inversion mapping between high and low frequency impedance sensors for the S400 model.
  3. Dependency Upgrade: Bumped xiaomi-ble to 1.14.2 to support these backend model data structure updates.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:
  • Link to developer documentation pull request:
  • Link to frontend pull request:

Checklist

  • I understand the code I am submitting and can explain how it works.
  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.
  • Any generated code has been carefully reviewed for correctness and compliance with project standards.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies a diff between library versions and ideally a link to the changelog/release notes is added to the PR description.

To help with the load of incoming pull requests:

Copilot AI review requested due to automatic review settings June 8, 2026 08:24
@dckiller51 dckiller51 requested review from Ernst79 and Jc2k as code owners June 8, 2026 08:24
@home-assistant home-assistant Bot added breaking-change cla-signed has-tests integration: xiaomi_ble new-feature small-pr PRs with less than 30 lines. Top 200 Integration is ranked within the top 200 by usage labels Jun 8, 2026
@home-assistant

home-assistant Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Hey there @Jc2k, @Ernst79, mind taking a look at this pull request as it has been labeled with an integration (xiaomi_ble) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of xiaomi_ble can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant mark-draft Mark the pull request as draft.
  • @home-assistant ready-for-review Remove the draft status from the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign xiaomi_ble Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant update-branch Update the pull request branch with the base branch.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) on the pull request.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR adds support for the Xiaomi Mi Scale S400 and introduces a "stabilized" binary sensor and stabilized weight sensor for all Mi Scale variants by bumping the xiaomi-ble library from 1.11.0 to 1.14.2.

Changes:

  • Bumps xiaomi-ble dependency to 1.14.2, adding support for the S400 scale with impedance_high/impedance_low sensors and a stabilized binary sensor.
  • Adds IMPEDANCE_HIGH sensor entity description and STABILIZED binary sensor entity description.
  • Adds comprehensive tests for the new S400 scale sensors and the stabilized binary sensor across V1, V2, and S400 scale variants.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
homeassistant/components/xiaomi_ble/manifest.json Bumps xiaomi-ble to 1.14.2
requirements_all.txt Updates xiaomi-ble requirement to 1.14.2
homeassistant/components/xiaomi_ble/sensor.py Adds IMPEDANCE_HIGH sensor entity description
homeassistant/components/xiaomi_ble/binary_sensor.py Adds STABILIZED binary sensor entity description
tests/components/xiaomi_ble/init.py Adds S400 test fixtures (packet 1 and packet 2)
tests/components/xiaomi_ble/test_sensor.py Updates state counts, adds S400 and stabilized sensor tests
tests/components/xiaomi_ble/test_binary_sensor.py Adds stabilized binary sensor tests for V1, V2, and S400

Comment thread tests/components/xiaomi_ble/test_sensor.py Outdated
Comment thread tests/components/xiaomi_ble/test_sensor.py
Comment thread tests/components/xiaomi_ble/test_sensor.py
@dckiller51

Copy link
Copy Markdown
Contributor Author

Hi @Ernst79, the Home Assistant CI is failing because xiaomi-ble==1.14.2 has a Python restriction <3.15. Could you please update the Python requirements in xiaomi-ble to support up to <3.16 (or remove the upper bound) and release a new version? Once done, I will update the manifest.json requirement here

@Ernst79

Ernst79 commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Hi @Ernst79, the Home Assistant CI is failing because xiaomi-ble==1.14.2 has a Python restriction <3.15. Could you please update the Python requirements in xiaomi-ble to support up to <3.16 (or remove the upper bound) and release a new version? Once done, I will update the manifest.json requirement here

Bluetooth-Devices/xiaomi-ble#324 --> merged

Copilot AI review requested due to automatic review settings June 8, 2026 09:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Comment thread tests/components/xiaomi_ble/test_sensor.py
Copilot AI review requested due to automatic review settings June 8, 2026 11:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Comment thread tests/components/xiaomi_ble/test_sensor.py Outdated
Comment thread tests/components/xiaomi_ble/test_sensor.py Outdated

@joostlek joostlek left a comment

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.

Does the unique id change? If not, then this isn't a breaking change. Can we bump the dependency in a separate PR?

@home-assistant home-assistant Bot marked this pull request as draft June 8, 2026 12:11
@home-assistant

home-assistant Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@dckiller51

dckiller51 commented Jun 8, 2026

Copy link
Copy Markdown
Contributor Author

Does the unique id change? If not, then this isn't a breaking change. Can we bump the dependency in a separate PR?

Hi @joostlek,

To be fully transparent about the entity lifecycle and history, here is exactly how the impedance entities are affected by this library update:

Legacy generic impedance: The entity remains in the registry so existing users don't lose their past data, but it is no longer updated and becomes obsolete for this device.

impedance_low: This entity keeps its current unique_id, but it will now receive the data stream that previously populated the generic impedance entity. Its technical history is preserved under the same ID.

impedance_high: This is a newly created entity. Due to the mapping inversion in the underlying library to fix the frequency specifications, it now receives the data values that used to go to impedance_low. As a result, it starts fresh with no prior history.

This is technically a minor breaking change regarding data routing between the low/high attributes, but it is a necessary correction to align the integration with the correct hardware specs of the scale. Let me know if you are aligned with this approach!

You are totally right, but separating them might be tricky here. If we bump the library to v1.14.3 in a separate PR first, the Home Assistant component will likely break or fail CI tests because the library will start emitting the new S400 data structures (like stabilized) before the HA component has the updated sensor.py and binary_sensor.py logic to handle them.

Since the library update and this PR's code are tightly coupled to prevent any breaking behavior or CI failures, keeping them together in this PR seems safer. But please let me know if you still prefer a separate bump PR first, and I'll adapt!

@dckiller51

Copy link
Copy Markdown
Contributor Author

@joostlek

I forgot to clarify an important detail: this routing shift and the need to re-add the device only applies to the new S400 model. *

*For the legacy Scale V1 and V2, absolutely nothing changes. Their data streams and existing generic impedance entities remain 100% untouched and will continue to work perfectly without any user intervention. *

Given that it only leaves the new S400 in an awkward state if users had a custom setup, a simple release note entry might be enough, but I'm open to your preference!"

Copilot AI review requested due to automatic review settings June 9, 2026 08:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Comment thread tests/components/xiaomi_ble/test_sensor.py Outdated
Copilot AI review requested due to automatic review settings June 9, 2026 09:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants