mirror of
https://github.com/esphome/esphome.git
synced 2026-10-03 09:46:03 +00:00
undo some templating
This commit is contained in:
@@ -87,8 +87,11 @@ 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)
|
||||
CoverPositionTrigger = cover_ns.class_(
|
||||
"CoverPositionTrigger", automation.Trigger.template()
|
||||
CoverOpenedTrigger = cover_ns.class_(
|
||||
"CoverOpenedTrigger", automation.Trigger.template()
|
||||
)
|
||||
CoverClosedTrigger = cover_ns.class_(
|
||||
"CoverClosedTrigger", automation.Trigger.template()
|
||||
)
|
||||
CoverTrigger = cover_ns.class_("CoverTrigger", automation.Trigger.template())
|
||||
|
||||
@@ -131,23 +134,17 @@ _COVER_SCHEMA = (
|
||||
# Deprecated trigger
|
||||
cv.Optional(CONF_ON_OPEN): automation.validate_automation(
|
||||
{
|
||||
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(
|
||||
CoverPositionTrigger.template(COVER_OPEN)
|
||||
),
|
||||
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(CoverOpenedTrigger),
|
||||
}
|
||||
),
|
||||
cv.Optional(CONF_ON_OPENED): automation.validate_automation(
|
||||
{
|
||||
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(
|
||||
CoverPositionTrigger.template(COVER_OPEN)
|
||||
),
|
||||
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(CoverOpenedTrigger),
|
||||
}
|
||||
),
|
||||
cv.Optional(CONF_ON_CLOSED): automation.validate_automation(
|
||||
{
|
||||
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(
|
||||
CoverPositionTrigger.template(COVER_CLOSED)
|
||||
),
|
||||
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(CoverClosedTrigger),
|
||||
}
|
||||
),
|
||||
**{
|
||||
|
||||
@@ -90,23 +90,49 @@ template<typename... Ts> class CoverPublishAction : public Action<Ts...> {
|
||||
Cover *cover_;
|
||||
};
|
||||
|
||||
template<float POS, typename... Ts> class CoverIsCondition : public Condition<Ts...> {
|
||||
template<typename... Ts> class CoverIsOpenCondition : public Condition<Ts...> {
|
||||
public:
|
||||
CoverIsCondition(Cover *cover) : cover_(cover) {}
|
||||
CoverIsOpenCondition(Cover *cover) : cover_(cover) {}
|
||||
|
||||
bool check(const Ts &...x) override { return this->cover_->position == POS; }
|
||||
bool check(const Ts &...x) override { return this->cover_->position == COVER_OPEN; }
|
||||
|
||||
protected:
|
||||
Cover *cover_;
|
||||
};
|
||||
|
||||
template<float POS> class CoverPositionTrigger : public Trigger<> {
|
||||
template<typename... Ts> class CoverIsClosedCondition : public Condition<Ts...> {
|
||||
public:
|
||||
CoverPositionTrigger(Cover *a_cover) {
|
||||
CoverIsClosedCondition(Cover *cover) : cover_(cover) {}
|
||||
|
||||
bool check(const Ts &...x) override { return this->cover_->position == COVER_CLOSED; }
|
||||
|
||||
protected:
|
||||
Cover *cover_;
|
||||
};
|
||||
|
||||
class CoverOpenedTrigger : public Trigger<> {
|
||||
public:
|
||||
CoverOpenedTrigger(Cover *a_cover) {
|
||||
a_cover->add_on_state_callback([this, a_cover]() {
|
||||
if (a_cover->position != this->last_position_) {
|
||||
this->last_position_ = a_cover->position;
|
||||
if (a_cover->position == POS)
|
||||
if (a_cover->position == COVER_OPEN)
|
||||
this->trigger();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected:
|
||||
float last_position_{NAN};
|
||||
};
|
||||
|
||||
class CoverClosedTrigger : public Trigger<> {
|
||||
public:
|
||||
CoverClosedTrigger(Cover *a_cover) {
|
||||
a_cover->add_on_state_callback([this, a_cover]() {
|
||||
if (a_cover->position != this->last_position_) {
|
||||
this->last_position_ = a_cover->position;
|
||||
if (a_cover->position == COVER_CLOSED)
|
||||
this->trigger();
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user