diff --git a/esphome/components/lvgl/lvgl_esphome.h b/esphome/components/lvgl/lvgl_esphome.h index 56413ad77e..8e89b02db9 100644 --- a/esphome/components/lvgl/lvgl_esphome.h +++ b/esphome/components/lvgl/lvgl_esphome.h @@ -59,6 +59,16 @@ inline void lv_img_set_src(lv_obj_t *obj, esphome::image::Image *image) { inline void lv_disp_set_bg_image(lv_disp_t *disp, esphome::image::Image *image) { lv_disp_set_bg_image(disp, image->get_lv_img_dsc()); } + +inline void lv_obj_set_style_bg_img_src(lv_obj_t *obj, esphome::image::Image *image, lv_style_selector_t selector) { + lv_obj_set_style_bg_img_src(obj, image->get_lv_img_dsc(), selector); +} +#ifdef USE_LVGL_METER +inline lv_meter_indicator_t *lv_meter_add_needle_img(lv_obj_t *obj, lv_meter_scale_t *scale, esphome::image::Image *src, + lv_coord_t pivot_x, lv_coord_t pivot_y) { + return lv_meter_add_needle_img(obj, scale, src->get_lv_img_dsc(), pivot_x, pivot_y); +} +#endif // USE_LVGL_METER #endif // USE_LVGL_IMAGE #ifdef USE_LVGL_ANIMIMG inline void lv_animimg_set_src(lv_obj_t *img, std::vector images) { diff --git a/esphome/components/lvgl/widgets/meter.py b/esphome/components/lvgl/widgets/meter.py index cd61d1c775..29a382f7cf 100644 --- a/esphome/components/lvgl/widgets/meter.py +++ b/esphome/components/lvgl/widgets/meter.py @@ -27,7 +27,7 @@ from ..defines import ( CONF_START_VALUE, CONF_TICKS, ) -from ..helpers import add_lv_use +from ..helpers import add_lv_use, lvgl_components_required from ..lv_validation import ( angle, get_end_value, @@ -182,6 +182,7 @@ class MeterType(WidgetType): async def to_code(self, w: Widget, config): """For a meter object, create and set parameters""" + lvgl_components_required.add(CONF_METER) var = w.obj for scale_conf in config.get(CONF_SCALES, ()): rotation = 90 + (360 - scale_conf[CONF_ANGLE_RANGE]) / 2 diff --git a/esphome/core/defines.h b/esphome/core/defines.h index eb3b20d007..c38a26c6a8 100644 --- a/esphome/core/defines.h +++ b/esphome/core/defines.h @@ -49,6 +49,7 @@ #define USE_LVGL_IMAGE #define USE_LVGL_KEY_LISTENER #define USE_LVGL_KEYBOARD +#define USE_LVGL_METER #define USE_LVGL_ROLLER #define USE_LVGL_ROTARY_ENCODER #define USE_LVGL_TOUCHSCREEN diff --git a/tests/components/lvgl/lvgl-package.yaml b/tests/components/lvgl/lvgl-package.yaml index b1b89adfe0..68f91884b2 100644 --- a/tests/components/lvgl/lvgl-package.yaml +++ b/tests/components/lvgl/lvgl-package.yaml @@ -132,6 +132,7 @@ lvgl: pages: - id: page1 + bg_image_src: cat_image on_load: - logger.log: page loaded - lvgl.widget.focus: