Files
esphome/tests/component_tests/udp/test_udp_write.py
T
J. Nick Kostonandpre-commit-ci-lite[bot] a3cb3732ee [sx127x][sx126x][cc1101][udp][uart] Send byte payloads with ApplyBytes (#21263)
Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
2026-10-22 08:19:09 -10:00

25 lines
1.0 KiB
Python

"""Tests for the udp.write action codegen."""
from collections.abc import Callable
from pathlib import Path
def test_write_payloads_share_a_progmem_table(
generate_main: Callable[[str | Path], str],
component_config_path: Callable[[str], Path],
) -> None:
"""Identical constant payloads share one flash table and are copied out of it on
ESP8266 before sending; an empty one needs none; a lambda is sent from its vector."""
main_cpp = generate_main(component_config_path("udp_write.yaml"))
table = "esphome__udp_write__bytes"
assert main_cpp.count(f"{table}[] PROGMEM = {{0xAA, 0x55, 0x01, 0x02}};") == 1
assert (
main_cpp.count(f"esphome::progmem_memcpy(esphome__bytes, ::{table}, 4);") == 2
)
assert main_cpp.count("->send_packet(esphome__bytes, 4);") == 2
assert "uint8_t esphome__bytes[1];" in main_cpp
assert "->send_packet(esphome__bytes, 0);" in main_cpp
assert "->send_packet(esphome__bytes.data(), esphome__bytes.size());" in main_cpp
assert main_cpp.count("->set_should_broadcast();") == 4