1111
1212import pytest
1313
14- from roborock .containers import NetworkInfo , RoborockBase , UserData
14+ from roborock .containers import NetworkInfo , RoborockBase , UserData , S5MaxStatus , RoborockStateCode
1515from roborock .devices .local_channel import LocalChannel , LocalSession
1616from roborock .devices .mqtt_channel import MqttChannel
1717from roborock .devices .v1_channel import V1Channel
3030TEST_HOST = "1.1.1.1"
3131
3232
33- @dataclass
34- class FakeResponse (RoborockBase ):
35- state : str
36-
37-
3833# Test messages for V1 protocol
3934TEST_REQUEST = RoborockMessage (
4035 protocol = RoborockMessageProtocol .RPC_REQUEST ,
4136 payload = json .dumps ({"dps" : {"101" : json .dumps ({"id" : 12345 , "method" : "get_status" })}}).encode (),
4237)
4338TEST_RESPONSE = RoborockMessage (
4439 protocol = RoborockMessageProtocol .RPC_RESPONSE ,
45- payload = json .dumps ({"dps" : {"102" : json .dumps ({"id" : 12345 , "result" : {"state" : " cleaning" }})}}).encode (),
40+ payload = json .dumps ({"dps" : {"102" : json .dumps ({"id" : 12345 , "result" : {"state" : RoborockStateCode . cleaning }})}}).encode (),
4641)
4742TEST_NETWORK_INFO_RESPONSE = RoborockMessage (
4843 protocol = RoborockMessageProtocol .RPC_RESPONSE ,
@@ -222,13 +217,13 @@ async def test_v1_channel_send_decoded_command_local_preferred(
222217 # Send command
223218 result = await v1_channel .send_decoded_command (
224219 RoborockCommand .CHANGE_SOUND_VOLUME ,
225- response_type = FakeResponse ,
220+ response_type = S5MaxStatus ,
226221 )
227222
228223 # Verify local was used, not MQTT
229224 mock_local_channel .send_command .assert_called_once ()
230225 mock_mqtt_channel .send_command .assert_not_called ()
231- assert result .state == " cleaning"
226+ assert result .state == RoborockStateCode . cleaning
232227
233228
234229async def test_v1_channel_send_decoded_command_fallback_to_mqtt (
@@ -252,13 +247,13 @@ async def test_v1_channel_send_decoded_command_fallback_to_mqtt(
252247 # Send command
253248 result = await v1_channel .send_decoded_command (
254249 RoborockCommand .CHANGE_SOUND_VOLUME ,
255- response_type = FakeResponse ,
250+ response_type = S5MaxStatus ,
256251 )
257252
258253 # Verify both were attempted
259254 mock_local_channel .send_command .assert_called_once ()
260255 mock_mqtt_channel .send_command .assert_called_once ()
261- assert result .state == " cleaning"
256+ assert result .state == RoborockStateCode . cleaning
262257
263258
264259async def test_v1_channel_send_decoded_command_mqtt_only (
@@ -283,13 +278,13 @@ def send_command(*args) -> RoborockMessage:
283278 # Send command
284279 result = await v1_channel .send_decoded_command (
285280 RoborockCommand .CHANGE_SOUND_VOLUME ,
286- response_type = FakeResponse ,
281+ response_type = S5MaxStatus ,
287282 )
288283
289284 # Verify only MQTT was used
290285 mock_local_channel .send_command .assert_not_called ()
291286 mock_mqtt_channel .send_command .assert_called_once ()
292- assert result .state == " cleaning"
287+ assert result .state == RoborockStateCode . cleaning
293288
294289
295290async def test_v1_channel_send_decoded_command_with_params (
@@ -310,15 +305,15 @@ async def test_v1_channel_send_decoded_command_with_params(
310305 test_params = {"volume" : 80 }
311306 result = await v1_channel .send_decoded_command (
312307 RoborockCommand .CHANGE_SOUND_VOLUME ,
313- response_type = FakeResponse ,
308+ response_type = S5MaxStatus ,
314309 params = test_params ,
315310 )
316311
317312 # Verify command was sent with correct params
318313 mock_local_channel .send_command .assert_called_once ()
319314 call_args = mock_local_channel .send_command .call_args
320315 assert call_args [1 ]["params" ] == test_params
321- assert result .state == " cleaning"
316+ assert result .state == RoborockStateCode . cleaning
322317
323318
324319# V1Channel message handling tests
@@ -517,13 +512,13 @@ async def test_v1_channel_full_subscribe_and_command_flow(
517512 # Send a command (should use local)
518513 result = await v1_channel .send_decoded_command (
519514 RoborockCommand .GET_STATUS ,
520- response_type = FakeResponse ,
515+ response_type = S5MaxStatus ,
521516 )
522517
523518 # Verify command was sent via local connection
524519 mock_local_channel .send_command .assert_called_once ()
525520 mock_mqtt_channel .send_command .assert_not_called ()
526- assert result .state == " cleaning"
521+ assert result .state == RoborockStateCode . cleaning
527522
528523 # Test message callback
529524 test_message = TEST_RESPONSE
@@ -559,15 +554,15 @@ async def test_v1_channel_graceful_degradation_local_to_mqtt(
559554
560555 # First command: local works
561556 mock_local_channel .send_command .return_value = TEST_RESPONSE
562- result1 = await v1_channel .send_decoded_command (RoborockCommand .GET_STATUS , response_type = FakeResponse )
563- assert result1 .state == " cleaning"
557+ result1 = await v1_channel .send_decoded_command (RoborockCommand .GET_STATUS , response_type = S5MaxStatus )
558+ assert result1 .state == RoborockStateCode . cleaning
564559 mock_local_channel .send_command .assert_called_once ()
565560
566561 # Second command: local fails, falls back to MQTT
567562 mock_local_channel .send_command .side_effect = RoborockException ("Local failed" )
568563 mock_mqtt_channel .send_command .return_value = TEST_RESPONSE
569- result2 = await v1_channel .send_decoded_command (RoborockCommand .GET_STATUS , response_type = FakeResponse )
570- assert result2 .state == " cleaning"
564+ result2 = await v1_channel .send_decoded_command (RoborockCommand .GET_STATUS , response_type = S5MaxStatus )
565+ assert result2 .state == RoborockStateCode . cleaning
571566
572567 # Verify both were attempted
573568 assert mock_local_channel .send_command .call_count == 2
0 commit comments