mirror of
https://github.com/esphome/esphome.git
synced 2026-10-02 17:30:22 +00:00
[gdk101] Use the sub_* helpers for optional child entities (#19942)
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user