mirror of
https://github.com/esphome/esphome.git
synced 2024-11-28 09:44:12 +01:00
[lvgl] Fix id config for the lvgl component (Bugfix) (#7731)
Co-authored-by: clydeps <U5yx99dok9>
This commit is contained in:
parent
c0658ffe2c
commit
d189cc1fbe
1 changed files with 25 additions and 27 deletions
|
@ -1,5 +1,4 @@
|
|||
from collections.abc import Awaitable
|
||||
from typing import Callable
|
||||
from typing import Any, Callable
|
||||
|
||||
from esphome import automation
|
||||
import esphome.codegen as cg
|
||||
|
@ -23,7 +22,6 @@ from .lvcode import (
|
|||
UPDATE_EVENT,
|
||||
LambdaContext,
|
||||
LocalVariable,
|
||||
LvglComponent,
|
||||
ReturnStatement,
|
||||
add_line_marks,
|
||||
lv,
|
||||
|
@ -58,7 +56,7 @@ focused_widgets = set()
|
|||
|
||||
async def action_to_code(
|
||||
widgets: list[Widget],
|
||||
action: Callable[[Widget], Awaitable[None]],
|
||||
action: Callable[[Widget], Any],
|
||||
action_id,
|
||||
template_arg,
|
||||
args,
|
||||
|
@ -159,14 +157,12 @@ async def obj_invalidate_to_code(config, action_id, template_arg, args):
|
|||
@automation.register_action(
|
||||
"lvgl.update",
|
||||
LvglAction,
|
||||
DISP_BG_SCHEMA.extend(
|
||||
{
|
||||
cv.GenerateID(): cv.use_id(LvglComponent),
|
||||
}
|
||||
).add_extra(cv.has_at_least_one_key(CONF_DISP_BG_COLOR, CONF_DISP_BG_IMAGE)),
|
||||
DISP_BG_SCHEMA.extend(LVGL_SCHEMA).add_extra(
|
||||
cv.has_at_least_one_key(CONF_DISP_BG_COLOR, CONF_DISP_BG_IMAGE)
|
||||
),
|
||||
)
|
||||
async def lvgl_update_to_code(config, action_id, template_arg, args):
|
||||
widgets = await get_widgets(config)
|
||||
widgets = await get_widgets(config, CONF_LVGL_ID)
|
||||
w = widgets[0]
|
||||
disp = literal(f"{w.obj}->get_disp()")
|
||||
async with LambdaContext(LVGL_COMP_ARG, where=action_id) as context:
|
||||
|
@ -179,32 +175,33 @@ async def lvgl_update_to_code(config, action_id, template_arg, args):
|
|||
@automation.register_action(
|
||||
"lvgl.pause",
|
||||
LvglAction,
|
||||
LVGL_SCHEMA.extend(
|
||||
{
|
||||
cv.GenerateID(): cv.use_id(LvglComponent),
|
||||
cv.Optional(CONF_SHOW_SNOW, default=False): lv_bool,
|
||||
},
|
||||
}
|
||||
),
|
||||
)
|
||||
async def pause_action_to_code(config, action_id, template_arg, args):
|
||||
lv_comp = await cg.get_variable(config[CONF_LVGL_ID])
|
||||
async with LambdaContext(LVGL_COMP_ARG) as context:
|
||||
add_line_marks(where=action_id)
|
||||
lv_add(lvgl_comp.set_paused(True, config[CONF_SHOW_SNOW]))
|
||||
var = cg.new_Pvariable(action_id, template_arg, await context.get_lambda())
|
||||
await cg.register_parented(var, config[CONF_ID])
|
||||
await cg.register_parented(var, lv_comp)
|
||||
return var
|
||||
|
||||
|
||||
@automation.register_action(
|
||||
"lvgl.resume",
|
||||
LvglAction,
|
||||
{
|
||||
cv.GenerateID(): cv.use_id(LvglComponent),
|
||||
},
|
||||
LVGL_SCHEMA,
|
||||
)
|
||||
async def resume_action_to_code(config, action_id, template_arg, args):
|
||||
lv_comp = await cg.get_variable(config[CONF_LVGL_ID])
|
||||
async with LambdaContext(LVGL_COMP_ARG, where=action_id) as context:
|
||||
lv_add(lvgl_comp.set_paused(False, False))
|
||||
var = cg.new_Pvariable(action_id, template_arg, await context.get_lambda())
|
||||
await cg.register_parented(var, config[CONF_ID])
|
||||
await cg.register_parented(var, lv_comp)
|
||||
return var
|
||||
|
||||
|
||||
|
@ -263,14 +260,15 @@ def focused_id(value):
|
|||
ObjUpdateAction,
|
||||
cv.Any(
|
||||
cv.maybe_simple_value(
|
||||
LVGL_SCHEMA.extend(
|
||||
{
|
||||
cv.Optional(CONF_GROUP): cv.use_id(lv_group_t),
|
||||
cv.Required(CONF_ACTION): cv.one_of(
|
||||
"MARK", "RESTORE", "NEXT", "PREVIOUS", upper=True
|
||||
),
|
||||
cv.GenerateID(CONF_LVGL_ID): cv.use_id(LvglComponent),
|
||||
cv.Optional(CONF_FREEZE, default=False): cv.boolean,
|
||||
},
|
||||
}
|
||||
),
|
||||
key=CONF_ACTION,
|
||||
),
|
||||
cv.maybe_simple_value(
|
||||
|
|
Loading…
Reference in a new issue