mirror of
https://github.com/esphome/esphome.git
synced 2026-08-22 22:26:21 +00:00
Sync new_config with current_config on the give-up path and gate the config writing actions on an explicit config read complete flag so a partial read can never be written to the module's NVM, raise the retry listen window above the module boot silence, treat replies shorter than the expected data length as silence, apply the parser mode only after the mode write is acknowledged, propagate write errors in the apply and factory reset actions before adopting the new config or clearing the warning, log drain failures and unbuildable startup frames, watch the runtime marked as failed log string in the tests, give the first enable command in the retry fixture genuine silence, and alternate the warm restart stream values so state deduplication cannot starve a late subscriber.
138 lines
4.0 KiB
YAML
138 lines
4.0 KiB
YAML
esphome:
|
|
name: uart-mock-ld2420-retry-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 ld2420's DEPENDENCIES = ["uart"]
|
|
uart:
|
|
baud_rate: 115200
|
|
port: /dev/null
|
|
|
|
# Exercises the per-command retry path: the module ignores the first config
|
|
# mode enable command and only answers the resend, so the startup handshake
|
|
# must time out once, resend, and then complete normally.
|
|
uart_mock:
|
|
id: mock_uart
|
|
baud_rate: 115200
|
|
auto_start: true
|
|
|
|
injections:
|
|
# Wake-up frame (t=700ms): energy frame (presence=1, distance=100).
|
|
# Delay=700ms keeps it outside the component's 500ms listen settle window.
|
|
- delay: 700ms
|
|
inject_rx:
|
|
[
|
|
0xF4, 0xF3, 0xF2, 0xF1,
|
|
0x23, 0x00,
|
|
0x01,
|
|
0x64, 0x00,
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
0xF8, 0xF7, 0xF6, 0xF5,
|
|
]
|
|
|
|
# The config mode enable command is matched by an empty responder so the
|
|
# catch-all cannot answer it (responders match on the TX suffix and every
|
|
# command ends with the frame footer); the on_tx hook below acks it from
|
|
# the second attempt on, so the first attempt is genuine silence.
|
|
responses:
|
|
- expect_tx:
|
|
[0xFD, 0xFC, 0xFB, 0xFA, 0x04, 0x00, 0xFF, 0x00, 0x02, 0x00, 0x04, 0x03, 0x02, 0x01]
|
|
inject_rx: []
|
|
|
|
# Version response: returns "v2.0.0" → 200 >= 154 → energy mode
|
|
- expect_tx:
|
|
[0xFD, 0xFC, 0xFB, 0xFA, 0x02, 0x00, 0x00, 0x00, 0x04, 0x03, 0x02, 0x01]
|
|
inject_rx:
|
|
[
|
|
0xFD, 0xFC, 0xFB, 0xFA,
|
|
0x0C, 0x00,
|
|
0x00, 0x01,
|
|
0x00, 0x00,
|
|
0x06, 0x00,
|
|
0x76, 0x32, 0x2E, 0x30, 0x2E, 0x30,
|
|
0x04, 0x03, 0x02, 0x01,
|
|
]
|
|
|
|
# System mode write: CMD_WRITE_SYS_PARAM (0x0012), mode = energy (0x0004)
|
|
- expect_tx:
|
|
[0xFD, 0xFC, 0xFB, 0xFA, 0x08, 0x00, 0x12, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x03, 0x02, 0x01]
|
|
inject_rx:
|
|
[
|
|
0xFD, 0xFC, 0xFB, 0xFA,
|
|
0x04, 0x00,
|
|
0x12, 0x01,
|
|
0x00, 0x00,
|
|
0x04, 0x03, 0x02, 0x01,
|
|
]
|
|
|
|
# Config mode disable: CMD_DISABLE_CONF (0x00FE)
|
|
- 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,
|
|
]
|
|
|
|
# Catch-all for the CMD_READ_ABD_PARAM (0x0008) reads: limits and the 16
|
|
# gate threshold reads. Three zeroed uint32 data values.
|
|
- expect_tx: [0x04, 0x03, 0x02, 0x01]
|
|
inject_rx:
|
|
[
|
|
0xFD, 0xFC, 0xFB, 0xFA,
|
|
0x10, 0x00,
|
|
0x08, 0x01,
|
|
0x00, 0x00,
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
0x04, 0x03, 0x02, 0x01,
|
|
]
|
|
|
|
# Ignore the first config mode enable command; ack every one after it
|
|
on_tx:
|
|
- lambda: |-
|
|
static int enable_count = 0;
|
|
if (data.size() == 14 && data[6] == 0xFF) {
|
|
enable_count++;
|
|
if (enable_count >= 2) {
|
|
id(mock_uart).inject_to_rx_buffer(std::vector<uint8_t>{
|
|
0xFD, 0xFC, 0xFB, 0xFA, 0x04, 0x00, 0xFF, 0x01, 0x00, 0x00, 0x04, 0x03, 0x02, 0x01});
|
|
}
|
|
}
|
|
|
|
ld2420:
|
|
id: ld2420_dev
|
|
uart_id: mock_uart
|
|
|
|
sensor:
|
|
- platform: ld2420
|
|
ld2420_id: ld2420_dev
|
|
moving_distance:
|
|
name: "Moving Distance"
|
|
filters:
|
|
- timeout:
|
|
timeout: 50ms
|
|
value: last
|
|
- throttle_with_priority: 50ms
|
|
|
|
binary_sensor:
|
|
- platform: ld2420
|
|
ld2420_id: ld2420_dev
|
|
has_target:
|
|
name: "Has Target"
|
|
filters:
|
|
- settle: 50ms
|