feat: add cover.on_state_change trigger (#195)
Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
parent
9df4cebd53
commit
38d2508edc
|
@ -18,9 +18,13 @@ CoverOpeningTrigger = ratgdo_ns.class_(
|
||||||
CoverClosingTrigger = ratgdo_ns.class_(
|
CoverClosingTrigger = ratgdo_ns.class_(
|
||||||
"CoverClosingTrigger", automation.Trigger.template()
|
"CoverClosingTrigger", automation.Trigger.template()
|
||||||
)
|
)
|
||||||
|
CoverStateTrigger = ratgdo_ns.class_(
|
||||||
|
"CoverStateTrigger", automation.Trigger.template()
|
||||||
|
)
|
||||||
|
|
||||||
CONF_ON_OPENING = "on_opening"
|
CONF_ON_OPENING = "on_opening"
|
||||||
CONF_ON_CLOSING = "on_closing"
|
CONF_ON_CLOSING = "on_closing"
|
||||||
|
CONF_ON_STATE_CHANGE = "on_state_change"
|
||||||
|
|
||||||
CONFIG_SCHEMA = cover.COVER_SCHEMA.extend(
|
CONFIG_SCHEMA = cover.COVER_SCHEMA.extend(
|
||||||
{
|
{
|
||||||
|
@ -31,6 +35,9 @@ CONFIG_SCHEMA = cover.COVER_SCHEMA.extend(
|
||||||
cv.Optional(CONF_ON_CLOSING): automation.validate_automation(
|
cv.Optional(CONF_ON_CLOSING): automation.validate_automation(
|
||||||
{cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(CoverClosingTrigger)}
|
{cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(CoverClosingTrigger)}
|
||||||
),
|
),
|
||||||
|
cv.Optional(CONF_ON_STATE_CHANGE): automation.validate_automation(
|
||||||
|
{cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(CoverStateTrigger)}
|
||||||
|
),
|
||||||
}
|
}
|
||||||
).extend(RATGDO_CLIENT_SCHMEA)
|
).extend(RATGDO_CLIENT_SCHMEA)
|
||||||
|
|
||||||
|
@ -46,5 +53,8 @@ async def to_code(config):
|
||||||
for conf in config.get(CONF_ON_CLOSING, []):
|
for conf in config.get(CONF_ON_CLOSING, []):
|
||||||
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var)
|
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var)
|
||||||
await automation.build_automation(trigger, [], conf)
|
await automation.build_automation(trigger, [], conf)
|
||||||
|
for conf in config.get(CONF_ON_STATE_CHANGE, []):
|
||||||
|
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var)
|
||||||
|
await automation.build_automation(trigger, [], conf)
|
||||||
|
|
||||||
await register_ratgdo_child(var, config)
|
await register_ratgdo_child(var, config)
|
||||||
|
|
|
@ -31,5 +31,15 @@ namespace ratgdo {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class CoverStateTrigger : public Trigger<> {
|
||||||
|
public:
|
||||||
|
CoverStateTrigger(cover::Cover* a_cover)
|
||||||
|
{
|
||||||
|
a_cover->add_on_state_callback([this, a_cover]() {
|
||||||
|
this->trigger();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace ratgdo
|
} // namespace ratgdo
|
||||||
} // namespace esphome
|
} // namespace esphome
|
||||||
|
|
Loading…
Reference in New Issue