Skip to content

Commit

Permalink
Add default "forever" for animimg repeat count;
Browse files Browse the repository at this point in the history
add lvgl.animimg.stop action.
Require duration.
  • Loading branch information
clydebarrow committed Mar 12, 2024
1 parent 9373afb commit 1b570fe
Showing 1 changed file with 32 additions and 8 deletions.
40 changes: 32 additions & 8 deletions esphome/components/lvgl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
CONF_ON_VALUE,
CONF_ARGS,
CONF_FORMAT,
CONF_DURATION,
)
from esphome.cpp_generator import (
LambdaExpression,
Expand Down Expand Up @@ -244,7 +245,6 @@
CONF_DEFAULT_FONT = "default_font"
CONF_DIR = "dir"
CONF_DISPLAY_ID = "display_id"
CONF_DURATION = "duration"
CONF_DISPLAYS = "displays"
CONF_END_ANGLE = "end_angle"
CONF_END_VALUE = "end_value"
Expand Down Expand Up @@ -676,19 +676,25 @@ def validate_printf(value):

LINE_SCHEMA = {cv.Optional(CONF_POINTS): cv_point_list}


def lv_repeat_count(value):
if isinstance(value, str) and value.lower() in ("forever", "infinite"):
value = 0xFFFF
return cv.positive_int(value)


ANIMIMG_SCHEMA = {
cv.Required(CONF_SRC): cv.ensure_list(cv.use_id(Image_)),
cv.Optional(CONF_DURATION): cv.positive_time_period_milliseconds,
cv.Optional(CONF_REPEAT_COUNT): cv.positive_int,
cv.Required(CONF_DURATION): cv.positive_time_period_milliseconds,
cv.Optional(CONF_REPEAT_COUNT, default="forever"): lv_repeat_count,
cv.Optional(CONF_AUTO_START, default=True): cv.boolean,
}

ANIMIMG_MODIFY_SCHEMA = {
cv.Optional(CONF_DURATION): cv.positive_time_period_milliseconds,
cv.Optional(CONF_REPEAT_COUNT): cv.positive_int,
cv.Optional(CONF_REPEAT_COUNT): lv_repeat_count,
}


IMG_SCHEMA = {
cv.Required(CONF_SRC): cv.use_id(Image_),
cv.Optional(CONF_PIVOT_X, default="50%"): lv_size,
Expand Down Expand Up @@ -1336,15 +1342,33 @@ async def animimg_start(config, action_id, template_arg, args):
return await action_to_code(init, action_id, widget, template_arg, args)


@automation.register_action(
"lvgl.animimg.stop",
ObjUpdateAction,
cv.maybe_simple_value(
{
cv.Required(CONF_ID): cv.use_id(lv_animimg_t),
},
key=CONF_ID,
),
)
async def animimg_stop(config, action_id, template_arg, args):
widget = await get_widget(config[CONF_ID])
init = widget.set_property(CONF_DURATION, 0)
init.append(f"lv_animimg_start({widget.obj})")
return await action_to_code(init, action_id, widget, template_arg, args)


@automation.register_action(
"lvgl.animimg.update",
ObjUpdateAction,
modify_schema(CONF_ANIMIMG),
)
async def animimg_update_to_code(config, action_id, template_arg, args):
obj = await get_widget(config[CONF_ID])
init = await animimg_to_code(obj, config)
return await update_to_code(config, action_id, obj, init, template_arg, args)
widget = await get_widget(config[CONF_ID])
init = await animimg_to_code(widget, config)
init.append(f"lv_animimg_start({widget.obj})")
return await update_to_code(config, action_id, widget, init, template_arg, args)


@automation.register_action(
Expand Down

0 comments on commit 1b570fe

Please sign in to comment.