Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
HomeAssistant
Core
Commits
e82e75ba
Commit
e82e75ba
authored
6 years ago
by
Anders Melchiorsen
Committed by
Paulus Schoutsen
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Improve precision of timer ticks (#16598)
parent
481f6e09
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
homeassistant/core.py
+2
-1
2 additions, 1 deletion
homeassistant/core.py
tests/test_core.py
+20
-6
20 additions, 6 deletions
tests/test_core.py
with
22 additions
and
7 deletions
homeassistant/core.py
+
2
−
1
View file @
e82e75ba
...
...
@@ -1256,4 +1256,5 @@ def _async_create_timer(hass: HomeAssistant) -> None:
hass
.
bus
.
async_listen_once
(
EVENT_HOMEASSISTANT_STOP
,
stop_timer
)
_LOGGER
.
info
(
"
Timer:starting
"
)
fire_time_event
(
monotonic
())
slp_seconds
=
1
-
(
dt_util
.
utcnow
().
microsecond
/
10
**
6
)
hass
.
loop
.
call_later
(
slp_seconds
,
lambda
:
fire_time_event
(
monotonic
()))
This diff is collapsed.
Click to expand it.
tests/test_core.py
+
20
−
6
View file @
e82e75ba
...
...
@@ -862,21 +862,29 @@ def test_create_timer(mock_monotonic, loop):
with
patch
.
object
(
ha
,
'
callback
'
,
mock_callback
),
\
patch
(
'
homeassistant.core.dt_util.utcnow
'
,
return_value
=
sentinel
.
mock_date
):
return_value
=
datetime
(
2018
,
12
,
31
,
3
,
4
,
5
,
333333
)
):
ha
.
_async_create_timer
(
hass
)
assert
len
(
hass
.
loop
.
call_later
.
mock_calls
)
==
1
slp_seconds
,
action
=
hass
.
loop
.
call_later
.
mock_calls
[
0
][
1
]
assert
abs
(
slp_seconds
-
0.666667
)
<
0.001
with
patch
(
'
homeassistant.core.dt_util.utcnow
'
,
return_value
=
sentinel
.
mock_date
):
action
()
assert
len
(
funcs
)
==
2
fire_time_event
,
stop_timer
=
funcs
assert
len
(
hass
.
bus
.
async_listen_once
.
mock_calls
)
==
1
assert
len
(
hass
.
bus
.
async_fire
.
mock_calls
)
==
1
assert
len
(
hass
.
loop
.
call_later
.
mock_calls
)
==
1
assert
len
(
hass
.
loop
.
call_later
.
mock_calls
)
==
2
event_type
,
callback
=
hass
.
bus
.
async_listen_once
.
mock_calls
[
0
][
1
]
assert
event_type
==
EVENT_HOMEASSISTANT_STOP
assert
callback
is
stop_timer
slp_seconds
,
callback
,
nxt
=
hass
.
loop
.
call_later
.
mock_calls
[
0
][
1
]
slp_seconds
,
callback
,
nxt
=
hass
.
loop
.
call_later
.
mock_calls
[
1
][
1
]
assert
abs
(
slp_seconds
-
0.9
)
<
0.001
assert
callback
is
fire_time_event
assert
abs
(
nxt
-
11.2
)
<
0.001
...
...
@@ -901,15 +909,21 @@ def test_timer_out_of_sync(mock_monotonic, loop):
with
patch
.
object
(
ha
,
'
callback
'
,
mock_callback
),
\
patch
(
'
homeassistant.core.dt_util.utcnow
'
,
return_value
=
sentinel
.
mock_date
):
return_value
=
datetime
(
2018
,
12
,
31
,
3
,
4
,
5
,
333333
)
):
ha
.
_async_create_timer
(
hass
)
_
,
action
=
hass
.
loop
.
call_later
.
mock_calls
[
0
][
1
]
with
patch
(
'
homeassistant.core.dt_util.utcnow
'
,
return_value
=
sentinel
.
mock_date
):
action
()
assert
len
(
funcs
)
==
2
fire_time_event
,
stop_timer
=
funcs
assert
len
(
hass
.
loop
.
call_later
.
mock_calls
)
==
1
assert
len
(
hass
.
loop
.
call_later
.
mock_calls
)
==
2
slp_seconds
,
callback
,
nxt
=
hass
.
loop
.
call_later
.
mock_calls
[
0
][
1
]
slp_seconds
,
callback
,
nxt
=
hass
.
loop
.
call_later
.
mock_calls
[
1
][
1
]
assert
slp_seconds
==
1
assert
callback
is
fire_time_event
assert
abs
(
nxt
-
12.3
)
<
0.001
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment