From ec5d88b98e399e5a726763aed4e60440d07a8594 Mon Sep 17 00:00:00 2001 From: magnusknutas Date: Tue, 26 Jan 2016 17:06:50 +0100 Subject: [PATCH] hourly periodic task --- .gitignore | 1 + homeassistant/components/automation/time.py | 2 +- homeassistant/helpers/event.py | 7 ++++--- tests/helpers/test_event.py | 18 ++++++++++++++++++ 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 90562a0f909..cee7b52c8a0 100644 --- a/.gitignore +++ b/.gitignore @@ -72,6 +72,7 @@ nosetests.xml # venv stuff pyvenv.cfg pip-selfcheck.json +venv # vimmy stuff *.swp diff --git a/homeassistant/components/automation/time.py b/homeassistant/components/automation/time.py index a289741a1f6..81acaeb0dfd 100644 --- a/homeassistant/components/automation/time.py +++ b/homeassistant/components/automation/time.py @@ -34,7 +34,7 @@ def trigger(hass, config, action): hours, minutes, seconds = after.hour, after.minute, after.second elif (CONF_HOURS in config or CONF_MINUTES in config or CONF_SECONDS in config): - hours = convert(config.get(CONF_HOURS), int) + hours = config.get(CONF_HOURS) minutes = config.get(CONF_MINUTES) seconds = config.get(CONF_SECONDS) else: diff --git a/homeassistant/helpers/event.py b/homeassistant/helpers/event.py index 9028e9e64b0..419c80189eb 100644 --- a/homeassistant/helpers/event.py +++ b/homeassistant/helpers/event.py @@ -162,7 +162,7 @@ def track_utc_time_change(hass, action, year=None, month=None, day=None, pmp = _process_match_param year, month, day = pmp(year), pmp(month), pmp(day) - hour, minute, second = pmp(hour), pmp(minute), pmp(second) + hour, minute, second = pmp(hour, rang=24), pmp(minute), pmp(second) @ft.wraps(action) def pattern_time_change_listener(event): @@ -196,12 +196,13 @@ def track_time_change(hass, action, year=None, month=None, day=None, local=True) -def _process_match_param(parameter): +def _process_match_param(parameter, rang=None): """ Wraps parameter in a tuple if it is not one and returns it. """ if parameter is None or parameter == MATCH_ALL: return MATCH_ALL elif isinstance(parameter, str) and parameter.startswith('/'): - return tuple(range(0, 60, convert(parameter.lstrip('/'), int))) + rang = rang or 60 + return tuple(range(0, rang, convert(parameter.lstrip('/'), int))) elif isinstance(parameter, str) or not hasattr(parameter, '__iter__'): return (parameter,) else: diff --git a/tests/helpers/test_event.py b/tests/helpers/test_event.py index 80937f8c33e..7c80a8de22f 100644 --- a/tests/helpers/test_event.py +++ b/tests/helpers/test_event.py @@ -237,3 +237,21 @@ class TestEventHelpers(unittest.TestCase): self._send_time_changed(datetime(2014, 5, 24, 12, 5, 0)) self.hass.pool.block_till_done() self.assertEqual(2, len(specific_runs)) + + def test_periodic_task_hour(self): + specific_runs = [] + + track_utc_time_change( + self.hass, lambda x: specific_runs.append(1), hour='/2') + + self._send_time_changed(datetime(2014, 5, 24, 12, 0, 0)) + self.hass.pool.block_till_done() + self.assertEqual(1, len(specific_runs)) + + self._send_time_changed(datetime(2014, 5, 24, 13, 0, 0)) + self.hass.pool.block_till_done() + self.assertEqual(1, len(specific_runs)) + + self._send_time_changed(datetime(2014, 5, 24, 14, 0, 0)) + self.hass.pool.block_till_done() + self.assertEqual(2, len(specific_runs)) \ No newline at end of file