1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-30 06:33:51 +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

@@ -2,7 +2,7 @@ import esphome.codegen as cg
import esphome.config_validation as cv
from esphome import core, automation
from esphome.automation import maybe_simple_id
from esphome.const import CONF_ID, CONF_LAMBDA, CONF_PAGES, CONF_ROTATION
from esphome.const import CONF_ID, CONF_LAMBDA, CONF_PAGES, CONF_PAGE_ID, CONF_ROTATION
from esphome.core import coroutine, coroutine_with_priority
IS_PLATFORM_COMPONENT = True
@@ -19,6 +19,9 @@ DisplayPageShowNextAction = display_ns.class_(
DisplayPageShowPrevAction = display_ns.class_(
"DisplayPageShowPrevAction", automation.Action
)
DisplayIsDisplayingPageCondition = display_ns.class_(
"DisplayIsDisplayingPageCondition", automation.Condition
)
DISPLAY_ROTATIONS = {
0: display_ns.DISPLAY_ROTATION_0_DEGREES,
@@ -125,6 +128,26 @@ def display_page_show_previous_to_code(config, action_id, template_arg, args):
yield cg.new_Pvariable(action_id, template_arg, paren)
@automation.register_condition(
"display.is_displaying_page",
DisplayIsDisplayingPageCondition,
cv.maybe_simple_value(
{
cv.GenerateID(CONF_ID): cv.use_id(DisplayBuffer),
cv.Required(CONF_PAGE_ID): cv.use_id(DisplayPage),
},
key=CONF_PAGE_ID,
),
)
def display_is_displaying_page_to_code(config, condition_id, template_arg, args):
paren = yield cg.get_variable(config[CONF_ID])
page = yield cg.get_variable(config[CONF_PAGE_ID])
var = cg.new_Pvariable(condition_id, template_arg, paren)
cg.add(var.set_page(page))
yield var
@coroutine_with_priority(100.0)
def to_code(config):
cg.add_global(display_ns.using)