Fix Rpi_power test race condition (#114662)
parent
850dac0655
commit
f85511255c
|
@ -6,6 +6,7 @@ from unittest.mock import MagicMock
|
|||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.rpi_power import binary_sensor
|
||||
from homeassistant.components.rpi_power.binary_sensor import (
|
||||
DESCRIPTION_NORMALIZED,
|
||||
DESCRIPTION_UNDER_VOLTAGE,
|
||||
|
@ -48,32 +49,25 @@ async def test_new_detected(
|
|||
"""Test new entry with under voltage detected."""
|
||||
mocked_under_voltage = await _async_setup_component(hass, True)
|
||||
state = hass.states.get(ENTITY_ID)
|
||||
assert state
|
||||
assert state.state == STATE_ON
|
||||
assert (
|
||||
len(
|
||||
[
|
||||
x
|
||||
for x in caplog.records
|
||||
if x.levelno == logging.WARNING
|
||||
and x.message == DESCRIPTION_UNDER_VOLTAGE
|
||||
]
|
||||
)
|
||||
== 1
|
||||
)
|
||||
binary_sensor.__name__,
|
||||
logging.WARNING,
|
||||
DESCRIPTION_UNDER_VOLTAGE,
|
||||
) in caplog.record_tuples
|
||||
|
||||
# back to normal
|
||||
type(mocked_under_voltage).get = MagicMock(return_value=False)
|
||||
future = dt_util.utcnow() + timedelta(minutes=1)
|
||||
async_fire_time_changed(hass, future)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done(wait_background_tasks=True)
|
||||
|
||||
state = hass.states.get(ENTITY_ID)
|
||||
assert state
|
||||
assert state.state == STATE_OFF
|
||||
assert (
|
||||
len(
|
||||
[
|
||||
x
|
||||
for x in caplog.records
|
||||
if x.levelno == logging.INFO and x.message == DESCRIPTION_NORMALIZED
|
||||
]
|
||||
)
|
||||
== 1
|
||||
)
|
||||
binary_sensor.__name__,
|
||||
logging.INFO,
|
||||
DESCRIPTION_NORMALIZED,
|
||||
) in caplog.record_tuples
|
||||
|
|
Loading…
Reference in New Issue