From 22c0e1079e83e7e28416b2bc612d5d98b96f9f9e Mon Sep 17 00:00:00 2001 From: Clyde Stubbs <2366188+clydebarrow@users.noreply.github.com> Date: Mon, 28 Apr 2025 10:23:18 +1000 Subject: [PATCH] [const] Create component-level const repository (#8385) --- CODEOWNERS | 1 + esphome/components/const/__init__.py | 5 +++ esphome/components/lvgl/__init__.py | 7 +-- esphome/components/lvgl/defines.py | 1 - esphome/components/qspi_dbi/__init__.py | 1 - esphome/components/qspi_dbi/display.py | 3 +- esphome/components/qspi_dbi/models.py | 3 +- tests/components/const/common.yaml | 44 +++++++++++++++++++ tests/components/const/test.esp32-s3-idf.yaml | 1 + 9 files changed, 58 insertions(+), 8 deletions(-) create mode 100644 esphome/components/const/__init__.py create mode 100644 tests/components/const/common.yaml create mode 100644 tests/components/const/test.esp32-s3-idf.yaml diff --git a/CODEOWNERS b/CODEOWNERS index d080563028..73973f420f 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -98,6 +98,7 @@ esphome/components/climate/* @esphome/core esphome/components/climate_ir/* @glmnet esphome/components/color_temperature/* @jesserockz esphome/components/combination/* @Cat-Ion @kahrendt +esphome/components/const/* @esphome/core esphome/components/coolix/* @glmnet esphome/components/copy/* @OttoWinter esphome/components/cover/* @esphome/core diff --git a/esphome/components/const/__init__.py b/esphome/components/const/__init__.py new file mode 100644 index 0000000000..6af357f23b --- /dev/null +++ b/esphome/components/const/__init__.py @@ -0,0 +1,5 @@ +"""Constants used by esphome components.""" + +CODEOWNERS = ["@esphome/core"] + +CONF_DRAW_ROUNDING = "draw_rounding" diff --git a/esphome/components/lvgl/__init__.py b/esphome/components/lvgl/__init__.py index 30fa58c380..69286ada88 100644 --- a/esphome/components/lvgl/__init__.py +++ b/esphome/components/lvgl/__init__.py @@ -2,6 +2,7 @@ import logging from esphome.automation import build_automation, register_action, validate_automation import esphome.codegen as cg +from esphome.components.const import CONF_DRAW_ROUNDING from esphome.components.display import Display import esphome.config_validation as cv from esphome.const import ( @@ -24,7 +25,7 @@ from esphome.helpers import write_file_if_changed from . import defines as df, helpers, lv_validation as lvalid from .automation import disp_update, focused_widgets, update_to_code -from .defines import CONF_DRAW_ROUNDING, add_define +from .defines import add_define from .encoders import ( ENCODERS_CONFIG, encoders_to_code, @@ -323,7 +324,7 @@ async def to_code(configs): displays, frac, config[df.CONF_FULL_REFRESH], - config[df.CONF_DRAW_ROUNDING], + config[CONF_DRAW_ROUNDING], config[df.CONF_RESUME_ON_INPUT], ) await cg.register_component(lv_component, config) @@ -413,7 +414,7 @@ LVGL_SCHEMA = cv.All( df.CONF_DEFAULT_FONT, default="montserrat_14" ): lvalid.lv_font, cv.Optional(df.CONF_FULL_REFRESH, default=False): cv.boolean, - cv.Optional(df.CONF_DRAW_ROUNDING, default=2): cv.positive_int, + cv.Optional(CONF_DRAW_ROUNDING, default=2): cv.positive_int, cv.Optional(CONF_BUFFER_SIZE, default="100%"): cv.percentage, cv.Optional(df.CONF_LOG_LEVEL, default="WARN"): cv.one_of( *df.LV_LOG_LEVELS, upper=True diff --git a/esphome/components/lvgl/defines.py b/esphome/components/lvgl/defines.py index 7dedb55418..7783fb2321 100644 --- a/esphome/components/lvgl/defines.py +++ b/esphome/components/lvgl/defines.py @@ -424,7 +424,6 @@ CONF_DEFAULT_FONT = "default_font" CONF_DEFAULT_GROUP = "default_group" CONF_DIR = "dir" CONF_DISPLAYS = "displays" -CONF_DRAW_ROUNDING = "draw_rounding" CONF_EDITING = "editing" CONF_ENCODERS = "encoders" CONF_END_ANGLE = "end_angle" diff --git a/esphome/components/qspi_dbi/__init__.py b/esphome/components/qspi_dbi/__init__.py index a4b833f6d7..290a864335 100644 --- a/esphome/components/qspi_dbi/__init__.py +++ b/esphome/components/qspi_dbi/__init__.py @@ -1,4 +1,3 @@ CODEOWNERS = ["@clydebarrow"] CONF_DRAW_FROM_ORIGIN = "draw_from_origin" -CONF_DRAW_ROUNDING = "draw_rounding" diff --git a/esphome/components/qspi_dbi/display.py b/esphome/components/qspi_dbi/display.py index 8c29991f37..5b01bcc6ca 100644 --- a/esphome/components/qspi_dbi/display.py +++ b/esphome/components/qspi_dbi/display.py @@ -1,6 +1,7 @@ from esphome import pins import esphome.codegen as cg from esphome.components import display, spi +from esphome.components.const import CONF_DRAW_ROUNDING import esphome.config_validation as cv from esphome.const import ( CONF_BRIGHTNESS, @@ -24,7 +25,7 @@ from esphome.const import ( ) from esphome.core import TimePeriod -from . import CONF_DRAW_FROM_ORIGIN, CONF_DRAW_ROUNDING +from . import CONF_DRAW_FROM_ORIGIN from .models import DriverChip DEPENDENCIES = ["spi"] diff --git a/esphome/components/qspi_dbi/models.py b/esphome/components/qspi_dbi/models.py index 7ae1a10ec0..8ce592e0cf 100644 --- a/esphome/components/qspi_dbi/models.py +++ b/esphome/components/qspi_dbi/models.py @@ -1,8 +1,7 @@ # Commands +from esphome.components.const import CONF_DRAW_ROUNDING from esphome.const import CONF_INVERT_COLORS, CONF_SWAP_XY -from . import CONF_DRAW_ROUNDING - SW_RESET_CMD = 0x01 SLEEP_IN = 0x10 SLEEP_OUT = 0x11 diff --git a/tests/components/const/common.yaml b/tests/components/const/common.yaml new file mode 100644 index 0000000000..655af304af --- /dev/null +++ b/tests/components/const/common.yaml @@ -0,0 +1,44 @@ +spi: + id: quad_spi + clk_pin: 15 + type: quad + data_pins: [14, 10, 16, 12] + +display: + - platform: qspi_dbi + model: RM690B0 + data_rate: 80MHz + spi_mode: mode0 + dimensions: + width: 450 + height: 600 + offset_width: 16 + color_order: rgb + invert_colors: false + brightness: 255 + cs_pin: 11 + reset_pin: 13 + enable_pin: 9 + + - platform: qspi_dbi + model: CUSTOM + id: main_lcd + draw_from_origin: true + dimensions: + height: 240 + width: 536 + transform: + mirror_x: true + swap_xy: true + color_order: rgb + brightness: 255 + cs_pin: 6 + reset_pin: 17 + enable_pin: 38 + init_sequence: + - [0x3A, 0x66] + - [0x11] + - delay 120ms + - [0x29] + - delay 20ms + diff --git a/tests/components/const/test.esp32-s3-idf.yaml b/tests/components/const/test.esp32-s3-idf.yaml new file mode 100644 index 0000000000..dade44d145 --- /dev/null +++ b/tests/components/const/test.esp32-s3-idf.yaml @@ -0,0 +1 @@ +<<: !include common.yaml