From dca2ec020e1e0aeed8d361f34b66cfebaeb0120e Mon Sep 17 00:00:00 2001 From: Anton Sergunov Date: Mon, 3 Jun 2024 12:22:12 +0000 Subject: [PATCH] Respct sntp status --- esphome/components/sntp/sntp_component.cpp | 11 ++++++----- esphome/components/sntp/sntp_component.h | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/esphome/components/sntp/sntp_component.cpp b/esphome/components/sntp/sntp_component.cpp index ee9bc3b332..1f418a7857 100644 --- a/esphome/components/sntp/sntp_component.cpp +++ b/esphome/components/sntp/sntp_component.cpp @@ -58,7 +58,9 @@ void SNTPComponent::setup() { sntp_set_time_sync_notification_cb(sntp_sync_time_cb); sntp_set_sync_interval(this->get_update_interval()); - sntp_set_sync_status(SNTP_SYNC_STATUS_RESET); + + // Stop pooler but ler the user update by the hands + this->stop_poller(); #endif sntp_init(); @@ -102,8 +104,6 @@ void SNTPComponent::loop() { break; case SNTP_SYNC_STATUS_COMPLETED: ESP_LOGD(TAG, "Time sync completed"); - this->has_time_ = true; - this->time_sync_callback_.call(); break; case SNTP_SYNC_STATUS_IN_PROGRESS: ESP_LOGD(TAG, "Time sync in progress"); @@ -115,7 +115,7 @@ void SNTPComponent::loop() { } } callback_args_.clear(); -#else +#endif if (this->has_time_) return; @@ -127,8 +127,9 @@ void SNTPComponent::loop() { time.minute, time.second); this->time_sync_callback_.call(); this->has_time_ = true; -#endif } +bool SNTPComponent::is_in_progress() const { return sntp_get_sync_status() != SNTP_SYNC_STATUS_COMPLETED; } + } // namespace sntp } // namespace esphome diff --git a/esphome/components/sntp/sntp_component.h b/esphome/components/sntp/sntp_component.h index 1ecef6750c..8683260c8b 100644 --- a/esphome/components/sntp/sntp_component.h +++ b/esphome/components/sntp/sntp_component.h @@ -27,7 +27,7 @@ class SNTPComponent : public time::RealTimeClock { void update() override; void loop() override; - bool is_in_progress() const { return !has_time_; } + bool is_in_progress() const; protected: std::string server_1_;