Remove scheduler

This commit is contained in:
Anton Sergunov 2024-06-07 07:27:37 +00:00
parent cec868bd3e
commit 062520b8b8

View file

@ -18,7 +18,6 @@ namespace esphome {
namespace sntp { namespace sntp {
static const char *const TAG = "sntp"; static const char *const TAG = "sntp";
static const std::string FORCE_UPDATE_SCHEDULE = "force_update_schedule";
const char *server_name_buffer(const std::string &server) { return server.empty() ? nullptr : server.c_str(); } const char *server_name_buffer(const std::string &server) { return server.empty() ? nullptr : server.c_str(); }
@ -47,7 +46,7 @@ void SNTPComponent::setup() {
#ifdef USE_ESP_IDF #ifdef USE_ESP_IDF
this->stop_poller(); this->stop_poller();
sntp_set_sync_interval(this->get_update_interval()); sntp_set_sync_interval(this->get_update_interval());
#endif // USE_ESP_IDF #endif
sntp_init(); sntp_init();
#endif // USE_HOST #endif // USE_HOST
@ -95,14 +94,12 @@ void SNTPComponent::update() {
} }
void SNTPComponent::loop() { void SNTPComponent::loop() {
#ifdef USE_ESP_IDF #ifdef USE_ESP_IDF
if (sntp_get_sync_status() == SNTP_SYNC_STATUS_RESET) if (sntp_get_sync_status() != SNTP_SYNC_STATUS_COMPLETED)
return; return;
auto time = this->now(); auto time = this->now();
if (!time.is_valid()) if (!time.is_valid())
return; return;
this->cancel_timeout(FORCE_UPDATE_SCHEDULE);
#else #else
if (this->has_time_) if (this->has_time_)
return; return;
@ -126,7 +123,7 @@ void SNTPComponent::set_update_interval(uint32_t update_interval) {
time::RealTimeClock::set_update_interval(new_sync_interval); time::RealTimeClock::set_update_interval(new_sync_interval);
if (previous_sync_interval > new_sync_interval) { if (previous_sync_interval > new_sync_interval) {
this->set_timeout(FORCE_UPDATE_SCHEDULE, new_sync_interval, [] { sntp_restart(); }); sntp_restart();
} }
} }
uint32_t SNTPComponent::get_update_interval() const { return sntp_get_sync_interval(); } uint32_t SNTPComponent::get_update_interval() const { return sntp_get_sync_interval(); }