Fixes bug in time trigger and adds test for ex. /two

This commit is contained in:
magnusknutas 2016-01-26 20:43:29 +01:00
parent 6f1f8ffea0
commit 33b0f4d05d
3 changed files with 12 additions and 1 deletions

View File

@ -45,7 +45,7 @@ def trigger(hass, config, action):
and not convert(seconds.lstrip('/'), int) % 60 == 0:
_LOGGER.warning('Periodic seconds should be divisible with 60'
'there will be an offset every minute')
if isinstance(minutes, str) and hours.startswith('/') \
if isinstance(hours, str) and hours.startswith('/') \
and not convert(hours.lstrip('/'), int) % 24 == 0:
_LOGGER.warning('Periodic hours should be divisible with 24'
'there will be an offset every midnight')

View File

@ -215,4 +215,5 @@ def _matcher(subject, pattern):
return subject % float(pattern[0].lstrip('/')) == 0
except ValueError:
return False
return MATCH_ALL == pattern or subject in pattern

View File

@ -299,3 +299,13 @@ class TestEventHelpers(unittest.TestCase):
self._send_time_changed(datetime(2016, 5, 2, 0, 0, 0))
self.hass.pool.block_till_done()
self.assertEqual(2, len(specific_runs))
def test_periodic_task_wrong_input(self):
specific_runs = []
track_utc_time_change(
self.hass, lambda x: specific_runs.append(1), year='/two')
self._send_time_changed(datetime(2014, 5, 2, 0, 0, 0))
self.hass.pool.block_till_done()
self.assertEqual(1, len(specific_runs))