mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 14:17:45 +00:00
Use freezegun in landisgyr_heat_meter tests (#99037)
This commit is contained in:
parent
75743ed947
commit
cb8842b1fb
@ -2,6 +2,7 @@
|
|||||||
import datetime
|
import datetime
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
from freezegun.api import FrozenDateTimeFactory
|
||||||
import pytest
|
import pytest
|
||||||
import serial
|
import serial
|
||||||
from syrupy import SnapshotAssertion
|
from syrupy import SnapshotAssertion
|
||||||
@ -122,7 +123,9 @@ async def test_create_sensors(
|
|||||||
|
|
||||||
|
|
||||||
@patch(API_HEAT_METER_SERVICE)
|
@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."""
|
"""Test sensor."""
|
||||||
entry_data = {
|
entry_data = {
|
||||||
"device": "/dev/USB0",
|
"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
|
# Now 'disable' the connection and wait for polling and see if it fails
|
||||||
mock_heat_meter().read.side_effect = serial.serialutil.SerialException
|
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()
|
await hass.async_block_till_done()
|
||||||
state = hass.states.get("sensor.heat_meter_heat_usage_gj")
|
state = hass.states.get("sensor.heat_meter_heat_usage_gj")
|
||||||
assert state.state == STATE_UNAVAILABLE
|
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.return_value = mock_heat_meter_response
|
||||||
mock_heat_meter().read.side_effect = None
|
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()
|
await hass.async_block_till_done()
|
||||||
state = hass.states.get("sensor.heat_meter_heat_usage_gj")
|
state = hass.states.get("sensor.heat_meter_heat_usage_gj")
|
||||||
assert state
|
assert state
|
||||||
|
Loading…
x
Reference in New Issue
Block a user