mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Use mock_restore_cache in tests (#77298)
This commit is contained in:
parent
c55505b47b
commit
3d723bddf8
@ -1,6 +1,5 @@
|
||||
"""Test KNX binary sensor."""
|
||||
from datetime import timedelta
|
||||
from unittest.mock import patch
|
||||
|
||||
from homeassistant.components.knx.const import CONF_STATE_ADDRESS, CONF_SYNC_STATE
|
||||
from homeassistant.components.knx.schema import BinarySensorSchema
|
||||
@ -12,7 +11,11 @@ from homeassistant.util import dt
|
||||
|
||||
from .conftest import KNXTestKit
|
||||
|
||||
from tests.common import async_capture_events, async_fire_time_changed
|
||||
from tests.common import (
|
||||
async_capture_events,
|
||||
async_fire_time_changed,
|
||||
mock_restore_cache,
|
||||
)
|
||||
|
||||
|
||||
async def test_binary_sensor_entity_category(hass: HomeAssistant, knx: KNXTestKit):
|
||||
@ -245,11 +248,8 @@ async def test_binary_sensor_restore_and_respond(hass, knx):
|
||||
"""Test restoring KNX binary sensor state and respond to read."""
|
||||
_ADDRESS = "2/2/2"
|
||||
fake_state = State("binary_sensor.test", STATE_ON)
|
||||
mock_restore_cache(hass, (fake_state,))
|
||||
|
||||
with patch(
|
||||
"homeassistant.helpers.restore_state.RestoreEntity.async_get_last_state",
|
||||
return_value=fake_state,
|
||||
):
|
||||
await knx.setup_integration(
|
||||
{
|
||||
BinarySensorSchema.PLATFORM: [
|
||||
@ -277,11 +277,8 @@ async def test_binary_sensor_restore_invert(hass, knx):
|
||||
"""Test restoring KNX binary sensor state with invert."""
|
||||
_ADDRESS = "2/2/2"
|
||||
fake_state = State("binary_sensor.test", STATE_ON)
|
||||
mock_restore_cache(hass, (fake_state,))
|
||||
|
||||
with patch(
|
||||
"homeassistant.helpers.restore_state.RestoreEntity.async_get_last_state",
|
||||
return_value=fake_state,
|
||||
):
|
||||
await knx.setup_integration(
|
||||
{
|
||||
BinarySensorSchema.PLATFORM: [
|
||||
|
@ -1,6 +1,4 @@
|
||||
"""Test KNX select."""
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.knx.const import (
|
||||
@ -17,6 +15,8 @@ from homeassistant.core import HomeAssistant, State
|
||||
|
||||
from .conftest import KNXTestKit
|
||||
|
||||
from tests.common import mock_restore_cache
|
||||
|
||||
|
||||
async def test_select_dpt_2_simple(hass: HomeAssistant, knx: KNXTestKit):
|
||||
"""Test simple KNX select."""
|
||||
@ -98,11 +98,8 @@ async def test_select_dpt_2_restore(hass: HomeAssistant, knx: KNXTestKit):
|
||||
test_address = "1/1/1"
|
||||
test_passive_address = "3/3/3"
|
||||
fake_state = State("select.test", "Control - On")
|
||||
mock_restore_cache(hass, (fake_state,))
|
||||
|
||||
with patch(
|
||||
"homeassistant.helpers.restore_state.RestoreEntity.async_get_last_state",
|
||||
return_value=fake_state,
|
||||
):
|
||||
await knx.setup_integration(
|
||||
{
|
||||
SelectSchema.PLATFORM: {
|
||||
|
@ -1,6 +1,4 @@
|
||||
"""Test KNX switch."""
|
||||
from unittest.mock import patch
|
||||
|
||||
from homeassistant.components.knx.const import (
|
||||
CONF_RESPOND_TO_READ,
|
||||
CONF_STATE_ADDRESS,
|
||||
@ -12,6 +10,8 @@ from homeassistant.core import HomeAssistant, State
|
||||
|
||||
from .conftest import KNXTestKit
|
||||
|
||||
from tests.common import mock_restore_cache
|
||||
|
||||
|
||||
async def test_switch_simple(hass: HomeAssistant, knx: KNXTestKit):
|
||||
"""Test simple KNX switch."""
|
||||
@ -115,11 +115,8 @@ async def test_switch_restore_and_respond(hass, knx):
|
||||
"""Test restoring KNX switch state and respond to read."""
|
||||
_ADDRESS = "1/1/1"
|
||||
fake_state = State("switch.test", "on")
|
||||
mock_restore_cache(hass, (fake_state,))
|
||||
|
||||
with patch(
|
||||
"homeassistant.helpers.restore_state.RestoreEntity.async_get_last_state",
|
||||
return_value=fake_state,
|
||||
):
|
||||
await knx.setup_integration(
|
||||
{
|
||||
SwitchSchema.PLATFORM: {
|
||||
|
@ -1,6 +1,5 @@
|
||||
"""UniFi Network switch platform tests."""
|
||||
from copy import deepcopy
|
||||
from unittest.mock import patch
|
||||
|
||||
from aiounifi.controller import MESSAGE_CLIENT_REMOVED, MESSAGE_DEVICE, MESSAGE_EVENT
|
||||
|
||||
@ -32,6 +31,8 @@ from .test_controller import (
|
||||
setup_unifi_integration,
|
||||
)
|
||||
|
||||
from tests.common import mock_restore_cache
|
||||
|
||||
CLIENT_1 = {
|
||||
"hostname": "client_1",
|
||||
"ip": "10.0.0.1",
|
||||
@ -1249,6 +1250,7 @@ async def test_restore_client_succeed(hass, aioclient_mock):
|
||||
"poe_mode": "auto",
|
||||
},
|
||||
)
|
||||
mock_restore_cache(hass, (fake_state,))
|
||||
|
||||
config_entry = config_entries.ConfigEntry(
|
||||
version=1,
|
||||
@ -1269,10 +1271,6 @@ async def test_restore_client_succeed(hass, aioclient_mock):
|
||||
config_entry=config_entry,
|
||||
)
|
||||
|
||||
with patch(
|
||||
"homeassistant.helpers.restore_state.RestoreEntity.async_get_last_state",
|
||||
return_value=fake_state,
|
||||
):
|
||||
await setup_unifi_integration(
|
||||
hass,
|
||||
aioclient_mock,
|
||||
|
Loading…
x
Reference in New Issue
Block a user