Compare commits

..

11 Commits

Author SHA1 Message Date
Clyde Stubbs
512ac3b8f3 Merge branch 'dev' into copilot/fix-dropdown-symbol-display 2026-01-21 11:14:07 +11:00
clydebarrow
65bd976aea Merge branch 'copilot/fix-dropdown-symbol-display' of https://github.com/esphome/esphome into copilot/fix-dropdown-symbol-display 2026-01-21 09:49:08 +11:00
clydebarrow
66776984d3 Fix import 2026-01-21 09:48:17 +11:00
clydebarrow
cf2e196d8d Merge branch 'dev' of https://github.com/esphome/esphome into copilot/fix-dropdown-symbol-display 2026-01-21 09:44:09 +11:00
pre-commit-ci-lite[bot]
bb05273772 [pre-commit.ci lite] apply automatic fixes 2026-01-20 22:44:08 +00:00
Clyde Stubbs
bef2b63deb Fix string handling 2026-01-21 09:42:27 +11:00
copilot-swe-agent[bot]
777456a5b4 Simplify dropdown symbol validator per feedback - remove LValidator wrapper
Co-authored-by: clydebarrow <2366188+clydebarrow@users.noreply.github.com>
2026-01-20 20:39:27 +00:00
copilot-swe-agent[bot]
35afdc015b Address final review feedback: clarify len() behavior and use constant
Co-authored-by: clydebarrow <2366188+clydebarrow@users.noreply.github.com>
2026-01-20 20:31:33 +00:00
copilot-swe-agent[bot]
7e90ea06f5 Address code review feedback: extract magic value to constant
Co-authored-by: clydebarrow <2366188+clydebarrow@users.noreply.github.com>
2026-01-20 20:29:30 +00:00
copilot-swe-agent[bot]
b24ae3bc93 Add validation for LVGL dropdown symbol requiring Unicode >= 0x100
Co-authored-by: clydebarrow <2366188+clydebarrow@users.noreply.github.com>
2026-01-20 20:27:40 +00:00
copilot-swe-agent[bot]
8b9868111f Initial plan 2026-01-20 20:20:28 +00:00

View File

@@ -1,3 +1,4 @@
from esphome import codegen as cg
import esphome.config_validation as cv
from esphome.const import CONF_OPTIONS
@@ -24,6 +25,34 @@ from .label import CONF_LABEL
CONF_DROPDOWN = "dropdown"
CONF_DROPDOWN_LIST = "dropdown_list"
# Example valid dropdown symbol (left arrow) for error messages
EXAMPLE_DROPDOWN_SYMBOL = "\U00002190" # ←
def dropdown_symbol_validator(value):
"""
Validate that the dropdown symbol is a single Unicode character
with a codepoint of 0x100 (256) or greater.
This is required because LVGL uses codepoints below 0x100 for internal symbols.
"""
value = cv.string(value)
# len(value) counts Unicode code points, not grapheme clusters or bytes
if len(value) != 1:
raise cv.Invalid(
f"Dropdown symbol must be a single character, got '{value}' with length {len(value)}"
)
codepoint = ord(value)
if codepoint < 0x100:
# Format the example symbol as a Unicode escape for the error message
example_escape = f"\\U{ord(EXAMPLE_DROPDOWN_SYMBOL):08X}"
raise cv.Invalid(
f"Dropdown symbol must have a Unicode codepoint of 0x100 (256) or greater. "
f"'{value}' has codepoint {codepoint} (0x{codepoint:X}). "
f"Use a character like '{example_escape}' ({EXAMPLE_DROPDOWN_SYMBOL}) or other Unicode symbols with codepoint >= 0x100."
)
return value
lv_dropdown_t = LvSelect("LvDropdownType", parents=(LvCompound,))
lv_dropdown_list_t = LvType("lv_dropdown_list_t")
@@ -33,7 +62,7 @@ dropdown_list_spec = WidgetType(
DROPDOWN_BASE_SCHEMA = cv.Schema(
{
cv.Optional(CONF_SYMBOL): lv_text,
cv.Optional(CONF_SYMBOL): dropdown_symbol_validator,
cv.Exclusive(CONF_SELECTED_INDEX, CONF_SELECTED_TEXT): lv_int,
cv.Exclusive(CONF_SELECTED_TEXT, CONF_SELECTED_TEXT): lv_text,
cv.Optional(CONF_DROPDOWN_LIST): part_schema(dropdown_list_spec.parts),
@@ -70,7 +99,7 @@ class DropdownType(WidgetType):
if options := config.get(CONF_OPTIONS):
lv_add(w.var.set_options(options))
if symbol := config.get(CONF_SYMBOL):
lv.dropdown_set_symbol(w.var.obj, await lv_text.process(symbol))
lv.dropdown_set_symbol(w.var.obj, cg.safe_exp(symbol))
if (selected := config.get(CONF_SELECTED_INDEX)) is not None:
value = await lv_int.process(selected)
lv_add(w.var.set_selected_index(value, literal("LV_ANIM_OFF")))