@@ -6,7 +6,7 @@ Cloud and Network.
66
77## Architecture Overview
88
9- The library is organized into distinct layers, each with a specific responsibility:
9+ The library is organized into distinct layers, each with a specific responsibility. ** Different device protocols use different channel implementations: **
1010
1111``` mermaid
1212graph TB
@@ -15,66 +15,110 @@ graph TB
1515 end
1616
1717 subgraph "Device Management Layer"
18- DM[DeviceManager]
19- Traits[Device Traits]
18+ DM[DeviceManager<br/>Detects protocol version]
19+ end
20+
21+ subgraph "Device Types by Protocol"
22+ V1Dev[V1 Devices<br/>pv=1.0<br/>Most vacuums]
23+ A01Dev[A01 Devices<br/>pv=A01<br/>Dyad, Zeo]
24+ B01Dev[B01 Devices<br/>pv=B01<br/>Some models]
25+ end
26+
27+ subgraph "Traits Layer"
28+ V1Traits[V1 Traits<br/>Clean, Map, etc.]
29+ A01Traits[A01 Traits<br/>DPS-based]
30+ B01Traits[B01 Traits<br/>DPS-based]
2031 end
2132
2233 subgraph "Channel Layer"
23- V1C[V1Channel]
24- RPC[RpcChannel]
25- MC[MqttChannel]
26- LC[LocalChannel]
34+ V1C[V1Channel<br/>MQTT + Local]
35+ A01C[A01 send_decoded_command<br/>MQTT only]
36+ B01C[B01 send_decoded_command<br/>MQTT only]
37+ RPC[RpcChannel<br/>Multi-strategy]
38+ MC1[MqttChannel]
39+ MC2[MqttChannel]
40+ MC3[MqttChannel]
41+ LC[LocalChannel<br/>TCP :58867]
2742 end
2843
2944 subgraph "Session Layer"
30- MS[MqttSession]
31- LS[LocalSession Factory]
45+ MS[MqttSession<br/>Shared connection<br/>Idle timeout ]
46+ LS[LocalSession<br/> Factory]
3247 end
3348
3449 subgraph "Protocol Layer"
35- Proto[Protocol Encoders/Decoders]
36- V1P[V1 Protocol]
37- A01P[A01 Protocol]
38- B01P[B01 Protocol]
50+ V1P[V1 Protocol<br/>JSON RPC + AES]
51+ A01P[A01 Protocol<br/>DPS format]
52+ B01P[B01 Protocol<br/>DPS format]
3953 end
4054
4155 subgraph "Transport Layer"
42- MQTT[MQTT Broker]
43- TCP[TCP Socket]
56+ MQTT[MQTT Broker<br/>Roborock Cloud ]
57+ TCP[TCP Socket<br/>Direct to device ]
4458 end
4559
4660 User --> DM
47- User --> Traits
48- DM --> V1C
49- Traits --> RPC
61+ DM -->|pv=1.0| V1Dev
62+ DM -->|pv=A01| A01Dev
63+ DM -->|pv=B01| B01Dev
64+
65+ V1Dev --> V1Traits
66+ A01Dev --> A01Traits
67+ B01Dev --> B01Traits
68+
69+ V1Traits --> V1C
70+ A01Traits --> A01C
71+ B01Traits --> B01C
72+
5073 V1C --> RPC
51- RPC --> MC
52- RPC --> LC
53- MC --> MS
74+ RPC -->|Strategy 1| LC
75+ RPC -->|Strategy 2| MC1
76+ A01C --> MC2
77+ B01C --> MC3
78+
79+ MC1 --> MS
80+ MC2 --> MS
81+ MC3 --> MS
5482 LC --> LS
55- MS --> Proto
56- LC --> Proto
57- Proto --> V1P
58- Proto --> A01P
59- Proto --> B01P
83+
84+ MC1 --> V1P
85+ MC2 --> A01P
86+ MC3 --> B01P
87+ LC --> V1P
88+
6089 MS --> MQTT
6190 LC --> TCP
91+ MQTT <--> TCP
6292
6393 style User fill:#e1f5ff
6494 style DM fill:#fff4e1
6595 style V1C fill:#ffe1e1
6696 style RPC fill:#ffe1e1
6797 style MS fill:#e1ffe1
68- style Proto fill:#f0e1ff
98+ style V1P fill:#f0e1ff
99+ style A01P fill:#f0e1ff
100+ style B01P fill:#f0e1ff
69101```
70102
71103### Layer Responsibilities
72104
73- 1 . ** Device Management Layer** : High-level device discovery and lifecycle management
74- 2 . ** Channel Layer** : Request/response correlation and connection management
75- 3 . ** Session Layer** : Connection pooling and subscription management
76- 4 . ** Protocol Layer** : Message encoding/decoding for different device versions
77- 5 . ** Transport Layer** : Low-level MQTT and TCP communication
105+ 1 . ** Device Management Layer** : Detects protocol version (` pv ` field) and creates appropriate channels
106+ 2 . ** Device Types** : Different devices based on protocol version (V1, A01, B01)
107+ 3 . ** Traits Layer** : Protocol-specific device capabilities and commands
108+ 4 . ** Channel Layer** : Protocol-specific communication patterns
109+ - ** V1** : Full RPC channel with local + MQTT fallback
110+ - ** A01/B01** : Helper functions wrapping MqttChannel (MQTT only)
111+ 5 . ** Session Layer** : Connection pooling and subscription management
112+ 6 . ** Protocol Layer** : Message encoding/decoding for different device versions
113+ 7 . ** Transport Layer** : Low-level MQTT and TCP communication
114+
115+ ### Protocol-Specific Architecture
116+
117+ | Protocol | Channel Type | Local Support | RPC Strategy | Use Case |
118+ | ----------| -------------| ---------------| --------------| ----------|
119+ | ** V1** (` pv=1.0 ` ) | ` V1Channel ` with ` RpcChannel ` | ✅ Yes | Multi-strategy (Local → MQTT) | Most vacuum robots |
120+ | ** A01** (` pv=A01 ` ) | ` MqttChannel ` + helpers | ❌ No | Direct MQTT | Dyad, Zeo washers |
121+ | ** B01** (` pv=B01 ` ) | ` MqttChannel ` + helpers | ❌ No | Direct MQTT | Some newer models |
78122
79123## Init account setup
80124
@@ -114,9 +158,11 @@ that a newer version of the API should be used.
114158
115159## Device Connections
116160
117- ### Connection Flow
161+ ### Connection Flow by Protocol
162+
163+ The connection flow differs based on the device protocol version:
118164
119- The following diagram shows how a device connection is established and how commands flow through the system:
165+ #### V1 Devices (Most Vacuums) - MQTT + Local
120166
121167``` mermaid
122168sequenceDiagram
@@ -128,17 +174,18 @@ sequenceDiagram
128174 participant LC as LocalChannel
129175 participant MS as MqttSession
130176 participant Broker as MQTT Broker
131- participant Device as Vacuum Device
177+ participant Device as V1 Vacuum
132178
133179 App->>DM: create_device_manager()
134180 DM->>MS: Create MQTT Session
135181 MS->>Broker: Connect
136182 Broker-->>MS: Connected
137183
138184 App->>DM: get_devices()
185+ Note over DM: Detect pv=1.0
139186 DM->>V1C: Create V1Channel
140187 V1C->>MC: Create MqttChannel
141- V1C->>LC: Create LocalChannel (if available )
188+ V1C->>LC: Create LocalChannel (deferred )
142189
143190 Note over V1C: Subscribe to device topics
144191 V1C->>MC: subscribe()
@@ -157,6 +204,78 @@ sequenceDiagram
157204 MC->>RPC: decoded message
158205 RPC-->>V1C: NetworkInfo
159206
207+ Note over V1C: Connect locally using IP
208+ V1C->>LC: connect()
209+ LC->>Device: TCP Connect :58867
210+ Device-->>LC: Connected
211+
212+ Note over App: Commands prefer local
213+ App->>V1C: send_command(GET_STATUS)
214+ V1C->>RPC: send_command()
215+ RPC->>LC: publish(request) [Try local first]
216+ LC->>Device: Command via TCP
217+ Device->>LC: Response
218+ LC->>RPC: decoded message
219+ RPC-->>App: Status
220+ ```
221+
222+ #### A01/B01 Devices (Dyad, Zeo) - MQTT Only
223+
224+ ``` mermaid
225+ sequenceDiagram
226+ participant App as Application
227+ participant DM as DeviceManager
228+ participant A01 as A01 Traits
229+ participant Helper as send_decoded_command
230+ participant MC as MqttChannel
231+ participant MS as MqttSession
232+ participant Broker as MQTT Broker
233+ participant Device as A01 Device
234+
235+ App->>DM: create_device_manager()
236+ DM->>MS: Create MQTT Session
237+ MS->>Broker: Connect
238+ Broker-->>MS: Connected
239+
240+ App->>DM: get_devices()
241+ Note over DM: Detect pv=A01
242+ DM->>MC: Create MqttChannel
243+ DM->>A01: Create A01 Traits
244+
245+ Note over A01: Subscribe to device topics
246+ A01->>MC: subscribe()
247+ MC->>MS: subscribe(topic, callback)
248+ MS->>Broker: SUBSCRIBE
249+
250+ Note over App: All commands via MQTT
251+ App->>A01: set_power(True)
252+ A01->>Helper: send_decoded_command()
253+ Helper->>MC: subscribe(find_response)
254+ Helper->>MC: publish(request)
255+ MC->>MS: publish(topic, message)
256+ MS->>Broker: PUBLISH
257+ Broker->>Device: Command
258+ Device->>Broker: Response
259+ Broker->>MS: Message
260+ MS->>MC: callback(message)
261+ MC->>Helper: decoded message
262+ Helper-->>App: Result
263+ ```
264+
265+ ### Key Differences
266+
267+ | Aspect | V1 Devices | A01/B01 Devices |
268+ | --------| ------------| -----------------|
269+ | ** Protocols** | V1 Protocol (JSON RPC) | DPS Protocol |
270+ | ** Transports** | MQTT + Local TCP | MQTT only |
271+ | ** Channel Type** | ` V1Channel ` with ` RpcChannel ` | ` MqttChannel ` with helpers |
272+ | ** Local Support** | ✅ Yes, preferred | ❌ No |
273+ | ** Fallback** | Local → MQTT | N/A |
274+ | ** Connection** | Requires network info fetch | Direct MQTT |
275+ | ** Examples** | Most vacuum robots | Dyad washers, Zeo models |
276+ MC->>RPC: decoded message
277+ RPC-->>V1C: NetworkInfo
278+
160279 Note over V1C: Connect locally using IP from NetworkInfo
161280 V1C->>LC: connect()
162281 LC->>Device: TCP Connect :58867
0 commit comments