From 181b563b968c03c51912bc85f90403bb574d3087 Mon Sep 17 00:00:00 2001 From: Marius Muja Date: Thu, 18 Jan 2024 18:13:28 -0800 Subject: [PATCH] Remove lean polling --- components/ratgdo/ratgdo.cpp | 9 +++++++++ components/ratgdo/secplus2.cpp | 26 +------------------------- components/ratgdo/secplus2.h | 1 - 3 files changed, 10 insertions(+), 26 deletions(-) diff --git a/components/ratgdo/ratgdo.cpp b/components/ratgdo/ratgdo.cpp index 8991652..eb2d438 100644 --- a/components/ratgdo/ratgdo.cpp +++ b/components/ratgdo/ratgdo.cpp @@ -190,6 +190,15 @@ namespace ratgdo { void RATGDOComponent::received(const LearnState learn_state) { ESP_LOGD(TAG, "Learn state=%s", LearnState_to_string(learn_state)); + + if (*this->learn_state == learn_state) { + return; + } + + if (learn_state == LearnState::INACTIVE) { + this->query_paired_devices(); + } + this->learn_state = learn_state; } diff --git a/components/ratgdo/secplus2.cpp b/components/ratgdo/secplus2.cpp index c95a1c8..c15fca8 100644 --- a/components/ratgdo/secplus2.cpp +++ b/components/ratgdo/secplus2.cpp @@ -238,7 +238,6 @@ namespace secplus2 { void Secplus2::activate_learn() { // Send LEARN with nibble = 0 then nibble = 1 to mimic wall control learn button - this->learn_poll_status_ = true; this->send_command(Command{CommandType::LEARN, 0}); this->scheduler_->set_timeout(this->ratgdo_, "", 150, [=] { this->send_command(Command{CommandType::LEARN, 1}); }); this->scheduler_->set_timeout(this->ratgdo_, "", 500, [=] { this->query_status(); }); @@ -381,24 +380,7 @@ namespace secplus2 { this->ratgdo_->received(to_LockState((cmd.byte2 & 1), LockState::UNKNOWN)); // ESP_LOGD(TAG, "Obstruction: reading from byte2, bit2, status=%d", ((byte2 >> 2) & 1) == 1); this->ratgdo_->received(to_ObstructionState((cmd.byte1 >> 6) & 1, ObstructionState::UNKNOWN)); - - auto learn_state = to_LearnState((cmd.byte2 >> 5) & 1, LearnState::UNKNOWN); - if (this->learn_state_ != learn_state) { - ESP_LOG1(TAG, "Learn state handle: %d", (int)this->learn_poll_status_); - if (learn_state == LearnState::ACTIVE && this->learn_poll_status_) { - this->scheduler_->set_interval(this->ratgdo_, "learn_poll", 1000, [=] { - this->query_status(); - }); - } else { - this->scheduler_->cancel_interval(this->ratgdo_, "learn_poll"); - this->learn_poll_status_ = true; - } - if (learn_state == LearnState::INACTIVE) { - this->query_paired_devices(); - } - this->learn_state_ = learn_state; - } - this->ratgdo_->received(learn_state); + this->ratgdo_->received(to_LearnState((cmd.byte2 >> 5) & 1, LearnState::UNKNOWN)); } else if (cmd.type == CommandType::LIGHT) { this->ratgdo_->received(to_LightAction(cmd.nibble, LightAction::UNKNOWN)); @@ -435,12 +417,6 @@ namespace secplus2 { } this->ratgdo_->received(pdc); } - else if (cmd.type == CommandType::LEARN) { - if (cmd.nibble == 1) { // LEARN sent from wall control, it will poll status every second. - // otherwise if ratgdo or gdo initiated ratgdo needs to poll - this->learn_poll_status_ = false; - } - } else if (cmd.type == CommandType::BATTERY_STATUS) { this->ratgdo_->received(to_BatteryState(cmd.byte1, BatteryState::UNKNOWN)); } diff --git a/components/ratgdo/secplus2.h b/components/ratgdo/secplus2.h index c9d0c65..1f8050c 100644 --- a/components/ratgdo/secplus2.h +++ b/components/ratgdo/secplus2.h @@ -120,7 +120,6 @@ namespace secplus2 { optional decode_packet(const WirePacket& packet) const; LearnState learn_state_ { LearnState::UNKNOWN }; - bool learn_poll_status_; observable rolling_code_counter_ { 0 }; uint64_t client_id_ { 0x539 };