Skip to content

Commit 9fcc0a8

Browse files
authored
chore: Restructure the channel modules (#728)
This provides a separation between the lower level protocol specific channels (MQTT vs Local) and the Application/RPC level command handling channel modules. This updates the pydoc to clarify the responsibilities between each layer. The motivation is from noticing that b01 introduced a number of new channels, protocols, traits, and it seemed worth separating for clarity as we want to add new developers to the code base.
1 parent f20ade9 commit 9fcc0a8

25 files changed

+81
-55
lines changed

docs/DEVICES.md

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -564,30 +564,40 @@ The new design:
564564
```
565565
roborock/
566566
├── devices/ # Device management and channels
567-
│ ├── device_manager.py # High-level device lifecycle
568-
│ ├── channel.py # Base Channel interface
569-
│ ├── mqtt_channel.py # MQTT channel implementation
570-
│ ├── local_channel.py # Local TCP channel implementation
571-
│ ├── v1_channel.py # V1 protocol channel with RPC strategies
572-
│ ├── a01_channel.py # A01 protocol helpers
573-
│ ├── b01_q7_channel.py # B01 Q7 protocol helpers
574-
│ └── traits/ # Device-specific command traits
575-
│ └── v1/ # V1 device traits
576-
│ ├── __init__.py # Trait initialization
577-
│ ├── clean.py # Cleaning commands
578-
│ ├── map.py # Map management
567+
│ ├── device_manager.py # High-level device lifecycle
568+
│ ├── transport/ # Module for network connections to devices
569+
│ | ├── channel.py # Base Channel interface
570+
│ | ├── mqtt_channel.py # MQTT channel implementation
571+
│ | ├── local_channel.py # Local TCP channel implementation
572+
│ | └── ...
573+
│ ├── rpc/ # Application-level protocol/device-specific glue
574+
│ | ├── v1_channel.py # V1 protocol channel with RPC strategies
575+
│ | ├── a01_channel.py # A01 protocol helpers
576+
│ | ├── b01_q7_channel.py # B01 Q7 protocol helpers
577+
│ | ├── b01_q10_channel.py # B01 Q10 protocol helpers
578+
│ | └── ...
579+
│ └── traits/ # High-level device-specific command traits
580+
│ └── v1/ # V1 device traits
581+
│ ├── __init__.py # Trait initialization
582+
│ ├── clean.py # Cleaning commands
583+
│ ├── map.py # Map management
579584
│ └── ...
580-
├── mqtt/ # MQTT session management
585+
├── mqtt/ # MQTT session management
581586
│ ├── session.py # Base session interface
582587
│ └── roborock_session.py # MQTT session with idle timeout
583-
├── protocols/ # Protocol encoders/decoders
588+
├── protocols/ # Low level protocol encoders/decoders
584589
│ ├── v1_protocol.py # V1 JSON RPC protocol
585590
│ ├── a01_protocol.py # A01 protocol
586591
│ ├── b01_q7_protocol.py # B01 Q7 protocol
587592
│ └── ...
588-
└── data/ # Data containers and mappings
593+
└── data/ # Data containers and mappings
589594
├── containers.py # Status, HomeData, etc.
590-
└── v1/ # V1-specific data structures
595+
├── v1/ # V1-specific data structures
596+
├── dyad/ # Dyad-specific data structures
597+
├── zeo/ # Zeo-specific data structures
598+
├── b01_q7/ # B01 Q7-specific data structures
599+
├── b01_q10/ # B01 Q10-specific data structures
600+
└── ...
591601
```
592602

593603
### Threading Model

roborock/devices/device.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
from roborock.roborock_message import RoborockMessage
1919
from roborock.util import RoborockLoggerAdapter
2020

21-
from .channel import Channel
2221
from .traits import Trait
2322
from .traits.traits_mixin import TraitsMixin
23+
from .transport.channel import Channel
2424

2525
_LOGGER = logging.getLogger(__name__)
2626

roborock/devices/device_manager.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
from roborock.web_api import RoborockApiClient, UserWebApiClient
2626

2727
from .cache import Cache, DeviceCache, NoCache
28-
from .channel import Channel
29-
from .mqtt_channel import create_mqtt_channel
28+
from .rpc.v1_channel import create_v1_channel
3029
from .traits import Trait, a01, b01, v1
31-
from .v1_channel import create_v1_channel
30+
from .transport.channel import Channel
31+
from .transport.mqtt_channel import create_mqtt_channel
3232

3333
_LOGGER = logging.getLogger(__name__)
3434

roborock/devices/rpc/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"""Module for sending device specific commands to Roborock devices.
2+
3+
This module provides a application-level interface for sending commands to Roborock
4+
devices. These modules can be used by traits (higher level APIs) to send commands.
5+
6+
Each module may contain details that are common across all traits, and may depend
7+
on the transport level modules (e.g. MQTT, Local device) for issuing the
8+
commands.
9+
10+
The lowest level protocol encoding is handled in `roborock.protocols` which
11+
have no dependencies on the transport level modules.
12+
"""
13+
14+
__all__: list[str] = []
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from collections.abc import Callable
66
from typing import Any, overload
77

8+
from roborock.devices.transport.mqtt_channel import MqttChannel
89
from roborock.exceptions import RoborockException
910
from roborock.protocols.a01_protocol import (
1011
decode_rpc_response,
@@ -16,8 +17,6 @@
1617
RoborockZeoProtocol,
1718
)
1819

19-
from .mqtt_channel import MqttChannel
20-
2120
_LOGGER = logging.getLogger(__name__)
2221
_TIMEOUT = 10.0
2322

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@
55
import logging
66

77
from roborock.data.b01_q10.b01_q10_code_mappings import B01_Q10_DP
8+
from roborock.devices.transport.mqtt_channel import MqttChannel
89
from roborock.exceptions import RoborockException
910
from roborock.protocols.b01_q10_protocol import (
1011
ParamsType,
1112
encode_mqtt_payload,
1213
)
1314

14-
from .mqtt_channel import MqttChannel
15-
1615
_LOGGER = logging.getLogger(__name__)
1716

1817

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import logging
88
from typing import Any
99

10+
from roborock.devices.transport.mqtt_channel import MqttChannel
1011
from roborock.exceptions import RoborockException
1112
from roborock.protocols.b01_q7_protocol import (
1213
Q7RequestMessage,
@@ -15,8 +16,6 @@
1516
)
1617
from roborock.roborock_message import RoborockMessage
1718

18-
from .mqtt_channel import MqttChannel
19-
2019
_LOGGER = logging.getLogger(__name__)
2120
_TIMEOUT = 10.0
2221

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
from typing import Any, TypeVar
1313

1414
from roborock.data import HomeDataDevice, NetworkInfo, RoborockBase, UserData
15+
from roborock.devices.cache import DeviceCache
16+
from roborock.devices.transport.channel import Channel
17+
from roborock.devices.transport.local_channel import LocalChannel, LocalSession, create_local_session
18+
from roborock.devices.transport.mqtt_channel import MqttChannel
1519
from roborock.exceptions import RoborockException
1620
from roborock.mqtt.health_manager import HealthManager
1721
from roborock.mqtt.session import MqttParams, MqttSession
@@ -32,11 +36,6 @@
3236
from roborock.roborock_typing import RoborockCommand
3337
from roborock.util import RoborockLoggerAdapter
3438

35-
from .cache import DeviceCache
36-
from .channel import Channel
37-
from .local_channel import LocalChannel, LocalSession, create_local_session
38-
from .mqtt_channel import MqttChannel
39-
4039
_LOGGER = logging.getLogger(__name__)
4140

4241
__all__ = [

roborock/devices/traits/a01/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@
4848
ZeoState,
4949
ZeoTemperature,
5050
)
51-
from roborock.devices.a01_channel import send_decoded_command
52-
from roborock.devices.mqtt_channel import MqttChannel
51+
from roborock.devices.rpc.a01_channel import send_decoded_command
5352
from roborock.devices.traits import Trait
53+
from roborock.devices.transport.mqtt_channel import MqttChannel
5454
from roborock.roborock_message import RoborockDyadDataProtocol, RoborockZeoProtocol
5555

5656
__init__ = [

roborock/devices/traits/b01/q10/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
from typing import Any
44

5-
from roborock.devices.b01_q7_channel import send_decoded_command
6-
from roborock.devices.mqtt_channel import MqttChannel
5+
from roborock.devices.rpc.b01_q7_channel import send_decoded_command
76
from roborock.devices.traits import Trait
7+
from roborock.devices.transport.mqtt_channel import MqttChannel
88

99
from .command import CommandTrait
1010

0 commit comments

Comments
 (0)