[display] Use register_apply_action for display.page.show_next and show_previous (#19519)

This commit is contained in:
J. Nick Koston
2026-09-23 23:24:12 +01:00
committed by GitHub
parent 2a26d5ab62
commit bd91d3ff23
3 changed files with 24 additions and 48 deletions
+13 -30
View File
@@ -39,12 +39,6 @@ DisplayPage = display_ns.class_("DisplayPage")
DisplayPagePtr = DisplayPage.operator("ptr") DisplayPagePtr = DisplayPage.operator("ptr")
DisplayRef = Display.operator("ref") DisplayRef = Display.operator("ref")
DisplayPageShowAction = display_ns.class_("DisplayPageShowAction", automation.Action) 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 = display_ns.class_(
"DisplayIsDisplayingPageCondition", automation.Condition "DisplayIsDisplayingPageCondition", automation.Condition
) )
@@ -288,34 +282,23 @@ async def display_page_show_to_code(config, action_id, template_arg, args):
return var 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", "display.page.show_next",
DisplayPageShowNextAction, DISPLAY_PAGE_CYCLE_ACTION_SCHEMA,
maybe_simple_id( automation.ApplyCall("show_next_page()"),
{
cv.GenerateID(CONF_ID): cv.templatable(cv.use_id(Display)),
}
),
synchronous=True,
) )
async def display_page_show_next_to_code(config, action_id, template_arg, args): automation.register_apply_action(
paren = await cg.get_variable(config[CONF_ID])
return cg.new_Pvariable(action_id, template_arg, paren)
@automation.register_action(
"display.page.show_previous", "display.page.show_previous",
DisplayPageShowPrevAction, DISPLAY_PAGE_CYCLE_ACTION_SCHEMA,
maybe_simple_id( automation.ApplyCall("show_prev_page()"),
{
cv.GenerateID(CONF_ID): cv.templatable(cv.use_id(Display)),
}
),
synchronous=True,
) )
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( @automation.register_condition(
-18
View File
@@ -848,24 +848,6 @@ template<typename... Ts> class DisplayPageShowAction final : public Action<Ts...
} }
}; };
template<typename... Ts> class DisplayPageShowNextAction final : public Action<Ts...> {
public:
DisplayPageShowNextAction(Display *buffer) : buffer_(buffer) {}
void play(const Ts &...x) override { this->buffer_->show_next_page(); }
Display *buffer_;
};
template<typename... Ts> class DisplayPageShowPrevAction final : public Action<Ts...> {
public:
DisplayPageShowPrevAction(Display *buffer) : buffer_(buffer) {}
void play(const Ts &...x) override { this->buffer_->show_prev_page(); }
Display *buffer_;
};
template<typename... Ts> class DisplayIsDisplayingPageCondition final : public Condition<Ts...> { template<typename... Ts> class DisplayIsDisplayingPageCondition final : public Condition<Ts...> {
public: public:
DisplayIsDisplayingPageCondition(Display *parent) : parent_(parent) {} DisplayIsDisplayingPageCondition(Display *parent) : parent_(parent) {}
+11
View File
@@ -1,3 +1,10 @@
esphome:
on_boot:
then:
- display.page.show_next: page_display
- display.page.show_previous:
id: page_display
display: display:
- platform: mipi_spi - platform: mipi_spi
spi_16: true spi_16: true
@@ -32,7 +39,11 @@ display:
bus_mode: single bus_mode: single
- platform: mipi_spi - platform: mipi_spi
id: page_display
model: WAVESHARE-1.83-V2 model: WAVESHARE-1.83-V2
pages:
- lambda: it.rectangle(0, 0, 10, 10);
- lambda: it.rectangle(10, 10, 10, 10);
dc_pin: dc_pin:
allow_other_uses: true allow_other_uses: true
number: ${dc_pin} number: ${dc_pin}