1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-23 12:29:55 +00:00

Add reload service to python_script (#9512)

* Add reload service

* add reload test

* Use global variable

* remove white space ....

* adjust as suggested

* remove annoying white space....

* fix travis

* fix travis, again

* rename Load_scripts to Discover_scripts

Travis complains that "Load_scripts" is an invalid name (I don't know why)

* Update python_script.py
This commit is contained in:
Sébastien RAMAGE
2017-09-21 17:00:45 +02:00
committed by Pascal Vizeli
parent 58cc3a2d7a
commit c26fb9906f
2 changed files with 60 additions and 2 deletions

View File

@@ -203,3 +203,38 @@ hass.states.set('hello.ab_list', '{}'.format(ab_list))
# No errors logged = good
assert caplog.text == ''
@asyncio.coroutine
def test_reload(hass):
"""Test we can re-discover scripts."""
scripts = [
'/some/config/dir/python_scripts/hello.py',
'/some/config/dir/python_scripts/world_beer.py'
]
with patch('homeassistant.components.python_script.os.path.isdir',
return_value=True), \
patch('homeassistant.components.python_script.glob.iglob',
return_value=scripts):
res = yield from async_setup_component(hass, 'python_script', {})
assert res
assert hass.services.has_service('python_script', 'hello')
assert hass.services.has_service('python_script', 'world_beer')
assert hass.services.has_service('python_script', 'reload')
scripts = [
'/some/config/dir/python_scripts/hello2.py',
'/some/config/dir/python_scripts/world_beer.py'
]
with patch('homeassistant.components.python_script.os.path.isdir',
return_value=True), \
patch('homeassistant.components.python_script.glob.iglob',
return_value=scripts):
yield from hass.services.async_call(
'python_script', 'reload', {}, blocking=True)
assert not hass.services.has_service('python_script', 'hello')
assert hass.services.has_service('python_script', 'hello2')
assert hass.services.has_service('python_script', 'world_beer')
assert hass.services.has_service('python_script', 'reload')