mirror of
https://github.com/esphome/esphome.git
synced 2026-12-01 17:26:22 +00:00
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com> Co-authored-by: J. Nick Koston <nick@home-assistant.io>
147 lines
6.0 KiB
YAML
147 lines
6.0 KiB
YAML
esphome:
|
|
name: uart-mock-ld2410s-test
|
|
|
|
host:
|
|
api:
|
|
batch_delay: 0ms # Disable batching to receive all state updates
|
|
logger:
|
|
level: VERBOSE
|
|
|
|
external_components:
|
|
- source:
|
|
type: local
|
|
path: EXTERNAL_COMPONENT_PATH
|
|
|
|
# Dummy uart entry to satisfy ld2410s's DEPENDENCIES = ["uart"]
|
|
# The actual UART bus used is the uart_mock component below
|
|
uart:
|
|
baud_rate: 115200
|
|
port: /dev/null
|
|
|
|
uart_mock:
|
|
id: mock_uart
|
|
baud_rate: 115200
|
|
auto_start: false
|
|
on_tx:
|
|
- then:
|
|
- lambda: |-
|
|
// Parameter read: the first answer stops after one value so the read is resent after the
|
|
// 300 ms timeout; the resend gets gates 0 to 16, no delay 10 s, 8 Hz reporting, normal speed
|
|
static const std::vector<uint8_t> PARAMETERS_READ = {
|
|
0xFD, 0xFC, 0xFB, 0xFA, 0x0E, 0x00, 0x71, 0x00, 0x05, 0x00, 0x0A, 0x00,
|
|
0x06, 0x00, 0x02, 0x00, 0x0C, 0x00, 0x0B, 0x00, 0x04, 0x03, 0x02, 0x01};
|
|
static int reads = 0;
|
|
if (data != PARAMETERS_READ) {
|
|
return;
|
|
}
|
|
if (++reads == 1) {
|
|
id(mock_uart).inject_to_rx_buffer(std::vector<uint8_t>{
|
|
0xFD, 0xFC, 0xFB, 0xFA, 0x08, 0x00, 0x71, 0x01, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
|
|
0x04, 0x03, 0x02, 0x01});
|
|
return;
|
|
}
|
|
id(mock_uart).inject_to_rx_buffer(std::vector<uint8_t>{
|
|
0xFD, 0xFC, 0xFB, 0xFA, 0x1C, 0x00, 0x71, 0x01, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
|
|
0x00, 0x00, 0x00, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, 0x50, 0x00,
|
|
0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x04, 0x03, 0x02, 0x01});
|
|
responses:
|
|
# Config-mode start, acknowledged with protocol version 2 and buffer size 0x20
|
|
- expect_tx: [0xFD, 0xFC, 0xFB, 0xFA, 0x04, 0x00, 0xFF, 0x00, 0x01, 0x00, 0x04, 0x03, 0x02, 0x01]
|
|
inject_rx: [0xFD, 0xFC, 0xFB, 0xFA, 0x08, 0x00, 0xFF, 0x01, 0x00, 0x00, 0x02, 0x00, 0x20, 0x00, 0x04, 0x03, 0x02, 0x01]
|
|
# Version read, answered with device type 1 and firmware 1.2.3
|
|
- expect_tx: [0xFD, 0xFC, 0xFB, 0xFA, 0x02, 0x00, 0x00, 0x00, 0x04, 0x03, 0x02, 0x01]
|
|
inject_rx:
|
|
[
|
|
0xFD, 0xFC, 0xFB, 0xFA, 0x0E, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00,
|
|
0x02, 0x00, 0x03, 0x00, 0x04, 0x03, 0x02, 0x01,
|
|
]
|
|
# The parameter read is answered by the on_tx lambda below: cut short once, then in full
|
|
# Output-mode switch to minimal, acknowledged
|
|
- expect_tx: [0xFD, 0xFC, 0xFB, 0xFA, 0x08, 0x00, 0x7A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x03, 0x02, 0x01]
|
|
inject_rx: [0xFD, 0xFC, 0xFB, 0xFA, 0x04, 0x00, 0x7A, 0x01, 0x00, 0x00, 0x04, 0x03, 0x02, 0x01]
|
|
# Config-mode end, acknowledged
|
|
- expect_tx: [0xFD, 0xFC, 0xFB, 0xFA, 0x02, 0x00, 0xFE, 0x00, 0x04, 0x03, 0x02, 0x01]
|
|
inject_rx: [0xFD, 0xFC, 0xFB, 0xFA, 0x04, 0x00, 0xFE, 0x01, 0x00, 0x00, 0x04, 0x03, 0x02, 0x01]
|
|
# Setting the max distance to 7 m writes all six parameters inside a configuration-mode session
|
|
- expect_tx: [0xFD, 0xFC, 0xFB, 0xFA, 0x04, 0x00, 0xFF, 0x00, 0x01, 0x00, 0x04, 0x03, 0x02, 0x01]
|
|
inject_rx: [0xFD, 0xFC, 0xFB, 0xFA, 0x08, 0x00, 0xFF, 0x01, 0x00, 0x00, 0x02, 0x00, 0x20, 0x00, 0x04, 0x03, 0x02, 0x01]
|
|
- expect_tx:
|
|
[
|
|
0xFD, 0xFC, 0xFB, 0xFA, 0x26, 0x00, 0x70, 0x00, 0x05, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x0A, 0x00,
|
|
0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x02, 0x00, 0x50, 0x00, 0x00, 0x00,
|
|
0x0C, 0x00, 0x50, 0x00, 0x00, 0x00, 0x0B, 0x00, 0x05, 0x00, 0x00, 0x00, 0x04, 0x03, 0x02, 0x01,
|
|
]
|
|
inject_rx: [0xFD, 0xFC, 0xFB, 0xFA, 0x04, 0x00, 0x70, 0x01, 0x00, 0x00, 0x04, 0x03, 0x02, 0x01]
|
|
- expect_tx: [0xFD, 0xFC, 0xFB, 0xFA, 0x02, 0x00, 0xFE, 0x00, 0x04, 0x03, 0x02, 0x01]
|
|
inject_rx: [0xFD, 0xFC, 0xFB, 0xFA, 0x04, 0x00, 0xFE, 0x01, 0x00, 0x00, 0x04, 0x03, 0x02, 0x01]
|
|
injections:
|
|
# Short frame, state 2 (target), distance 300 -> presence on
|
|
- delay: 100ms
|
|
inject_rx: [0x6E, 0x02, 0x2C, 0x01, 0x62]
|
|
# Short frame, state 0 (no target) -> presence off
|
|
- delay: 100ms
|
|
inject_rx: [0x6E, 0x00, 0x00, 0x00, 0x62]
|
|
# Standard data frame, type 1, state 2, distance 300 -> presence on
|
|
- delay: 100ms
|
|
inject_rx: [0xF4, 0xF3, 0xF2, 0xF1, 0x05, 0x00, 0x01, 0x02, 0x2C, 0x01, 0x00, 0xF8, 0xF7, 0xF6, 0xF5]
|
|
# Short frame, state 1 (no target) -> presence off
|
|
- delay: 100ms
|
|
inject_rx: [0x6E, 0x01, 0x00, 0x00, 0x62]
|
|
# Noise byte directly followed by a short frame, state 2 -> presence on
|
|
- delay: 100ms
|
|
inject_rx: [0xAA, 0x6E, 0x02, 0x2C, 0x01, 0x62]
|
|
# Short frame, state 0 -> presence off
|
|
- delay: 100ms
|
|
inject_rx: [0x6E, 0x00, 0x00, 0x00, 0x62]
|
|
# Partial standard header byte directly followed by a short frame, state 3 -> presence on
|
|
- delay: 100ms
|
|
inject_rx: [0xF4, 0x6E, 0x03, 0x2C, 0x01, 0x62]
|
|
# Short frame with the impossible state 7, dropped, then a short frame, state 0 -> presence off
|
|
- delay: 100ms
|
|
inject_rx: [0x6E, 0x07, 0x00, 0x00, 0x62, 0x6E, 0x00, 0x00, 0x00, 0x62]
|
|
# Standard data frame, type 1, with the impossible state 7, dropped, then a short frame, state 2
|
|
# -> presence on
|
|
- delay: 100ms
|
|
inject_rx:
|
|
[
|
|
0xF4, 0xF3, 0xF2, 0xF1, 0x05, 0x00, 0x01, 0x07, 0x2C, 0x01, 0x00, 0xF8, 0xF7, 0xF6, 0xF5, 0x6E,
|
|
0x02, 0x2C, 0x01, 0x62,
|
|
]
|
|
|
|
ld2410s:
|
|
id: ld2410s_dev
|
|
uart_id: mock_uart
|
|
|
|
binary_sensor:
|
|
- platform: ld2410s
|
|
ld2410s_id: ld2410s_dev
|
|
has_target:
|
|
name: "Has Target"
|
|
|
|
sensor:
|
|
- platform: ld2410s
|
|
ld2410s_id: ld2410s_dev
|
|
distance:
|
|
name: "Distance"
|
|
|
|
text_sensor:
|
|
- platform: ld2410s
|
|
ld2410s_id: ld2410s_dev
|
|
version:
|
|
name: "Version"
|
|
|
|
number:
|
|
- platform: ld2410s
|
|
ld2410s_id: ld2410s_dev
|
|
max_distance:
|
|
name: "Max Distance"
|
|
no_delay:
|
|
name: "No Delay"
|
|
|
|
button:
|
|
- platform: template
|
|
name: "Start Scenario"
|
|
id: start_scenario_btn
|
|
on_press:
|
|
- lambda: 'id(mock_uart).start_scenario();'
|