[light] Keep the effect list in a flash table (#20204)

Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
This commit is contained in:
J. Nick Koston
2026-10-09 15:55:09 -10:00
committed by GitHub
co-authored by pre-commit-ci-lite[bot]
parent 6b03d68fac
commit 41cc96bbb8
19 changed files with 207 additions and 80 deletions
+41 -1
View File
@@ -4,7 +4,7 @@ import math
import pytest
from esphome import cpp_generator as cg, cpp_types as ct
from esphome.core import CORE, ID
from esphome.core import CORE, ID, EsphomeError
class TestExpressions:
@@ -829,6 +829,46 @@ class TestSharedProgmemArray:
assert str(a) != str(b)
assert sum("PROGMEM" in str(st) for st in CORE.global_statements) == 2
def test_is_static_pointer_only_for_placement_new(self) -> None:
CORE.config = {}
static = cg.new_Pvariable(ID("static_obj", is_declaration=True, type=ct.uint8))
dynamic = cg.Pvariable(
ID("dynamic_obj", is_declaration=True, type=ct.uint8),
cg.RawExpression("nullptr"),
)
assert cg.is_static_pointer(static)
assert not cg.is_static_pointer(dynamic)
def test_constexpr_and_const_arrays_are_not_shared(self) -> None:
CORE.config = {}
a = cg.shared_progmem_array("table", ct.uint8, [1], constexpr=False)
b = cg.shared_progmem_array("table", ct.uint8, [1])
assert str(a) != str(b)
def test_constexpr_false_rejects_dynamic_pointers(self) -> None:
CORE.config = {}
dynamic = cg.Pvariable(
ID("dynamic_obj", is_declaration=True, type=ct.uint8),
cg.RawExpression("nullptr"),
)
with pytest.raises(EsphomeError, match="dynamic_obj"):
cg.shared_progmem_array(
"table",
ct.uint8.operator("ptr"),
cg.ArrayInitializer(dynamic),
constexpr=False,
)
def test_constexpr_false_emits_a_const_array(self) -> None:
CORE.config = {}
cg.shared_progmem_array("table", ct.uint8, [1], constexpr=False)
(statement,) = (
str(st) for st in CORE.global_statements if "PROGMEM" in str(st)
)
assert statement.startswith(
"ESPHOME_FLASH_CONSTINIT static uint8_t const table[] PROGMEM = {1}"
)
def test_same_contents_different_type_are_separate(self) -> None:
CORE.config = {}
a = cg.shared_progmem_array("table", ct.uint8, [1])