[gdk101] Use the sub_* helpers for optional child entities (#19942)

This commit is contained in:
J. Nick Koston
2026-09-30 04:58:30 -04:00
committed by GitHub
parent 08ed25833d
commit a706fa9e6b
+5 -15
View File
@@ -63,18 +63,8 @@ CONFIG_SCHEMA = cv.Schema(
async def to_code(config: ConfigType) -> None:
hub = await cg.get_variable(config[CONF_GDK101_ID])
if radiation_dose_per_1m := config.get(CONF_RADIATION_DOSE_PER_1M):
sens = await sensor.new_sensor(radiation_dose_per_1m)
cg.add(hub.set_rad_1m_sensor(sens))
if radiation_dose_per_10m := config.get(CONF_RADIATION_DOSE_PER_10M):
sens = await sensor.new_sensor(radiation_dose_per_10m)
cg.add(hub.set_rad_10m_sensor(sens))
if status_config := config.get(CONF_STATUS):
sens = await sensor.new_sensor(status_config)
cg.add(hub.set_status_sensor(sens))
if measurement_duration_config := config.get(CONF_MEASUREMENT_DURATION):
sens = await sensor.new_sensor(measurement_duration_config)
cg.add(hub.set_measurement_duration_sensor(sens))
sensors = sensor.sub_sensors(config)
await sensors(CONF_RADIATION_DOSE_PER_1M, hub.set_rad_1m_sensor)
await sensors(CONF_RADIATION_DOSE_PER_10M, hub.set_rad_10m_sensor)
await sensors(CONF_STATUS, hub.set_status_sensor)
await sensors(CONF_MEASUREMENT_DURATION, hub.set_measurement_duration_sensor)