From b70983ed09140c1188ec7b1ec5af775a49edecb2 Mon Sep 17 00:00:00 2001 From: Chad Matsalla <48810546+ChadMatsalla@users.noreply.github.com> Date: Sun, 10 Aug 2025 17:41:37 -0600 Subject: [PATCH] [display] Disallow ``show_test_card: true`` and ``update_interval: never`` (#9927) Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com> --- esphome/components/display/__init__.py | 16 +++++++++++++++- esphome/const.py | 4 ++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/esphome/components/display/__init__.py b/esphome/components/display/__init__.py index 81f2536e96..8021a8f9b1 100644 --- a/esphome/components/display/__init__.py +++ b/esphome/components/display/__init__.py @@ -12,6 +12,8 @@ from esphome.const import ( CONF_ROTATION, CONF_TO, CONF_TRIGGER_ID, + CONF_UPDATE_INTERVAL, + SCHEDULER_DONT_RUN, ) from esphome.core import coroutine_with_priority @@ -67,6 +69,18 @@ BASIC_DISPLAY_SCHEMA = cv.Schema( } ).extend(cv.polling_component_schema("1s")) + +def _validate_test_card(config): + if ( + config.get(CONF_SHOW_TEST_CARD, False) + and config.get(CONF_UPDATE_INTERVAL, False) == SCHEDULER_DONT_RUN + ): + raise cv.Invalid( + f"`{CONF_SHOW_TEST_CARD}: True` cannot be used with `{CONF_UPDATE_INTERVAL}: never` because this combination will not show a test_card." + ) + return config + + FULL_DISPLAY_SCHEMA = BASIC_DISPLAY_SCHEMA.extend( { cv.Optional(CONF_ROTATION): validate_rotation, @@ -94,6 +108,7 @@ FULL_DISPLAY_SCHEMA = BASIC_DISPLAY_SCHEMA.extend( cv.Optional(CONF_SHOW_TEST_CARD): cv.boolean, } ) +FULL_DISPLAY_SCHEMA.add_extra(_validate_test_card) async def setup_display_core_(var, config): @@ -200,7 +215,6 @@ async def display_is_displaying_page_to_code(config, condition_id, template_arg, page = await cg.get_variable(config[CONF_PAGE_ID]) var = cg.new_Pvariable(condition_id, template_arg, paren) cg.add(var.set_page(page)) - return var diff --git a/esphome/const.py b/esphome/const.py index 56e0edab9b..983850746d 100644 --- a/esphome/const.py +++ b/esphome/const.py @@ -1331,3 +1331,7 @@ ENTITY_CATEGORY_CONFIG = "config" # The entity category for read only diagnostic values, for example RSSI, uptime or MAC Address ENTITY_CATEGORY_DIAGNOSTIC = "diagnostic" + +# The corresponding constant exists in c++ +# when update_interval is set to never, it becomes SCHEDULER_DONT_RUN milliseconds +SCHEDULER_DONT_RUN = 4294967295