From e4666206ec1f83c29ed42169e7d5015c5d659254 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 18 Nov 2022 21:04:19 -0600 Subject: [PATCH] Improve time change helper comments (#82349) * Improve time change helper comments https://github.com/home-assistant/core/pull/82324#discussion_r1026962806 * Improve time change helper comments https://github.com/home-assistant/core/pull/82324#discussion_r1026962806 --- tests/common.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/tests/common.py b/tests/common.py index b1eec13a851..48e51303a0c 100644 --- a/tests/common.py +++ b/tests/common.py @@ -385,10 +385,10 @@ def async_fire_time_changed_exact( ) -> None: """Fire a time changed event at an exact microsecond. - Consider that its not possible to actually achieve an exact microsecond - in production as the event loop is not precise enough. If your code - relies on this level of precision, consider a different approach - as this is only for testing. + Consider that it is not possible to actually achieve an exact + microsecond in production as the event loop is not precise enough. + If your code relies on this level of precision, consider a different + approach, as this is only for testing. """ if datetime_ is None: utc_datetime = date_util.utcnow() @@ -404,10 +404,13 @@ def async_fire_time_changed( ) -> None: """Fire a time changed event. - This function will ensure microseconds at at least 500000 - to account for the synchronization repeating listeners. + This function will add up to 0.5 seconds to the time to ensure that + it accounts for the accidental synchronization avoidance code in repeating + listeners. - If you need to fire an exact microsecond, use async_fire_time_changed_exact. + As asyncio is cooperative, we can't guarantee that the event loop will + run an event at the exact time we want. If you need to fire time changed + for an exact microsecond, use async_fire_time_changed_exact. """ if datetime_ is None: utc_datetime = date_util.utcnow()