mirror of
https://github.com/esphome/esphome.git
synced 2026-09-22 04:28:43 +00:00
Add conditions
This commit is contained in:
@@ -86,7 +86,8 @@ StopAction = cover_ns.class_("StopAction", automation.Action)
|
||||
ToggleAction = cover_ns.class_("ToggleAction", automation.Action)
|
||||
ControlAction = cover_ns.class_("ControlAction", automation.Action)
|
||||
CoverPublishAction = cover_ns.class_("CoverPublishAction", automation.Action)
|
||||
CoverIsCondition = cover_ns.class_("CoverIsCondition", Condition)
|
||||
CoverIsOpenCondition = cover_ns.class_("CoverIsOpenCondition", Condition)
|
||||
CoverIsClosedCondition = cover_ns.class_("CoverIsClosedCondition", Condition)
|
||||
CoverOpenedTrigger = cover_ns.class_(
|
||||
"CoverOpenedTrigger", automation.Trigger.template()
|
||||
)
|
||||
@@ -305,6 +306,26 @@ async def cover_control_to_code(config, action_id, template_arg, args):
|
||||
return var
|
||||
|
||||
|
||||
@automation.register_condition(
|
||||
"cover.is_open",
|
||||
CoverIsOpenCondition,
|
||||
cv.maybe_simple_value({cv.Required(CONF_ID): cv.use_id(Cover)}, key=CONF_ID),
|
||||
)
|
||||
async def cover_is_open_to_code(config, condition_id, template_arg, args):
|
||||
paren = await cg.get_variable(config[CONF_ID])
|
||||
return cg.new_Pvariable(condition_id, template_arg, paren)
|
||||
|
||||
|
||||
@automation.register_condition(
|
||||
"cover.is_closed",
|
||||
CoverIsClosedCondition,
|
||||
cv.maybe_simple_value({cv.Required(CONF_ID): cv.use_id(Cover)}, key=CONF_ID),
|
||||
)
|
||||
async def cover_is_closed_to_code(config, condition_id, template_arg, args):
|
||||
paren = await cg.get_variable(config[CONF_ID])
|
||||
return cg.new_Pvariable(condition_id, template_arg, paren)
|
||||
|
||||
|
||||
@coroutine_with_priority(CoroPriority.CORE)
|
||||
async def to_code(config):
|
||||
cg.add_global(cover_ns.using)
|
||||
|
||||
@@ -272,6 +272,17 @@ cover:
|
||||
- logger.log: "Cover started closing"
|
||||
on_idle:
|
||||
- logger.log: "Cover stopped moving"
|
||||
- logger.log: "Cover stopped moving"
|
||||
- if:
|
||||
condition:
|
||||
cover.is_open: template_cover_with_triggers
|
||||
then:
|
||||
logger.log: Cover is open
|
||||
- if:
|
||||
condition:
|
||||
cover.is_closed: template_cover_with_triggers
|
||||
then:
|
||||
logger.log: Cover is closed
|
||||
|
||||
number:
|
||||
- platform: template
|
||||
|
||||
Reference in New Issue
Block a user