[combination][libretiny][sound_level] Use the sub_* helpers for optional child entities (#20050)

This commit is contained in:
J. Nick Koston
2026-10-02 14:32:45 -04:00
committed by GitHub
parent 3cc4df4b3a
commit 483b9ebe2c
3 changed files with 8 additions and 13 deletions
+2 -3
View File
@@ -203,6 +203,5 @@ async def to_code(config: ConfigType) -> None:
else:
cg.add(var.add_source(source))
if CONF_STD_DEV in config:
sens = await sensor.new_sensor(config[CONF_STD_DEV])
cg.add(var.set_std_dev_sensor(sens))
sensors = sensor.sub_sensors(config)
await sensors(CONF_STD_DEV, var.set_std_dev_sensor)
+3 -4
View File
@@ -25,8 +25,7 @@ CONFIG_SCHEMA = cv.Schema(
async def to_code(config):
lt_component = await cg.get_variable(config[CONF_LIBRETINY])
hub = await cg.get_variable(config[CONF_LIBRETINY])
if CONF_VERSION in config:
sens = await text_sensor.new_text_sensor(config[CONF_VERSION])
cg.add(lt_component.set_version_sensor(sens))
text_sensors = text_sensor.sub_text_sensors(config)
await text_sensors(CONF_VERSION, hub.set_version_sensor)
+3 -6
View File
@@ -73,12 +73,9 @@ async def to_code(config: ConfigType) -> None:
cg.add(var.set_measurement_duration(config[CONF_MEASUREMENT_DURATION]))
if peak_config := config.get(CONF_PEAK):
sens = await sensor.new_sensor(peak_config)
cg.add(var.set_peak_sensor(sens))
if rms_config := config.get(CONF_RMS):
sens = await sensor.new_sensor(rms_config)
cg.add(var.set_rms_sensor(sens))
sensors = sensor.sub_sensors(config)
await sensors(CONF_PEAK, var.set_peak_sensor)
await sensors(CONF_RMS, var.set_rms_sensor)
SOUND_LEVEL_ACTION_SCHEMA = automation.maybe_simple_id(