Defer the stop_pollercall from setup. Call get_update_interval from the base class.

This commit is contained in:
Anton Sergunov 2024-08-19 06:28:46 +00:00
parent d426cae2f3
commit df801778b3

View file

@ -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();