diff --git a/homeassistant/components/automation/time.py b/homeassistant/components/automation/time.py index 1ca714026a2..8ba082e3331 100644 --- a/homeassistant/components/automation/time.py +++ b/homeassistant/components/automation/time.py @@ -10,7 +10,7 @@ import logging import voluptuous as vol from homeassistant.core import callback -from homeassistant.const import CONF_AFTER, CONF_PLATFORM +from homeassistant.const import CONF_AT, CONF_PLATFORM, CONF_AFTER from homeassistant.helpers import config_validation as cv from homeassistant.helpers.event import async_track_time_change @@ -22,20 +22,26 @@ _LOGGER = logging.getLogger(__name__) TRIGGER_SCHEMA = vol.All(vol.Schema({ vol.Required(CONF_PLATFORM): 'time', + CONF_AT: cv.time, CONF_AFTER: cv.time, CONF_HOURS: vol.Any(vol.Coerce(int), vol.Coerce(str)), CONF_MINUTES: vol.Any(vol.Coerce(int), vol.Coerce(str)), CONF_SECONDS: vol.Any(vol.Coerce(int), vol.Coerce(str)), }), cv.has_at_least_one_key(CONF_HOURS, CONF_MINUTES, - CONF_SECONDS, CONF_AFTER)) + CONF_SECONDS, CONF_AT, CONF_AFTER)) @asyncio.coroutine def async_trigger(hass, config, action): """Listen for state changes based on configuration.""" - if CONF_AFTER in config: - after = config.get(CONF_AFTER) - hours, minutes, seconds = after.hour, after.minute, after.second + if CONF_AT in config: + at_time = config.get(CONF_AT) + hours, minutes, seconds = at_time.hour, at_time.minute, at_time.second + elif CONF_AFTER in config: + _LOGGER.warning("'after' is deprecated for the time trigger. Please " + "rename 'after' to 'at' in your configuration file.") + at_time = config.get(CONF_AFTER) + hours, minutes, seconds = at_time.hour, at_time.minute, at_time.second else: hours = config.get(CONF_HOURS) minutes = config.get(CONF_MINUTES) diff --git a/homeassistant/const.py b/homeassistant/const.py index 2e886a992a2..18c73bdb9b7 100644 --- a/homeassistant/const.py +++ b/homeassistant/const.py @@ -59,6 +59,7 @@ CONF_ACCESS_TOKEN = 'access_token' CONF_AFTER = 'after' CONF_ALIAS = 'alias' CONF_API_KEY = 'api_key' +CONF_AT = 'at' CONF_AUTHENTICATION = 'authentication' CONF_BASE = 'base' CONF_BEFORE = 'before' diff --git a/tests/components/automation/test_time.py b/tests/components/automation/test_time.py index 3489699d588..5d5d5ea29ec 100644 --- a/tests/components/automation/test_time.py +++ b/tests/components/automation/test_time.py @@ -179,13 +179,13 @@ class TestAutomationTime(unittest.TestCase): self.hass.block_till_done() self.assertEqual(1, len(self.calls)) - def test_if_fires_using_after(self): - """Test for firing after.""" + def test_if_fires_using_at(self): + """Test for firing at.""" assert setup_component(self.hass, automation.DOMAIN, { automation.DOMAIN: { 'trigger': { 'platform': 'time', - 'after': '5:00:00', + 'at': '5:00:00', }, 'action': { 'service': 'test.automation', @@ -224,7 +224,7 @@ class TestAutomationTime(unittest.TestCase): self.hass.block_till_done() self.assertEqual(0, len(self.calls)) - def test_if_not_fires_using_wrong_after(self): + def test_if_not_fires_using_wrong_at(self): """YAML translates time values to total seconds. This should break the before rule. @@ -234,7 +234,7 @@ class TestAutomationTime(unittest.TestCase): automation.DOMAIN: { 'trigger': { 'platform': 'time', - 'after': 3605, + 'at': 3605, # Total seconds. Hour = 3600 second }, 'action': {