Fix Rpi_power test race condition (#114662)

pull/114668/head
Robert Resch 2024-04-02 20:19:43 +02:00 committed by GitHub
parent 850dac0655
commit f85511255c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 14 additions and 20 deletions

View File

@ -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