mirror of
https://github.com/esphome/esphome.git
synced 2025-04-16 07:40:29 +01:00
[lvgl] Ensure captured lambdas are in correct order (#8560)
This commit is contained in:
parent
6ca72a3a26
commit
2bb86641f8
@ -4,6 +4,7 @@ from esphome import automation
|
|||||||
import esphome.codegen as cg
|
import esphome.codegen as cg
|
||||||
import esphome.config_validation as cv
|
import esphome.config_validation as cv
|
||||||
from esphome.const import CONF_ACTION, CONF_GROUP, CONF_ID, CONF_TIMEOUT
|
from esphome.const import CONF_ACTION, CONF_GROUP, CONF_ID, CONF_TIMEOUT
|
||||||
|
from esphome.core import Lambda
|
||||||
from esphome.cpp_generator import TemplateArguments, get_variable
|
from esphome.cpp_generator import TemplateArguments, get_variable
|
||||||
from esphome.cpp_types import nullptr
|
from esphome.cpp_types import nullptr
|
||||||
|
|
||||||
@ -64,7 +65,14 @@ async def action_to_code(
|
|||||||
action_id,
|
action_id,
|
||||||
template_arg,
|
template_arg,
|
||||||
args,
|
args,
|
||||||
|
config=None,
|
||||||
):
|
):
|
||||||
|
# Ensure all required ids have been processed, so our LambdaContext doesn't get context-switched.
|
||||||
|
if config:
|
||||||
|
for lamb in config.values():
|
||||||
|
if isinstance(lamb, Lambda):
|
||||||
|
for id_ in lamb.requires_ids:
|
||||||
|
await get_variable(id_)
|
||||||
await wait_for_widgets()
|
await wait_for_widgets()
|
||||||
async with LambdaContext(parameters=args, where=action_id) as context:
|
async with LambdaContext(parameters=args, where=action_id) as context:
|
||||||
for widget in widgets:
|
for widget in widgets:
|
||||||
@ -84,7 +92,9 @@ async def update_to_code(config, action_id, template_arg, args):
|
|||||||
lv.event_send(widget.obj, UPDATE_EVENT, nullptr)
|
lv.event_send(widget.obj, UPDATE_EVENT, nullptr)
|
||||||
|
|
||||||
widgets = await get_widgets(config[CONF_ID])
|
widgets = await get_widgets(config[CONF_ID])
|
||||||
return await action_to_code(widgets, do_update, action_id, template_arg, args)
|
return await action_to_code(
|
||||||
|
widgets, do_update, action_id, template_arg, args, config
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@automation.register_condition(
|
@automation.register_condition(
|
||||||
@ -348,4 +358,6 @@ async def obj_update_to_code(config, action_id, template_arg, args):
|
|||||||
await set_obj_properties(widget, config)
|
await set_obj_properties(widget, config)
|
||||||
|
|
||||||
widgets = await get_widgets(config[CONF_ID])
|
widgets = await get_widgets(config[CONF_ID])
|
||||||
return await action_to_code(widgets, do_update, action_id, template_arg, args)
|
return await action_to_code(
|
||||||
|
widgets, do_update, action_id, template_arg, args, config
|
||||||
|
)
|
||||||
|
@ -250,7 +250,7 @@ async def button_update_to_code(config, action_id, template_arg, args):
|
|||||||
widgets = await get_widgets(config[CONF_ID])
|
widgets = await get_widgets(config[CONF_ID])
|
||||||
assert all(isinstance(w, MatrixButton) for w in widgets)
|
assert all(isinstance(w, MatrixButton) for w in widgets)
|
||||||
|
|
||||||
async def do_button_update(w: MatrixButton):
|
async def do_button_update(w):
|
||||||
if (width := config.get(CONF_WIDTH)) is not None:
|
if (width := config.get(CONF_WIDTH)) is not None:
|
||||||
lv.btnmatrix_set_btn_width(w.obj, w.index, width)
|
lv.btnmatrix_set_btn_width(w.obj, w.index, width)
|
||||||
if config.get(CONF_SELECTED):
|
if config.get(CONF_SELECTED):
|
||||||
@ -275,5 +275,5 @@ async def button_update_to_code(config, action_id, template_arg, args):
|
|||||||
)
|
)
|
||||||
|
|
||||||
return await action_to_code(
|
return await action_to_code(
|
||||||
widgets, do_button_update, action_id, template_arg, args
|
widgets, do_button_update, action_id, template_arg, args, config
|
||||||
)
|
)
|
||||||
|
@ -97,7 +97,7 @@ async def canvas_fill(config, action_id, template_arg, args):
|
|||||||
async def do_fill(w: Widget):
|
async def do_fill(w: Widget):
|
||||||
lv.canvas_fill_bg(w.obj, color, opa)
|
lv.canvas_fill_bg(w.obj, color, opa)
|
||||||
|
|
||||||
return await action_to_code(widget, do_fill, action_id, template_arg, args)
|
return await action_to_code(widget, do_fill, action_id, template_arg, args, config)
|
||||||
|
|
||||||
|
|
||||||
@automation.register_action(
|
@automation.register_action(
|
||||||
@ -145,7 +145,9 @@ async def canvas_set_pixel(config, action_id, template_arg, args):
|
|||||||
x, y = point
|
x, y = point
|
||||||
lv.canvas_set_px_opa(w.obj, x, y, opa_var)
|
lv.canvas_set_px_opa(w.obj, x, y, opa_var)
|
||||||
|
|
||||||
return await action_to_code(widget, do_set_pixels, action_id, template_arg, args)
|
return await action_to_code(
|
||||||
|
widget, do_set_pixels, action_id, template_arg, args, config
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
DRAW_SCHEMA = cv.Schema(
|
DRAW_SCHEMA = cv.Schema(
|
||||||
@ -181,7 +183,9 @@ async def draw_to_code(config, dsc_type, props, do_draw, action_id, template_arg
|
|||||||
lv_assign(getattr(dsc, mapped_prop), value)
|
lv_assign(getattr(dsc, mapped_prop), value)
|
||||||
await do_draw(w, x, y, dsc_addr)
|
await do_draw(w, x, y, dsc_addr)
|
||||||
|
|
||||||
return await action_to_code(widget, action_func, action_id, template_arg, args)
|
return await action_to_code(
|
||||||
|
widget, action_func, action_id, template_arg, args, config
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
RECT_PROPS = {
|
RECT_PROPS = {
|
||||||
|
@ -297,7 +297,9 @@ async def indicator_update_to_code(config, action_id, template_arg, args):
|
|||||||
async def set_value(w: Widget):
|
async def set_value(w: Widget):
|
||||||
await set_indicator_values(w.var, w.obj, config)
|
await set_indicator_values(w.var, w.obj, config)
|
||||||
|
|
||||||
return await action_to_code(widget, set_value, action_id, template_arg, args)
|
return await action_to_code(
|
||||||
|
widget, set_value, action_id, template_arg, args, config
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
async def set_indicator_values(meter, indicator, config):
|
async def set_indicator_values(meter, indicator, config):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user