1
0
mirror of https://github.com/esphome/esphome.git synced 2025-03-23 19:18:17 +00:00
esphome/esphome/components/udp/binary_sensor.py
Clyde Stubbs ba6963cf72
[udp] Implement UDP sensor broadcast (#6865)
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
Co-authored-by: clydebarrow <366188+clydebarrow@users.noreply.github.com>
2024-08-30 20:59:55 +12:00

28 lines
784 B
Python

import esphome.codegen as cg
from esphome.components import binary_sensor
from esphome.config_validation import All, has_at_least_one_key
from esphome.const import CONF_ID
from . import (
CONF_PROVIDER,
CONF_REMOTE_ID,
CONF_UDP_ID,
SENSOR_SCHEMA,
require_internal_with_name,
)
DEPENDENCIES = ["udp"]
CONFIG_SCHEMA = All(
binary_sensor.binary_sensor_schema().extend(SENSOR_SCHEMA),
has_at_least_one_key(CONF_ID, CONF_REMOTE_ID),
require_internal_with_name,
)
async def to_code(config):
var = await binary_sensor.new_binary_sensor(config)
comp = await cg.get_variable(config[CONF_UDP_ID])
remote_id = str(config.get(CONF_REMOTE_ID) or config.get(CONF_ID))
cg.add(comp.add_remote_binary_sensor(config[CONF_PROVIDER], remote_id, var))