[ld6002b] Use the sub_* helpers for optional child entities (#19918)

This commit is contained in:
J. Nick Koston
2026-09-29 21:32:13 -04:00
committed by GitHub
parent 83d689d944
commit ef4d06e0ea
3 changed files with 8 additions and 16 deletions
+2 -3
View File
@@ -40,9 +40,8 @@ CONFIG_SCHEMA = (
async def to_code(config: ConfigType) -> None:
hub = await cg.get_variable(config[CONF_LD6002B_ID])
if target_config := config.get(CONF_TARGET):
sens = await binary_sensor.new_binary_sensor(target_config)
cg.add(hub.set_presence_binary_sensor(sens))
binary_sensors = binary_sensor.sub_binary_sensors(config)
await binary_sensors(CONF_TARGET, hub.set_presence_binary_sensor)
for i in range(MAX_TARGETS):
if target_config := config.get(f"target_{i + 1}"):
+3 -7
View File
@@ -154,13 +154,9 @@ CONFIG_SCHEMA = (
async def to_code(config: ConfigType) -> None:
hub = await cg.get_variable(config[CONF_LD6002B_ID])
if target_count_config := config.get(CONF_TARGET_COUNT):
sens = await sensor.new_sensor(target_count_config)
cg.add(hub.set_target_count_sensor(sens))
if point_count_config := config.get(CONF_POINT_COUNT):
sens = await sensor.new_sensor(point_count_config)
cg.add(hub.set_point_count_sensor(sens))
sensors = sensor.sub_sensors(config)
await sensors(CONF_TARGET_COUNT, hub.set_target_count_sensor)
await sensors(CONF_POINT_COUNT, hub.set_point_count_sensor)
for i in range(MAX_TARGETS):
if target_config := config.get(f"target_{i + 1}"):
+3 -6
View File
@@ -24,9 +24,6 @@ CONFIG_SCHEMA = cv.Schema(
async def to_code(config: ConfigType) -> None:
hub = await cg.get_variable(config[CONF_LD6002B_ID])
if work_mode_config := config.get(CONF_WORK_MODE):
sens = await text_sensor.new_text_sensor(work_mode_config)
cg.add(hub.set_work_mode_text_sensor(sens))
if ota_config := config.get(CONF_OTA_VERSION):
sens = await text_sensor.new_text_sensor(ota_config)
cg.add(hub.set_ota_version_text_sensor(sens))
text_sensors = text_sensor.sub_text_sensors(config)
await text_sensors(CONF_WORK_MODE, hub.set_work_mode_text_sensor)
await text_sensors(CONF_OTA_VERSION, hub.set_ota_version_text_sensor)