diff --git a/esphome/components/lvgl/automation.py b/esphome/components/lvgl/automation.py index c26ae54892..a987cf4097 100644 --- a/esphome/components/lvgl/automation.py +++ b/esphome/components/lvgl/automation.py @@ -10,13 +10,14 @@ from esphome.cpp_types import nullptr from .defines import ( CONF_DISP_BG_COLOR, CONF_DISP_BG_IMAGE, + CONF_DISP_BG_OPA, CONF_EDITING, CONF_FREEZE, CONF_LVGL_ID, CONF_SHOW_SNOW, literal, ) -from .lv_validation import lv_bool, lv_color, lv_image +from .lv_validation import lv_bool, lv_color, lv_image, opacity from .lvcode import ( LVGL_COMP_ARG, UPDATE_EVENT, @@ -119,13 +120,22 @@ async def lvgl_is_idle(config, condition_id, template_arg, args): async def disp_update(disp, config: dict): - if CONF_DISP_BG_COLOR not in config and CONF_DISP_BG_IMAGE not in config: + if ( + CONF_DISP_BG_COLOR not in config + and CONF_DISP_BG_IMAGE not in config + and CONF_DISP_BG_OPA not in config + ): return with LocalVariable("lv_disp_tmp", lv_disp_t, disp) as disp_temp: if (bg_color := config.get(CONF_DISP_BG_COLOR)) is not None: lv.disp_set_bg_color(disp_temp, await lv_color.process(bg_color)) if bg_image := config.get(CONF_DISP_BG_IMAGE): - lv.disp_set_bg_image(disp_temp, await lv_image.process(bg_image)) + if bg_image == "none": + lv.disp_set_bg_image(disp_temp, static_cast("void *", "nullptr")) + else: + lv.disp_set_bg_image(disp_temp, await lv_image.process(bg_image)) + if (bg_opa := config.get(CONF_DISP_BG_OPA)) is not None: + lv.disp_set_bg_opa(disp_temp, await opacity.process(bg_opa)) @automation.register_action( diff --git a/esphome/components/lvgl/defines.py b/esphome/components/lvgl/defines.py index 7587c336bb..733a6bc180 100644 --- a/esphome/components/lvgl/defines.py +++ b/esphome/components/lvgl/defines.py @@ -403,6 +403,7 @@ CONF_COLUMN = "column" CONF_DIGITS = "digits" CONF_DISP_BG_COLOR = "disp_bg_color" CONF_DISP_BG_IMAGE = "disp_bg_image" +CONF_DISP_BG_OPA = "disp_bg_opa" CONF_BODY = "body" CONF_BUTTONS = "buttons" CONF_BYTE_ORDER = "byte_order" diff --git a/esphome/components/lvgl/schemas.py b/esphome/components/lvgl/schemas.py index 3f56b3345f..271dbea19f 100644 --- a/esphome/components/lvgl/schemas.py +++ b/esphome/components/lvgl/schemas.py @@ -19,7 +19,7 @@ from esphome.schema_extractors import SCHEMA_EXTRACT from . import defines as df, lv_validation as lvalid from .defines import CONF_TIME_FORMAT, LV_GRAD_DIR from .helpers import add_lv_use, requires_component, validate_printf -from .lv_validation import lv_color, lv_font, lv_gradient, lv_image +from .lv_validation import lv_color, lv_font, lv_gradient, lv_image, opacity from .lvcode import LvglComponent, lv_event_t_ptr from .types import ( LVEncoderListener, @@ -344,8 +344,11 @@ FLEX_OBJ_SCHEMA = { DISP_BG_SCHEMA = cv.Schema( { - cv.Optional(df.CONF_DISP_BG_IMAGE): lv_image, + cv.Optional(df.CONF_DISP_BG_IMAGE): cv.Any( + cv.one_of("none", lower=True), lv_image + ), cv.Optional(df.CONF_DISP_BG_COLOR): lv_color, + cv.Optional(df.CONF_DISP_BG_OPA): opacity, } ) diff --git a/tests/components/lvgl/lvgl-package.yaml b/tests/components/lvgl/lvgl-package.yaml index 68f91884b2..512045d748 100644 --- a/tests/components/lvgl/lvgl-package.yaml +++ b/tests/components/lvgl/lvgl-package.yaml @@ -27,6 +27,7 @@ lvgl: bg_color: light_blue disp_bg_color: color_id disp_bg_image: cat_image + disp_bg_opa: cover theme: obj: border_width: 1 @@ -207,7 +208,7 @@ lvgl: - lvgl.animimg.stop: anim_img - lvgl.update: disp_bg_color: 0xffff00 - disp_bg_image: cat_image + disp_bg_image: none - lvgl.widget.show: message_box - label: text: "Hello shiny day"