From 2886b217ab97055edce8aa53185eb65ef66aeb5d Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Fri, 28 Jun 2019 08:49:33 -0700 Subject: [PATCH] Fix calling empty script turn off (#24827) --- homeassistant/components/script/__init__.py | 7 ++++++- tests/components/script/test_init.py | 10 ++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/script/__init__.py b/homeassistant/components/script/__init__.py index 36cb144fada..495df2c5e17 100644 --- a/homeassistant/components/script/__init__.py +++ b/homeassistant/components/script/__init__.py @@ -79,9 +79,14 @@ async def async_setup(hass, config): async def turn_off_service(service): """Cancel a script.""" # Stopping a script is ok to be done in parallel + scripts = await component.async_extract_from_service(service) + + if not scripts: + return + await asyncio.wait([ script.async_turn_off() for script - in await component.async_extract_from_service(service) + in scripts ]) async def toggle_service(service): diff --git a/tests/components/script/test_init.py b/tests/components/script/test_init.py index c2ff17d9444..9e0b751c430 100644 --- a/tests/components/script/test_init.py +++ b/tests/components/script/test_init.py @@ -322,3 +322,13 @@ async def test_logging_script_error(hass, caplog): assert err.value.domain == 'non' assert err.value.service == 'existing' assert 'Error executing script' in caplog.text + + +async def test_turning_no_scripts_off(hass): + """Test it is possible to turn two scripts off.""" + assert await async_setup_component(hass, 'script', {}) + + # Testing it doesn't raise + await hass.services.async_call( + DOMAIN, SERVICE_TURN_OFF, {'entity_id': []}, blocking=True + )