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 Any, Callable
|
||||||
from typing import Callable
|
|
||||||
|
|
||||||
from esphome import automation
|
from esphome import automation
|
||||||
import esphome.codegen as cg
|
import esphome.codegen as cg
|
||||||
|
@ -23,7 +22,6 @@ from .lvcode import (
|
||||||
UPDATE_EVENT,
|
UPDATE_EVENT,
|
||||||
LambdaContext,
|
LambdaContext,
|
||||||
LocalVariable,
|
LocalVariable,
|
||||||
LvglComponent,
|
|
||||||
ReturnStatement,
|
ReturnStatement,
|
||||||
add_line_marks,
|
add_line_marks,
|
||||||
lv,
|
lv,
|
||||||
|
@ -58,7 +56,7 @@ focused_widgets = set()
|
||||||
|
|
||||||
async def action_to_code(
|
async def action_to_code(
|
||||||
widgets: list[Widget],
|
widgets: list[Widget],
|
||||||
action: Callable[[Widget], Awaitable[None]],
|
action: Callable[[Widget], Any],
|
||||||
action_id,
|
action_id,
|
||||||
template_arg,
|
template_arg,
|
||||||
args,
|
args,
|
||||||
|
@ -159,14 +157,12 @@ async def obj_invalidate_to_code(config, action_id, template_arg, args):
|
||||||
@automation.register_action(
|
@automation.register_action(
|
||||||
"lvgl.update",
|
"lvgl.update",
|
||||||
LvglAction,
|
LvglAction,
|
||||||
DISP_BG_SCHEMA.extend(
|
DISP_BG_SCHEMA.extend(LVGL_SCHEMA).add_extra(
|
||||||
{
|
cv.has_at_least_one_key(CONF_DISP_BG_COLOR, CONF_DISP_BG_IMAGE)
|
||||||
cv.GenerateID(): cv.use_id(LvglComponent),
|
),
|
||||||
}
|
|
||||||
).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):
|
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]
|
w = widgets[0]
|
||||||
disp = literal(f"{w.obj}->get_disp()")
|
disp = literal(f"{w.obj}->get_disp()")
|
||||||
async with LambdaContext(LVGL_COMP_ARG, where=action_id) as context:
|
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(
|
@automation.register_action(
|
||||||
"lvgl.pause",
|
"lvgl.pause",
|
||||||
LvglAction,
|
LvglAction,
|
||||||
{
|
LVGL_SCHEMA.extend(
|
||||||
cv.GenerateID(): cv.use_id(LvglComponent),
|
{
|
||||||
cv.Optional(CONF_SHOW_SNOW, default=False): lv_bool,
|
cv.Optional(CONF_SHOW_SNOW, default=False): lv_bool,
|
||||||
},
|
}
|
||||||
|
),
|
||||||
)
|
)
|
||||||
async def pause_action_to_code(config, action_id, template_arg, args):
|
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:
|
async with LambdaContext(LVGL_COMP_ARG) as context:
|
||||||
add_line_marks(where=action_id)
|
add_line_marks(where=action_id)
|
||||||
lv_add(lvgl_comp.set_paused(True, config[CONF_SHOW_SNOW]))
|
lv_add(lvgl_comp.set_paused(True, config[CONF_SHOW_SNOW]))
|
||||||
var = cg.new_Pvariable(action_id, template_arg, await context.get_lambda())
|
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
|
return var
|
||||||
|
|
||||||
|
|
||||||
@automation.register_action(
|
@automation.register_action(
|
||||||
"lvgl.resume",
|
"lvgl.resume",
|
||||||
LvglAction,
|
LvglAction,
|
||||||
{
|
LVGL_SCHEMA,
|
||||||
cv.GenerateID(): cv.use_id(LvglComponent),
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
async def resume_action_to_code(config, action_id, template_arg, args):
|
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:
|
async with LambdaContext(LVGL_COMP_ARG, where=action_id) as context:
|
||||||
lv_add(lvgl_comp.set_paused(False, False))
|
lv_add(lvgl_comp.set_paused(False, False))
|
||||||
var = cg.new_Pvariable(action_id, template_arg, await context.get_lambda())
|
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
|
return var
|
||||||
|
|
||||||
|
|
||||||
|
@ -263,14 +260,15 @@ def focused_id(value):
|
||||||
ObjUpdateAction,
|
ObjUpdateAction,
|
||||||
cv.Any(
|
cv.Any(
|
||||||
cv.maybe_simple_value(
|
cv.maybe_simple_value(
|
||||||
{
|
LVGL_SCHEMA.extend(
|
||||||
cv.Optional(CONF_GROUP): cv.use_id(lv_group_t),
|
{
|
||||||
cv.Required(CONF_ACTION): cv.one_of(
|
cv.Optional(CONF_GROUP): cv.use_id(lv_group_t),
|
||||||
"MARK", "RESTORE", "NEXT", "PREVIOUS", upper=True
|
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,
|
cv.Optional(CONF_FREEZE, default=False): cv.boolean,
|
||||||
},
|
}
|
||||||
|
),
|
||||||
key=CONF_ACTION,
|
key=CONF_ACTION,
|
||||||
),
|
),
|
||||||
cv.maybe_simple_value(
|
cv.maybe_simple_value(
|
||||||
|
|
Loading…
Reference in a new issue