Skip to content

Commit

Permalink
Merge pull request #64 from konnected-io/wait-for-wifi
Browse files Browse the repository at this point in the history
Wait until WiFi is connected before starting the gdo loop.
  • Loading branch information
heythisisnate authored Jun 18, 2024
2 parents b388fec + ed267db commit 5f722ff
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
16 changes: 14 additions & 2 deletions components/secplus_gdo/secplus_gdo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,20 @@ namespace secplus_gdo {

gdo_init(&gdo_conf);
gdo_get_status(&this->status_);
gdo_start(gdo_event_handler, this);
ESP_LOGI(TAG, "secplus GDO started!");
if (this->start_gdo_) {
gdo_start(gdo_event_handler, this);
ESP_LOGI(TAG, "secplus GDO started!");
} else {
// check every 500ms for readiness before starting GDO
this->set_interval("gdo_start", 500, [=]() {
if (this->start_gdo_) {
gdo_start(gdo_event_handler, this);
ESP_LOGI(TAG, "secplus GDO started!");
this->cancel_interval("gdo_start");
}
});

}
}

void GDOComponent::dump_config() {
Expand Down
3 changes: 3 additions & 0 deletions components/secplus_gdo/secplus_gdo.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ namespace secplus_gdo {
void loop() override {};
void dump_config() override;
void on_shutdown() override { gdo_deinit(); }
void start_gdo() { start_gdo_ = true; }

// Use Late priority so we do not start the GDO lib until all saved preferences are loaded
float get_setup_priority() const override { return setup_priority::LATE; }

Expand Down Expand Up @@ -103,6 +105,7 @@ namespace secplus_gdo {
GDOSelect* protocol_select_{nullptr};
GDOSwitch* learn_switch_{nullptr};
GDOSwitch* toggle_only_switch_{nullptr};
bool start_gdo_{false};

}; // GDOComponent
} // namespace secplus_gdo
Expand Down
4 changes: 4 additions & 0 deletions packages/secplus-gdo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,7 @@ number:
type: rolling_code
mode: box
internal: true

wifi:
on_connect:
lambda: id(gdo_blaq).start_gdo();

0 comments on commit 5f722ff

Please sign in to comment.