mirror of
https://github.com/esphome/esphome.git
synced 2026-09-22 04:28:43 +00:00
Address code review feedback: add comments and fix trigger initialization
Co-authored-by: clydebarrow <2366188+clydebarrow@users.noreply.github.com>
This commit is contained in:
co-authored by
clydebarrow
parent
1dfb8926d3
commit
35fb44da36
@@ -119,6 +119,8 @@ class CoverOpenTrigger : public Trigger<> {
|
||||
}
|
||||
};
|
||||
|
||||
// Separate CoverOpenedTrigger class for improved naming clarity.
|
||||
// Both on_open and on_opened are supported for backward compatibility.
|
||||
class CoverOpenedTrigger : public Trigger<> {
|
||||
public:
|
||||
CoverOpenedTrigger(Cover *a_cover) {
|
||||
@@ -146,15 +148,17 @@ class CoverOpeningTrigger : public Trigger<> {
|
||||
CoverOpeningTrigger(Cover *a_cover) {
|
||||
a_cover->add_on_state_callback([this, a_cover]() {
|
||||
auto current_op = a_cover->current_operation;
|
||||
if (current_op == COVER_OPERATION_OPENING && this->last_operation_ != COVER_OPERATION_OPENING) {
|
||||
this->trigger();
|
||||
if (current_op == COVER_OPERATION_OPENING) {
|
||||
if (!this->last_operation_.has_value() || this->last_operation_.value() != COVER_OPERATION_OPENING) {
|
||||
this->trigger();
|
||||
}
|
||||
}
|
||||
this->last_operation_ = current_op;
|
||||
});
|
||||
}
|
||||
|
||||
protected:
|
||||
CoverOperation last_operation_{COVER_OPERATION_IDLE};
|
||||
optional<CoverOperation> last_operation_{};
|
||||
};
|
||||
|
||||
class CoverClosingTrigger : public Trigger<> {
|
||||
@@ -162,15 +166,17 @@ class CoverClosingTrigger : public Trigger<> {
|
||||
CoverClosingTrigger(Cover *a_cover) {
|
||||
a_cover->add_on_state_callback([this, a_cover]() {
|
||||
auto current_op = a_cover->current_operation;
|
||||
if (current_op == COVER_OPERATION_CLOSING && this->last_operation_ != COVER_OPERATION_CLOSING) {
|
||||
this->trigger();
|
||||
if (current_op == COVER_OPERATION_CLOSING) {
|
||||
if (!this->last_operation_.has_value() || this->last_operation_.value() != COVER_OPERATION_CLOSING) {
|
||||
this->trigger();
|
||||
}
|
||||
}
|
||||
this->last_operation_ = current_op;
|
||||
});
|
||||
}
|
||||
|
||||
protected:
|
||||
CoverOperation last_operation_{COVER_OPERATION_IDLE};
|
||||
optional<CoverOperation> last_operation_{};
|
||||
};
|
||||
|
||||
class CoverIdleTrigger : public Trigger<> {
|
||||
@@ -178,15 +184,17 @@ class CoverIdleTrigger : public Trigger<> {
|
||||
CoverIdleTrigger(Cover *a_cover) {
|
||||
a_cover->add_on_state_callback([this, a_cover]() {
|
||||
auto current_op = a_cover->current_operation;
|
||||
if (current_op == COVER_OPERATION_IDLE && this->last_operation_ != COVER_OPERATION_IDLE) {
|
||||
this->trigger();
|
||||
if (current_op == COVER_OPERATION_IDLE) {
|
||||
if (this->last_operation_.has_value() && this->last_operation_.value() != COVER_OPERATION_IDLE) {
|
||||
this->trigger();
|
||||
}
|
||||
}
|
||||
this->last_operation_ = current_op;
|
||||
});
|
||||
}
|
||||
|
||||
protected:
|
||||
CoverOperation last_operation_{COVER_OPERATION_IDLE};
|
||||
optional<CoverOperation> last_operation_{};
|
||||
};
|
||||
|
||||
} // namespace esphome::cover
|
||||
|
||||
Reference in New Issue
Block a user