mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Rename time trigger 'after' to 'at' (#7846)
This commit is contained in:
parent
4bcbeef480
commit
cf42303afb
@ -10,7 +10,7 @@ import logging
|
|||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.core import callback
|
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 import config_validation as cv
|
||||||
from homeassistant.helpers.event import async_track_time_change
|
from homeassistant.helpers.event import async_track_time_change
|
||||||
|
|
||||||
@ -22,20 +22,26 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
|
|
||||||
TRIGGER_SCHEMA = vol.All(vol.Schema({
|
TRIGGER_SCHEMA = vol.All(vol.Schema({
|
||||||
vol.Required(CONF_PLATFORM): 'time',
|
vol.Required(CONF_PLATFORM): 'time',
|
||||||
|
CONF_AT: cv.time,
|
||||||
CONF_AFTER: cv.time,
|
CONF_AFTER: cv.time,
|
||||||
CONF_HOURS: vol.Any(vol.Coerce(int), vol.Coerce(str)),
|
CONF_HOURS: vol.Any(vol.Coerce(int), vol.Coerce(str)),
|
||||||
CONF_MINUTES: 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)),
|
CONF_SECONDS: vol.Any(vol.Coerce(int), vol.Coerce(str)),
|
||||||
}), cv.has_at_least_one_key(CONF_HOURS, CONF_MINUTES,
|
}), cv.has_at_least_one_key(CONF_HOURS, CONF_MINUTES,
|
||||||
CONF_SECONDS, CONF_AFTER))
|
CONF_SECONDS, CONF_AT, CONF_AFTER))
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def async_trigger(hass, config, action):
|
def async_trigger(hass, config, action):
|
||||||
"""Listen for state changes based on configuration."""
|
"""Listen for state changes based on configuration."""
|
||||||
if CONF_AFTER in config:
|
if CONF_AT in config:
|
||||||
after = config.get(CONF_AFTER)
|
at_time = config.get(CONF_AT)
|
||||||
hours, minutes, seconds = after.hour, after.minute, after.second
|
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:
|
else:
|
||||||
hours = config.get(CONF_HOURS)
|
hours = config.get(CONF_HOURS)
|
||||||
minutes = config.get(CONF_MINUTES)
|
minutes = config.get(CONF_MINUTES)
|
||||||
|
@ -59,6 +59,7 @@ CONF_ACCESS_TOKEN = 'access_token'
|
|||||||
CONF_AFTER = 'after'
|
CONF_AFTER = 'after'
|
||||||
CONF_ALIAS = 'alias'
|
CONF_ALIAS = 'alias'
|
||||||
CONF_API_KEY = 'api_key'
|
CONF_API_KEY = 'api_key'
|
||||||
|
CONF_AT = 'at'
|
||||||
CONF_AUTHENTICATION = 'authentication'
|
CONF_AUTHENTICATION = 'authentication'
|
||||||
CONF_BASE = 'base'
|
CONF_BASE = 'base'
|
||||||
CONF_BEFORE = 'before'
|
CONF_BEFORE = 'before'
|
||||||
|
@ -179,13 +179,13 @@ class TestAutomationTime(unittest.TestCase):
|
|||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
self.assertEqual(1, len(self.calls))
|
||||||
|
|
||||||
def test_if_fires_using_after(self):
|
def test_if_fires_using_at(self):
|
||||||
"""Test for firing after."""
|
"""Test for firing at."""
|
||||||
assert setup_component(self.hass, automation.DOMAIN, {
|
assert setup_component(self.hass, automation.DOMAIN, {
|
||||||
automation.DOMAIN: {
|
automation.DOMAIN: {
|
||||||
'trigger': {
|
'trigger': {
|
||||||
'platform': 'time',
|
'platform': 'time',
|
||||||
'after': '5:00:00',
|
'at': '5:00:00',
|
||||||
},
|
},
|
||||||
'action': {
|
'action': {
|
||||||
'service': 'test.automation',
|
'service': 'test.automation',
|
||||||
@ -224,7 +224,7 @@ class TestAutomationTime(unittest.TestCase):
|
|||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(0, len(self.calls))
|
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.
|
"""YAML translates time values to total seconds.
|
||||||
|
|
||||||
This should break the before rule.
|
This should break the before rule.
|
||||||
@ -234,7 +234,7 @@ class TestAutomationTime(unittest.TestCase):
|
|||||||
automation.DOMAIN: {
|
automation.DOMAIN: {
|
||||||
'trigger': {
|
'trigger': {
|
||||||
'platform': 'time',
|
'platform': 'time',
|
||||||
'after': 3605,
|
'at': 3605,
|
||||||
# Total seconds. Hour = 3600 second
|
# Total seconds. Hour = 3600 second
|
||||||
},
|
},
|
||||||
'action': {
|
'action': {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user