Skip to content

Commit 6199707

Browse files
committed
chore: revert changes to rpc channel
1 parent 1286b9b commit 6199707

File tree

6 files changed

+20
-31
lines changed

6 files changed

+20
-31
lines changed

roborock/devices/traits/dnd.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"""
66

77
import logging
8-
from collections.abc import Callable
98

109
from roborock.containers import DnDTimer
1110
from roborock.devices.v1_rpc_channel import V1RpcChannel
@@ -25,18 +24,18 @@ class DoNotDisturbTrait(Trait):
2524

2625
name = "do_not_disturb"
2726

28-
def __init__(self, rpc_channel: Callable[[], V1RpcChannel]) -> None:
27+
def __init__(self, rpc_channel: V1RpcChannel) -> None:
2928
"""Initialize the DoNotDisturbTrait."""
30-
self._send_command = lambda *args, **kwargs: rpc_channel().send_command(*args, **kwargs)
29+
self._rpc_channel = rpc_channel
3130

3231
async def get_dnd_timer(self) -> DnDTimer:
3332
"""Get the current Do Not Disturb (DND) timer settings of the device."""
34-
return await self._send_command(RoborockCommand.GET_DND_TIMER, response_type=DnDTimer)
33+
return await self._rpc_channel.send_command(RoborockCommand.GET_DND_TIMER, response_type=DnDTimer)
3534

3635
async def set_dnd_timer(self, dnd_timer: DnDTimer) -> None:
3736
"""Set the Do Not Disturb (DND) timer settings of the device."""
38-
await self._send_command(RoborockCommand.SET_DND_TIMER, params=dnd_timer.as_dict())
37+
await self._rpc_channel.send_command(RoborockCommand.SET_DND_TIMER, params=dnd_timer.as_dict())
3938

4039
async def clear_dnd_timer(self) -> None:
4140
"""Clear the Do Not Disturb (DND) timer settings of the device."""
42-
await self._send_command(RoborockCommand.CLOSE_DND_TIMER)
41+
await self._rpc_channel.send_command(RoborockCommand.CLOSE_DND_TIMER)

roborock/devices/traits/status.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"""
66

77
import logging
8-
from collections.abc import Callable
98

109
from roborock.containers import (
1110
HomeDataProduct,
@@ -30,15 +29,15 @@ class StatusTrait(Trait):
3029

3130
name = "status"
3231

33-
def __init__(self, product_info: HomeDataProduct, rpc_channel: Callable[[], V1RpcChannel]) -> None:
32+
def __init__(self, product_info: HomeDataProduct, rpc_channel: V1RpcChannel) -> None:
3433
"""Initialize the StatusTrait."""
3534
self._product_info = product_info
36-
self._send_command = lambda *args, **kwargs: rpc_channel().send_command(*args, **kwargs)
35+
self._rpc_channel = rpc_channel
3736

3837
async def get_status(self) -> Status:
3938
"""Get the current status of the device.
4039
4140
This is a placeholder command and will likely be changed/moved in the future.
4241
"""
4342
status_type: type[Status] = ModelStatus.get(self._product_info.model, S7MaxVStatus)
44-
return await self._send_command(RoborockCommand.GET_STATUS, response_type=status_type)
43+
return await self._rpc_channel.send_command(RoborockCommand.GET_STATUS, response_type=status_type)

roborock/devices/v1_channel.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,9 @@ def is_mqtt_connected(self) -> bool:
8181
"""Return whether MQTT connection is available."""
8282
return self._mqtt_unsub is not None and self._mqtt_channel.is_connected
8383

84+
@property
8485
def rpc_channel(self) -> V1RpcChannel:
85-
"""Return the combined RPC channel prefers local with a fallback to MQTT.
86-
87-
This is dynamic based on the current connection status. That is, it may return
88-
a different channel depending on whether local or MQTT is available.
89-
"""
86+
"""Return the combined RPC channel prefers local with a fallback to MQTT."""
9087
return self._combined_rpc_channel or self._mqtt_rpc_channel
9188

9289
@property

tests/devices/test_v1_channel.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ async def test_v1_channel_send_command_local_preferred(
254254

255255
# Send command
256256
mock_local_channel.response_queue.append(TEST_RESPONSE)
257-
result = await v1_channel.rpc_channel().send_command(
257+
result = await v1_channel.rpc_channel.send_command(
258258
RoborockCommand.CHANGE_SOUND_VOLUME,
259259
response_type=S5MaxStatus,
260260
)
@@ -280,7 +280,7 @@ async def test_v1_channel_send_command_local_fails(
280280

281281
# Send command
282282
with pytest.raises(RoborockException, match="Local failed"):
283-
await v1_channel.rpc_channel().send_command(
283+
await v1_channel.rpc_channel.send_command(
284284
RoborockCommand.CHANGE_SOUND_VOLUME,
285285
response_type=S5MaxStatus,
286286
)
@@ -300,7 +300,7 @@ async def test_v1_channel_send_decoded_command_mqtt_only(
300300

301301
# Send command
302302
mock_mqtt_channel.response_queue.append(TEST_RESPONSE)
303-
result = await v1_channel.rpc_channel().send_command(
303+
result = await v1_channel.rpc_channel.send_command(
304304
RoborockCommand.CHANGE_SOUND_VOLUME,
305305
response_type=S5MaxStatus,
306306
)
@@ -322,7 +322,7 @@ async def test_v1_channel_send_decoded_command_with_params(
322322
# Send command with params
323323
mock_local_channel.response_queue.append(TEST_RESPONSE)
324324
test_params = {"volume": 80}
325-
await v1_channel.rpc_channel().send_command(
325+
await v1_channel.rpc_channel.send_command(
326326
RoborockCommand.CHANGE_SOUND_VOLUME,
327327
response_type=S5MaxStatus,
328328
params=test_params,
@@ -444,7 +444,7 @@ async def test_v1_channel_command_encoding_validation(
444444

445445
# Send local command and capture the request
446446
mock_local_channel.response_queue.append(TEST_RESPONSE_2)
447-
await v1_channel.rpc_channel().send_command(RoborockCommand.CHANGE_SOUND_VOLUME, params={"volume": 50})
447+
await v1_channel.rpc_channel.send_command(RoborockCommand.CHANGE_SOUND_VOLUME, params={"volume": 50})
448448
assert mock_local_channel.published_messages
449449
local_message = mock_local_channel.published_messages[0]
450450

@@ -512,7 +512,7 @@ async def test_v1_channel_full_subscribe_and_command_flow(
512512

513513
# Send a command (should use local)
514514
mock_local_channel.response_queue.append(TEST_RESPONSE)
515-
result = await v1_channel.rpc_channel().send_command(
515+
result = await v1_channel.rpc_channel.send_command(
516516
RoborockCommand.GET_STATUS,
517517
response_type=S5MaxStatus,
518518
)

tests/devices/test_v1_device.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def traits_fixture(rpc_channel: AsyncMock) -> list[Trait]:
4444
return [
4545
StatusTrait(
4646
product_info=HOME_DATA.products[0],
47-
rpc_channel=lambda: rpc_channel,
47+
rpc_channel=rpc_channel,
4848
)
4949
]
5050

tests/devices/traits/test_dnd.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Tests for the DoNotDisturbTrait class."""
22

3-
from unittest.mock import AsyncMock, Mock
3+
from unittest.mock import AsyncMock
44

55
import pytest
66

@@ -20,15 +20,9 @@ def mock_rpc_channel() -> AsyncMock:
2020

2121

2222
@pytest.fixture
23-
def mock_rpc_channel_callable(mock_rpc_channel: AsyncMock) -> Mock:
24-
"""Create a callable that returns the mock RPC channel."""
25-
return Mock(return_value=mock_rpc_channel)
26-
27-
28-
@pytest.fixture
29-
def dnd_trait(mock_rpc_channel_callable: Mock) -> DoNotDisturbTrait:
23+
def dnd_trait(mock_rpc_channel: AsyncMock) -> DoNotDisturbTrait:
3024
"""Create a DoNotDisturbTrait instance with mocked dependencies."""
31-
return DoNotDisturbTrait(mock_rpc_channel_callable)
25+
return DoNotDisturbTrait(mock_rpc_channel)
3226

3327

3428
@pytest.fixture

0 commit comments

Comments
 (0)