From 32ad04c584bafda784d1a19357142d7b3af776b8 Mon Sep 17 00:00:00 2001 From: Rasad Regmi <123284094+rasadregmi@users.noreply.github.com> Date: Wed, 16 Sep 2026 11:11:56 +0545 Subject: [PATCH] Add missing stabilized binary sensor description for Xiaomi BLE scales (#182328) --- .../components/xiaomi_ble/binary_sensor.py | 3 ++ .../xiaomi_ble/test_binary_sensor.py | 31 ++++++++++++++++++- tests/components/xiaomi_ble/test_sensor.py | 8 ++--- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/xiaomi_ble/binary_sensor.py b/homeassistant/components/xiaomi_ble/binary_sensor.py index 14ba80628073..9d8a32e63845 100644 --- a/homeassistant/components/xiaomi_ble/binary_sensor.py +++ b/homeassistant/components/xiaomi_ble/binary_sensor.py @@ -101,6 +101,9 @@ BINARY_SENSOR_DESCRIPTIONS = { key=ExtendedBinarySensorDeviceClass.PRY_THE_DOOR, device_class=BinarySensorDeviceClass.TAMPER, ), + ExtendedBinarySensorDeviceClass.STABILIZED: BinarySensorEntityDescription( + key=ExtendedBinarySensorDeviceClass.STABILIZED, + ), ExtendedBinarySensorDeviceClass.TOOTHBRUSH: BinarySensorEntityDescription( key=ExtendedBinarySensorDeviceClass.TOOTHBRUSH, ), diff --git a/tests/components/xiaomi_ble/test_binary_sensor.py b/tests/components/xiaomi_ble/test_binary_sensor.py index e48679438a54..4c5ab407d4ee 100644 --- a/tests/components/xiaomi_ble/test_binary_sensor.py +++ b/tests/components/xiaomi_ble/test_binary_sensor.py @@ -16,7 +16,7 @@ from homeassistant.const import ( from homeassistant.core import HomeAssistant from homeassistant.util import dt as dt_util -from . import make_advertisement +from . import MISCALE_V2_SERVICE_INFO, make_advertisement from tests.common import MockConfigEntry, async_fire_time_changed from tests.components.bluetooth import ( @@ -175,6 +175,35 @@ async def test_opening(hass: HomeAssistant) -> None: await hass.async_block_till_done() +async def test_miscale_v2_stabilized_binary_sensor(hass: HomeAssistant) -> None: + """Test MiScale V2 stabilized binary sensor.""" + entry = MockConfigEntry( + domain=DOMAIN, + unique_id="50:FB:19:1B:B5:DC", + ) + entry.add_to_hass(hass) + + assert await hass.config_entries.async_setup(entry.entry_id) + await hass.async_block_till_done() + + inject_bluetooth_service_info_bleak(hass, MISCALE_V2_SERVICE_INFO) + + await hass.async_block_till_done() + assert len(hass.states.async_all()) == 4 + + stabilized_sensor = hass.states.get( + "binary_sensor.mi_body_composition_scale_b5dc_stabilized" + ) + assert stabilized_sensor.state == STATE_ON + assert ( + stabilized_sensor.attributes[ATTR_FRIENDLY_NAME] + == "Mi Body Composition Scale (B5DC) Stabilized" + ) + + assert await hass.config_entries.async_unload(entry.entry_id) + await hass.async_block_till_done() + + async def test_opening_problem_sensors(hass: HomeAssistant) -> None: """Test setting up a opening binary sensor with additional problem sensors.""" entry = MockConfigEntry( diff --git a/tests/components/xiaomi_ble/test_sensor.py b/tests/components/xiaomi_ble/test_sensor.py index d382dbaf8d00..b07c07800d28 100644 --- a/tests/components/xiaomi_ble/test_sensor.py +++ b/tests/components/xiaomi_ble/test_sensor.py @@ -692,7 +692,7 @@ async def test_miscale_v1_uuid(hass: HomeAssistant) -> None: inject_bluetooth_service_info_bleak(hass, MISCALE_V1_SERVICE_INFO) await hass.async_block_till_done() - assert len(hass.states.async_all()) == 2 + assert len(hass.states.async_all()) == 3 mass_non_stabilized_sensor = hass.states.get( "sensor.mi_smart_scale_b5dc_weight_non_stabilized" @@ -734,7 +734,7 @@ async def test_miscale_v2_uuid(hass: HomeAssistant) -> None: inject_bluetooth_service_info_bleak(hass, MISCALE_V2_SERVICE_INFO) await hass.async_block_till_done() - assert len(hass.states.async_all()) == 3 + assert len(hass.states.async_all()) == 4 mass_non_stabilized_sensor = hass.states.get( "sensor.mi_body_composition_scale_b5dc_weight_non_stabilized" @@ -844,7 +844,7 @@ async def test_sleepy_device(hass: HomeAssistant) -> None: inject_bluetooth_service_info_bleak(hass, MISCALE_V1_SERVICE_INFO) await hass.async_block_till_done() - assert len(hass.states.async_all()) == 2 + assert len(hass.states.async_all()) == 3 mass_non_stabilized_sensor = hass.states.get( "sensor.mi_smart_scale_b5dc_weight_non_stabilized" @@ -895,7 +895,7 @@ async def test_sleepy_device_restore_state(hass: HomeAssistant) -> None: inject_bluetooth_service_info_bleak(hass, MISCALE_V1_SERVICE_INFO) await hass.async_block_till_done() - assert len(hass.states.async_all()) == 2 + assert len(hass.states.async_all()) == 3 mass_non_stabilized_sensor = hass.states.get( "sensor.mi_smart_scale_b5dc_weight_non_stabilized"