feat(xiaomi_ble): Add stabilized binary sensor and update impedance for MiScale S400#173260
feat(xiaomi_ble): Add stabilized binary sensor and update impedance for MiScale S400#173260dckiller51 wants to merge 9 commits into
Conversation
|
Hey there @Jc2k, @Ernst79, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
There was a problem hiding this comment.
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-bledependency to 1.14.2, adding support for the S400 scale with impedance_high/impedance_low sensors and a stabilized binary sensor. - Adds
IMPEDANCE_HIGHsensor entity description andSTABILIZEDbinary 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 |
|
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 |
joostlek
left a comment
There was a problem hiding this comment.
Does the unique id change? If not, then this isn't a breaking change. Can we bump the dependency in a separate PR?
|
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
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! |
|
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!" |
Breaking change
The impedance sensor entity names for the Xiaomi MiScale S400 have been corrected to align with the library definitions.
impedance_lowsensor is nowimpedance_high.impedancesensor is nowimpedance_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_bleintegration by bringing unified functionality to Xiaomi body composition scales and correcting technical descriptions for the MiScale S400:ExtendedBinarySensorDeviceClass.STABILIZEDbinary sensor to MiScale V1, V2, and S400 models to explicitly expose weight stabilization status.xiaomi-bleto1.14.2to support these backend model data structure updates.Type of change
Additional information
Checklist
ruff format homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all.To help with the load of incoming pull requests: