"""Runtime tile configuration transported through the normal ESPHome API. `smart_display: language: nl` (app 0.2.90) builds the screen's texts in that language: the `screen` section of screen_manager/translations/nl.json, with English for any key it lacks, becomes one table in main.cpp (screen_text_gen.py, screen_text.h). The shared core sets it from the LANGUAGE substitution, which ESP Screens writes into a screen's YAML. `smart_display: partitions: 4mb_wide_slots` (firmware 0.2.79) builds with one of the partition tables of partitions.py instead of ESPHome's own: two update slots of 1,984 KB on a 4 MB ESP32-S3, which the Elecrow CrowPanel 7.0" needs. """ import logging import esphome.codegen as cg from esphome.components import esp32 import esphome.config_validation as cv from esphome.core import CORE from esphome.helpers import write_file_if_changed from . import partitions, screen_text_gen CODEOWNERS = [] AUTO_LOAD = ["json"] _LOGGER = logging.getLogger(__name__) CONF_LANGUAGE = "language" CONF_PARTITIONS = "partitions" def _language(value): value = cv.string_strict(value).strip() if not screen_text_gen.LANGUAGE_CODE.fullmatch(value): raise cv.Invalid("Expected a language code such as en, nl or pt-BR") return value CONFIG_SCHEMA = cv.Schema({ cv.Optional(CONF_LANGUAGE, default="en"): _language, cv.Optional(CONF_PARTITIONS): cv.one_of(*partitions.TABLES, lower=True), }) async def to_code(config): wanted = config[CONF_LANGUAGE] language, code = screen_text_gen.definitions(wanted) if language != wanted: # ESP Screens only writes languages it has; a hand-written one it lacks builds in the nearest it does have. _LOGGER.warning("No translation for %s yet; the screen's texts are in %s", wanted, language) cg.add_global(cg.RawStatement(code)) if CONF_PARTITIONS in config: # ESPHome writes no partitions.csv of its own when one is among the extra build files (esp32.copy_files). table = CORE.relative_build_path("smart_display_partitions.csv") write_file_if_changed(table, partitions.TABLES[config[CONF_PARTITIONS]]) esp32.add_extra_build_file("partitions.csv", table)