[ufm01] Use the sub_* helpers for optional child entities (#19927)

This commit is contained in:
J. Nick Koston
2026-09-30 04:14:11 -04:00
committed by GitHub
parent 4a00cebd61
commit 4a34315fc7
2 changed files with 15 additions and 28 deletions
+10 -16
View File
@@ -34,20 +34,14 @@ CONFIG_SCHEMA = {
async def to_code(config: ConfigType) -> None:
ufm01_component = await cg.get_variable(config[CONF_UFM01_ID])
hub = await cg.get_variable(config[CONF_UFM01_ID])
if ufc_chip_error_config := config.get(CONF_UFC_CHIP_ERROR):
sens = await binary_sensor.new_binary_sensor(ufc_chip_error_config)
cg.add(ufm01_component.set_ufc_chip_error_binary_sensor(sens))
if flow_direction_wrong_config := config.get(CONF_FLOW_DIRECTION_WRONG):
sens = await binary_sensor.new_binary_sensor(flow_direction_wrong_config)
cg.add(ufm01_component.set_flow_direction_wrong_binary_sensor(sens))
if empty_tube_config := config.get(CONF_EMPTY_TUBE):
sens = await binary_sensor.new_binary_sensor(empty_tube_config)
cg.add(ufm01_component.set_empty_tube_binary_sensor(sens))
if flow_rate_out_of_range_config := config.get(CONF_FLOW_RATE_OUT_OF_RANGE):
sens = await binary_sensor.new_binary_sensor(flow_rate_out_of_range_config)
cg.add(ufm01_component.set_flow_rate_out_of_range_binary_sensor(sens))
binary_sensors = binary_sensor.sub_binary_sensors(config)
await binary_sensors(CONF_UFC_CHIP_ERROR, hub.set_ufc_chip_error_binary_sensor)
await binary_sensors(
CONF_FLOW_DIRECTION_WRONG, hub.set_flow_direction_wrong_binary_sensor
)
await binary_sensors(CONF_EMPTY_TUBE, hub.set_empty_tube_binary_sensor)
await binary_sensors(
CONF_FLOW_RATE_OUT_OF_RANGE, hub.set_flow_rate_out_of_range_binary_sensor
)
+5 -12
View File
@@ -49,16 +49,9 @@ CONFIG_SCHEMA = cv.Schema(
async def to_code(config: ConfigType) -> None:
ufm01_component = await cg.get_variable(config[CONF_UFM01_ID])
hub = await cg.get_variable(config[CONF_UFM01_ID])
if CONF_ACCUMULATED_FLOW in config:
sens = await sensor.new_sensor(config[CONF_ACCUMULATED_FLOW])
cg.add(ufm01_component.set_accumulated_flow_sensor(sens))
if CONF_FLOW in config:
sens = await sensor.new_sensor(config[CONF_FLOW])
cg.add(ufm01_component.set_flow_sensor(sens))
if CONF_TEMPERATURE in config:
sens = await sensor.new_sensor(config[CONF_TEMPERATURE])
cg.add(ufm01_component.set_temperature_sensor(sens))
sensors = sensor.sub_sensors(config)
await sensors(CONF_ACCUMULATED_FLOW, hub.set_accumulated_flow_sensor)
await sensors(CONF_FLOW, hub.set_flow_sensor)
await sensors(CONF_TEMPERATURE, hub.set_temperature_sensor)