Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions homeassistant/components/automation/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
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

Expand All @@ -22,20 +22,26 @@

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)
Expand Down
1 change: 1 addition & 0 deletions homeassistant/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
CONF_AFTER = 'after'
CONF_ALIAS = 'alias'
CONF_API_KEY = 'api_key'
CONF_AT = 'at'
CONF_AUTHENTICATION = 'authentication'
CONF_BASE = 'base'
CONF_BEFORE = 'before'
Expand Down
10 changes: 5 additions & 5 deletions tests/components/automation/test_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,13 @@ def test_if_fires_periodic_hours(self):
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',
Expand Down Expand Up @@ -224,7 +224,7 @@ def test_if_not_working_if_no_values_in_conf_provided(self):
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.
Expand All @@ -234,7 +234,7 @@ def test_if_not_fires_using_wrong_after(self):
automation.DOMAIN: {
'trigger': {
'platform': 'time',
'after': 3605,
'at': 3605,
# Total seconds. Hour = 3600 second
},
'action': {
Expand Down