[lc709203f][max17043][pulse_counter][pulse_meter][duty_time] Use the sub_* helpers for optional child entities (#20046)

This commit is contained in:
J. Nick Koston
2026-10-02 14:30:17 -04:00
committed by GitHub
parent b15bc083f6
commit b0d5681022
5 changed files with 15 additions and 27 deletions
+2 -3
View File
@@ -63,9 +63,8 @@ async def to_code(config: ConfigType) -> None:
if CONF_LAMBDA in config:
lambda_ = await cg.process_lambda(config[CONF_LAMBDA], [], return_type=cg.bool_)
cg.add(var.set_lambda(lambda_))
if CONF_LAST_TIME in config:
sens = await sensor.new_sensor(config[CONF_LAST_TIME])
cg.add(var.set_last_duty_time_sensor(sens))
sensors = sensor.sub_sensors(config)
await sensors(CONF_LAST_TIME, var.set_last_duty_time_sensor)
# AUTOMATIONS
+6 -11
View File
@@ -79,15 +79,10 @@ async def to_code(config: ConfigType) -> None:
cg.add(var.set_pack_size(config.get(CONF_SIZE)))
cg.add(var.set_pack_voltage(BATTERY_VOLTAGE_OPTIONS[config[CONF_VOLTAGE]]))
if voltage_config := config.get(CONF_BATTERY_VOLTAGE):
sens = await sensor.new_sensor(voltage_config)
cg.add(var.set_voltage_sensor(sens))
sensors = sensor.sub_sensors(config)
await sensors(CONF_BATTERY_VOLTAGE, var.set_voltage_sensor)
await sensors(CONF_BATTERY_LEVEL, var.set_battery_remaining_sensor)
if level_config := config.get(CONF_BATTERY_LEVEL):
sens = await sensor.new_sensor(level_config)
cg.add(var.set_battery_remaining_sensor(sens))
if temp_config := config.get(CONF_TEMPERATURE):
sens = await sensor.new_sensor(temp_config)
cg.add(var.set_temperature_sensor(sens))
cg.add(var.set_thermistor_b_constant(temp_config[CONF_B_CONSTANT]))
if await sensors(CONF_TEMPERATURE, var.set_temperature_sensor):
b_constant = config[CONF_TEMPERATURE][CONF_B_CONSTANT]
cg.add(var.set_thermistor_b_constant(b_constant))
+3 -7
View File
@@ -53,13 +53,9 @@ async def to_code(config: ConfigType) -> None:
await cg.register_component(var, config)
await i2c.register_i2c_device(var, config)
if voltage_config := config.get(CONF_BATTERY_VOLTAGE):
sens = await sensor.new_sensor(voltage_config)
cg.add(var.set_voltage_sensor(sens))
if CONF_BATTERY_LEVEL in config:
sens = await sensor.new_sensor(config[CONF_BATTERY_LEVEL])
cg.add(var.set_battery_remaining_sensor(sens))
sensors = sensor.sub_sensors(config)
await sensors(CONF_BATTERY_VOLTAGE, var.set_voltage_sensor)
await sensors(CONF_BATTERY_LEVEL, var.set_battery_remaining_sensor)
MAX17043_ACTION_SCHEMA = maybe_simple_id(
+2 -3
View File
@@ -140,9 +140,8 @@ async def to_code(config: ConfigType) -> None:
cg.add(var.set_falling_edge_mode(count[CONF_FALLING_EDGE]))
cg.add(var.set_filter_us(config[CONF_INTERNAL_FILTER]))
if CONF_TOTAL in config:
sens = await sensor.new_sensor(config[CONF_TOTAL])
cg.add(var.set_total_sensor(sens))
sensors = sensor.sub_sensors(config)
await sensors(CONF_TOTAL, var.set_total_sensor)
automation.register_apply_action(
+2 -3
View File
@@ -92,9 +92,8 @@ async def to_code(config: ConfigType) -> None:
cg.add(var.set_timeout_us(config[CONF_TIMEOUT]))
cg.add(var.set_filter_mode(config[CONF_INTERNAL_FILTER_MODE]))
if CONF_TOTAL in config:
sens = await sensor.new_sensor(config[CONF_TOTAL])
cg.add(var.set_total_sensor(sens))
sensors = sensor.sub_sensors(config)
await sensors(CONF_TOTAL, var.set_total_sensor)
automation.register_apply_action(