-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
time sync notification #1442
time sync notification #1442
Conversation
Hey there @OttoWinter, mind taking a look at this pull request as its been labeled with an integration ( |
fc7cb89
to
7f417cf
Compare
this is a follow-up to #1441 |
Would it make sense to have the on_time_sync be part of the base time component, so that all time sources fire this event? |
Ah, I think this is exactly what was done in this PR. I just was confused by the extra changes for DS1307 |
Right - that's just because I based the branch on the one from the previous PR. Once that one is merged, this one will look a bit cleaner... |
7f417cf
to
6d8cf84
Compare
Is SNTP is forgotten here? |
It should not. The automation should work for all time sources, I don't see a reason why it shouldn't work with SNTP. |
Are you sure? I don't see a call to the base method from sntp |
And you are right! There was none. I was fooled because sntp logged the exact same debug output "Synchronized time: [...]" |
@@ -54,6 +54,7 @@ void SNTPComponent::loop() { | |||
char buf[128]; | |||
time.strftime(buf, sizeof(buf), "%c"); | |||
ESP_LOGD(TAG, "Synchronized time: %s", buf); | |||
this->time_sync_callback_.call(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is going to report false positives, i.e. if the clock is actually synchronized because of e.g. home assistant, there is no way this thing is going to realize that.
This code makes sense if this is the only use of a time component in your whole yaml, but as your intention is to have many I'm pointing this out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your remark is totally valid. but I am fine with this: the 'false positive' in this case is OK.
It may lead to a double write to the RTC in a set-up with DS1307, HA and SNTP enabled for the first synchronization if that happens to be from the HA. If I don't get things wrong, after the initial sync, the SNTP will never sync again, so this is really not a dramatic thing.
Actually, the SNTP component does not care if its own library is responsible for the sync. Independent of this PR, it would write a duplicate "Synchronized time: ..."-log in a configuration with HA and SNTP even it the initial sync was from HA. But as said: I'm OK with that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm ok with that. I'm adding a quick note in the docs so people does not believe is a bug
* add on_time_sync trigger * cleanup lint * fix review remark (sntp didn't trigger callbacks)
* add on_time_sync trigger * cleanup lint * fix review remark (sntp didn't trigger callbacks)
Description:
RFC: is this a valid approach to get notified of time synchronizations that are initiated by other clock sources?
Checklist:
tests/
folder).If user exposed functionality or configuration variables are added/changed: