Add missing timeout to command_line platforms: cover, notify, switch (#38497)
* Add missing timeout to command_line platforms: cover, notify, switch * add timeout test for notify
This commit is contained in:
1 parent
dddcb8e299
commit
7b728b17f7
11 files changed
+132
-67
No files matched your search
@@ -27,6 +27,7 @@ def rs(hass):
|
||||
"command_stop",
|
||||
"command_state",
|
||||
None,
|
||||
15,
|
||||
)
|
||||
|
||||
|
||||
@@ -45,7 +46,7 @@ def test_query_state_value(rs):
|
||||
assert "foo bar" == result
|
||||
assert mock_run.call_count == 1
|
||||
assert mock_run.call_args == mock.call(
|
||||
"runme", shell=True, # nosec # shell by design
|
||||
"runme", shell=True, timeout=15 # nosec # shell by design
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import tempfile
|
||||
import unittest
|
||||
|
||||
import homeassistant.components.notify as notify
|
||||
from homeassistant.setup import setup_component
|
||||
from homeassistant.setup import async_setup_component, setup_component
|
||||
|
||||
from tests.async_mock import patch
|
||||
from tests.common import assert_setup_component, get_test_home_assistant
|
||||
@@ -93,3 +93,25 @@ class TestCommandLine(unittest.TestCase):
|
||||
"notify", "test", {"message": "error"}, blocking=True
|
||||
)
|
||||
assert mock_error.call_count == 1
|
||||
|
||||
|
||||
async def test_timeout(hass, caplog):
|
||||
"""Test we do not block forever."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
notify.DOMAIN,
|
||||
{
|
||||
"notify": {
|
||||
"name": "test",
|
||||
"platform": "command_line",
|
||||
"command": "sleep 10000",
|
||||
"command_timeout": 0.0000001,
|
||||
}
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert await hass.services.async_call(
|
||||
"notify", "test", {"message": "error"}, blocking=True
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert "Timeout" in caplog.text
|
||||
@@ -74,7 +74,7 @@ class TestCommandSensorSensor(unittest.TestCase):
|
||||
"""Ensure command with templates and quotes get rendered properly."""
|
||||
self.hass.states.set("sensor.test_state", "Works 2")
|
||||
with patch(
|
||||
"homeassistant.components.command_line.sensor.subprocess.check_output",
|
||||
"homeassistant.components.command_line.subprocess.check_output",
|
||||
return_value=b"Works\n",
|
||||
) as check_output:
|
||||
data = command_line.CommandSensorData(
|
||||
|
||||
@@ -180,13 +180,14 @@ class TestCommandSwitch(unittest.TestCase):
|
||||
"echo 'off command'",
|
||||
None,
|
||||
None,
|
||||
15,
|
||||
]
|
||||
|
||||
no_state_device = command_line.CommandSwitch(*init_args)
|
||||
assert no_state_device.assumed_state
|
||||
|
||||
# Set state command
|
||||
init_args[-2] = "cat {}"
|
||||
init_args[-3] = "cat {}"
|
||||
|
||||
state_device = command_line.CommandSwitch(*init_args)
|
||||
assert not state_device.assumed_state
|
||||
@@ -201,6 +202,7 @@ class TestCommandSwitch(unittest.TestCase):
|
||||
"echo 'off command'",
|
||||
False,
|
||||
None,
|
||||
15,
|
||||
]
|
||||
|
||||
test_switch = command_line.CommandSwitch(*init_args)
|
||||
|
||||
Reference in new issue
Block a user