diff --git a/esphome/components/mipi/__init__.py b/esphome/components/mipi/__init__.py index a6cb8f31eb..387df10c32 100644 --- a/esphome/components/mipi/__init__.py +++ b/esphome/components/mipi/__init__.py @@ -234,6 +234,15 @@ class DriverChip: self.defaults = defaults DriverChip.models[name] = self + @classmethod + def get_models(cls): + """ + Return the current set of models and reset the models dictionary. + """ + models = cls.models + cls.models = {} + return models + def extend(self, name, **kwargs) -> "DriverChip": defaults = self.defaults.copy() if ( diff --git a/esphome/components/mipi_spi/display.py b/esphome/components/mipi_spi/display.py index d5c9d7aa0f..cb2de6c3d7 100644 --- a/esphome/components/mipi_spi/display.py +++ b/esphome/components/mipi_spi/display.py @@ -1,4 +1,6 @@ +import importlib import logging +import pkgutil from esphome import pins import esphome.codegen as cg @@ -52,8 +54,7 @@ from esphome.core import CORE from esphome.cpp_generator import TemplateArguments from esphome.final_validate import full_config -from . import CONF_BUS_MODE, CONF_SPI_16, DOMAIN -from .models import adafruit, amoled, cyd, ili, jc, lanbon, lilygo, waveshare +from . import CONF_BUS_MODE, CONF_SPI_16, DOMAIN, models DEPENDENCIES = ["spi"] @@ -91,10 +92,11 @@ BusTypes = { DriverChip("CUSTOM") -MODELS = DriverChip.models -# This loop is a noop, but suppresses linting of side-effect-only imports -for _ in (ili, jc, amoled, lilygo, lanbon, cyd, waveshare, adafruit): - pass +# Import all models dynamically from the models package +for module_info in pkgutil.iter_modules(models.__path__): + importlib.import_module(f".models.{module_info.name}", package=__package__) + +MODELS = DriverChip.get_models() DISPLAY_18BIT = "18bit"