Merge pull request #406 from balloob/automation-action-config

Change automation action config keys
This commit is contained in:
Paulus Schoutsen 2015-09-19 10:42:37 -07:00
commit 79cdda2bd9
8 changed files with 90 additions and 69 deletions

View File

@ -16,9 +16,9 @@ DOMAIN = 'automation'
DEPENDENCIES = ['group'] DEPENDENCIES = ['group']
CONF_ALIAS = 'alias' CONF_ALIAS = 'alias'
CONF_SERVICE = 'execute_service' CONF_SERVICE = 'service'
CONF_SERVICE_ENTITY_ID = 'service_entity_id' CONF_SERVICE_ENTITY_ID = 'entity_id'
CONF_SERVICE_DATA = 'service_data' CONF_SERVICE_DATA = 'data'
CONF_CONDITION = 'condition' CONF_CONDITION = 'condition'
CONF_ACTION = 'action' CONF_ACTION = 'action'
@ -118,7 +118,10 @@ def _migrate_old_config(config):
('trigger', 'state_from', 'from'), ('trigger', 'state_from', 'from'),
('trigger', 'state_hours', 'hours'), ('trigger', 'state_hours', 'hours'),
('trigger', 'state_minutes', 'minutes'), ('trigger', 'state_minutes', 'minutes'),
('trigger', 'state_seconds', 'seconds')): ('trigger', 'state_seconds', 'seconds'),
('action', 'execute_service', 'service'),
('action', 'service_entity_id', 'entity_id'),
('action', 'service_data', 'data')):
if key in new_conf[cat]: if key in new_conf[cat]:
new_conf[cat][new_key] = new_conf[cat].pop(key) new_conf[cat][new_key] = new_conf[cat].pop(key)

View File

@ -75,7 +75,7 @@ class TestAutomationEvent(unittest.TestCase):
'event_type': 'test_event', 'event_type': 'test_event',
}, },
'action': { 'action': {
'execute_service': 'test.automation', 'service': 'test.automation',
} }
} }
})) }))
@ -93,7 +93,7 @@ class TestAutomationEvent(unittest.TestCase):
'event_data': {'some_attr': 'some_value'} 'event_data': {'some_attr': 'some_value'}
}, },
'action': { 'action': {
'execute_service': 'test.automation', 'service': 'test.automation',
} }
} }
})) }))
@ -111,7 +111,7 @@ class TestAutomationEvent(unittest.TestCase):
'event_data': {'some_attr': 'some_value'} 'event_data': {'some_attr': 'some_value'}
}, },
'action': { 'action': {
'execute_service': 'test.automation', 'service': 'test.automation',
} }
} }
})) }))

View File

@ -10,7 +10,7 @@ import homeassistant.components.automation as automation
from homeassistant.const import ATTR_ENTITY_ID from homeassistant.const import ATTR_ENTITY_ID
class TestAutomationEvent(unittest.TestCase): class TestAutomation(unittest.TestCase):
""" Test the event automation. """ """ Test the event automation. """
def setUp(self): # pylint: disable=invalid-name def setUp(self): # pylint: disable=invalid-name
@ -26,7 +26,7 @@ class TestAutomationEvent(unittest.TestCase):
""" Stop down stuff we started. """ """ Stop down stuff we started. """
self.hass.stop() self.hass.stop()
def test_service_data_not_a_dict(self): def test_old_config_service_data_not_a_dict(self):
automation.setup(self.hass, { automation.setup(self.hass, {
automation.DOMAIN: { automation.DOMAIN: {
'platform': 'event', 'platform': 'event',
@ -87,6 +87,24 @@ class TestAutomationEvent(unittest.TestCase):
self.assertEqual(['hello.world', 'hello.world2'], self.assertEqual(['hello.world', 'hello.world2'],
self.calls[0].data.get(ATTR_ENTITY_ID)) self.calls[0].data.get(ATTR_ENTITY_ID))
def test_service_data_not_a_dict(self):
automation.setup(self.hass, {
automation.DOMAIN: {
'trigger': {
'platform': 'event',
'event_type': 'test_event',
},
'action': {
'service': 'test.automation',
'data': 100,
}
}
})
self.hass.bus.fire('test_event')
self.hass.pool.block_till_done()
self.assertEqual(1, len(self.calls))
def test_service_specify_data(self): def test_service_specify_data(self):
automation.setup(self.hass, { automation.setup(self.hass, {
automation.DOMAIN: { automation.DOMAIN: {
@ -95,8 +113,8 @@ class TestAutomationEvent(unittest.TestCase):
'event_type': 'test_event', 'event_type': 'test_event',
}, },
'action': { 'action': {
'execute_service': 'test.automation', 'service': 'test.automation',
'service_data': {'some': 'data'} 'data': {'some': 'data'}
} }
} }
}) })
@ -114,8 +132,8 @@ class TestAutomationEvent(unittest.TestCase):
'event_type': 'test_event', 'event_type': 'test_event',
}, },
'action': { 'action': {
'execute_service': 'test.automation', 'service': 'test.automation',
'service_entity_id': 'hello.world' 'entity_id': 'hello.world'
} }
} }
}) })
@ -134,8 +152,8 @@ class TestAutomationEvent(unittest.TestCase):
'event_type': 'test_event', 'event_type': 'test_event',
}, },
'action': { 'action': {
'execute_service': 'test.automation', 'service': 'test.automation',
'service_entity_id': ['hello.world', 'hello.world2'] 'entity_id': ['hello.world', 'hello.world2']
} }
} }
}) })
@ -160,7 +178,7 @@ class TestAutomationEvent(unittest.TestCase):
} }
], ],
'action': { 'action': {
'execute_service': 'test.automation', 'service': 'test.automation',
} }
} }
}) })
@ -195,7 +213,7 @@ class TestAutomationEvent(unittest.TestCase):
} }
], ],
'action': { 'action': {
'execute_service': 'test.automation', 'service': 'test.automation',
} }
} }
}) })
@ -239,7 +257,7 @@ class TestAutomationEvent(unittest.TestCase):
} }
], ],
'action': { 'action': {
'execute_service': 'test.automation', 'service': 'test.automation',
} }
} }
}) })
@ -278,7 +296,7 @@ class TestAutomationEvent(unittest.TestCase):
], ],
'condition': 'use_trigger_values', 'condition': 'use_trigger_values',
'action': { 'action': {
'execute_service': 'test.automation', 'service': 'test.automation',
} }
} }
}) })
@ -314,7 +332,7 @@ class TestAutomationEvent(unittest.TestCase):
], ],
'condition': 'use_trigger_values', 'condition': 'use_trigger_values',
'action': { 'action': {
'execute_service': 'test.automation', 'service': 'test.automation',
} }
} }
}) })

View File

@ -77,7 +77,7 @@ class TestAutomationState(unittest.TestCase):
'topic': 'test-topic' 'topic': 'test-topic'
}, },
'action': { 'action': {
'execute_service': 'test.automation' 'service': 'test.automation'
} }
} }
})) }))
@ -95,7 +95,7 @@ class TestAutomationState(unittest.TestCase):
'payload': 'hello' 'payload': 'hello'
}, },
'action': { 'action': {
'execute_service': 'test.automation' 'service': 'test.automation'
} }
} }
})) }))
@ -113,7 +113,7 @@ class TestAutomationState(unittest.TestCase):
'payload': 'hello' 'payload': 'hello'
}, },
'action': { 'action': {
'execute_service': 'test.automation' 'service': 'test.automation'
} }
} }
})) }))

View File

@ -35,7 +35,7 @@ class TestAutomationNumericState(unittest.TestCase):
'below': 10, 'below': 10,
}, },
'action': { 'action': {
'execute_service': 'test.automation' 'service': 'test.automation'
} }
} }
})) }))
@ -56,7 +56,7 @@ class TestAutomationNumericState(unittest.TestCase):
'below': 10, 'below': 10,
}, },
'action': { 'action': {
'execute_service': 'test.automation' 'service': 'test.automation'
} }
} }
})) }))
@ -78,7 +78,7 @@ class TestAutomationNumericState(unittest.TestCase):
'below': 10, 'below': 10,
}, },
'action': { 'action': {
'execute_service': 'test.automation' 'service': 'test.automation'
} }
} }
})) }))
@ -97,7 +97,7 @@ class TestAutomationNumericState(unittest.TestCase):
'above': 10, 'above': 10,
}, },
'action': { 'action': {
'execute_service': 'test.automation' 'service': 'test.automation'
} }
} }
})) }))
@ -119,7 +119,7 @@ class TestAutomationNumericState(unittest.TestCase):
'above': 10, 'above': 10,
}, },
'action': { 'action': {
'execute_service': 'test.automation' 'service': 'test.automation'
} }
} }
})) }))
@ -142,7 +142,7 @@ class TestAutomationNumericState(unittest.TestCase):
'above': 10, 'above': 10,
}, },
'action': { 'action': {
'execute_service': 'test.automation' 'service': 'test.automation'
} }
} }
})) }))
@ -162,7 +162,7 @@ class TestAutomationNumericState(unittest.TestCase):
'above': 5, 'above': 5,
}, },
'action': { 'action': {
'execute_service': 'test.automation' 'service': 'test.automation'
} }
} }
})) }))
@ -181,7 +181,7 @@ class TestAutomationNumericState(unittest.TestCase):
'above': 5, 'above': 5,
}, },
'action': { 'action': {
'execute_service': 'test.automation' 'service': 'test.automation'
} }
} }
})) }))
@ -203,7 +203,7 @@ class TestAutomationNumericState(unittest.TestCase):
'above': 5, 'above': 5,
}, },
'action': { 'action': {
'execute_service': 'test.automation' 'service': 'test.automation'
} }
} }
})) }))
@ -226,7 +226,7 @@ class TestAutomationNumericState(unittest.TestCase):
'above': 5, 'above': 5,
}, },
'action': { 'action': {
'execute_service': 'test.automation' 'service': 'test.automation'
} }
} }
})) }))
@ -244,7 +244,7 @@ class TestAutomationNumericState(unittest.TestCase):
'entity_id': 'test.another_entity', 'entity_id': 'test.another_entity',
}, },
'action': { 'action': {
'execute_service': 'test.automation' 'service': 'test.automation'
} }
} }
})) }))
@ -269,7 +269,7 @@ class TestAutomationNumericState(unittest.TestCase):
'below': test_state + 2 'below': test_state + 2
}, },
'action': { 'action': {
'execute_service': 'test.automation' 'service': 'test.automation'
} }
} }
}) })

View File

@ -164,7 +164,7 @@ class TestAutomationState(unittest.TestCase):
'entity_id': 'test.entity', 'entity_id': 'test.entity',
}, },
'action': { 'action': {
'execute_service': 'test.automation' 'service': 'test.automation'
} }
} }
})) }))
@ -182,7 +182,7 @@ class TestAutomationState(unittest.TestCase):
'from': 'hello' 'from': 'hello'
}, },
'action': { 'action': {
'execute_service': 'test.automation' 'service': 'test.automation'
} }
} }
})) }))
@ -200,7 +200,7 @@ class TestAutomationState(unittest.TestCase):
'to': 'world' 'to': 'world'
}, },
'action': { 'action': {
'execute_service': 'test.automation' 'service': 'test.automation'
} }
} }
})) }))
@ -218,7 +218,7 @@ class TestAutomationState(unittest.TestCase):
'state': 'world' 'state': 'world'
}, },
'action': { 'action': {
'execute_service': 'test.automation' 'service': 'test.automation'
} }
} }
})) }))
@ -237,7 +237,7 @@ class TestAutomationState(unittest.TestCase):
'to': 'world' 'to': 'world'
}, },
'action': { 'action': {
'execute_service': 'test.automation' 'service': 'test.automation'
} }
} }
})) }))
@ -256,7 +256,7 @@ class TestAutomationState(unittest.TestCase):
'to': 'world' 'to': 'world'
}, },
'action': { 'action': {
'execute_service': 'test.automation' 'service': 'test.automation'
} }
} }
})) }))
@ -277,7 +277,7 @@ class TestAutomationState(unittest.TestCase):
'to': 'world' 'to': 'world'
}, },
'action': { 'action': {
'execute_service': 'test.automation' 'service': 'test.automation'
} }
} }
})) }))
@ -294,7 +294,7 @@ class TestAutomationState(unittest.TestCase):
'entity_id': 'test.anoter_entity', 'entity_id': 'test.anoter_entity',
}, },
'action': { 'action': {
'execute_service': 'test.automation' 'service': 'test.automation'
} }
} }
})) }))
@ -318,7 +318,7 @@ class TestAutomationState(unittest.TestCase):
'state': test_state 'state': test_state
}], }],
'action': { 'action': {
'execute_service': 'test.automation' 'service': 'test.automation'
} }
} }
}) })

View File

@ -51,7 +51,7 @@ class TestAutomationSun(unittest.TestCase):
'event': 'sunset', 'event': 'sunset',
}, },
'action': { 'action': {
'execute_service': 'test.automation', 'service': 'test.automation',
} }
} }
})) }))
@ -77,7 +77,7 @@ class TestAutomationSun(unittest.TestCase):
'event': 'sunrise', 'event': 'sunrise',
}, },
'action': { 'action': {
'execute_service': 'test.automation', 'service': 'test.automation',
} }
} }
})) }))
@ -104,7 +104,7 @@ class TestAutomationSun(unittest.TestCase):
'offset': '0:30:00' 'offset': '0:30:00'
}, },
'action': { 'action': {
'execute_service': 'test.automation', 'service': 'test.automation',
} }
} }
})) }))
@ -131,7 +131,7 @@ class TestAutomationSun(unittest.TestCase):
'offset': '-0:30:00' 'offset': '-0:30:00'
}, },
'action': { 'action': {
'execute_service': 'test.automation', 'service': 'test.automation',
} }
} }
})) }))

View File

@ -36,9 +36,9 @@ class TestAutomationTime(unittest.TestCase):
def test_old_config_if_fires_when_hour_matches(self): def test_old_config_if_fires_when_hour_matches(self):
self.assertTrue(automation.setup(self.hass, { self.assertTrue(automation.setup(self.hass, {
automation.DOMAIN: { automation.DOMAIN: {
CONF_PLATFORM: 'time', 'platform': 'time',
time.CONF_HOURS: 0, time.CONF_HOURS: 0,
automation.CONF_SERVICE: 'test.automation' 'execute_service': 'test.automation'
} }
})) }))
@ -51,9 +51,9 @@ class TestAutomationTime(unittest.TestCase):
def test_old_config_if_fires_when_minute_matches(self): def test_old_config_if_fires_when_minute_matches(self):
self.assertTrue(automation.setup(self.hass, { self.assertTrue(automation.setup(self.hass, {
automation.DOMAIN: { automation.DOMAIN: {
CONF_PLATFORM: 'time', 'platform': 'time',
time.CONF_MINUTES: 0, time.CONF_MINUTES: 0,
automation.CONF_SERVICE: 'test.automation' 'execute_service': 'test.automation'
} }
})) }))
@ -66,9 +66,9 @@ class TestAutomationTime(unittest.TestCase):
def test_old_config_if_fires_when_second_matches(self): def test_old_config_if_fires_when_second_matches(self):
self.assertTrue(automation.setup(self.hass, { self.assertTrue(automation.setup(self.hass, {
automation.DOMAIN: { automation.DOMAIN: {
CONF_PLATFORM: 'time', 'platform': 'time',
time.CONF_SECONDS: 0, time.CONF_SECONDS: 0,
automation.CONF_SERVICE: 'test.automation' 'execute_service': 'test.automation'
} }
})) }))
@ -85,7 +85,7 @@ class TestAutomationTime(unittest.TestCase):
time.CONF_HOURS: 0, time.CONF_HOURS: 0,
time.CONF_MINUTES: 0, time.CONF_MINUTES: 0,
time.CONF_SECONDS: 0, time.CONF_SECONDS: 0,
automation.CONF_SERVICE: 'test.automation' 'execute_service': 'test.automation'
} }
})) }))
@ -101,7 +101,7 @@ class TestAutomationTime(unittest.TestCase):
automation.DOMAIN: { automation.DOMAIN: {
CONF_PLATFORM: 'event', CONF_PLATFORM: 'event',
event.CONF_EVENT_TYPE: 'test_event', event.CONF_EVENT_TYPE: 'test_event',
automation.CONF_SERVICE: 'test.automation', 'execute_service': 'test.automation',
'if': { 'if': {
CONF_PLATFORM: 'time', CONF_PLATFORM: 'time',
time.CONF_BEFORE: '10:00' time.CONF_BEFORE: '10:00'
@ -131,7 +131,7 @@ class TestAutomationTime(unittest.TestCase):
automation.DOMAIN: { automation.DOMAIN: {
CONF_PLATFORM: 'event', CONF_PLATFORM: 'event',
event.CONF_EVENT_TYPE: 'test_event', event.CONF_EVENT_TYPE: 'test_event',
automation.CONF_SERVICE: 'test.automation', 'execute_service': 'test.automation',
'if': { 'if': {
CONF_PLATFORM: 'time', CONF_PLATFORM: 'time',
time.CONF_AFTER: '10:00' time.CONF_AFTER: '10:00'
@ -161,7 +161,7 @@ class TestAutomationTime(unittest.TestCase):
automation.DOMAIN: { automation.DOMAIN: {
CONF_PLATFORM: 'event', CONF_PLATFORM: 'event',
event.CONF_EVENT_TYPE: 'test_event', event.CONF_EVENT_TYPE: 'test_event',
automation.CONF_SERVICE: 'test.automation', 'execute_service': 'test.automation',
'if': { 'if': {
CONF_PLATFORM: 'time', CONF_PLATFORM: 'time',
time.CONF_WEEKDAY: 'mon', time.CONF_WEEKDAY: 'mon',
@ -192,7 +192,7 @@ class TestAutomationTime(unittest.TestCase):
automation.DOMAIN: { automation.DOMAIN: {
CONF_PLATFORM: 'event', CONF_PLATFORM: 'event',
event.CONF_EVENT_TYPE: 'test_event', event.CONF_EVENT_TYPE: 'test_event',
automation.CONF_SERVICE: 'test.automation', 'execute_service': 'test.automation',
'if': { 'if': {
CONF_PLATFORM: 'time', CONF_PLATFORM: 'time',
time.CONF_WEEKDAY: ['mon', 'tue'], time.CONF_WEEKDAY: ['mon', 'tue'],
@ -234,7 +234,7 @@ class TestAutomationTime(unittest.TestCase):
'hours': 0, 'hours': 0,
}, },
'action': { 'action': {
'execute_service': 'test.automation' 'service': 'test.automation'
} }
} }
})) }))
@ -252,7 +252,7 @@ class TestAutomationTime(unittest.TestCase):
'minutes': 0, 'minutes': 0,
}, },
'action': { 'action': {
'execute_service': 'test.automation' 'service': 'test.automation'
} }
} }
})) }))
@ -270,7 +270,7 @@ class TestAutomationTime(unittest.TestCase):
'seconds': 0, 'seconds': 0,
}, },
'action': { 'action': {
'execute_service': 'test.automation' 'service': 'test.automation'
} }
} }
})) }))
@ -290,7 +290,7 @@ class TestAutomationTime(unittest.TestCase):
'seconds': 3, 'seconds': 3,
}, },
'action': { 'action': {
'execute_service': 'test.automation' 'service': 'test.automation'
} }
} }
})) }))
@ -309,7 +309,7 @@ class TestAutomationTime(unittest.TestCase):
'after': '5:00:00', 'after': '5:00:00',
}, },
'action': { 'action': {
'execute_service': 'test.automation' 'service': 'test.automation'
} }
} }
})) }))
@ -332,7 +332,7 @@ class TestAutomationTime(unittest.TestCase):
# Total seconds. Hour = 3600 second # Total seconds. Hour = 3600 second
}, },
'action': { 'action': {
'execute_service': 'test.automation' 'service': 'test.automation'
} }
} }
})) }))
@ -356,7 +356,7 @@ class TestAutomationTime(unittest.TestCase):
'before': '10:00', 'before': '10:00',
}, },
'action': { 'action': {
'execute_service': 'test.automation' 'service': 'test.automation'
} }
} }
}) })
@ -390,7 +390,7 @@ class TestAutomationTime(unittest.TestCase):
'after': '10:00', 'after': '10:00',
}, },
'action': { 'action': {
'execute_service': 'test.automation' 'service': 'test.automation'
} }
} }
}) })
@ -424,7 +424,7 @@ class TestAutomationTime(unittest.TestCase):
'weekday': 'mon', 'weekday': 'mon',
}, },
'action': { 'action': {
'execute_service': 'test.automation' 'service': 'test.automation'
} }
} }
}) })
@ -459,7 +459,7 @@ class TestAutomationTime(unittest.TestCase):
'weekday': ['mon', 'tue'], 'weekday': ['mon', 'tue'],
}, },
'action': { 'action': {
'execute_service': 'test.automation' 'service': 'test.automation'
} }
} }
}) })