From bd91d3ff239726578675e53ee3edd0eda8a495fc Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 23 Sep 2026 23:24:12 +0100 Subject: [PATCH] [display] Use register_apply_action for display.page.show_next and show_previous (#19519) --- esphome/components/display/__init__.py | 43 ++++++++------------------ esphome/components/display/display.h | 18 ----------- tests/components/mipi_spi/common.yaml | 11 +++++++ 3 files changed, 24 insertions(+), 48 deletions(-) diff --git a/esphome/components/display/__init__.py b/esphome/components/display/__init__.py index 7a66da11f2..b664579be9 100644 --- a/esphome/components/display/__init__.py +++ b/esphome/components/display/__init__.py @@ -39,12 +39,6 @@ DisplayPage = display_ns.class_("DisplayPage") DisplayPagePtr = DisplayPage.operator("ptr") DisplayRef = Display.operator("ref") DisplayPageShowAction = display_ns.class_("DisplayPageShowAction", automation.Action) -DisplayPageShowNextAction = display_ns.class_( - "DisplayPageShowNextAction", automation.Action -) -DisplayPageShowPrevAction = display_ns.class_( - "DisplayPageShowPrevAction", automation.Action -) DisplayIsDisplayingPageCondition = display_ns.class_( "DisplayIsDisplayingPageCondition", automation.Condition ) @@ -288,34 +282,23 @@ async def display_page_show_to_code(config, action_id, template_arg, args): return var -@automation.register_action( +# The id is the display itself, so it cannot be a lambda; a plain use_id rejects one clearly. +DISPLAY_PAGE_CYCLE_ACTION_SCHEMA = maybe_simple_id( + { + cv.GenerateID(CONF_ID): cv.use_id(Display), + } +) + +automation.register_apply_action( "display.page.show_next", - DisplayPageShowNextAction, - maybe_simple_id( - { - cv.GenerateID(CONF_ID): cv.templatable(cv.use_id(Display)), - } - ), - synchronous=True, + DISPLAY_PAGE_CYCLE_ACTION_SCHEMA, + automation.ApplyCall("show_next_page()"), ) -async def display_page_show_next_to_code(config, action_id, template_arg, args): - paren = await cg.get_variable(config[CONF_ID]) - return cg.new_Pvariable(action_id, template_arg, paren) - - -@automation.register_action( +automation.register_apply_action( "display.page.show_previous", - DisplayPageShowPrevAction, - maybe_simple_id( - { - cv.GenerateID(CONF_ID): cv.templatable(cv.use_id(Display)), - } - ), - synchronous=True, + DISPLAY_PAGE_CYCLE_ACTION_SCHEMA, + automation.ApplyCall("show_prev_page()"), ) -async def display_page_show_previous_to_code(config, action_id, template_arg, args): - paren = await cg.get_variable(config[CONF_ID]) - return cg.new_Pvariable(action_id, template_arg, paren) @automation.register_condition( diff --git a/esphome/components/display/display.h b/esphome/components/display/display.h index c138972149..af5a7bc132 100644 --- a/esphome/components/display/display.h +++ b/esphome/components/display/display.h @@ -848,24 +848,6 @@ template class DisplayPageShowAction final : public Action class DisplayPageShowNextAction final : public Action { - public: - DisplayPageShowNextAction(Display *buffer) : buffer_(buffer) {} - - void play(const Ts &...x) override { this->buffer_->show_next_page(); } - - Display *buffer_; -}; - -template class DisplayPageShowPrevAction final : public Action { - public: - DisplayPageShowPrevAction(Display *buffer) : buffer_(buffer) {} - - void play(const Ts &...x) override { this->buffer_->show_prev_page(); } - - Display *buffer_; -}; - template class DisplayIsDisplayingPageCondition final : public Condition { public: DisplayIsDisplayingPageCondition(Display *parent) : parent_(parent) {} diff --git a/tests/components/mipi_spi/common.yaml b/tests/components/mipi_spi/common.yaml index a867b726ed..6bdee9e54a 100644 --- a/tests/components/mipi_spi/common.yaml +++ b/tests/components/mipi_spi/common.yaml @@ -1,3 +1,10 @@ +esphome: + on_boot: + then: + - display.page.show_next: page_display + - display.page.show_previous: + id: page_display + display: - platform: mipi_spi spi_16: true @@ -32,7 +39,11 @@ display: bus_mode: single - platform: mipi_spi + id: page_display model: WAVESHARE-1.83-V2 + pages: + - lambda: it.rectangle(0, 0, 10, 10); + - lambda: it.rectangle(10, 10, 10, 10); dc_pin: allow_other_uses: true number: ${dc_pin}