mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
Support longer-than-60-second scan_interval and interval_seconds (#5147)
* Update scan_interval and interval_seconds max to 1 day vs. 60 seconds * Format fixes * Add docstring on unittest. * Added and implemented new async_track_time_interval helper. * Format fixes, removed unused import. * Undid whoops on unsub_polling. * Updated unit tests for scan_interval. * Added unit test for track_time_interval. * Allow other forms of time interval input for scan_interval and interval_seconds
This commit is contained in:
committed by
Paulus Schoutsen
parent
f88b5a9c5e
commit
a36ca62445
@@ -15,6 +15,7 @@ from homeassistant.helpers.event import (
|
||||
track_utc_time_change,
|
||||
track_time_change,
|
||||
track_state_change,
|
||||
track_time_interval,
|
||||
track_sunrise,
|
||||
track_sunset,
|
||||
)
|
||||
@@ -187,6 +188,34 @@ class TestEventHelpers(unittest.TestCase):
|
||||
self.assertEqual(5, len(wildcard_runs))
|
||||
self.assertEqual(6, len(wildercard_runs))
|
||||
|
||||
def test_track_time_interval(self):
|
||||
"""Test tracking time interval."""
|
||||
specific_runs = []
|
||||
|
||||
utc_now = dt_util.utcnow()
|
||||
unsub = track_time_interval(
|
||||
self.hass, lambda x: specific_runs.append(1),
|
||||
timedelta(seconds=10)
|
||||
)
|
||||
|
||||
self._send_time_changed(utc_now + timedelta(seconds=5))
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(0, len(specific_runs))
|
||||
|
||||
self._send_time_changed(utc_now + timedelta(seconds=13))
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(1, len(specific_runs))
|
||||
|
||||
self._send_time_changed(utc_now + timedelta(minutes=20))
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(2, len(specific_runs))
|
||||
|
||||
unsub()
|
||||
|
||||
self._send_time_changed(utc_now + timedelta(seconds=30))
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(2, len(specific_runs))
|
||||
|
||||
def test_track_sunrise(self):
|
||||
"""Test track the sunrise."""
|
||||
latitude = 32.87336
|
||||
|
||||
Reference in New Issue
Block a user