1
0
mirror of https://github.com/esphome/esphome.git synced 2025-01-18 12:05:41 +00:00

[lgvl] disp_bg_image and disp_bg_opa changes (#8025)

This commit is contained in:
Clyde Stubbs 2025-01-13 05:46:17 +11:00 committed by GitHub
parent 8a98b69a57
commit 0df6a913b3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 21 additions and 6 deletions

View File

@ -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(

View File

@ -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"

View File

@ -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,
}
)

View File

@ -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"