From e68cc83e64865cffc5b957cbb6852ccb13480c0b Mon Sep 17 00:00:00 2001 From: Stefan Jonasson <stefan.jonasson@sitedirect.se> Date: Thu, 17 Sep 2015 08:24:06 +0200 Subject: [PATCH] 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. """ -- GitLab