1-
2- import asyncio
31import datetime
4- import logging
5- from unittest .mock import AsyncMock , Mock , patch
2+ from unittest .mock import AsyncMock , Mock
63
74import pytest
85
96from roborock .data import NetworkInfo
107from roborock .devices .cache import CacheData , InMemoryCache
118from roborock .devices .local_channel import LocalSession
12- from roborock .devices .v1_channel import V1Channel , NETWORK_INFO_REFRESH_INTERVAL
9+ from roborock .devices .v1_channel import NETWORK_INFO_REFRESH_INTERVAL , V1Channel
1310from roborock .exceptions import RoborockException
1411from roborock .protocols .v1_protocol import SecurityData
1512
1916TEST_SECURITY_DATA = SecurityData (endpoint = "test_endpoint" , nonce = b"test_nonce" )
2017TEST_IP = "192.168.1.100"
2118
19+
2220@pytest .fixture (name = "mock_mqtt_channel" )
2321async def setup_mock_mqtt_channel () -> FakeChannel :
2422 """Mock MQTT channel for testing."""
@@ -28,19 +26,22 @@ async def setup_mock_mqtt_channel() -> FakeChannel:
2826 channel .send_command = AsyncMock (side_effect = RoborockException ("MQTT Failed" ))
2927 return channel
3028
29+
3130@pytest .fixture (name = "mock_local_channel" )
3231async def setup_mock_local_channel () -> FakeChannel :
3332 """Mock Local channel for testing."""
3433 channel = FakeChannel ()
3534 return channel
3635
36+
3737@pytest .fixture (name = "mock_local_session" )
3838def setup_mock_local_session (mock_local_channel : Mock ) -> Mock :
3939 """Mock Local session factory for testing."""
4040 mock_session = Mock (spec = LocalSession )
4141 mock_session .return_value = mock_local_channel
4242 return mock_session
4343
44+
4445@pytest .mark .asyncio
4546async def test_v1_channel_reconnect_with_stale_cache_and_mqtt_down (
4647 mock_mqtt_channel : FakeChannel ,
@@ -67,7 +68,9 @@ async def test_v1_channel_reconnect_with_stale_cache_and_mqtt_down(
6768 )
6869
6970 # Manually set the last refresh to be old to simulate stale cache
70- v1_channel ._last_network_info_refresh = datetime .datetime .now (datetime .UTC ) - (NETWORK_INFO_REFRESH_INTERVAL + datetime .timedelta (hours = 1 ))
71+ # Break long line
72+ last_refresh = datetime .datetime .now (datetime .UTC ) - (NETWORK_INFO_REFRESH_INTERVAL + datetime .timedelta (hours = 1 ))
73+ v1_channel ._last_network_info_refresh = last_refresh
7174
7275 # 2. Mock MQTT RPC channel to fail
7376 # V1Channel creates _mqtt_rpc_channel in __init__. We need to mock its send_command.
0 commit comments