From 34d0b48c6bee687a50fa37d87eb294503e1a7240 Mon Sep 17 00:00:00 2001 From: Ryan Powell Date: Tue, 18 Jun 2024 13:42:22 -0600 Subject: [PATCH] Wait until WiFi is connected before starting the gdo loop. --- components/secplus_gdo/secplus_gdo.cpp | 16 ++++++++++++++-- components/secplus_gdo/secplus_gdo.h | 3 +++ packages/wifi.yaml | 3 +++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/components/secplus_gdo/secplus_gdo.cpp b/components/secplus_gdo/secplus_gdo.cpp index ca9cb37..c0d8566 100644 --- a/components/secplus_gdo/secplus_gdo.cpp +++ b/components/secplus_gdo/secplus_gdo.cpp @@ -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() { diff --git a/components/secplus_gdo/secplus_gdo.h b/components/secplus_gdo/secplus_gdo.h index 4f16d7e..03f2065 100644 --- a/components/secplus_gdo/secplus_gdo.h +++ b/components/secplus_gdo/secplus_gdo.h @@ -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; } @@ -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 diff --git a/packages/wifi.yaml b/packages/wifi.yaml index b1e1094..3f96451 100644 --- a/packages/wifi.yaml +++ b/packages/wifi.yaml @@ -1,4 +1,7 @@ wifi: + on_connect: + lambda: id(gdo_blaq).start_gdo(); + # Enable fallback hotspot (captive portal) in case wifi connection fails ap: