8000 [lvgl] add on_boot trigger by clydebarrow · Pull Request #8498 · esphome/esphome · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[lvgl] add on_boot trigger #8498

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion esphome/components/lvgl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
CONF_GROUP,
CONF_ID,
CONF_LAMBDA,
CONF_ON_BOOT,
CONF_ON_IDLE,
CONF_PAGES,
CONF_TIMEOUT,
Expand Down Expand Up @@ -50,7 +51,7 @@
)
from .styles import add_top_layer, styles_to_code, theme_to_code
from .touchscreens import touchscreen_schema, touchscreens_to_code
from .trigger import generate_triggers
from .trigger import add_on_boot_triggers, generate_triggers
from .types import (
FontEngine,
IdleTrigger,
Expand Down Expand Up @@ -365,6 +366,7 @@ async def to_code(configs):
conf[CONF_TRIGGER_ID], lv_component, False
)
await build_automation(resume_trigger, [], conf)
await add_on_boot_triggers(config.get(CONF_ON_BOOT, ()))

# This must be done after all widgets are created
for comp in helpers.lvgl_components_required:
Expand Down
28 changes: 20 additions & 8 deletions esphome/components/lvgl/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
CONF_FORMAT,
CONF_GROUP,
CONF_ID,
CONF_ON_BOOT,
CONF_ON_VALUE,
CONF_STATE,
CONF_TEXT,
Expand All @@ -14,6 +15,7 @@
CONF_TYPE,
)
from esphome.core import TimePeriod
from esphome.core.config import StartupTrigger
from esphome.schema_extractors import SCHEMA_EXTRACT

from . import defines as df, lv_validation as lvalid
Expand Down Expand Up @@ -216,14 +218,24 @@ def automation_schema(typ: LvType):
events = events + (CONF_ON_VALUE,)
args = typ.get_arg_type() if isinstance(typ, LvType) else []
args.append(lv_event_t_ptr)
return {
cv.Optional(event): validate_automation(
{
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(Trigger.template(*args)),
}
)
for event in events
}
return cv.Schema(
{
cv.Optional(event): validate_automation(
{
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(
Trigger.template(*args)
),
}
)
for event in events
}
).extend(
{
cv.Optional(CONF_ON_BOOT): validate_automation(
{cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(StartupTrigger)}
)
}
)


def base_update_schema(widget_type, parts):
Expand Down
11 changes: 10 additions & 1 deletion esphome/components/lvgl/trigger.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from esphome import automation
import esphome.codegen as cg
from esphome.const import CONF_ID, CONF_ON_VALUE, CONF_TRIGGER_ID
from esphome.const import CONF_ID, CONF_ON_BOOT, CONF_ON_VALUE, CONF_TRIGGER_ID

from .defines import (
CONF_ALIGN,
Expand Down Expand Up @@ -28,6 +28,13 @@
from .widgets import LvScrActType, get_scr_act, widget_map


async def add_on_boot_triggers(triggers):
for conf in triggers:
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], 390)
await cg.register_component(trigger, conf)
await automation.build_automation(trigger, [], conf)


async def generate_triggers():
"""
Generate LVGL triggers for all defined widgets
Expand Down Expand Up < 8000 /td> @@ -75,6 +82,8 @@ async def generate_triggers():
UPDATE_EVENT,
)

await add_on_boot_triggers(w.config.get(CONF_ON_BOOT, ()))

# Generate align to directives while we're here
if align_to := w.config.get(CONF_ALIGN_TO):
target = widget_map[align_to[CONF_ID]].obj
Expand Down
6 changes: 6 additions & 0 deletions tests/components/lvgl/lvgl-package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ lvgl:
logger.log: LVGL is Paused
on_resume:
logger.log: LVGL has resumed
on_boot:
logger.log: LVGL has started
bg_color: light_blue
disp_bg_color: color_id
disp_bg_image: cat_image
Expand Down Expand Up @@ -210,6 +212,10 @@ lvgl:
src: !lambda "return {dog_image, cat_image};"
duration: 2s
- label:
on_boot:
lvgl.label.update:
id: hello_label
text: Goodbye Cruel World
id: hello_label
text: Hello world
text_color: 0xFF8000
Expand Down
0