From 9b964711822b82e1aa4db3d4f87702582cb974e5 Mon Sep 17 00:00:00 2001 From: Stefan Jonasson Date: Wed, 16 Sep 2015 22:46:21 +0200 Subject: [PATCH 1/5] Fixed after param --- homeassistant/components/automation/time.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/automation/time.py b/homeassistant/components/automation/time.py index 821295fdffa..922b6b8287e 100644 --- a/homeassistant/components/automation/time.py +++ b/homeassistant/components/automation/time.py @@ -22,6 +22,10 @@ WEEKDAYS = ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun'] def trigger(hass, config, action): """ Listen for state changes based on `config`. """ + hours = convert(config.get(CONF_HOURS), int) + minutes = convert(config.get(CONF_MINUTES), int) + seconds = convert(config.get(CONF_SECONDS), int) + if CONF_AFTER in config: after = dt_util.parse_time_str(config[CONF_AFTER]) if after is None: @@ -30,10 +34,6 @@ def trigger(hass, config, action): return False hours, minutes, seconds = after.hour, after.minute, after.second - hours = convert(config.get(CONF_HOURS), int) - minutes = convert(config.get(CONF_MINUTES), int) - seconds = convert(config.get(CONF_SECONDS), int) - def time_automation_listener(now): """ Listens for time changes and calls action. """ action() From e68cc83e64865cffc5b957cbb6852ccb13480c0b Mon Sep 17 00:00:00 2001 From: Stefan Jonasson Date: Thu, 17 Sep 2015 08:24:06 +0200 Subject: [PATCH 2/5] return and output error if none of the 4 keys provided only parse hour/minute/second if after is not available --- homeassistant/components/automation/time.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/automation/time.py b/homeassistant/components/automation/time.py index 922b6b8287e..0f0e2fe38dd 100644 --- a/homeassistant/components/automation/time.py +++ b/homeassistant/components/automation/time.py @@ -19,20 +19,27 @@ CONF_WEEKDAY = "weekday" WEEKDAYS = ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun'] +_LOGGER = logging.getLogger(__name__) + def trigger(hass, config, action): """ Listen for state changes based on `config`. """ - hours = convert(config.get(CONF_HOURS), int) - minutes = convert(config.get(CONF_MINUTES), int) - seconds = convert(config.get(CONF_SECONDS), int) - if CONF_AFTER in config: after = dt_util.parse_time_str(config[CONF_AFTER]) if after is None: - logging.getLogger(__name__).error( + _LOGGER.error( 'Received invalid after value: %s', config[CONF_AFTER]) return False 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) + minutes = convert(config.get(CONF_MINUTES), int) + seconds = convert(config.get(CONF_SECONDS), int) + else: + _LOGGER.error('One of %s, %s, %s OR %s needs to be specified', + CONF_HOURS, CONF_MINUTES, CONF_SECONDS, CONF_AFTER) + return False def time_automation_listener(now): """ Listens for time changes and calls action. """ From 1a00d4a095ea367dc30f911c1344b07164ce5c65 Mon Sep 17 00:00:00 2001 From: Stefan Jonasson Date: Thu, 17 Sep 2015 08:35:18 +0200 Subject: [PATCH 3/5] pylint fix --- homeassistant/components/automation/time.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/automation/time.py b/homeassistant/components/automation/time.py index 0f0e2fe38dd..9c60b766c6f 100644 --- a/homeassistant/components/automation/time.py +++ b/homeassistant/components/automation/time.py @@ -32,13 +32,13 @@ def trigger(hass, config, action): return False hours, minutes, seconds = after.hour, after.minute, after.second elif CONF_HOURS in config or CONF_MINUTES in config \ - or CONF_SECONDS in config: + or CONF_SECONDS in config: hours = convert(config.get(CONF_HOURS), int) minutes = convert(config.get(CONF_MINUTES), int) seconds = convert(config.get(CONF_SECONDS), int) else: _LOGGER.error('One of %s, %s, %s OR %s needs to be specified', - CONF_HOURS, CONF_MINUTES, CONF_SECONDS, CONF_AFTER) + CONF_HOURS, CONF_MINUTES, CONF_SECONDS, CONF_AFTER) return False def time_automation_listener(now): From 47af247d6a4a398f2a1ec903e0a01c865c53406d Mon Sep 17 00:00:00 2001 From: Stefan Jonasson Date: Thu, 17 Sep 2015 08:39:41 +0200 Subject: [PATCH 4/5] flake8 fix --- homeassistant/components/automation/time.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/automation/time.py b/homeassistant/components/automation/time.py index 9c60b766c6f..8679cac8667 100644 --- a/homeassistant/components/automation/time.py +++ b/homeassistant/components/automation/time.py @@ -32,7 +32,7 @@ def trigger(hass, config, action): return False hours, minutes, seconds = after.hour, after.minute, after.second elif CONF_HOURS in config or CONF_MINUTES in config \ - or CONF_SECONDS in config: + or CONF_SECONDS in config: hours = convert(config.get(CONF_HOURS), int) minutes = convert(config.get(CONF_MINUTES), int) seconds = convert(config.get(CONF_SECONDS), int) From 90e2aefd2346eab47890e43aaa04b4705580acb4 Mon Sep 17 00:00:00 2001 From: Stefan Jonasson Date: Thu, 17 Sep 2015 08:55:17 +0200 Subject: [PATCH 5/5] flake8 fix --- homeassistant/components/automation/time.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/automation/time.py b/homeassistant/components/automation/time.py index 8679cac8667..17b0c989f16 100644 --- a/homeassistant/components/automation/time.py +++ b/homeassistant/components/automation/time.py @@ -31,8 +31,8 @@ def trigger(hass, config, action): 'Received invalid after value: %s', config[CONF_AFTER]) return False hours, minutes, seconds = after.hour, after.minute, after.second - elif CONF_HOURS in config or CONF_MINUTES in config \ - or CONF_SECONDS in config: + elif (CONF_HOURS in config or CONF_MINUTES in config + or CONF_SECONDS in config): hours = convert(config.get(CONF_HOURS), int) minutes = convert(config.get(CONF_MINUTES), int) seconds = convert(config.get(CONF_SECONDS), int)