1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-06 21:32:21 +01:00

[lvgl] Make line points templatable (#8502)

This commit is contained in:
Clyde Stubbs
2025-04-09 09:03:29 +10:00
committed by GitHub
parent 1c72fd4674
commit 6240bfff97
8 changed files with 80 additions and 38 deletions

View File

@@ -19,7 +19,7 @@ from esphome.core.config import StartupTrigger
from esphome.schema_extractors import SCHEMA_EXTRACT
from . import defines as df, lv_validation as lvalid
from .defines import CONF_TIME_FORMAT, LV_GRAD_DIR
from .defines import CONF_TIME_FORMAT, CONF_X, CONF_Y, LV_GRAD_DIR
from .helpers import add_lv_use, requires_component, validate_printf
from .lv_validation import lv_color, lv_font, lv_gradient, lv_image, opacity
from .lvcode import LvglComponent, lv_event_t_ptr
@@ -87,6 +87,33 @@ ENCODER_SCHEMA = cv.Schema(
}
)
def point_shorthand(value):
"""
A shorthand for a point in the form of x,y
:param value: The value to check
:return: The value as a tuple of x,y
"""
if isinstance(value, str):
try:
x, y = map(int, value.split(","))
return {CONF_X: x, CONF_Y: y}
except ValueError:
pass
raise cv.Invalid("Invalid point format, should be <x_value>, <y_value>")
POINT_SCHEMA = cv.Any(
cv.Schema(
{
cv.Required(CONF_X): cv.templatable(cv.int_),
cv.Required(CONF_Y): cv.templatable(cv.int_),
}
),
point_shorthand,
)
# All LVGL styles and their validators
STYLE_PROPS = {
"align": df.CHILD_ALIGNMENTS.one_of,