From 32c03f20797968c64de82dcfd1328c001c7eef31 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 28 Sep 2026 00:42:58 +0200 Subject: [PATCH] [xiaomi_body_scale] Use the sub_* helpers for optional child entities (#19772) --- .../components/xiaomi_body_scale/sensor.py | 21 +++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/esphome/components/xiaomi_body_scale/sensor.py b/esphome/components/xiaomi_body_scale/sensor.py index c8cbc0e820..cb0802d270 100644 --- a/esphome/components/xiaomi_body_scale/sensor.py +++ b/esphome/components/xiaomi_body_scale/sensor.py @@ -78,16 +78,11 @@ async def to_code(config: ConfigType) -> None: await cg.register_component(var, config) await ble_device_base.register_ble_device(var, config) - for key, setter in ( - (CONF_WEIGHT, var.set_weight), - (CONF_IMPEDANCE_LOW, var.set_impedance_low), - (CONF_IMPEDANCE_HIGH, var.set_impedance_high), - (CONF_HEART_RATE, var.set_heart_rate), - (CONF_PROFILE_ID, var.set_profile_id), - ): - if (conf := config.get(key)) is not None: - sens = await sensor.new_sensor(conf) - cg.add(setter(sens)) - if (conf := config.get(CONF_STABILIZED)) is not None: - sens = await binary_sensor.new_binary_sensor(conf) - cg.add(var.set_stabilized(sens)) + sensors = sensor.sub_sensors(config) + await sensors(CONF_WEIGHT, var.set_weight) + await sensors(CONF_IMPEDANCE_LOW, var.set_impedance_low) + await sensors(CONF_IMPEDANCE_HIGH, var.set_impedance_high) + await sensors(CONF_HEART_RATE, var.set_heart_rate) + await sensors(CONF_PROFILE_ID, var.set_profile_id) + binary_sensors = binary_sensor.sub_binary_sensors(config) + await binary_sensors(CONF_STABILIZED, var.set_stabilized)