|
23 | 23 | create_mqtt_encoder, |
24 | 24 | ) |
25 | 25 | from roborock.protocols.v1_protocol import MapResponse, SecurityData, V1RpcChannel |
26 | | -from roborock.roborock_message import RoborockMessage, RoborockMessageProtocol |
| 26 | +from roborock.roborock_message import RoborockDataProtocol, RoborockMessage, RoborockMessageProtocol |
27 | 27 | from roborock.roborock_typing import RoborockCommand |
28 | 28 | from tests import mock_data |
29 | 29 | from tests.fixtures.channel_fixtures import FakeChannel |
@@ -580,3 +580,35 @@ async def test_v1_channel_send_map_command( |
580 | 580 |
|
581 | 581 | # Verify the result is the data from our mocked decoder |
582 | 582 | assert result == decompressed_map_data |
| 583 | + |
| 584 | + |
| 585 | +async def test_v1_channel_add_dps_listener( |
| 586 | + v1_channel: V1Channel, |
| 587 | + mock_mqtt_channel: FakeChannel, |
| 588 | +) -> None: |
| 589 | + """Test that DPS listeners receive decoded protocol updates from MQTT.""" |
| 590 | + mock_mqtt_channel.response_queue.append(TEST_NETWORK_INFO_RESPONSE) |
| 591 | + await v1_channel.subscribe(Mock()) |
| 592 | + |
| 593 | + # Create a mock listener for DPS updates |
| 594 | + dps_listener = Mock() |
| 595 | + unsub_dps = v1_channel.add_dps_listener(dps_listener) |
| 596 | + |
| 597 | + # Simulate an incoming MQTT message with data protocol payload. |
| 598 | + dps_payload = json.dumps({"dps": {"121": 5}}).encode() |
| 599 | + push_message = RoborockMessage( |
| 600 | + protocol=RoborockMessageProtocol.GENERAL_REQUEST, |
| 601 | + payload=dps_payload, |
| 602 | + ) |
| 603 | + mock_mqtt_channel.notify_subscribers(push_message) |
| 604 | + |
| 605 | + dps_listener.assert_called_once() |
| 606 | + called_args = dps_listener.call_args[0][0] |
| 607 | + assert called_args[RoborockDataProtocol.STATE] == 5 |
| 608 | + |
| 609 | + unsub_dps() |
| 610 | + |
| 611 | + # Verify unsubscribe works |
| 612 | + dps_listener.reset_mock() |
| 613 | + v1_channel._on_mqtt_message(push_message) |
| 614 | + dps_listener.assert_not_called() |
0 commit comments