diff --git a/tests/components/command_line/test_binary_sensor.py b/tests/components/command_line/test_binary_sensor.py index 9e97f053e07..910288d6920 100644 --- a/tests/components/command_line/test_binary_sensor.py +++ b/tests/components/command_line/test_binary_sensor.py @@ -240,16 +240,18 @@ async def test_updating_to_often( ) await hass.async_block_till_done() - assert len(called) == 1 + assert called assert ( "Updating Command Line Binary Sensor Test took longer than the scheduled update interval" not in caplog.text ) + called.clear() + caplog.clear() async_fire_time_changed(hass, dt_util.now() + timedelta(seconds=1)) await hass.async_block_till_done() - assert len(called) == 2 + assert called assert ( "Updating Command Line Binary Sensor Test took longer than the scheduled update interval" in caplog.text @@ -266,13 +268,11 @@ async def test_updating_manually( called = [] class MockCommandBinarySensor(CommandBinarySensor): - """Mock entity that updates slow.""" + """Mock entity that updates.""" async def _async_update(self) -> None: - """Update slow.""" + """Update.""" called.append(1) - # Add waiting time - await asyncio.sleep(1) with patch( "homeassistant.components.command_line.binary_sensor.CommandBinarySensor", @@ -297,7 +297,8 @@ async def test_updating_manually( ) await hass.async_block_till_done() - assert len(called) == 1 + assert called + called.clear await hass.services.async_call( HA_DOMAIN, @@ -306,6 +307,4 @@ async def test_updating_manually( blocking=True, ) await hass.async_block_till_done() - assert len(called) == 2 - - await asyncio.sleep(0.2) + assert called diff --git a/tests/components/command_line/test_cover.py b/tests/components/command_line/test_cover.py index ac0a33fc7a9..d4114f9bbbd 100644 --- a/tests/components/command_line/test_cover.py +++ b/tests/components/command_line/test_cover.py @@ -326,16 +326,18 @@ async def test_updating_to_often( ) await hass.async_block_till_done() - assert len(called) == 0 + assert not called assert ( "Updating Command Line Cover Test took longer than the scheduled update interval" not in caplog.text ) + called.clear() + caplog.clear() async_fire_time_changed(hass, dt_util.now() + timedelta(seconds=1)) await hass.async_block_till_done() - assert len(called) == 1 + assert called assert ( "Updating Command Line Cover Test took longer than the scheduled update interval" in caplog.text @@ -352,13 +354,11 @@ async def test_updating_manually( called = [] class MockCommandCover(CommandCover): - """Mock entity that updates slow.""" + """Mock entity that updates.""" async def _async_update(self) -> None: - """Update slow.""" + """Update.""" called.append(1) - # Add waiting time - await asyncio.sleep(1) with patch( "homeassistant.components.command_line.cover.CommandCover", @@ -384,7 +384,8 @@ async def test_updating_manually( async_fire_time_changed(hass, dt_util.now() + timedelta(seconds=10)) await hass.async_block_till_done() - assert len(called) == 1 + assert called + called.clear() await hass.services.async_call( HA_DOMAIN, @@ -393,6 +394,4 @@ async def test_updating_manually( blocking=True, ) await hass.async_block_till_done() - assert len(called) == 2 - - await asyncio.sleep(0.2) + assert called diff --git a/tests/components/command_line/test_sensor.py b/tests/components/command_line/test_sensor.py index b837f580862..af7bf3222a1 100644 --- a/tests/components/command_line/test_sensor.py +++ b/tests/components/command_line/test_sensor.py @@ -575,16 +575,18 @@ async def test_updating_to_often( ) await hass.async_block_till_done() - assert len(called) == 1 + assert called assert ( "Updating Command Line Sensor Test took longer than the scheduled update interval" not in caplog.text ) + called.clear() + caplog.clear() async_fire_time_changed(hass, dt_util.now() + timedelta(seconds=1)) await hass.async_block_till_done() - assert len(called) == 2 + assert called assert ( "Updating Command Line Sensor Test took longer than the scheduled update interval" in caplog.text @@ -601,13 +603,11 @@ async def test_updating_manually( called = [] class MockCommandSensor(CommandSensor): - """Mock entity that updates slow.""" + """Mock entity that updates.""" async def _async_update(self) -> None: """Update slow.""" called.append(1) - # Add waiting time - await asyncio.sleep(1) with patch( "homeassistant.components.command_line.sensor.CommandSensor", @@ -630,7 +630,8 @@ async def test_updating_manually( ) await hass.async_block_till_done() - assert len(called) == 1 + assert called + called.clear() await hass.services.async_call( HA_DOMAIN, @@ -639,6 +640,4 @@ async def test_updating_manually( blocking=True, ) await hass.async_block_till_done() - assert len(called) == 2 - - await asyncio.sleep(0.2) + assert called diff --git a/tests/components/command_line/test_switch.py b/tests/components/command_line/test_switch.py index e5331fbe7dd..12a037f0dd1 100644 --- a/tests/components/command_line/test_switch.py +++ b/tests/components/command_line/test_switch.py @@ -684,16 +684,18 @@ async def test_updating_to_often( ) await hass.async_block_till_done() - assert len(called) == 0 + assert not called assert ( "Updating Command Line Switch Test took longer than the scheduled update interval" not in caplog.text ) + called.clear() + caplog.clear() async_fire_time_changed(hass, dt_util.now() + timedelta(seconds=1)) await hass.async_block_till_done() - assert len(called) == 1 + assert called assert ( "Updating Command Line Switch Test took longer than the scheduled update interval" in caplog.text @@ -710,13 +712,11 @@ async def test_updating_manually( called = [] class MockCommandSwitch(CommandSwitch): - """Mock entity that updates slow.""" + """Mock entity that updates.""" async def _async_update(self) -> None: """Update slow.""" called.append(1) - # Add waiting time - await asyncio.sleep(1) with patch( "homeassistant.components.command_line.switch.CommandSwitch", @@ -743,7 +743,8 @@ async def test_updating_manually( async_fire_time_changed(hass, dt_util.now() + timedelta(seconds=10)) await hass.async_block_till_done() - assert len(called) == 1 + assert called + called.clear() await hass.services.async_call( HA_DOMAIN, @@ -752,6 +753,4 @@ async def test_updating_manually( blocking=True, ) await hass.async_block_till_done() - assert len(called) == 2 - - await asyncio.sleep(0.2) + assert called