Skip to content

Commit e841c35

Browse files
committed
feat: Fix tests referencing RoborockStateCode
1 parent 279e6b3 commit e841c35

File tree

1 file changed

+16
-21
lines changed

1 file changed

+16
-21
lines changed

tests/devices/test_v1_channel.py

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
import pytest
1313

14-
from roborock.containers import NetworkInfo, RoborockBase, UserData
14+
from roborock.containers import NetworkInfo, RoborockBase, UserData, S5MaxStatus, RoborockStateCode
1515
from roborock.devices.local_channel import LocalChannel, LocalSession
1616
from roborock.devices.mqtt_channel import MqttChannel
1717
from roborock.devices.v1_channel import V1Channel
@@ -30,19 +30,14 @@
3030
TEST_HOST = "1.1.1.1"
3131

3232

33-
@dataclass
34-
class FakeResponse(RoborockBase):
35-
state: str
36-
37-
3833
# Test messages for V1 protocol
3934
TEST_REQUEST = RoborockMessage(
4035
protocol=RoborockMessageProtocol.RPC_REQUEST,
4136
payload=json.dumps({"dps": {"101": json.dumps({"id": 12345, "method": "get_status"})}}).encode(),
4237
)
4338
TEST_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
)
4742
TEST_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

234229
async 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

264259
async 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

295290
async 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

Comments
 (0)