Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove support for old deprecated automation config #1531

Merged
merged 1 commit into from
Mar 14, 2016
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
68 changes: 11 additions & 57 deletions homeassistant/components/automation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
from homeassistant.bootstrap import prepare_setup_platform
from homeassistant.const import CONF_PLATFORM
from homeassistant.components import logbook
from homeassistant.helpers.service import call_from_config
from homeassistant.helpers.service import validate_service_call
from homeassistant.helpers import extract_domain_configs
from homeassistant.helpers.service import (call_from_config,
validate_service_call)


DOMAIN = 'automation'
Expand All @@ -35,29 +36,16 @@

def setup(hass, config):
"""Setup the automation."""
config_key = DOMAIN
found = 1

while config_key in config:
# Check for one block syntax
if isinstance(config[config_key], dict):
config_block = _migrate_old_config(config[config_key])
name = config_block.get(CONF_ALIAS, config_key)
_setup_automation(hass, config_block, name, config)

# Check for multiple block syntax
elif isinstance(config[config_key], list):
for list_no, config_block in enumerate(config[config_key]):
name = config_block.get(CONF_ALIAS,
"{}, {}".format(config_key, list_no))
_setup_automation(hass, config_block, name, config)
for config_key in extract_domain_configs(config, DOMAIN):
conf = config[config_key]

# Any scalar value is incorrect
else:
_LOGGER.error('Error in config in section %s.', config_key)
if not isinstance(conf, list):
conf = [conf]

found += 1
config_key = "{} {}".format(DOMAIN, found)
for list_no, config_block in enumerate(conf):
name = config_block.get(CONF_ALIAS, "{}, {}".format(config_key,
list_no))
_setup_automation(hass, config_block, name, config)

return True

Expand Down Expand Up @@ -97,40 +85,6 @@ def action():
return action


def _migrate_old_config(config):
"""Migrate old configuration to new."""
if CONF_PLATFORM not in config:
return config

_LOGGER.warning(
'You are using an old configuration format. Please upgrade: '
'https://home-assistant.io/components/automation/')

new_conf = {
CONF_TRIGGER: dict(config),
CONF_CONDITION: config.get('if', []),
CONF_ACTION: dict(config),
}

for cat, key, new_key in (('trigger', 'mqtt_topic', 'topic'),
('trigger', 'mqtt_payload', 'payload'),
('trigger', 'state_entity_id', 'entity_id'),
('trigger', 'state_before', 'before'),
('trigger', 'state_after', 'after'),
('trigger', 'state_to', 'to'),
('trigger', 'state_from', 'from'),
('trigger', 'state_hours', 'hours'),
('trigger', 'state_minutes', 'minutes'),
('trigger', 'state_seconds', 'seconds'),
('action', 'execute_service', 'service'),
('action', 'service_entity_id', 'entity_id'),
('action', 'service_data', 'data')):
if key in new_conf[cat]:
new_conf[cat][new_key] = new_conf[cat].pop(key)

return new_conf


def _process_if(hass, config, p_config, action):
"""Process if checks."""
cond_type = p_config.get(CONF_CONDITION_TYPE,
Expand Down
44 changes: 0 additions & 44 deletions tests/components/automation/test_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,50 +24,6 @@ def tearDown(self): # pylint: disable=invalid-name
""""Stop everything that was started."""
self.hass.stop()

def test_old_config_if_fires_on_event(self):
"""."""
self.assertTrue(automation.setup(self.hass, {
automation.DOMAIN: {
'platform': 'event',
'event_type': 'test_event',
'execute_service': 'test.automation'
}
}))

self.hass.bus.fire('test_event')
self.hass.pool.block_till_done()
self.assertEqual(1, len(self.calls))

def test_old_config_if_fires_on_event_with_data(self):
"""Test old configuration ."""
self.assertTrue(automation.setup(self.hass, {
automation.DOMAIN: {
'platform': 'event',
'event_type': 'test_event',
'event_data': {'some_attr': 'some_value'},
'execute_service': 'test.automation'
}
}))

self.hass.bus.fire('test_event', {'some_attr': 'some_value'})
self.hass.pool.block_till_done()
self.assertEqual(1, len(self.calls))

def test_old_config_if_not_fires_if_event_data_not_matches(self):
"""test old configuration."""
self.assertTrue(automation.setup(self.hass, {
automation.DOMAIN: {
'platform': 'event',
'event_type': 'test_event',
'event_data': {'some_attr': 'some_value'},
'execute_service': 'test.automation'
}
}))

self.hass.bus.fire('test_event', {'some_attr': 'some_other_value'})
self.hass.pool.block_till_done()
self.assertEqual(0, len(self.calls))

def test_if_fires_on_event(self):
"""Test the firing of events."""
self.assertTrue(automation.setup(self.hass, {
Expand Down
65 changes: 0 additions & 65 deletions tests/components/automation/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,71 +24,6 @@ def tearDown(self): # pylint: disable=invalid-name
"""Stop everything that was started."""
self.hass.stop()

def test_old_config_service_data_not_a_dict(self):
"""Test old configuration service data."""
automation.setup(self.hass, {
automation.DOMAIN: {
'platform': 'event',
'event_type': 'test_event',
'execute_service': 'test.automation',
'service_data': 100
}
})

self.hass.bus.fire('test_event')
self.hass.pool.block_till_done()
self.assertEqual(1, len(self.calls))

def test_old_config_service_specify_data(self):
"""Test old configuration service data."""
automation.setup(self.hass, {
automation.DOMAIN: {
'platform': 'event',
'event_type': 'test_event',
'execute_service': 'test.automation',
'service_data': {'some': 'data'}
}
})

self.hass.bus.fire('test_event')
self.hass.pool.block_till_done()
self.assertEqual(1, len(self.calls))
self.assertEqual('data', self.calls[0].data['some'])

def test_old_config_service_specify_entity_id(self):
"""Test old configuration service data."""
automation.setup(self.hass, {
automation.DOMAIN: {
'platform': 'event',
'event_type': 'test_event',
'execute_service': 'test.automation',
'service_entity_id': 'hello.world'
}
})

self.hass.bus.fire('test_event')
self.hass.pool.block_till_done()
self.assertEqual(1, len(self.calls))
self.assertEqual(['hello.world'],
self.calls[0].data.get(ATTR_ENTITY_ID))

def test_old_config_service_specify_entity_id_list(self):
"""Test old configuration service data."""
automation.setup(self.hass, {
automation.DOMAIN: {
'platform': 'event',
'event_type': 'test_event',
'execute_service': 'test.automation',
'service_entity_id': ['hello.world', 'hello.world2']
}
})

self.hass.bus.fire('test_event')
self.hass.pool.block_till_done()
self.assertEqual(1, len(self.calls))
self.assertEqual(['hello.world', 'hello.world2'],
self.calls[0].data.get(ATTR_ENTITY_ID))

def test_service_data_not_a_dict(self):
"""Test service data not dict."""
automation.setup(self.hass, {
Expand Down
44 changes: 0 additions & 44 deletions tests/components/automation/test_mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,50 +24,6 @@ def tearDown(self): # pylint: disable=invalid-name
"""Stop everything that was started."""
self.hass.stop()

def test_old_config_if_fires_on_topic_match(self):
"""Test if message is fired on topic match."""
self.assertTrue(automation.setup(self.hass, {
automation.DOMAIN: {
'platform': 'mqtt',
'mqtt_topic': 'test-topic',
'execute_service': 'test.automation'
}
}))

fire_mqtt_message(self.hass, 'test-topic', '')
self.hass.pool.block_till_done()
self.assertEqual(1, len(self.calls))

def test_old_config_if_fires_on_topic_and_payload_match(self):
"""Test if message is fired on topic and payload match."""
self.assertTrue(automation.setup(self.hass, {
automation.DOMAIN: {
'platform': 'mqtt',
'mqtt_topic': 'test-topic',
'mqtt_payload': 'hello',
'execute_service': 'test.automation'
}
}))

fire_mqtt_message(self.hass, 'test-topic', 'hello')
self.hass.pool.block_till_done()
self.assertEqual(1, len(self.calls))

def test_old_config_if_not_fires_on_topic_but_no_payload_match(self):
"""Test if message is not fired on topic but no payload."""
self.assertTrue(automation.setup(self.hass, {
automation.DOMAIN: {
'platform': 'mqtt',
'mqtt_topic': 'test-topic',
'mqtt_payload': 'hello',
'execute_service': 'test.automation'
}
}))

fire_mqtt_message(self.hass, 'test-topic', 'no-hello')
self.hass.pool.block_till_done()
self.assertEqual(0, len(self.calls))

def test_if_fires_on_topic_match(self):
"""Test if message is fired on topic match."""
self.assertTrue(automation.setup(self.hass, {
Expand Down
Loading