mirror of
https://github.com/esphome/esphome.git
synced 2025-09-06 21:32:21 +01:00
[lvgl] Add initial_focus for encoders (#7256)
This commit is contained in:
@@ -14,11 +14,19 @@ from esphome.const import (
|
||||
from esphome.core import TimePeriod
|
||||
from esphome.schema_extractors import SCHEMA_EXTRACT
|
||||
|
||||
from . import defines as df, lv_validation as lvalid, types as ty
|
||||
from . import defines as df, lv_validation as lvalid
|
||||
from .helpers import add_lv_use, requires_component, validate_printf
|
||||
from .lv_validation import lv_color, lv_font, lv_image
|
||||
from .lvcode import LvglComponent
|
||||
from .types import WidgetType, lv_group_t
|
||||
from .types import (
|
||||
LVEncoderListener,
|
||||
LvType,
|
||||
WidgetType,
|
||||
lv_group_t,
|
||||
lv_obj_t,
|
||||
lv_pseudo_button_t,
|
||||
lv_style_t,
|
||||
)
|
||||
|
||||
# this will be populated later, in __init__.py to avoid circular imports.
|
||||
WIDGET_TYPES: dict = {}
|
||||
@@ -46,7 +54,7 @@ TEXT_SCHEMA = cv.Schema(
|
||||
LIST_ACTION_SCHEMA = cv.ensure_list(
|
||||
cv.maybe_simple_value(
|
||||
{
|
||||
cv.Required(CONF_ID): cv.use_id(ty.lv_pseudo_button_t),
|
||||
cv.Required(CONF_ID): cv.use_id(lv_pseudo_button_t),
|
||||
},
|
||||
key=CONF_ID,
|
||||
)
|
||||
@@ -59,9 +67,10 @@ PRESS_TIME = cv.All(
|
||||
ENCODER_SCHEMA = cv.Schema(
|
||||
{
|
||||
cv.GenerateID(): cv.All(
|
||||
cv.declare_id(ty.LVEncoderListener), requires_component("binary_sensor")
|
||||
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_LONG_PRESS_TIME, default="400ms"): PRESS_TIME,
|
||||
cv.Optional(df.CONF_LONG_PRESS_REPEAT_TIME, default="100ms"): PRESS_TIME,
|
||||
}
|
||||
@@ -161,7 +170,7 @@ STYLE_REMAP = {
|
||||
# Complete object style schema
|
||||
STYLE_SCHEMA = cv.Schema({cv.Optional(k): v for k, v in STYLE_PROPS.items()}).extend(
|
||||
{
|
||||
cv.Optional(df.CONF_STYLES): cv.ensure_list(cv.use_id(ty.lv_style_t)),
|
||||
cv.Optional(df.CONF_STYLES): cv.ensure_list(cv.use_id(lv_style_t)),
|
||||
cv.Optional(df.CONF_SCROLLBAR_MODE): df.LvConstant(
|
||||
"LV_SCROLLBAR_MODE_", "OFF", "ON", "ACTIVE", "AUTO"
|
||||
).one_of,
|
||||
@@ -193,12 +202,12 @@ def part_schema(widget_type: WidgetType):
|
||||
)
|
||||
|
||||
|
||||
def automation_schema(typ: ty.LvType):
|
||||
def automation_schema(typ: LvType):
|
||||
if typ.has_on_value:
|
||||
events = df.LV_EVENT_TRIGGERS + (CONF_ON_VALUE,)
|
||||
else:
|
||||
events = df.LV_EVENT_TRIGGERS
|
||||
if isinstance(typ, ty.LvType):
|
||||
if isinstance(typ, LvType):
|
||||
template = Trigger.template(typ.get_arg_type())
|
||||
else:
|
||||
template = Trigger.template()
|
||||
@@ -261,7 +270,7 @@ LAYOUT_SCHEMAS = {}
|
||||
ALIGN_TO_SCHEMA = {
|
||||
cv.Optional(df.CONF_ALIGN_TO): cv.Schema(
|
||||
{
|
||||
cv.Required(CONF_ID): cv.use_id(ty.lv_obj_t),
|
||||
cv.Required(CONF_ID): cv.use_id(lv_obj_t),
|
||||
cv.Required(df.CONF_ALIGN): df.ALIGN_ALIGNMENTS.one_of,
|
||||
cv.Optional(df.CONF_X, default=0): lvalid.pixels_or_percent,
|
||||
cv.Optional(df.CONF_Y, default=0): lvalid.pixels_or_percent,
|
||||
|
Reference in New Issue
Block a user