mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-05-18 20:23:27 +02:00
b107948c47
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Co-authored-by: Simone Rossetto <simros85@gmail.com> Co-authored-by: Thomas Bernard <thomas0bernard@gmail.com>
31 lines
852 B
Python
31 lines
852 B
Python
import esphome.codegen as cg
|
|
import esphome.config_validation as cv
|
|
from esphome.components import sensor
|
|
from esphome.const import (
|
|
DEVICE_CLASS_TIMESTAMP,
|
|
ENTITY_CATEGORY_DIAGNOSTIC,
|
|
)
|
|
|
|
from . import Wireguard
|
|
|
|
CONF_WIREGUARD_ID = "wireguard_id"
|
|
CONF_LATEST_HANDSHAKE = "latest_handshake"
|
|
|
|
DEPENDENCIES = ["wireguard"]
|
|
|
|
CONFIG_SCHEMA = {
|
|
cv.GenerateID(CONF_WIREGUARD_ID): cv.use_id(Wireguard),
|
|
cv.Optional(CONF_LATEST_HANDSHAKE): sensor.sensor_schema(
|
|
device_class=DEVICE_CLASS_TIMESTAMP,
|
|
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
|
),
|
|
}
|
|
|
|
|
|
async def to_code(config):
|
|
parent = 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))
|