From 67c03b02af809584a35e7ba35f2909972a501198 Mon Sep 17 00:00:00 2001 From: Anton Sergunov Date: Thu, 9 May 2024 03:52:38 +0000 Subject: [PATCH] simplify --- esphome/components/sntp/sntp_component.cpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/esphome/components/sntp/sntp_component.cpp b/esphome/components/sntp/sntp_component.cpp index 9ecf694b56..489a96781e 100644 --- a/esphome/components/sntp/sntp_component.cpp +++ b/esphome/components/sntp/sntp_component.cpp @@ -26,9 +26,12 @@ static const char *const TAG = "sntp"; std::vector, sntp_sync_status_t>> callback_args_; -static std::function g_sync_callback = nullptr; - -void sntp_sync_time_cb(struct timeval *tv) { g_sync_callback(tv); } +void sntp_sync_time_cb(struct timeval *tv) { + callback_args_.push_back({}); + if (tv) + callback_args_.back().first = *tv; + callback_args_.back().second = sntp_get_sync_status(); +} void SNTPComponent::setup() { #ifndef USE_HOST @@ -54,13 +57,6 @@ void SNTPComponent::setup() { sntp_set_sync_interval(this->get_update_interval()); #endif - g_sync_callback = [](struct timeval *tv) { - callback_args_.push_back({}); - if (tv) - callback_args_.back().first = *tv; - callback_args_.back().second = sntp_get_sync_status(); - }; - ESP_LOGD(TAG, "Set notification callback"); sntp_set_time_sync_notification_cb(sntp_sync_time_cb);