1
0
mirror of https://github.com/esphome/esphome.git synced 2025-04-16 07:40:29 +01:00

[lvgl] Fix initial focus on roller (#8547)

This commit is contained in:
Clyde Stubbs 2025-04-14 08:41:42 +10:00 committed by Jesse Hills
parent fe51ee6257
commit 566968b6be
No known key found for this signature in database
GPG Key ID: BEAAE804EFD8E83A
3 changed files with 7 additions and 3 deletions

View File

@ -18,6 +18,7 @@ from .helpers import lvgl_components_required, requires_component
from .lvcode import lv, lv_add, lv_assign, lv_expr, lv_Pvariable
from .schemas import ENCODER_SCHEMA
from .types import lv_group_t, lv_indev_type_t, lv_key_t
from .widgets import get_widgets
ENCODERS_CONFIG = cv.ensure_list(
ENCODER_SCHEMA.extend(
@ -76,5 +77,5 @@ async def encoders_to_code(var, config, default_group):
async def initial_focus_to_code(config):
for enc_conf in config[CONF_ENCODERS]:
if default_focus := enc_conf.get(CONF_INITIAL_FOCUS):
obj = await cg.get_variable(default_focus)
lv.group_focus_obj(obj)
widget = await get_widgets(default_focus)
lv.group_focus_obj(widget[0].obj)

View File

@ -81,7 +81,9 @@ ENCODER_SCHEMA = cv.Schema(
cv.declare_id(LVEncoderListener), requires_component("binary_sensor")
),
cv.Optional(CONF_GROUP): cv.declare_id(lv_group_t),
cv.Optional(df.CONF_INITIAL_FOCUS): cv.use_id(lv_obj_t),
cv.Optional(df.CONF_INITIAL_FOCUS): cv.All(
LIST_ACTION_SCHEMA, cv.Length(min=1, max=1)
),
cv.Optional(df.CONF_LONG_PRESS_TIME, default="400ms"): PRESS_TIME,
cv.Optional(df.CONF_LONG_PRESS_REPEAT_TIME, default="100ms"): PRESS_TIME,
}

View File

@ -71,5 +71,6 @@ lvgl:
sensor: encoder
enter_button: pushbutton
group: general
initial_focus: lv_roller
<<: !include common.yaml