Skip to content

Commit

Permalink
prevent flooding cloud requests with subsequent duplicate garage door…
Browse files Browse the repository at this point in the history
… states
  • Loading branch information
heythisisnate committed Oct 18, 2024
1 parent f025fc9 commit e48b8c9
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions components/secplus_gdo/cover/gdo_door.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ void GDODoor::set_state(gdo_door_state_t state, float position) {
}

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

// save the previous operation
this->prev_operation = this->current_operation;

switch (state) {
case GDO_DOOR_STATE_OPEN:
Expand All @@ -46,26 +49,29 @@ void GDODoor::set_state(gdo_door_state_t state, float position) {
this->current_operation = COVER_OPERATION_CLOSING;
this->position = position;
break;
case GDO_DOOR_STATE_STOPPED:
this->prev_operation = this->current_operation;
// falls through
case GDO_DOOR_STATE_MAX:
case GDO_DOOR_STATE_STOPPED: // falls through
case GDO_DOOR_STATE_MAX: // falls through
default:
this->current_operation = COVER_OPERATION_IDLE;
this->position = position;
break;
}

this->publish_state(false);
this->state_ = state;

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

this->publish_state(false);
}

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

if (this->pre_close_active_) {
return;
}

this->set_state(GDO_DOOR_STATE_CLOSING, this->position);
this->publish_state(false); // publish state to acknowledge command was received

Expand Down

0 comments on commit e48b8c9

Please sign in to comment.