1
0
mirror of https://github.com/esphome/esphome.git synced 2025-11-20 00:35:44 +00:00

Add the display.is_displaying_page condition (#1646)

* display: add the display.is_displaying_page condition

* use maybe_simple_value for page_id

* add test
This commit is contained in:
Stanislav Meduna
2021-04-03 04:00:41 +02:00
committed by GitHub
parent 9e23987db8
commit 808e3be324
3 changed files with 45 additions and 1 deletions

View File

@@ -296,6 +296,8 @@ class DisplayBuffer {
void set_pages(std::vector<DisplayPage *> pages);
const DisplayPage *get_active_page() const { return this->page_; }
/// Internal method to set the display rotation with.
void set_rotation(DisplayRotation rotation);
@@ -448,5 +450,17 @@ template<typename... Ts> class DisplayPageShowPrevAction : public Action<Ts...>
DisplayBuffer *buffer_;
};
template<typename... Ts> class DisplayIsDisplayingPageCondition : public Condition<Ts...> {
public:
DisplayIsDisplayingPageCondition(DisplayBuffer *parent) : parent_(parent) {}
void set_page(DisplayPage *page) { this->page_ = page; }
bool check(Ts... x) override { return this->parent_->get_active_page() == this->page_; }
protected:
DisplayBuffer *parent_;
DisplayPage *page_;
};
} // namespace display
} // namespace esphome