Use freezegun in landisgyr_heat_meter tests (#99037)
This commit is contained in:
parent
75743ed947
commit
cb8842b1fb
1 changed files with 8 additions and 3 deletions
|
@ -2,6 +2,7 @@
|
|||
import datetime
|
||||
from unittest.mock import patch
|
||||
|
||||
from freezegun.api import FrozenDateTimeFactory
|
||||
import pytest
|
||||
import serial
|
||||
from syrupy import SnapshotAssertion
|
||||
|
@ -122,7 +123,9 @@ async def test_create_sensors(
|
|||
|
||||
|
||||
@patch(API_HEAT_METER_SERVICE)
|
||||
async def test_exception_on_polling(mock_heat_meter, hass: HomeAssistant) -> None:
|
||||
async def test_exception_on_polling(
|
||||
mock_heat_meter, hass: HomeAssistant, freezer: FrozenDateTimeFactory
|
||||
) -> None:
|
||||
"""Test sensor."""
|
||||
entry_data = {
|
||||
"device": "/dev/USB0",
|
||||
|
@ -148,7 +151,8 @@ async def test_exception_on_polling(mock_heat_meter, hass: HomeAssistant) -> Non
|
|||
|
||||
# Now 'disable' the connection and wait for polling and see if it fails
|
||||
mock_heat_meter().read.side_effect = serial.serialutil.SerialException
|
||||
async_fire_time_changed(hass, dt_util.utcnow() + POLLING_INTERVAL)
|
||||
freezer.tick(POLLING_INTERVAL)
|
||||
async_fire_time_changed(hass)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get("sensor.heat_meter_heat_usage_gj")
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
@ -159,7 +163,8 @@ async def test_exception_on_polling(mock_heat_meter, hass: HomeAssistant) -> Non
|
|||
|
||||
mock_heat_meter().read.return_value = mock_heat_meter_response
|
||||
mock_heat_meter().read.side_effect = None
|
||||
async_fire_time_changed(hass, dt_util.utcnow() + POLLING_INTERVAL)
|
||||
freezer.tick(POLLING_INTERVAL)
|
||||
async_fire_time_changed(hass)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get("sensor.heat_meter_heat_usage_gj")
|
||||
assert state
|
||||
|
|
Loading…
Add table
Reference in a new issue