mirror of
https://github.com/esphome/esphome.git
synced 2026-11-10 23:25:58 +00:00
Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
25 lines
1.0 KiB
Python
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
|