mirror of
https://github.com/esphome/esphome.git
synced 2025-04-14 06:40:32 +01:00
[lvgl] add on_boot trigger (#8498)
This commit is contained in:
parent
2291a1dc39
commit
1c72fd4674
@ -10,6 +10,7 @@ from esphome.const import (
|
||||
CONF_GROUP,
|
||||
CONF_ID,
|
||||
CONF_LAMBDA,
|
||||
CONF_ON_BOOT,
|
||||
CONF_ON_IDLE,
|
||||
CONF_PAGES,
|
||||
CONF_TIMEOUT,
|
||||
@ -50,7 +51,7 @@ from .schemas import (
|
||||
)
|
||||
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,
|
||||
@ -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:
|
||||
|
@ -6,6 +6,7 @@ from esphome.const import (
|
||||
CONF_FORMAT,
|
||||
CONF_GROUP,
|
||||
CONF_ID,
|
||||
CONF_ON_BOOT,
|
||||
CONF_ON_VALUE,
|
||||
CONF_STATE,
|
||||
CONF_TEXT,
|
||||
@ -14,6 +15,7 @@ from esphome.const import (
|
||||
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
|
||||
@ -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):
|
||||
|
@ -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,
|
||||
@ -28,6 +28,13 @@ from .types import LV_EVENT
|
||||
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
|
||||
@ -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
|
||||
|
@ -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
|
||||
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user