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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user