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