[ld6004] Add sensor platform (#19841)

Co-authored-by: J. Nick Koston <nick@home-assistant.io>
Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
authored and GitHub committed 2026-10-30 17:40:09 -10:00
1 parent c82e275eee
commit 7ee82fbc90
11 files changed
+234 -30

No files matched your search

@@ -0,0 +1,20 @@
esphome:
name: test
esp32:
board: esp32dev
framework:
type: esp-idf
uart:
tx_pin: GPIO17
rx_pin: GPIO16
baud_rate: 115200
ld6004:
id: radar
binary_sensor:
- platform: ld6004
target:
name: Presence
@@ -0,0 +1,2 @@
packages:
base: !include base.yaml
@@ -0,0 +1,8 @@
packages:
base: !include base.yaml
sensor:
- platform: ld6004
detection_area_0:
x_min:
name: Detection X Min
@@ -0,0 +1,8 @@
packages:
base: !include base.yaml
sensor:
- platform: ld6004
dwell_area_1:
x_min:
name: Dwell X Min
+15 -28
View File
@@ -3,39 +3,26 @@
from collections.abc import Callable
from pathlib import Path
import pytest
from esphome.core import CORE
BASE = """
esphome:
name: test
esp32:
board: esp32dev
framework:
type: esp-idf
uart:
tx_pin: GPIO17
rx_pin: GPIO16
baud_rate: 115200
ld6004:
id: radar
binary_sensor:
- platform: ld6004
target:
name: Presence
"""
@pytest.mark.parametrize(
("config_file", "area_kinds"),
[
("binary_sensor_only.yaml", "2"),
("detection_area_sensor.yaml", "2"),
("dwell_area_sensor.yaml", "3"),
],
)
def test_area_kinds(
generate_main: Callable[[str | Path], str],
tmp_path: Path,
component_config_path: Callable[[str], Path],
config_file: str,
area_kinds: str,
) -> None:
path = tmp_path / "test.yaml"
path.write_text(BASE)
generate_main(path)
generate_main(component_config_path(config_file))
defines = {define.name: str(define.value) for define in CORE.defines}
assert defines["LD600X_AREA_KINDS"] == "2"
assert defines["LD600X_AREA_KINDS"] == area_kinds
assert defines["LD600X_MAX_TARGETS"] == "3"
@@ -0,0 +1,48 @@
"""Validate LD6004 sensor target and area limits."""
import pytest
from esphome.components.ld6004 import LD6004Component
from esphome.components.ld6004.sensor import CONFIG_SCHEMA
import esphome.config_validation as cv
from esphome.const import PlatformFramework
from esphome.types import ConfigType
from tests.component_tests.types import SetCoreConfigCallable
@pytest.mark.parametrize(
("key", "fields"),
[
("target_3", ("x", "y", "z", "doppler_index", "cluster_id")),
("dwell_area_3", ("x_min", "x_max", "y_min", "y_max", "z_min", "z_max")),
],
)
def test_model_sensor_keys(
set_core_config: SetCoreConfigCallable, key: str, fields: tuple[str, ...]
) -> None:
set_core_config(PlatformFramework.ESP32_IDF)
config: ConfigType = CONFIG_SCHEMA(
{key: {field: {"name": field} for field in fields}}
)
assert config["ld6004_id"].type == LD6004Component
assert set(config[key]) == set(fields)
for field in fields:
assert config[key][field]["name"] == field
@pytest.mark.parametrize(
"key",
[
"target_0",
"target_4",
"interference_area_4",
"detection_area_4",
"dwell_area_4",
],
)
def test_out_of_range_sensor_keys(
set_core_config: SetCoreConfigCallable, key: str
) -> None:
set_core_config(PlatformFramework.ESP32_IDF)
with pytest.raises(cv.Invalid, match=key):
CONFIG_SCHEMA({key: {"x": {"name": "Invalid sensor"}}})