Skip to content

Commit 3da1d6b

Browse files
committed
improve handling of subsequent duplicate state events
1 parent 4373989 commit 3da1d6b

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

components/secplus_gdo/cover/gdo_door.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ void GDODoor::set_state(gdo_door_state_t state, float position) {
2929

3030
ESP_LOGI(TAG, "Door state: %s, position: %.0f%%", gdo_door_state_to_string(state), position * 100.0f);
3131

32-
// save the previous operation
33-
this->prev_operation = this->current_operation;
32+
this->prev_operation = this->current_operation; // save the previous operation
3433

3534
switch (state) {
3635
case GDO_DOOR_STATE_OPEN:
@@ -56,14 +55,13 @@ void GDODoor::set_state(gdo_door_state_t state, float position) {
5655
this->position = position;
5756
break;
5857
}
59-
60-
this->state_ = state;
6158

6259
#ifdef USE_MQTT // if MQTT component is enabled, do not publish the same state more than once
63-
if (this->current_operation == this->prev_operation) { return; }
60+
if (this->state_ == state && this->current_operation == this->prev_operation) { return; }
6461
#endif
6562

66-
this->publish_state(false);
63+
this->publish_state(false);
64+
this->state_ = state;
6765
}
6866

6967
void GDODoor::do_action_after_warning(const cover::CoverCall& call) {

components/secplus_gdo/cover/gdo_door.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ using namespace esphome::cover;
6464
bool toggle_only_{false};
6565
optional<float> target_position_{0};
6666
CoverOperation prev_operation{COVER_OPERATION_IDLE};
67-
gdo_door_state_t state_{GDO_DOOR_STATE_MAX};
67+
gdo_door_state_t state_{GDO_DOOR_STATE_UNKNOWN};
6868
bool synced_{false};
6969
};
7070
} // namespace secplus_gdo

0 commit comments

Comments
 (0)