[wireguard] Use the sub_* helpers for optional child entities (#19833)

This commit is contained in:
J. Nick Koston
2026-09-28 08:44:07 -04:00
committed by GitHub
parent 9f7d7284a2
commit b4b4000633
3 changed files with 10 additions and 16 deletions
@@ -24,12 +24,8 @@ CONFIG_SCHEMA = {
async def to_code(config):
parent = await cg.get_variable(config[CONF_WIREGUARD_ID])
hub = await cg.get_variable(config[CONF_WIREGUARD_ID])
if status_config := config.get(CONF_STATUS):
sens = await binary_sensor.new_binary_sensor(status_config)
cg.add(parent.set_status_sensor(sens))
if enabled_config := config.get(CONF_ENABLED):
sens = await binary_sensor.new_binary_sensor(enabled_config)
cg.add(parent.set_enabled_sensor(sens))
binary_sensors = binary_sensor.sub_binary_sensors(config)
await binary_sensors(CONF_STATUS, hub.set_status_sensor)
await binary_sensors(CONF_ENABLED, hub.set_enabled_sensor)
+3 -4
View File
@@ -19,8 +19,7 @@ CONFIG_SCHEMA = {
async def to_code(config):
parent = await cg.get_variable(config[CONF_WIREGUARD_ID])
hub = await cg.get_variable(config[CONF_WIREGUARD_ID])
if latest_handshake_config := config.get(CONF_LATEST_HANDSHAKE):
sens = await sensor.new_sensor(latest_handshake_config)
cg.add(parent.set_handshake_sensor(sens))
sensors = sensor.sub_sensors(config)
await sensors(CONF_LATEST_HANDSHAKE, hub.set_handshake_sensor)
+3 -4
View File
@@ -16,8 +16,7 @@ CONFIG_SCHEMA = {
async def to_code(config):
parent = await cg.get_variable(config[CONF_WIREGUARD_ID])
hub = await cg.get_variable(config[CONF_WIREGUARD_ID])
if address_config := config.get(CONF_ADDRESS):
sens = await text_sensor.new_text_sensor(address_config)
cg.add(parent.set_address_sensor(sens))
text_sensors = text_sensor.sub_text_sensors(config)
await text_sensors(CONF_ADDRESS, hub.set_address_sensor)