From df801778b376aece1fbd0bf611afbb0fa880409f Mon Sep 17 00:00:00 2001 From: Anton Sergunov Date: Mon, 19 Aug 2024 06:28:46 +0000 Subject: [PATCH] Defer the `stop_poller`call from `setup`. Call `get_update_interval` from the base class. --- esphome/components/sntp/sntp_component.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/esphome/components/sntp/sntp_component.cpp b/esphome/components/sntp/sntp_component.cpp index f7d41bd07b..a9ac11f4cb 100644 --- a/esphome/components/sntp/sntp_component.cpp +++ b/esphome/components/sntp/sntp_component.cpp @@ -38,10 +38,13 @@ void SNTPComponent::setup() { } } #ifdef USE_ESP_IDF - // Stop the puller to prevent periodically update calls. IDF Handles periodic updates by itself. - // The user still able to call `update` to trigger manual update. - this->stop_poller(); - esp_sntp_set_sync_interval(this->get_update_interval()); + // We can't call `stop_poller` here because it will be started after `setup` call. So defer the execution. + this->defer([this] { + // Stop the puller to prevent periodically update calls. IDF Handles periodic updates by itself. + // The user still able to call `update` to trigger manual update. + this->stop_poller(); + }); + esp_sntp_set_sync_interval(time::RealTimeClock::get_update_interval()); #endif sntp_init(); @@ -110,7 +113,8 @@ void SNTPComponent::loop() { /** Sets the update interval calling `sntp_set_sync_interval()`. -Calls `sntp_restart()` if update interval is less then it was before as ESP IDF according documentation. Without this cal interval will be updated only after previously scheduled update. +Calls `sntp_restart()` if update interval is less then it was before as ESP IDF according documentation. Without this +cal interval will be updated only after previously scheduled update. */ void SNTPComponent::set_update_interval(uint32_t update_interval) { const auto previous_sync_interval = sntp_get_sync_interval();