Remove service helper (5) (#16917)
* Update switch * Update script * Update light * Fix tests * Fix config/script hook * Async_create_task * Fix flux switch
This commit is contained in:
1 parent
a7248d4574
commit
70b901017f
27 files changed
+385
-316
No files matched your search
@@ -3,9 +3,13 @@
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
from homeassistant.core import Context, callback
|
||||
from homeassistant.setup import setup_component
|
||||
from homeassistant.components import script
|
||||
from homeassistant.components.script import DOMAIN
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID, SERVICE_RELOAD, SERVICE_TOGGLE, SERVICE_TURN_OFF)
|
||||
from homeassistant.core import Context, callback, split_entity_id
|
||||
from homeassistant.loader import bind_hass
|
||||
from homeassistant.setup import setup_component
|
||||
|
||||
from tests.common import get_test_home_assistant
|
||||
|
||||
@@ -13,6 +17,44 @@ from tests.common import get_test_home_assistant
|
||||
ENTITY_ID = 'script.test'
|
||||
|
||||
|
||||
@bind_hass
|
||||
def turn_on(hass, entity_id, variables=None, context=None):
|
||||
"""Turn script on.
|
||||
|
||||
This is a legacy helper method. Do not use it for new tests.
|
||||
"""
|
||||
_, object_id = split_entity_id(entity_id)
|
||||
|
||||
hass.services.call(DOMAIN, object_id, variables, context=context)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def turn_off(hass, entity_id):
|
||||
"""Turn script on.
|
||||
|
||||
This is a legacy helper method. Do not use it for new tests.
|
||||
"""
|
||||
hass.services.call(DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: entity_id})
|
||||
|
||||
|
||||
@bind_hass
|
||||
def toggle(hass, entity_id):
|
||||
"""Toggle the script.
|
||||
|
||||
This is a legacy helper method. Do not use it for new tests.
|
||||
"""
|
||||
hass.services.call(DOMAIN, SERVICE_TOGGLE, {ATTR_ENTITY_ID: entity_id})
|
||||
|
||||
|
||||
@bind_hass
|
||||
def reload(hass):
|
||||
"""Reload script component.
|
||||
|
||||
This is a legacy helper method. Do not use it for new tests.
|
||||
"""
|
||||
hass.services.call(DOMAIN, SERVICE_RELOAD)
|
||||
|
||||
|
||||
class TestScriptComponent(unittest.TestCase):
|
||||
"""Test the Script component."""
|
||||
|
||||
@@ -76,17 +118,17 @@ class TestScriptComponent(unittest.TestCase):
|
||||
}
|
||||
})
|
||||
|
||||
script.turn_on(self.hass, ENTITY_ID)
|
||||
turn_on(self.hass, ENTITY_ID)
|
||||
self.hass.block_till_done()
|
||||
self.assertTrue(script.is_on(self.hass, ENTITY_ID))
|
||||
self.assertEqual(0, len(events))
|
||||
|
||||
# Calling turn_on a second time should not advance the script
|
||||
script.turn_on(self.hass, ENTITY_ID)
|
||||
turn_on(self.hass, ENTITY_ID)
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(0, len(events))
|
||||
|
||||
script.turn_off(self.hass, ENTITY_ID)
|
||||
turn_off(self.hass, ENTITY_ID)
|
||||
self.hass.block_till_done()
|
||||
self.assertFalse(script.is_on(self.hass, ENTITY_ID))
|
||||
self.assertEqual(0, len(events))
|
||||
@@ -121,12 +163,12 @@ class TestScriptComponent(unittest.TestCase):
|
||||
}
|
||||
})
|
||||
|
||||
script.toggle(self.hass, ENTITY_ID)
|
||||
toggle(self.hass, ENTITY_ID)
|
||||
self.hass.block_till_done()
|
||||
self.assertTrue(script.is_on(self.hass, ENTITY_ID))
|
||||
self.assertEqual(0, len(events))
|
||||
|
||||
script.toggle(self.hass, ENTITY_ID)
|
||||
toggle(self.hass, ENTITY_ID)
|
||||
self.hass.block_till_done()
|
||||
self.assertFalse(script.is_on(self.hass, ENTITY_ID))
|
||||
self.assertEqual(0, len(events))
|
||||
@@ -156,7 +198,7 @@ class TestScriptComponent(unittest.TestCase):
|
||||
},
|
||||
})
|
||||
|
||||
script.turn_on(self.hass, ENTITY_ID, {
|
||||
turn_on(self.hass, ENTITY_ID, {
|
||||
'greeting': 'world'
|
||||
}, context=context)
|
||||
|
||||
@@ -204,7 +246,7 @@ class TestScriptComponent(unittest.TestCase):
|
||||
}}}):
|
||||
with patch('homeassistant.config.find_config_file',
|
||||
return_value=''):
|
||||
script.reload(self.hass)
|
||||
reload(self.hass)
|
||||
self.hass.block_till_done()
|
||||
|
||||
assert self.hass.states.get(ENTITY_ID) is None
|
||||
|
||||
Reference in new issue
Block a user