Skip to content

Commit 328a72a

Browse files
committed
fix: revert subscribe to AsyncMock for backward compatibility
1 parent 7ebc0ad commit 328a72a

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

roborock/testing/channel.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ def __init__(self, is_local: bool = False):
5656
# channel.publish.side_effect = RoborockException("timeout")
5757
self.publish = AsyncMock(side_effect=self._publish)
5858

59+
# AsyncMock wrapping _subscribe. Callers can replace side_effect to
60+
# simulate subscription failures, e.g.:
61+
# channel.subscribe.side_effect = RoborockException("sub failed")
62+
self.subscribe = AsyncMock(side_effect=self._subscribe) # type: ignore[assignment]
63+
5964
# AsyncMock wrapping _connect. Callers can replace side_effect to
6065
# simulate connection failures, e.g.:
6166
# channel.connect.side_effect = RoborockException("refused")
@@ -100,10 +105,10 @@ async def _publish(self, message: RoborockMessage) -> None:
100105
response = self.response_queue.pop(0)
101106
self.notify_subscribers(response)
102107

103-
async def subscribe(self, callback: Callable[[RoborockMessage], None]) -> Callable[[], None]:
104-
"""Register a callback and return an unsubscribe function.
108+
async def _subscribe(self, callback: Callable[[RoborockMessage], None]) -> Callable[[], None]:
109+
"""Default subscribe implementation.
105110
106-
This is a real method implementing the Channel protocol, not a mock.
111+
Registers the callback and returns an unsubscribe function.
107112
"""
108113
self.subscribers.append(callback)
109114
return lambda: self.subscribers.remove(callback)

roborock/testing/simulator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,14 @@ def __init__(
7171
)
7272

7373
# MQTT channel is always present — all protocols use it.
74-
self.mqtt_channel = FakeChannel(is_local=False)
74+
self.mqtt_channel = FakeChannel(is_local=False) # type: ignore[abstract]
7575
self.mqtt_channel.publish.side_effect = self._handle_mqtt_publish
7676

7777
# Local channel is only used by V1 devices. A01/B01 (MQTT-only)
7878
# simulators should pass has_local_channel=False.
7979
self.local_channel: FakeChannel | None = None
8080
if has_local_channel:
81-
self.local_channel = FakeChannel(is_local=True)
81+
self.local_channel = FakeChannel(is_local=True) # type: ignore[abstract]
8282
self.local_channel.publish.side_effect = self._handle_local_publish
8383

8484
async def _handle_local_publish(self, message: RoborockMessage) -> None:

0 commit comments

Comments
 (0)