mirror of
https://github.com/home-assistant/core.git
synced 2025-07-28 15:47:12 +00:00
Remove deprecated automation keywords (#8510)
* Remove deprecated automation keywords * Remove retired test case * Remove retired keyword
This commit is contained in:
parent
8c9b3898fc
commit
b83ff739bc
@ -12,13 +12,11 @@ import homeassistant.util.dt as dt_util
|
|||||||
from homeassistant.const import MATCH_ALL, CONF_PLATFORM
|
from homeassistant.const import MATCH_ALL, CONF_PLATFORM
|
||||||
from homeassistant.helpers.event import (
|
from homeassistant.helpers.event import (
|
||||||
async_track_state_change, async_track_point_in_utc_time)
|
async_track_state_change, async_track_point_in_utc_time)
|
||||||
from homeassistant.helpers.deprecation import get_deprecated
|
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
|
||||||
CONF_ENTITY_ID = 'entity_id'
|
CONF_ENTITY_ID = 'entity_id'
|
||||||
CONF_FROM = 'from'
|
CONF_FROM = 'from'
|
||||||
CONF_TO = 'to'
|
CONF_TO = 'to'
|
||||||
CONF_STATE = 'state'
|
|
||||||
CONF_FOR = 'for'
|
CONF_FOR = 'for'
|
||||||
|
|
||||||
TRIGGER_SCHEMA = vol.All(
|
TRIGGER_SCHEMA = vol.All(
|
||||||
@ -28,11 +26,9 @@ TRIGGER_SCHEMA = vol.All(
|
|||||||
# These are str on purpose. Want to catch YAML conversions
|
# These are str on purpose. Want to catch YAML conversions
|
||||||
CONF_FROM: str,
|
CONF_FROM: str,
|
||||||
CONF_TO: str,
|
CONF_TO: str,
|
||||||
CONF_STATE: str,
|
|
||||||
CONF_FOR: vol.All(cv.time_period, cv.positive_timedelta),
|
CONF_FOR: vol.All(cv.time_period, cv.positive_timedelta),
|
||||||
}),
|
}),
|
||||||
vol.Any(cv.key_dependency(CONF_FOR, CONF_TO),
|
cv.key_dependency(CONF_FOR, CONF_TO),
|
||||||
cv.key_dependency(CONF_FOR, CONF_STATE))
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -41,7 +37,7 @@ def async_trigger(hass, config, action):
|
|||||||
"""Listen for state changes based on configuration."""
|
"""Listen for state changes based on configuration."""
|
||||||
entity_id = config.get(CONF_ENTITY_ID)
|
entity_id = config.get(CONF_ENTITY_ID)
|
||||||
from_state = config.get(CONF_FROM, MATCH_ALL)
|
from_state = config.get(CONF_FROM, MATCH_ALL)
|
||||||
to_state = get_deprecated(config, CONF_TO, CONF_STATE, MATCH_ALL)
|
to_state = config.get(CONF_TO, MATCH_ALL)
|
||||||
time_delta = config.get(CONF_FOR)
|
time_delta = config.get(CONF_FOR)
|
||||||
async_remove_state_for_cancel = None
|
async_remove_state_for_cancel = None
|
||||||
async_remove_state_for_listener = None
|
async_remove_state_for_listener = None
|
||||||
|
@ -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_AT, CONF_PLATFORM, CONF_AFTER
|
from homeassistant.const import CONF_AT, CONF_PLATFORM
|
||||||
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
|
||||||
|
|
||||||
@ -23,12 +23,10 @@ _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_AT: 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_AT))
|
||||||
CONF_SECONDS, CONF_AT, CONF_AFTER))
|
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
@ -37,11 +35,6 @@ def async_trigger(hass, config, action):
|
|||||||
if CONF_AT in config:
|
if CONF_AT in config:
|
||||||
at_time = config.get(CONF_AT)
|
at_time = config.get(CONF_AT)
|
||||||
hours, minutes, seconds = at_time.hour, at_time.minute, at_time.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)
|
||||||
|
@ -130,25 +130,6 @@ class TestAutomationState(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_on_entity_change_with_state_filter(self):
|
|
||||||
"""Test for firing on entity change with state filter."""
|
|
||||||
assert setup_component(self.hass, automation.DOMAIN, {
|
|
||||||
automation.DOMAIN: {
|
|
||||||
'trigger': {
|
|
||||||
'platform': 'state',
|
|
||||||
'entity_id': 'test.entity',
|
|
||||||
'state': 'world'
|
|
||||||
},
|
|
||||||
'action': {
|
|
||||||
'service': 'test.automation'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
self.hass.states.set('test.entity', 'world')
|
|
||||||
self.hass.block_till_done()
|
|
||||||
self.assertEqual(1, len(self.calls))
|
|
||||||
|
|
||||||
def test_if_fires_on_entity_change_with_both_filters(self):
|
def test_if_fires_on_entity_change_with_both_filters(self):
|
||||||
"""Test for firing if both filters are a non match."""
|
"""Test for firing if both filters are a non match."""
|
||||||
assert setup_component(self.hass, automation.DOMAIN, {
|
assert setup_component(self.hass, automation.DOMAIN, {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user