mirror of
https://github.com/esphome/esphome.git
synced 2024-12-24 14:34:54 +01:00
simplify
This commit is contained in:
parent
5035a1f40e
commit
67c03b02af
1 changed files with 6 additions and 10 deletions
|
@ -26,9 +26,12 @@ static const char *const TAG = "sntp";
|
||||||
|
|
||||||
std::vector<std::pair<optional<struct timeval>, sntp_sync_status_t>> callback_args_;
|
std::vector<std::pair<optional<struct timeval>, sntp_sync_status_t>> callback_args_;
|
||||||
|
|
||||||
static std::function<void(struct timeval *tv)> g_sync_callback = nullptr;
|
void sntp_sync_time_cb(struct timeval *tv) {
|
||||||
|
callback_args_.push_back({});
|
||||||
void sntp_sync_time_cb(struct timeval *tv) { g_sync_callback(tv); }
|
if (tv)
|
||||||
|
callback_args_.back().first = *tv;
|
||||||
|
callback_args_.back().second = sntp_get_sync_status();
|
||||||
|
}
|
||||||
|
|
||||||
void SNTPComponent::setup() {
|
void SNTPComponent::setup() {
|
||||||
#ifndef USE_HOST
|
#ifndef USE_HOST
|
||||||
|
@ -54,13 +57,6 @@ void SNTPComponent::setup() {
|
||||||
sntp_set_sync_interval(this->get_update_interval());
|
sntp_set_sync_interval(this->get_update_interval());
|
||||||
#endif
|
#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");
|
ESP_LOGD(TAG, "Set notification callback");
|
||||||
sntp_set_time_sync_notification_cb(sntp_sync_time_cb);
|
sntp_set_time_sync_notification_cb(sntp_sync_time_cb);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue