[mipi_spi] Run spi final validation (#15418)

Co-authored-by: Jonathan Swoboda <154711427+swoboda1337@users.noreply.github.com>
This commit is contained in:
Clyde Stubbs
2026-04-05 11:11:49 +10:00
committed by GitHub
parent 2d9a42e4ba
commit 4d2062282e
3 changed files with 19 additions and 4 deletions

View File

@@ -279,6 +279,10 @@ def _final_validate(config):
from esphome.components.lvgl import DOMAIN as LVGL_DOMAIN
if config[CONF_BUS_MODE] == TYPE_SINGLE:
spi.final_validate_device_schema(DOMAIN, require_miso=False, require_mosi=True)(
config
)
if not requires_buffer(config) and LVGL_DOMAIN not in global_config:
# If no drawing methods are configured, and LVGL is not enabled, show a test card
config[CONF_SHOW_TEST_CARD] = True
@@ -286,7 +290,7 @@ def _final_validate(config):
if PSRAM_DOMAIN not in global_config and CONF_BUFFER_SIZE not in config:
# If PSRAM is not enabled, choose a small buffer size by default
if not requires_buffer(config):
return config # No buffer needed, so no need to set a buffer size
return # No need to pick a size
color_depth = get_color_depth(config)
frac = denominator(config)
width, height, _offset_width, _offset_height = model.get_dimensions(config)
@@ -298,8 +302,6 @@ def _final_validate(config):
x for x in range(2, 17) if fraction >= 1 / x
)
return config
FINAL_VALIDATE_SCHEMA = _final_validate

View File

@@ -1,6 +1,7 @@
"""Tests for mpip_spi configuration validation."""
from collections.abc import Callable, Generator
from unittest import mock
import pytest
@@ -12,6 +13,16 @@ from esphome.core import CORE
from esphome.pins import gpio_pin_schema
@pytest.fixture(autouse=True)
def mock_spi_final_validate():
"""Mock spi.final_validate_device_schema since unit tests have no real SPI bus config."""
with mock.patch(
"esphome.components.spi.final_validate_device_schema",
return_value=lambda config: None,
):
yield
@pytest.fixture
def choose_variant_with_pins() -> Generator[Callable[[list], None]]:
"""

View File

@@ -25,7 +25,9 @@ from tests.component_tests.types import SetCoreConfigCallable
def validated_config(config):
"""Run schema + final validation and return the validated config."""
return FINAL_VALIDATE_SCHEMA(CONFIG_SCHEMA(config))
config = CONFIG_SCHEMA(config)
FINAL_VALIDATE_SCHEMA(config)
return config
def test_metadata_native_quad_default_test_card(