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