mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 07:03:55 +00:00 
			
		
		
		
	[lvgl] add on_boot trigger (#8498)
This commit is contained in:
		| @@ -10,6 +10,7 @@ from esphome.const import ( | |||||||
|     CONF_GROUP, |     CONF_GROUP, | ||||||
|     CONF_ID, |     CONF_ID, | ||||||
|     CONF_LAMBDA, |     CONF_LAMBDA, | ||||||
|  |     CONF_ON_BOOT, | ||||||
|     CONF_ON_IDLE, |     CONF_ON_IDLE, | ||||||
|     CONF_PAGES, |     CONF_PAGES, | ||||||
|     CONF_TIMEOUT, |     CONF_TIMEOUT, | ||||||
| @@ -50,7 +51,7 @@ from .schemas import ( | |||||||
| ) | ) | ||||||
| from .styles import add_top_layer, styles_to_code, theme_to_code | from .styles import add_top_layer, styles_to_code, theme_to_code | ||||||
| from .touchscreens import touchscreen_schema, touchscreens_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 ( | from .types import ( | ||||||
|     FontEngine, |     FontEngine, | ||||||
|     IdleTrigger, |     IdleTrigger, | ||||||
| @@ -365,6 +366,7 @@ async def to_code(configs): | |||||||
|                     conf[CONF_TRIGGER_ID], lv_component, False |                     conf[CONF_TRIGGER_ID], lv_component, False | ||||||
|                 ) |                 ) | ||||||
|                 await build_automation(resume_trigger, [], conf) |                 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 |     # This must be done after all widgets are created | ||||||
|     for comp in helpers.lvgl_components_required: |     for comp in helpers.lvgl_components_required: | ||||||
|   | |||||||
| @@ -6,6 +6,7 @@ from esphome.const import ( | |||||||
|     CONF_FORMAT, |     CONF_FORMAT, | ||||||
|     CONF_GROUP, |     CONF_GROUP, | ||||||
|     CONF_ID, |     CONF_ID, | ||||||
|  |     CONF_ON_BOOT, | ||||||
|     CONF_ON_VALUE, |     CONF_ON_VALUE, | ||||||
|     CONF_STATE, |     CONF_STATE, | ||||||
|     CONF_TEXT, |     CONF_TEXT, | ||||||
| @@ -14,6 +15,7 @@ from esphome.const import ( | |||||||
|     CONF_TYPE, |     CONF_TYPE, | ||||||
| ) | ) | ||||||
| from esphome.core import TimePeriod | from esphome.core import TimePeriod | ||||||
|  | from esphome.core.config import StartupTrigger | ||||||
| from esphome.schema_extractors import SCHEMA_EXTRACT | from esphome.schema_extractors import SCHEMA_EXTRACT | ||||||
|  |  | ||||||
| from . import defines as df, lv_validation as lvalid | from . import defines as df, lv_validation as lvalid | ||||||
| @@ -216,14 +218,24 @@ def automation_schema(typ: LvType): | |||||||
|         events = events + (CONF_ON_VALUE,) |         events = events + (CONF_ON_VALUE,) | ||||||
|     args = typ.get_arg_type() if isinstance(typ, LvType) else [] |     args = typ.get_arg_type() if isinstance(typ, LvType) else [] | ||||||
|     args.append(lv_event_t_ptr) |     args.append(lv_event_t_ptr) | ||||||
|     return { |     return cv.Schema( | ||||||
|  |         { | ||||||
|             cv.Optional(event): validate_automation( |             cv.Optional(event): validate_automation( | ||||||
|                 { |                 { | ||||||
|                 cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(Trigger.template(*args)), |                     cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id( | ||||||
|  |                         Trigger.template(*args) | ||||||
|  |                     ), | ||||||
|                 } |                 } | ||||||
|             ) |             ) | ||||||
|             for event in events |             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): | def base_update_schema(widget_type, parts): | ||||||
|   | |||||||
| @@ -1,6 +1,6 @@ | |||||||
| from esphome import automation | from esphome import automation | ||||||
| import esphome.codegen as cg | 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 ( | from .defines import ( | ||||||
|     CONF_ALIGN, |     CONF_ALIGN, | ||||||
| @@ -28,6 +28,13 @@ from .types import LV_EVENT | |||||||
| from .widgets import LvScrActType, get_scr_act, widget_map | 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(): | async def generate_triggers(): | ||||||
|     """ |     """ | ||||||
|     Generate LVGL triggers for all defined widgets |     Generate LVGL triggers for all defined widgets | ||||||
| @@ -75,6 +82,8 @@ async def generate_triggers(): | |||||||
|                     UPDATE_EVENT, |                     UPDATE_EVENT, | ||||||
|                 ) |                 ) | ||||||
|  |  | ||||||
|  |             await add_on_boot_triggers(w.config.get(CONF_ON_BOOT, ())) | ||||||
|  |  | ||||||
|             # Generate align to directives while we're here |             # Generate align to directives while we're here | ||||||
|             if align_to := w.config.get(CONF_ALIGN_TO): |             if align_to := w.config.get(CONF_ALIGN_TO): | ||||||
|                 target = widget_map[align_to[CONF_ID]].obj |                 target = widget_map[align_to[CONF_ID]].obj | ||||||
|   | |||||||
| @@ -24,6 +24,8 @@ lvgl: | |||||||
|     logger.log: LVGL is Paused |     logger.log: LVGL is Paused | ||||||
|   on_resume: |   on_resume: | ||||||
|     logger.log: LVGL has resumed |     logger.log: LVGL has resumed | ||||||
|  |   on_boot: | ||||||
|  |     logger.log: LVGL has started | ||||||
|   bg_color: light_blue |   bg_color: light_blue | ||||||
|   disp_bg_color: color_id |   disp_bg_color: color_id | ||||||
|   disp_bg_image: cat_image |   disp_bg_image: cat_image | ||||||
| @@ -210,6 +212,10 @@ lvgl: | |||||||
|                   src: !lambda "return {dog_image, cat_image};" |                   src: !lambda "return {dog_image, cat_image};" | ||||||
|                   duration: 2s |                   duration: 2s | ||||||
|         - label: |         - label: | ||||||
|  |             on_boot: | ||||||
|  |               lvgl.label.update: | ||||||
|  |                 id: hello_label | ||||||
|  |                 text: Goodbye Cruel World | ||||||
|             id: hello_label |             id: hello_label | ||||||
|             text: Hello world |             text: Hello world | ||||||
|             text_color: 0xFF8000 |             text_color: 0xFF8000 | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user