mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 02:07:09 +00:00
parent
858f0e6657
commit
466ec0b596
@ -11,7 +11,6 @@ import uuid
|
|||||||
import pytest
|
import pytest
|
||||||
from roborock import RoborockCategory, RoomMapping
|
from roborock import RoborockCategory, RoomMapping
|
||||||
from roborock.code_mappings import DyadError, RoborockDyadStateCode, ZeoError, ZeoState
|
from roborock.code_mappings import DyadError, RoborockDyadStateCode, ZeoError, ZeoState
|
||||||
from roborock.containers import NetworkInfo
|
|
||||||
from roborock.roborock_message import RoborockDyadDataProtocol, RoborockZeoProtocol
|
from roborock.roborock_message import RoborockDyadDataProtocol, RoborockZeoProtocol
|
||||||
from roborock.version_a01_apis import RoborockMqttClientA01
|
from roborock.version_a01_apis import RoborockMqttClientA01
|
||||||
|
|
||||||
@ -30,7 +29,6 @@ from .mock_data import (
|
|||||||
MAP_DATA,
|
MAP_DATA,
|
||||||
MULTI_MAP_LIST,
|
MULTI_MAP_LIST,
|
||||||
NETWORK_INFO,
|
NETWORK_INFO,
|
||||||
NETWORK_INFO_2,
|
|
||||||
PROP,
|
PROP,
|
||||||
SCENES,
|
SCENES,
|
||||||
USER_DATA,
|
USER_DATA,
|
||||||
@ -89,13 +87,6 @@ def bypass_api_client_fixture() -> None:
|
|||||||
yield
|
yield
|
||||||
|
|
||||||
|
|
||||||
def cycle_network_info() -> Generator[NetworkInfo]:
|
|
||||||
"""Return the appropriate network info for the corresponding device."""
|
|
||||||
while True:
|
|
||||||
yield NETWORK_INFO
|
|
||||||
yield NETWORK_INFO_2
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="bypass_api_fixture")
|
@pytest.fixture(name="bypass_api_fixture")
|
||||||
def bypass_api_fixture(bypass_api_client_fixture: Any) -> None:
|
def bypass_api_fixture(bypass_api_client_fixture: Any) -> None:
|
||||||
"""Skip calls to the API."""
|
"""Skip calls to the API."""
|
||||||
@ -107,7 +98,7 @@ def bypass_api_fixture(bypass_api_client_fixture: Any) -> None:
|
|||||||
),
|
),
|
||||||
patch(
|
patch(
|
||||||
"homeassistant.components.roborock.RoborockMqttClientV1.get_networking",
|
"homeassistant.components.roborock.RoborockMqttClientV1.get_networking",
|
||||||
side_effect=cycle_network_info(),
|
return_value=NETWORK_INFO,
|
||||||
),
|
),
|
||||||
patch(
|
patch(
|
||||||
"homeassistant.components.roborock.coordinator.RoborockLocalClientV1.get_prop",
|
"homeassistant.components.roborock.coordinator.RoborockLocalClientV1.get_prop",
|
||||||
|
@ -357,7 +357,7 @@
|
|||||||
}),
|
}),
|
||||||
'network_info': dict({
|
'network_info': dict({
|
||||||
'bssid': '**REDACTED**',
|
'bssid': '**REDACTED**',
|
||||||
'ip': '123.232.12.2',
|
'ip': '123.232.12.1',
|
||||||
'mac': '**REDACTED**',
|
'mac': '**REDACTED**',
|
||||||
'rssi': 90,
|
'rssi': 90,
|
||||||
'ssid': 'wifi',
|
'ssid': 'wifi',
|
||||||
|
@ -20,7 +20,7 @@ from homeassistant.core import HomeAssistant
|
|||||||
from homeassistant.helpers.device_registry import DeviceRegistry
|
from homeassistant.helpers.device_registry import DeviceRegistry
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from .mock_data import HOME_DATA, NETWORK_INFO
|
from .mock_data import HOME_DATA, NETWORK_INFO, NETWORK_INFO_2
|
||||||
|
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
from tests.typing import ClientSessionGenerator
|
from tests.typing import ClientSessionGenerator
|
||||||
@ -305,6 +305,10 @@ async def test_stale_device(
|
|||||||
device_registry: DeviceRegistry,
|
device_registry: DeviceRegistry,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test that we remove a device if it no longer is given by home_data."""
|
"""Test that we remove a device if it no longer is given by home_data."""
|
||||||
|
with patch(
|
||||||
|
"homeassistant.components.roborock.RoborockMqttClientV1.get_networking",
|
||||||
|
side_effect=[NETWORK_INFO, NETWORK_INFO_2],
|
||||||
|
):
|
||||||
await hass.config_entries.async_setup(mock_roborock_entry.entry_id)
|
await hass.config_entries.async_setup(mock_roborock_entry.entry_id)
|
||||||
assert mock_roborock_entry.state is ConfigEntryState.LOADED
|
assert mock_roborock_entry.state is ConfigEntryState.LOADED
|
||||||
existing_devices = device_registry.devices.get_devices_for_config_entry_id(
|
existing_devices = device_registry.devices.get_devices_for_config_entry_id(
|
||||||
@ -314,9 +318,15 @@ async def test_stale_device(
|
|||||||
hd = deepcopy(HOME_DATA)
|
hd = deepcopy(HOME_DATA)
|
||||||
hd.devices = [hd.devices[0]]
|
hd.devices = [hd.devices[0]]
|
||||||
|
|
||||||
with patch(
|
with (
|
||||||
|
patch(
|
||||||
"homeassistant.components.roborock.RoborockApiClient.get_home_data_v2",
|
"homeassistant.components.roborock.RoborockApiClient.get_home_data_v2",
|
||||||
return_value=hd,
|
return_value=hd,
|
||||||
|
),
|
||||||
|
patch(
|
||||||
|
"homeassistant.components.roborock.RoborockMqttClientV1.get_networking",
|
||||||
|
side_effect=[NETWORK_INFO, NETWORK_INFO_2],
|
||||||
|
),
|
||||||
):
|
):
|
||||||
await hass.config_entries.async_reload(mock_roborock_entry.entry_id)
|
await hass.config_entries.async_reload(mock_roborock_entry.entry_id)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
@ -336,6 +346,10 @@ async def test_no_stale_device(
|
|||||||
device_registry: DeviceRegistry,
|
device_registry: DeviceRegistry,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test that we don't remove a device if fails to setup."""
|
"""Test that we don't remove a device if fails to setup."""
|
||||||
|
with patch(
|
||||||
|
"homeassistant.components.roborock.RoborockMqttClientV1.get_networking",
|
||||||
|
side_effect=[NETWORK_INFO, NETWORK_INFO_2],
|
||||||
|
):
|
||||||
await hass.config_entries.async_setup(mock_roborock_entry.entry_id)
|
await hass.config_entries.async_setup(mock_roborock_entry.entry_id)
|
||||||
assert mock_roborock_entry.state is ConfigEntryState.LOADED
|
assert mock_roborock_entry.state is ConfigEntryState.LOADED
|
||||||
existing_devices = device_registry.devices.get_devices_for_config_entry_id(
|
existing_devices = device_registry.devices.get_devices_for_config_entry_id(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user