|
| 1 | +import esphome.codegen as cg |
| 2 | +from esphome.components import binary_sensor |
| 3 | +import esphome.config_validation as cv |
| 4 | +from esphome.const import ( |
| 5 | + CONF_HAS_MOVING_TARGET, |
| 6 | + CONF_HAS_STILL_TARGET, |
| 7 | + CONF_HAS_TARGET, |
| 8 | + DEVICE_CLASS_MOTION, |
| 9 | + DEVICE_CLASS_OCCUPANCY, |
| 10 | +) |
| 11 | + |
| 12 | +from . import CONF_LD2450_ID, LD2450Component |
| 13 | + |
| 14 | +DEPENDENCIES = ["ld2450"] |
| 15 | + |
| 16 | +ICON_MEDITATION = "mdi:meditation" |
| 17 | +ICON_SHIELD_ACCOUNT = "mdi:shield-account" |
| 18 | +ICON_TARGET_ACCOUNT = "mdi:target-account" |
| 19 | + |
| 20 | +CONFIG_SCHEMA = { |
| 21 | + cv.GenerateID(CONF_LD2450_ID): cv.use_id(LD2450Component), |
| 22 | + cv.Optional(CONF_HAS_TARGET): binary_sensor.binary_sensor_schema( |
| 23 | + device_class=DEVICE_CLASS_OCCUPANCY, |
| 24 | + icon=ICON_SHIELD_ACCOUNT, |
| 25 | + ), |
| 26 | + cv.Optional(CONF_HAS_MOVING_TARGET): binary_sensor.binary_sensor_schema( |
| 27 | + device_class=DEVICE_CLASS_MOTION, |
| 28 | + icon=ICON_TARGET_ACCOUNT, |
| 29 | + ), |
| 30 | + cv.Optional(CONF_HAS_STILL_TARGET): binary_sensor.binary_sensor_schema( |
| 31 | + device_class=DEVICE_CLASS_OCCUPANCY, |
| 32 | + icon=ICON_MEDITATION, |
| 33 | + ), |
| 34 | +} |
| 35 | + |
| 36 | + |
| 37 | +async def to_code(config): |
| 38 | + ld2450_component = await cg.get_variable(config[CONF_LD2450_ID]) |
| 39 | + if has_target_config := config.get(CONF_HAS_TARGET): |
| 40 | + sens = await binary_sensor.new_binary_sensor(has_target_config) |
| 41 | + cg.add(ld2450_component.set_target_binary_sensor(sens)) |
| 42 | + if has_moving_target_config := config.get(CONF_HAS_MOVING_TARGET): |
| 43 | + sens = await binary_sensor.new_binary_sensor(has_moving_target_config) |
| 44 | + cg.add(ld2450_component.set_moving_target_binary_sensor(sens)) |
| 45 | + if has_still_target_config := config.get(CONF_HAS_STILL_TARGET): |
| 46 | + sens = await binary_sensor.new_binary_sensor(has_still_target_config) |
| 47 | + cg.add(ld2450_component.set_still_target_binary_sensor(sens)) |
0 commit comments