Merge remote-tracking branch 'upstream/component-8byte-optimization' into integration

This commit is contained in:
J. Nick Koston
2026-03-29 08:36:03 -10:00
4 changed files with 46 additions and 4 deletions
+6
View File
@@ -348,6 +348,12 @@ uint8_t TM1637Display::print(uint8_t start_pos, const char *str) {
return pos - start_pos;
}
uint8_t TM1637Display::print(const char *str) { return this->print(0, str); }
void TM1637Display::set_buffer(const uint8_t *data, uint8_t length) {
uint8_t len = std::min(length, (uint8_t) sizeof(this->buffer_));
memcpy(this->buffer_, data, len);
}
uint8_t TM1637Display::printf(uint8_t pos, const char *format, ...) {
va_list arg;
va_start(arg, format);
+3
View File
@@ -47,6 +47,9 @@ class TM1637Display : public PollingComponent {
/// Print `str` at position 0.
uint8_t print(const char *str);
/// Set raw buffer bytes from data array up to length bytes.
void set_buffer(const uint8_t *data, uint8_t length);
void set_intensity(uint8_t intensity) { this->intensity_ = intensity; }
void set_inverted(bool inverted) { this->inverted_ = inverted; }
void set_length(uint8_t length) { this->length_ = length; }
+2
View File
@@ -5,3 +5,5 @@ display:
intensity: 3
lambda: |-
it.print("1234");
static const uint8_t buf[] = {0x3f, 0x06, 0x5b, 0x4f | 0x80};
it.set_buffer(buf, sizeof(buf));
+35 -4
View File
@@ -82,12 +82,14 @@ async def test_register_component__with_setup_priority(monkeypatch):
assert core_mock.component_ids == []
def test_register_component_source_empty_name(monkeypatch):
def test_register_component_source_empty_name(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr(ch, "CORE", Mock(data={}))
assert register_component_source("") == 0
def test_register_component_source_deduplicates(monkeypatch):
def test_register_component_source_deduplicates(
monkeypatch: pytest.MonkeyPatch,
) -> None:
monkeypatch.setattr(ch, "CORE", Mock(data={}))
idx1 = register_component_source("wifi")
idx2 = register_component_source("api")
@@ -97,13 +99,42 @@ def test_register_component_source_deduplicates(monkeypatch):
assert idx3 == 1 # deduplicated
def test_generate_source_table_code_empty():
def test_generate_source_table_code_empty() -> None:
from esphome.cpp_helpers import _generate_source_table_code
assert _generate_source_table_code("TBL", "lookup", {}) == ""
def test_register_component_source_overflow_warns(monkeypatch, caplog):
def test_generate_source_table_code_non_empty() -> None:
from esphome.cpp_helpers import _generate_source_table_code
code = _generate_source_table_code("TBL", "lookup", {"wifi": 1, "api": 2})
assert "PROGMEM" in code
assert "wifi" in code
assert "api" in code
assert "lookup" in code
assert "index == 0" in code
assert "progmem_read_ptr" in code
assert "index > 2" in code
@pytest.mark.asyncio
async def test_generate_component_source_table_empty_pool(
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""Test that _generate_component_source_table does nothing with an empty pool."""
from esphome.cpp_helpers import _generate_component_source_table
monkeypatch.setattr(ch, "CORE", Mock(data={}))
add_global_mock = Mock()
monkeypatch.setattr(ch, "add_global", add_global_mock)
await _generate_component_source_table()
add_global_mock.assert_not_called()
def test_register_component_source_overflow_warns(
monkeypatch: pytest.MonkeyPatch, caplog: pytest.LogCaptureFixture
) -> None:
# Pre-fill pool to max
pool = ComponentSourcePool(
sources={f"comp_{i}": i + 1 for i in range(0xFF)},