Skip to content
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

Improve precision of timer ticks #16598

Merged
merged 1 commit into from
Sep 14, 2018

Conversation

amelchio
Copy link
Contributor

Description:

The timer tries to tick a whole number of seconds since it was started. Thus, if it is started very close to a second rolling over, many ticks will fire on the wrong second. This is because we are usually a little bit late with scheduled tasks. I added a log statement to show this.

2018-07-29 09:27:16 [...] Timer tick 2018-07-29 07:27:16.998479+00:00
2018-07-29 09:27:18 [...] Timer tick 2018-07-29 07:27:18.000322+00:00 <-- :17
2018-07-29 09:27:18 [...] Timer tick 2018-07-29 07:27:18.995209+00:00
2018-07-29 09:27:20 [...] Timer tick 2018-07-29 07:27:20.000136+00:00 <-- :19
2018-07-29 09:27:21 [...] Timer tick 2018-07-29 07:27:21.000139+00:00 <-- :20
2018-07-29 09:27:22 [...] Timer tick 2018-07-29 07:27:22.000105+00:00 <-- :21
2018-07-29 09:27:22 [...] Timer tick 2018-07-29 07:27:22.999665+00:00

To help avoid these double and missed ticks, this PR delays the first tick until a second rolls over. This means that we can be almost one second late and still work as expected.

This is just an improvement, more complete fixes are discussed in home-assistant/architecture#50.

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox.

If the code does not interact with devices:

  • Tests have been added to verify that the new code works.

@amelchio amelchio requested a review from a team as a code owner September 13, 2018 16:23
@homeassistant homeassistant added cla-signed core small-pr PRs with less than 30 lines. labels Sep 13, 2018
@ghost ghost assigned amelchio Sep 13, 2018
@ghost ghost added the in progress label Sep 13, 2018
@balloob balloob merged commit e82e75b into home-assistant:dev Sep 14, 2018
@ghost ghost removed the in progress label Sep 14, 2018
@balloob
Copy link
Member

balloob commented Sep 14, 2018

This is a good smaller version of the other PR.

@pvizeli
Copy link
Member

pvizeli commented Sep 15, 2018

I think on reset we need also fallback to slp_seconds = 1 - (dt_util.utcnow().microsecond / 10**6)

@amelchio
Copy link
Contributor Author

Thanks, that’s right. I will make the PR.

@amelchio amelchio mentioned this pull request Sep 16, 2018
3 tasks
@balloob balloob mentioned this pull request Sep 28, 2018
@home-assistant home-assistant locked and limited conversation to collaborators Feb 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla-signed core small-pr PRs with less than 30 lines.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants