mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 08:47: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,24 +574,21 @@ 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(
|
||||||
)
|
hass,
|
||||||
|
config_sensor,
|
||||||
await base_config_test(
|
sensor_name,
|
||||||
hass,
|
SENSOR_DOMAIN,
|
||||||
config_sensor,
|
CONF_SENSORS,
|
||||||
sensor_name,
|
None,
|
||||||
SENSOR_DOMAIN,
|
method_discovery=True,
|
||||||
CONF_SENSORS,
|
)
|
||||||
None,
|
entity_id = f"{SENSOR_DOMAIN}.{sensor_name}"
|
||||||
method_discovery=True,
|
assert hass.states.get(entity_id).state == test_value
|
||||||
)
|
|
||||||
entity_id = f"{SENSOR_DOMAIN}.{sensor_name}"
|
|
||||||
assert hass.states.get(entity_id).state == test_value
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user