Add actions.
This commit is contained in:
1 parent
9a9dbcfaea
commit
5521096c02
2 files changed
+76
-2
No files matched your search
@@ -6,6 +6,7 @@ Tests template switch.
|
||||
"""
|
||||
|
||||
import homeassistant.core as ha
|
||||
import homeassistant.components as core
|
||||
import homeassistant.components.switch as switch
|
||||
|
||||
from homeassistant.const import (
|
||||
@@ -19,6 +20,14 @@ class TestTemplateSwitch:
|
||||
def setup_method(self, method):
|
||||
self.hass = ha.HomeAssistant()
|
||||
|
||||
self.calls = []
|
||||
|
||||
def record_call(service):
|
||||
self.calls.append(service)
|
||||
|
||||
self.hass.services.register('test', 'automation', record_call)
|
||||
|
||||
|
||||
def teardown_method(self, method):
|
||||
""" Stop down stuff we started. """
|
||||
self.hass.stop()
|
||||
@@ -238,3 +247,65 @@ class TestTemplateSwitch:
|
||||
}
|
||||
})
|
||||
assert self.hass.states.all() == []
|
||||
|
||||
def test_on_action(self):
|
||||
assert switch.setup(self.hass, {
|
||||
'switch': {
|
||||
'platform': 'template',
|
||||
'switches': {
|
||||
'test_template_switch': {
|
||||
'value_template':
|
||||
"{{ states.switch.test_state.state }}",
|
||||
'turn_on': {
|
||||
'service': 'test.automation'
|
||||
},
|
||||
'turn_off': {
|
||||
'service': 'switch.turn_off',
|
||||
'entity_id': 'switch.test_state'
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
self.hass.states.set('switch.test_state', STATE_OFF)
|
||||
self.hass.pool.block_till_done()
|
||||
|
||||
state = self.hass.states.get('switch.test_template_switch')
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
core.switch.turn_on(self.hass, 'switch.test_template_switch')
|
||||
self.hass.pool.block_till_done()
|
||||
|
||||
assert 1 == len(self.calls)
|
||||
|
||||
|
||||
def test_off_action(self):
|
||||
assert switch.setup(self.hass, {
|
||||
'switch': {
|
||||
'platform': 'template',
|
||||
'switches': {
|
||||
'test_template_switch': {
|
||||
'value_template':
|
||||
"{{ states.switch.test_state.state }}",
|
||||
'turn_on': {
|
||||
'service': 'switch.turn_on',
|
||||
'entity_id': 'switch.test_state'
|
||||
|
||||
},
|
||||
'turn_off': {
|
||||
'service': 'test.automation'
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
self.hass.states.set('switch.test_state', STATE_ON)
|
||||
self.hass.pool.block_till_done()
|
||||
|
||||
state = self.hass.states.get('switch.test_template_switch')
|
||||
assert state.state == STATE_ON
|
||||
|
||||
core.switch.turn_off(self.hass, 'switch.test_template_switch')
|
||||
self.hass.pool.block_till_done()
|
||||
|
||||
assert 1 == len(self.calls)
|
||||
Reference in new issue
Block a user