mirror of
https://github.com/home-assistant/core.git
synced 2025-12-23 20:39:01 +00:00
Convert command_line to use asyncio for subprocesses (#111927)
* Convert command_line to use asyncio for subprocesses * fixes * fix * fixes * more test fixes * more fixes * fixes * preen
This commit is contained in:
@@ -30,16 +30,15 @@ from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
import homeassistant.util.dt as dt_util
|
||||
|
||||
from . import mock_asyncio_subprocess_run
|
||||
|
||||
from tests.common import async_fire_time_changed
|
||||
|
||||
|
||||
async def test_no_poll_when_cover_has_no_command_state(hass: HomeAssistant) -> None:
|
||||
"""Test that the cover does not polls when there's no state command."""
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.command_line.utils.subprocess.check_output",
|
||||
return_value=b"50\n",
|
||||
) as check_output:
|
||||
with mock_asyncio_subprocess_run(b"50\n") as mock_subprocess_run:
|
||||
assert await setup.async_setup_component(
|
||||
hass,
|
||||
COVER_DOMAIN,
|
||||
@@ -51,7 +50,7 @@ async def test_no_poll_when_cover_has_no_command_state(hass: HomeAssistant) -> N
|
||||
)
|
||||
async_fire_time_changed(hass, dt_util.utcnow() + SCAN_INTERVAL)
|
||||
await hass.async_block_till_done()
|
||||
assert not check_output.called
|
||||
assert not mock_subprocess_run.called
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -74,17 +73,13 @@ async def test_poll_when_cover_has_command_state(
|
||||
) -> None:
|
||||
"""Test that the cover polls when there's a state command."""
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.command_line.utils.subprocess.check_output",
|
||||
return_value=b"50\n",
|
||||
) as check_output:
|
||||
with mock_asyncio_subprocess_run(b"50\n") as mock_subprocess_run:
|
||||
async_fire_time_changed(hass, dt_util.utcnow() + SCAN_INTERVAL)
|
||||
await hass.async_block_till_done()
|
||||
check_output.assert_called_once_with(
|
||||
mock_subprocess_run.assert_called_once_with(
|
||||
"echo state",
|
||||
shell=True, # noqa: S604 # shell by design
|
||||
timeout=15,
|
||||
close_fds=False,
|
||||
stdout=-1,
|
||||
)
|
||||
|
||||
|
||||
@@ -379,10 +374,7 @@ async def test_availability(
|
||||
|
||||
hass.states.async_set("sensor.input1", "off")
|
||||
await hass.async_block_till_done()
|
||||
with patch(
|
||||
"homeassistant.components.command_line.utils.subprocess.check_output",
|
||||
return_value=b"50\n",
|
||||
):
|
||||
with mock_asyncio_subprocess_run(b"50\n"):
|
||||
freezer.tick(timedelta(minutes=1))
|
||||
async_fire_time_changed(hass)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
Reference in New Issue
Block a user