[light] Shrink LightState by 12 bytes per light (#19711)

This commit is contained in:
J. Nick Koston
2026-09-27 11:53:03 +02:00
committed by GitHub
parent ea4754e798
commit 2844236e77
13 changed files with 215 additions and 48 deletions
@@ -1,5 +1,5 @@
import esphome.codegen as cg
from esphome.components.light import generate_gamma_table
from esphome.components.light import gamma_table_initializer
from tests.testing_helpers import ComponentManifestOverride
@@ -12,15 +12,13 @@ def override_manifest(manifest: ComponentManifestOverride) -> None:
async def to_code(config):
await original_to_code(config)
cg.add_define("USE_LIGHT_GAMMA_LUT")
# Use the light component's own generate_gamma_table() so the
# Use the light component's own gamma_table_initializer() so the
# benchmark stays in sync with any formula changes.
forward = generate_gamma_table(2.8)
values = ", ".join(f"0x{int(v):04X}" for v in forward)
# Use extern-visible (non-static) array so the benchmark .cpp
# can reference it via extern declaration.
# Extern-visible (non-static) so the benchmark .cpp can reference it.
cg.add_global(
cg.RawStatement(
f"extern const uint16_t bench_gamma_2_8_fwd[256] PROGMEM = {{{values}}};"
"extern const esphome::light::GammaTable bench_gamma_2_8 PROGMEM = "
f"{gamma_table_initializer(2.8)};"
)
)
@@ -4,8 +4,8 @@
#include "esphome/components/light/light_state.h"
// Gamma 2.8 forward LUT generated by the light component's Python codegen
// (see tests/benchmarks/components/light/__init__.py which calls generate_gamma_table())
extern const uint16_t bench_gamma_2_8_fwd[256];
// (see tests/benchmarks/components/light/__init__.py which calls gamma_table_initializer())
extern const esphome::light::GammaTable bench_gamma_2_8;
namespace esphome::benchmarks {
@@ -37,8 +37,7 @@ static void setup_rgbww_light(BenchLightOutput &output, TestLightState &light) {
output.traits_.set_max_mireds(500.0f);
light.configure("test_light");
light.set_default_transition_length(0);
light.set_gamma_correct(2.8f);
light.set_gamma_table(bench_gamma_2_8_fwd);
light.set_gamma_table(&bench_gamma_2_8);
}
// --- LightCall::perform() with instant RGB color change (Home Assistant API path) ---