-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbinary_sensor.py
36 lines (32 loc) · 1.44 KB
/
binary_sensor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import esphome.codegen as cg
from esphome.components import binary_sensor
import esphome.config_validation as cv
from esphome.const import DEVICE_CLASS_MOTION, DEVICE_CLASS_OCCUPANCY
from . import CONF_LD2420_ID, LD2420Component
DEPENDENCIES = ["ld2420"]
CONF_HAS_TARGET = "has_target"
CONF_HAS_MOVING_TARGET = "has_moving_target"
CONF_HAS_STILL_TARGET = "has_still_target"
CONFIG_SCHEMA = {
cv.GenerateID(CONF_LD2420_ID): cv.use_id(LD2420Component),
cv.Optional(CONF_HAS_TARGET): binary_sensor.binary_sensor_schema(
device_class=DEVICE_CLASS_OCCUPANCY
),
cv.Optional(CONF_HAS_MOVING_TARGET): binary_sensor.binary_sensor_schema(
device_class=DEVICE_CLASS_MOTION
),
cv.Optional(CONF_HAS_STILL_TARGET): binary_sensor.binary_sensor_schema(
device_class=DEVICE_CLASS_OCCUPANCY
),
}
async def to_code(config):
ld2420_component = await cg.get_variable(config[CONF_LD2420_ID])
if CONF_HAS_TARGET in config:
sens = await binary_sensor.new_binary_sensor(config[CONF_HAS_TARGET])
cg.add(ld2420_component.set_presence_sensor(sens))
if CONF_HAS_MOVING_TARGET in config:
sens = await binary_sensor.new_binary_sensor(config[CONF_HAS_MOVING_TARGET])
cg.add(ld2420_component.set_moving_target_sensor(sens))
if CONF_HAS_STILL_TARGET in config:
sens = await binary_sensor.new_binary_sensor(config[CONF_HAS_STILL_TARGET])
cg.add(ld2420_component.set_still_target_sensor(sens))