From 06c9b4947b00781174f0fcb2fc872e22d787822c Mon Sep 17 00:00:00 2001 From: Maxim Prokhorov Date: Tue, 2 Mar 2021 18:05:07 +0300 Subject: [PATCH] ha: call stop() when out of retries Also, more logging --- code/espurna/homeassistant.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/code/espurna/homeassistant.cpp b/code/espurna/homeassistant.cpp index 7e11512b..74409b1b 100644 --- a/code/espurna/homeassistant.cpp +++ b/code/espurna/homeassistant.cpp @@ -718,7 +718,7 @@ public: return false; } - return (--_retry < 0); + return (--_retry > 0); } Context& context() { @@ -797,7 +797,13 @@ void send(TaskPtr ptr, FlagPtr flag_ptr); void stop(bool done) { timer.detach(); - state = done ? State::Sent : State::Pending; + if (done) { + DEBUG_MSG_P(PSTR("[HA] Stopping discovery\n")); + state = State::Sent; + } else { + DEBUG_MSG_P(PSTR("[HA] Discovery error\n")); + state = State::Pending; + } } void schedule(unsigned long wait, TaskPtr ptr, FlagPtr flag_ptr) { @@ -861,10 +867,7 @@ void send(TaskPtr ptr, FlagPtr flag_ptr) { return; } - if (task.done()) { - stop(true); - return; - } + stop(false); } } // namespace internal