mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 16:57:10 +00:00
Use mock_restore_state in testing of modbus sensor (#50455)
This commit is contained in:
parent
5da64d01e2
commit
ca558545a1
@ -1,6 +1,5 @@
|
|||||||
"""The tests for the Modbus sensor component."""
|
"""The tests for the Modbus sensor component."""
|
||||||
import logging
|
import logging
|
||||||
from unittest import mock
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
@ -42,6 +41,8 @@ from homeassistant.core import State
|
|||||||
|
|
||||||
from .conftest import ReadResult, base_config_test, base_test, prepare_service_update
|
from .conftest import ReadResult, base_config_test, base_test, prepare_service_update
|
||||||
|
|
||||||
|
from tests.common import mock_restore_cache
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"do_discovery, do_config",
|
"do_discovery, do_config",
|
||||||
@ -573,13 +574,10 @@ async def test_restore_state_sensor(hass):
|
|||||||
sensor_name = "test_sensor"
|
sensor_name = "test_sensor"
|
||||||
test_value = "117"
|
test_value = "117"
|
||||||
config_sensor = {CONF_NAME: sensor_name, CONF_ADDRESS: 17}
|
config_sensor = {CONF_NAME: sensor_name, CONF_ADDRESS: 17}
|
||||||
with mock.patch(
|
mock_restore_cache(
|
||||||
"homeassistant.components.modbus.sensor.ModbusRegisterSensor.async_get_last_state"
|
hass,
|
||||||
) as mock_get_last_state:
|
(State(f"{SENSOR_DOMAIN}.{sensor_name}", test_value),),
|
||||||
mock_get_last_state.return_value = State(
|
|
||||||
f"{SENSOR_DOMAIN}.{sensor_name}", f"{test_value}"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
await base_config_test(
|
await base_config_test(
|
||||||
hass,
|
hass,
|
||||||
config_sensor,
|
config_sensor,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user