diff --git a/esphome/components/display/__init__.py b/esphome/components/display/__init__.py index 32a8b3b090..99224df7b3 100644 --- a/esphome/components/display/__init__.py +++ b/esphome/components/display/__init__.py @@ -39,6 +39,7 @@ DisplayOnPageChangeTrigger = display_ns.class_( CONF_ON_PAGE_CHANGE = "on_page_change" CONF_SHOW_TEST_CARD = "show_test_card" +CONF_UNSPECIFIED = "unspecified" DISPLAY_ROTATIONS = { 0: display_ns.DISPLAY_ROTATION_0_DEGREES, @@ -55,16 +56,22 @@ def validate_rotation(value): return cv.enum(DISPLAY_ROTATIONS, int=True)(value) +def validate_auto_clear(value): + if value == CONF_UNSPECIFIED: + return value + return cv.boolean(value) + + BASIC_DISPLAY_SCHEMA = cv.Schema( { - cv.Optional(CONF_LAMBDA): cv.lambda_, + cv.Exclusive(CONF_LAMBDA, CONF_LAMBDA): cv.lambda_, } ).extend(cv.polling_component_schema("1s")) FULL_DISPLAY_SCHEMA = BASIC_DISPLAY_SCHEMA.extend( { cv.Optional(CONF_ROTATION): validate_rotation, - cv.Optional(CONF_PAGES): cv.All( + cv.Exclusive(CONF_PAGES, CONF_LAMBDA): cv.All( cv.ensure_list( { cv.GenerateID(): cv.declare_id(DisplayPage), @@ -82,7 +89,9 @@ FULL_DISPLAY_SCHEMA = BASIC_DISPLAY_SCHEMA.extend( cv.Optional(CONF_TO): cv.use_id(DisplayPage), } ), - cv.Optional(CONF_AUTO_CLEAR_ENABLED, default=True): cv.boolean, + cv.Optional( + CONF_AUTO_CLEAR_ENABLED, default=CONF_UNSPECIFIED + ): validate_auto_clear, cv.Optional(CONF_SHOW_TEST_CARD): cv.boolean, } ) @@ -92,8 +101,12 @@ async def setup_display_core_(var, config): if CONF_ROTATION in config: cg.add(var.set_rotation(DISPLAY_ROTATIONS[config[CONF_ROTATION]])) - if CONF_AUTO_CLEAR_ENABLED in config: - cg.add(var.set_auto_clear(config[CONF_AUTO_CLEAR_ENABLED])) + if auto_clear := config.get(CONF_AUTO_CLEAR_ENABLED): + # Default to true if pages or lambda is specified. Ideally this would be done during validation, but + # the possible schemas are too complex to do this easily. + if auto_clear == CONF_UNSPECIFIED: + auto_clear = CONF_LAMBDA in config or CONF_PAGES in config + cg.add(var.set_auto_clear(auto_clear)) if CONF_PAGES in config: pages = [] diff --git a/esphome/components/lvgl/__init__.py b/esphome/components/lvgl/__init__.py index b858e8df01..c64ffcb5f2 100644 --- a/esphome/components/lvgl/__init__.py +++ b/esphome/components/lvgl/__init__.py @@ -197,11 +197,11 @@ def final_validation(configs): for display_id in config[df.CONF_DISPLAYS]: path = global_config.get_path_for_id(display_id)[:-1] display = global_config.get_config_for_path(path) - if CONF_LAMBDA in display: + if CONF_LAMBDA in display or CONF_PAGES in display: raise cv.Invalid( - "Using lambda: in display config not compatible with LVGL" + "Using lambda: or pages: in display config is not compatible with LVGL" ) - if display[CONF_AUTO_CLEAR_ENABLED]: + if display.get(CONF_AUTO_CLEAR_ENABLED) is True: raise cv.Invalid( "Using auto_clear_enabled: true in display config not compatible with LVGL" ) diff --git a/tests/components/lvgl/test.host.yaml b/tests/components/lvgl/test.host.yaml index 34918cb113..39d9a0ebf3 100644 --- a/tests/components/lvgl/test.host.yaml +++ b/tests/components/lvgl/test.host.yaml @@ -7,7 +7,6 @@ display: height: 320 - platform: sdl id: sdl1 - auto_clear_enabled: false dimensions: width: 480 height: 480 @@ -40,4 +39,3 @@ lvgl: text: Click ME on_click: logger.log: Clicked -