mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 15:12:06 +00:00 
			
		
		
		
	[display] auto_clear_enabled defaults (#7986)
This commit is contained in:
		| @@ -39,6 +39,7 @@ DisplayOnPageChangeTrigger = display_ns.class_( | |||||||
|  |  | ||||||
| CONF_ON_PAGE_CHANGE = "on_page_change" | CONF_ON_PAGE_CHANGE = "on_page_change" | ||||||
| CONF_SHOW_TEST_CARD = "show_test_card" | CONF_SHOW_TEST_CARD = "show_test_card" | ||||||
|  | CONF_UNSPECIFIED = "unspecified" | ||||||
|  |  | ||||||
| DISPLAY_ROTATIONS = { | DISPLAY_ROTATIONS = { | ||||||
|     0: display_ns.DISPLAY_ROTATION_0_DEGREES, |     0: display_ns.DISPLAY_ROTATION_0_DEGREES, | ||||||
| @@ -55,16 +56,22 @@ def validate_rotation(value): | |||||||
|     return cv.enum(DISPLAY_ROTATIONS, int=True)(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( | 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")) | ).extend(cv.polling_component_schema("1s")) | ||||||
|  |  | ||||||
| FULL_DISPLAY_SCHEMA = BASIC_DISPLAY_SCHEMA.extend( | FULL_DISPLAY_SCHEMA = BASIC_DISPLAY_SCHEMA.extend( | ||||||
|     { |     { | ||||||
|         cv.Optional(CONF_ROTATION): validate_rotation, |         cv.Optional(CONF_ROTATION): validate_rotation, | ||||||
|         cv.Optional(CONF_PAGES): cv.All( |         cv.Exclusive(CONF_PAGES, CONF_LAMBDA): cv.All( | ||||||
|             cv.ensure_list( |             cv.ensure_list( | ||||||
|                 { |                 { | ||||||
|                     cv.GenerateID(): cv.declare_id(DisplayPage), |                     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_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, |         cv.Optional(CONF_SHOW_TEST_CARD): cv.boolean, | ||||||
|     } |     } | ||||||
| ) | ) | ||||||
| @@ -92,8 +101,12 @@ async def setup_display_core_(var, config): | |||||||
|     if CONF_ROTATION in config: |     if CONF_ROTATION in config: | ||||||
|         cg.add(var.set_rotation(DISPLAY_ROTATIONS[config[CONF_ROTATION]])) |         cg.add(var.set_rotation(DISPLAY_ROTATIONS[config[CONF_ROTATION]])) | ||||||
|  |  | ||||||
|     if CONF_AUTO_CLEAR_ENABLED in config: |     if auto_clear := config.get(CONF_AUTO_CLEAR_ENABLED): | ||||||
|         cg.add(var.set_auto_clear(config[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: |     if CONF_PAGES in config: | ||||||
|         pages = [] |         pages = [] | ||||||
|   | |||||||
| @@ -197,11 +197,11 @@ def final_validation(configs): | |||||||
|         for display_id in config[df.CONF_DISPLAYS]: |         for display_id in config[df.CONF_DISPLAYS]: | ||||||
|             path = global_config.get_path_for_id(display_id)[:-1] |             path = global_config.get_path_for_id(display_id)[:-1] | ||||||
|             display = global_config.get_config_for_path(path) |             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( |                 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( |                 raise cv.Invalid( | ||||||
|                     "Using auto_clear_enabled: true in display config not compatible with LVGL" |                     "Using auto_clear_enabled: true in display config not compatible with LVGL" | ||||||
|                 ) |                 ) | ||||||
|   | |||||||
| @@ -7,7 +7,6 @@ display: | |||||||
|       height: 320 |       height: 320 | ||||||
|   - platform: sdl |   - platform: sdl | ||||||
|     id: sdl1 |     id: sdl1 | ||||||
|     auto_clear_enabled: false |  | ||||||
|     dimensions: |     dimensions: | ||||||
|       width: 480 |       width: 480 | ||||||
|       height: 480 |       height: 480 | ||||||
| @@ -40,4 +39,3 @@ lvgl: | |||||||
|                 text: Click ME |                 text: Click ME | ||||||
|           on_click: |           on_click: | ||||||
|             logger.log: Clicked |             logger.log: Clicked | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user