Respct sntp status

This commit is contained in:
Anton Sergunov 2024-06-03 12:22:12 +00:00
parent f55ea9428e
commit dca2ec020e
2 changed files with 7 additions and 6 deletions

View file

@ -58,7 +58,9 @@ void SNTPComponent::setup() {
sntp_set_time_sync_notification_cb(sntp_sync_time_cb); sntp_set_time_sync_notification_cb(sntp_sync_time_cb);
sntp_set_sync_interval(this->get_update_interval()); 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 #endif
sntp_init(); sntp_init();
@ -102,8 +104,6 @@ void SNTPComponent::loop() {
break; break;
case SNTP_SYNC_STATUS_COMPLETED: case SNTP_SYNC_STATUS_COMPLETED:
ESP_LOGD(TAG, "Time sync completed"); ESP_LOGD(TAG, "Time sync completed");
this->has_time_ = true;
this->time_sync_callback_.call();
break; break;
case SNTP_SYNC_STATUS_IN_PROGRESS: case SNTP_SYNC_STATUS_IN_PROGRESS:
ESP_LOGD(TAG, "Time sync in progress"); ESP_LOGD(TAG, "Time sync in progress");
@ -115,7 +115,7 @@ void SNTPComponent::loop() {
} }
} }
callback_args_.clear(); callback_args_.clear();
#else #endif
if (this->has_time_) if (this->has_time_)
return; return;
@ -127,8 +127,9 @@ void SNTPComponent::loop() {
time.minute, time.second); time.minute, time.second);
this->time_sync_callback_.call(); this->time_sync_callback_.call();
this->has_time_ = true; this->has_time_ = true;
#endif
} }
bool SNTPComponent::is_in_progress() const { return sntp_get_sync_status() != SNTP_SYNC_STATUS_COMPLETED; }
} // namespace sntp } // namespace sntp
} // namespace esphome } // namespace esphome

View file

@ -27,7 +27,7 @@ class SNTPComponent : public time::RealTimeClock {
void update() override; void update() override;
void loop() override; void loop() override;
bool is_in_progress() const { return !has_time_; } bool is_in_progress() const;
protected: protected:
std::string server_1_; std::string server_1_;