diff --git a/roborock/devices/device.py b/roborock/devices/device.py index e58bac9d..d7908c74 100644 --- a/roborock/devices/device.py +++ b/roborock/devices/device.py @@ -33,7 +33,9 @@ MIN_BACKOFF_INTERVAL = datetime.timedelta(seconds=10) MAX_BACKOFF_INTERVAL = datetime.timedelta(minutes=30) BACKOFF_MULTIPLIER = 1.5 -START_ATTEMPT_TIMEOUT = datetime.timedelta(seconds=5) +# Give time for the NETWORK_INFO fetch and V1 hello attempt +# and potential fallback to L01. +START_ATTEMPT_TIMEOUT = datetime.timedelta(seconds=15) DeviceReadyCallback = Callable[["RoborockDevice"], None] diff --git a/tests/e2e/__snapshots__/test_device_manager.ambr b/tests/e2e/__snapshots__/test_device_manager.ambr index 5f0f70c6..ccea0922 100644 --- a/tests/e2e/__snapshots__/test_device_manager.ambr +++ b/tests/e2e/__snapshots__/test_device_manager.ambr @@ -1,5 +1,215 @@ # serializer version: 1 -# name: test_device_manager +# name: test_l01_device + [mqtt >] + 00000000 10 29 00 04 4d 51 54 54 05 c2 00 3c 00 00 00 00 |.)..MQTT...<....| + 00000010 08 31 39 36 34 38 66 39 34 00 10 32 33 34 36 37 |.19648f94..23467| + 00000020 38 65 61 38 35 34 66 31 39 39 65 |8ea854f199e| + [mqtt <] + 00000000 20 09 02 00 06 22 00 0a 21 00 14 | ...."..!..| + [mqtt >] + 00000000 82 24 00 01 00 00 1e 72 72 2f 6d 2f 6f 2f 75 73 |.$.....rr/m/o/us| + 00000010 65 72 31 32 33 2f 31 39 36 34 38 66 39 34 2f 61 |er123/19648f94/a| + 00000020 62 63 31 32 33 00 |bc123.| + [mqtt <] + 00000000 90 04 00 01 00 00 |......| + [mqtt >] + 00000000 30 f8 01 00 1e 72 72 2f 6d 2f 69 2f 75 73 65 72 |0....rr/m/i/user| + 00000010 31 32 33 2f 31 39 36 34 38 66 39 34 2f 61 62 63 |123/19648f94/abc| + 00000020 31 32 33 00 31 2e 30 00 00 23 83 00 00 23 84 68 |123.1.0..#...#.h| + 00000030 a6 a2 27 00 65 00 c0 d5 b7 f1 34 a4 76 21 76 0a |..'.e.....4.v!v.| + 00000040 ed 60 71 51 04 ae bd 39 9b 41 c6 34 63 89 66 1f |.`qQ...9.A.4c.f.| + 00000050 c2 8b 96 83 ec 93 45 55 f0 cf ed 93 0f 45 ff a9 |......EU.....E..| + 00000060 a4 8b a5 5a c9 25 36 1a eb cf 1d 6d d9 b5 b6 37 |...Z.%6....m...7| + 00000070 8a a3 4d 9c 2f e4 41 f3 75 28 11 6c 2d 39 83 cb |..M./.A.u(.l-9..| + 00000080 b1 60 8b 92 d5 b7 a7 be e3 c0 aa 80 94 0c 99 12 |.`..............| + 00000090 a2 e1 97 7e 3e ea 29 27 0f 9e 9c 22 97 0b 9c 59 |...~>.)'..."...Y| + 000000a0 78 da 88 55 6b 52 58 b7 a3 2b 85 67 49 5e 90 85 |x..UkRX..+.gI^..| + 000000b0 d8 7a bb b3 c9 14 6c fb 42 1c 85 96 23 ff 30 02 |.z....l.B...#.0.| + 000000c0 78 20 1c 5b 96 e1 f2 ad f2 62 28 c2 8a 9f 97 79 |x .[.....b(....y| + 000000d0 f9 73 25 c4 66 98 e8 ea f3 37 20 f9 94 7e 2b d6 |.s%.f....7 ..~+.| + 000000e0 fb 9a ed 2c 37 e8 b2 b0 3d f3 93 6f 17 d7 89 31 |...,7...=..o...1| + 000000f0 bb e0 42 8b 18 fd 0d 62 2d 95 ca |..B....b-..| + [mqtt <] + 00000000 30 8c 02 00 1e 72 72 2f 6d 2f 6f 2f 75 73 65 72 |0....rr/m/o/user| + 00000010 31 32 33 2f 31 39 36 34 38 66 39 34 2f 61 62 63 |123/19648f94/abc| + 00000020 31 32 33 00 00 00 00 e7 31 2e 30 00 00 00 01 00 |123.....1.0.....| + 00000030 00 00 17 68 a6 a2 23 00 66 00 d0 84 66 bd 8c 5a |...h..#.f...f..Z| + 00000040 42 4a aa 2d 9e bf 93 7e 3e 92 5a 46 38 2b db 75 |BJ.-...~>.ZF8+.u| + 00000050 ab 6c 28 b5 3d 80 d9 b7 73 cf b9 9e cf 62 52 ca |.l(.=...s....bR.| + 00000060 4e b4 7e b9 89 e9 50 45 4d f3 e1 c8 a9 a4 65 f1 |N.~...PEM.....e.| + 00000070 6d ff 2d e4 c6 c8 4e 8b 85 08 5c 20 91 76 f7 af |m.-...N...\ .v..| + 00000080 cf 25 80 48 e6 95 97 b1 0f b0 6e 1e 62 26 a1 d1 |.%.H......n.b&..| + 00000090 38 c4 f1 39 2a b9 3b 05 0e 37 cb d5 5b cd 95 e7 |8..9*.;..7..[...| + 000000a0 4b f6 ff d7 03 dc 6b e3 ac d6 7e ec a7 75 64 08 |K.....k...~..ud.| + 000000b0 2d 2a 6d e1 af 94 ee a4 b3 4f ed 1e d8 aa 76 f0 |-*m......O....v.| + 000000c0 bd 02 37 7c 6b 5b fb 8d 62 b0 c1 85 79 49 df 67 |..7|k[..b...yI.g| + 000000d0 3c 1e 9a a3 b3 4d 1d 50 ac 9f 62 b9 99 4f 45 47 |<....M.P..b..OEG| + 000000e0 ba 41 30 53 19 63 92 84 c5 bc a4 33 2f 21 8c dd |.A0S.c.....3/!..| + 000000f0 6e f2 b1 ed 08 59 50 2a b1 a9 e2 f1 bb af 4b 6b |n....YP*......Kk| + 00000100 7c 87 7f 0c dd 9b 6d 26 a4 20 bb a7 e0 82 5c ||.....m&. ....\| + [local >] + 00000000 00 00 00 15 31 2e 30 00 00 00 01 00 00 23 85 68 |....1.0......#.h| + 00000010 a6 a2 28 00 00 2a 04 e3 89 |..(..*...| + [local <] + 00000000 00 |.| + [local >] + 00000000 00 00 00 15 4c 30 31 00 00 00 01 00 00 23 85 68 |....L01......#.h| + 00000010 a6 a2 29 00 00 22 92 f7 02 |..).."...| + [local <] + 00000000 00 00 00 29 4c 30 31 00 00 00 01 00 00 00 17 68 |...)L01........h| + 00000010 a6 a2 24 00 01 00 12 c1 07 5b 52 43 96 97 c5 29 |..$......[RC...)| + 00000020 59 36 cc 5c 9c 8b f2 ab 8a f0 30 d7 a9 |Y6.\......0..| + [local >] + 00000000 00 00 00 86 4c 30 31 00 00 23 87 00 00 23 88 68 |....L01..#...#.h| + 00000010 a6 a2 2a 00 04 00 6f 62 62 b7 96 c7 51 5f a7 4b |..*...obb...Q_.K| + 00000020 92 8f ce 25 cb 15 55 28 7a 93 03 83 ec 3c d9 9b |...%..U(z....<..| + 00000030 e2 c0 34 22 93 c0 c6 9a ff b2 9a df c3 01 b3 ad |..4"............| + 00000040 f3 a4 7f 05 f5 9c c5 89 38 55 42 09 ad 60 56 88 |........8UB..`V.| + 00000050 b7 cb 6f 62 f2 6d 04 a3 39 1f 69 70 64 41 29 d8 |..ob.m..9.ipdA).| + 00000060 20 a8 b4 64 d0 ae 37 79 b4 85 44 bb 66 87 14 39 | ..d..7y..D.f..9| + 00000070 33 20 60 02 0f 4e b1 bf 87 8a 84 5a 29 44 e1 d5 |3 `..N.....Z)D..| + 00000080 40 a6 02 6a 67 81 63 37 eb 07 |@..jg.c7..| + [local <] + 00000000 00 00 03 b5 4c 30 31 00 00 00 02 00 00 00 17 68 |....L01........h| + 00000010 a6 a2 25 00 66 03 9e f6 bf 79 0a 3e 32 de 58 fa |..%.f....y.>2.X.| + 00000020 f1 b0 dd a2 47 f6 30 37 c6 c1 24 70 3d bd 9c 15 |....G.07..$p=...| + 00000030 1f 2e 64 c7 95 7a e4 4f 5d 0a c6 d6 7a 9f b9 ad |..d..z.O]...z...| + 00000040 10 75 e3 b5 ff 4c e0 b5 dd 20 34 53 6f 40 4d ef |.u...L... 4So@M.| + 00000050 9c fd c7 83 49 99 80 0b 29 c9 b0 e7 57 4f 7d 24 |....I...)...WO}$| + 00000060 3b 09 42 fb 78 1f cc 39 2e ff 05 e3 0a 19 7f be |;.B.x..9........| + 00000070 6e cc ee d4 fe 3a dc 92 00 9e 07 09 ae 74 fc 95 |n....:.......t..| + 00000080 8b 4e 87 73 40 da bc 06 40 62 e7 49 86 e8 03 36 |.N.s@...@b.I...6| + 00000090 01 21 84 47 2b 1c 5f 64 26 8a 3c 65 0f 83 91 86 |.!.G+._d&..Mv..Z| + 000002d0 e0 cf 61 65 3b d4 30 04 f1 9f c0 14 33 b4 dc a0 |..ae;.0.....3...| + 000002e0 6e cc b7 eb 7d 52 e0 e2 c7 87 7e 31 52 64 92 3f |n...}R....~1Rd.?| + 000002f0 5d 55 d8 92 d0 d9 c0 11 92 36 40 f1 cc 67 14 84 |]U.......6@..g..| + 00000300 2a 00 08 91 21 b5 c9 12 c0 56 34 57 d2 e8 ef 51 |*...!....V4W...Q| + 00000310 81 10 eb c9 d9 84 a3 38 6d b5 b7 2c b6 52 a5 d6 |.......8m..,.R..| + 00000320 c5 33 94 a7 ed 27 00 c1 2e e2 88 0f 73 16 59 06 |.3...'......s.Y.| + 00000330 47 aa 45 6e e1 c7 31 69 b8 87 ae 1d 8f 01 ab 38 |G.En..1i.......8| + 00000340 69 ba a0 48 a0 47 3b a4 8f bf ac 51 64 6d e8 6a |i..H.G;....Qdm.j| + 00000350 ce a4 0a 2f af 36 04 97 60 f7 98 da df 84 7b d2 |.../.6..`.....{.| + 00000360 c6 c4 ac 9e 7d d7 86 b8 61 2b 1f b7 8e 19 67 69 |....}...a+....gi| + 00000370 cf 4e 65 b0 e9 50 b2 19 23 9e 8b de 4f 08 87 d2 |.Ne..P..#...O...| + 00000380 14 64 53 b8 f1 34 a9 ce 34 d3 c4 81 64 c0 9f 43 |.dS..4..4...d..C| + 00000390 c2 c4 bb 0b b0 ae ed e7 3f 28 cd 90 dd f6 7e dd |........?(....~.| + 000003a0 f7 2a 36 ad a6 a3 e2 1c 5e 52 41 a7 da 02 1e b4 |.*6.....^RA.....| + 000003b0 b5 c6 bf 22 a1 9f 76 65 45 |..."..veE| + [local >] + 00000000 00 00 00 7d 4c 30 31 00 00 23 8a 00 00 23 8b 68 |...}L01..#...#.h| + 00000010 a6 a2 2b 00 04 00 66 20 60 4b 53 1e 12 de 76 a8 |..+...f `KS...v.| + 00000020 54 c9 45 0a 1f 8d ec 16 42 2c 16 30 9b 69 03 a8 |T.E.....B,.0.i..| + 00000030 28 76 60 ff cf 40 84 05 29 92 68 05 71 df b5 5f |(v`..@..).h.q.._| + 00000040 56 f6 f1 d1 05 89 8f 23 6c 02 56 38 a2 e8 5a 08 |V......#l.V8..Z.| + 00000050 02 bd 2b db b7 c8 ff 25 52 ac 76 52 50 e7 a3 24 |..+....%R.vRP..$| + 00000060 4d ee 52 b4 00 f9 e2 49 c7 23 4b bd 11 6e cd 31 |M.R....I.#K..n.1| + 00000070 32 b3 57 f0 68 3d f4 87 10 21 5d 5a 0f e7 5a b4 |2.W.h=...!]Z..Z.| + 00000080 55 |U| + [local <] + 00000000 00 00 04 2a 4c 30 31 00 00 00 03 00 00 00 17 68 |...*L01........h| + 00000010 a6 a2 26 00 66 04 13 ce 36 7e 30 29 16 38 0c d3 |..&.f...6~0).8..| + 00000020 b0 34 ac 93 71 51 2c 20 ac a7 fb fa b7 1d 24 98 |.4..qQ, ......$.| + 00000030 4f 23 6e 89 0c 21 07 b4 8b a1 5a 86 ab c8 8e 94 |O#n..!....Z.....| + 00000040 9b 0f fc 8d 57 bc 01 a8 8e 95 27 e3 6a 08 5f b6 |....W.....'.j._.| + 00000050 cc 78 7c 39 c5 07 44 ae 70 2b bb e2 0a 0f 90 e9 |.x|9..D.p+......| + 00000060 a2 00 c5 9f 06 f2 b0 a5 85 e8 59 c5 36 bd 87 83 |..........Y.6...| + 00000070 78 e4 ed 0d 48 1c 60 bc 7f d9 aa c7 e5 25 cb 1b |x...H.`......%..| + 00000080 24 c7 c6 d8 96 c7 5d c8 f7 e5 a9 03 c9 6b 52 3e |$.....]......kR>| + 00000090 43 56 0a 82 9f bb f8 3d 92 38 9d 65 d0 26 53 cf |CV.....=.8.e.&S.| + 000000a0 62 48 ae ce 77 df 70 4a 0f e1 fc c7 36 da e7 64 |bH..w.pJ....6..d| + 000000b0 1f b0 aa 07 a1 1a 46 78 55 ad b7 52 99 33 16 a7 |......FxU..R.3..| + 000000c0 ed f4 a6 a3 45 58 bc a9 c0 4e db 0d 8c 7e 23 a2 |....EX...N...~#.| + 000000d0 d1 08 34 49 e5 ba 3e df c1 e3 b7 a4 38 78 47 e2 |..4I..>.....8xG.| + 000000e0 21 5f 16 30 86 c3 14 f8 f6 16 f9 aa d9 7f f5 87 |!_.0............| + 000000f0 70 a1 d2 3b a6 55 63 fe 78 7f c5 f5 bf 6d 51 80 |p..;.Uc.x....mQ.| + 00000100 d1 d9 e6 ce 5f 93 16 8b f7 b2 02 41 62 a9 90 95 |...._......Ab...| + 00000110 1f a9 82 3b 9e 22 ed 84 c5 31 12 bc 2d 7b 52 05 |...;."...1..-{R.| + 00000120 eb c3 b8 e9 66 5e 59 cf cb 4f b1 39 6b 8a 61 b8 |....f^Y..O.9k.a.| + 00000130 48 f4 a8 de 92 5e 68 c5 01 36 65 3c 5c 60 83 93 |H....^h..6e<\`..| + 00000140 25 f1 d4 96 fa a1 e9 3e 22 18 c2 b5 27 1e bb 92 |%......>"...'...| + 00000150 06 3c 6a ee 3e 03 fb a3 73 fe 22 5c ca f4 90 95 |....s."\....| + 00000160 be cf 91 dd 1e 3f fe ef 5b ac a6 5d 23 f2 9a 28 |.....?..[..]#..(| + 00000170 20 79 ec b7 0c 4b cc a3 3c a6 02 ce 3c eb b9 93 | y...K..<...<...| + 00000180 60 5b bb ab ab 1a 86 1f d2 3a 63 38 12 d2 2c 15 |`[.......:c8..,.| + 00000190 5e f0 12 23 c0 86 93 b7 70 fc 29 2b 75 41 e5 43 |^..#....p.)+uA.C| + 000001a0 ad 64 64 33 4d f3 a9 7b f9 4c 79 62 b0 3a 22 d5 |.dd3M..{.Lyb.:".| + 000001b0 0c 22 ee 55 60 11 0d 30 f5 ac ac a6 42 ec 12 85 |.".U`..0....B...| + 000001c0 d4 7f d1 ba 11 d3 da 40 03 d6 d6 1b d6 35 72 77 |.......@.....5rw| + 000001d0 49 05 be e6 c8 c7 84 4c 25 0b 4d b6 1f 59 2b 09 |I......L%.M..Y+.| + 000001e0 d5 4a 59 f1 7d 19 70 a9 39 29 25 fd 0e d1 ad 5d |.JY.}.p.9)%....]| + 000001f0 6a 91 c3 61 c7 ad c1 ed 4f 47 8c 54 d7 27 25 ee |j..a....OG.T.'%.| + 00000200 77 30 2d 36 73 60 3a d1 9b 5b 8a 8f 52 be f3 f7 |w0-6s`:..[..R...| + 00000210 68 a3 f5 16 a6 c3 df 2d c0 93 15 4a f9 00 3b 7d |h......-...J..;}| + 00000220 29 8c c4 ab 25 a5 ea d3 03 fc 67 06 b3 d3 23 55 |)...%.....g...#U| + 00000230 ef 8c 03 84 e2 af 3c b9 22 f4 cf 9e 44 9f df 4a |......<."...D..J| + 00000240 95 7e 22 8a 92 29 ce 86 6f 0a 70 6d 7b 47 2e 99 |.~"..)..o.pm{G..| + 00000250 6f d5 46 a8 61 13 2c 00 cb 06 80 fa 6d 73 20 88 |o.F.a.,.....ms .| + 00000260 e5 ec 00 89 4d 38 93 5c 11 28 5a 0e e7 3c 21 18 |....M8.\.(Z.....p......| + 00000340 12 85 2a 27 5a 92 54 fe ec 6f 51 ee 9a d6 ec 5a |..*'Z.T..oQ....Z| + 00000350 60 3e 12 5e 4b 78 c2 60 c5 3e 06 c1 24 43 4f 31 |`>.^Kx.`.>..$CO1| + 00000360 1a 37 61 06 d7 b3 f4 a9 bd 5b 1f 4e cf d7 c9 81 |.7a......[.N....| + 00000370 1b 5e f5 94 af 10 55 b2 01 e6 89 a7 1d 68 df b2 |.^....U......h..| + 00000380 8c a6 9a 2b 36 5c e2 9c 4b 69 0e 2e 03 b6 e3 18 |...+6\..Ki......| + 00000390 4c ca 5e 4e e6 44 1b 1f e9 e0 7d 73 2e 72 ce 39 |L.^N.D....}s.r.9| + 000003a0 e3 12 90 89 12 eb 93 34 1a 11 4f d1 98 33 c0 41 |.......4..O..3.A| + 000003b0 f0 6b 5d 64 90 4a cc 5c f6 2f 46 a0 55 20 d7 36 |.k]d.J.\./F.U .6| + 000003c0 0c 92 1a 85 68 aa 44 73 1d d0 7c c4 ba 31 33 a0 |....h.Ds..|..13.| + 000003d0 43 00 0e b3 43 68 98 7b 3d f9 4f 7c e8 c4 30 9e |C...Ch.{=.O|..0.| + 000003e0 0c b8 c1 89 56 88 a1 1c 5b ff dd 92 2c ef bf 0e |....V...[...,...| + 000003f0 23 48 d2 bd 48 84 99 14 a7 e8 19 cc 50 5e 0a 05 |#H..H.......P^..| + 00000400 90 1a e0 25 1a 4b 55 74 fe 59 36 47 e3 e5 79 fd |...%.KUt.Y6G..y.| + 00000410 a0 9b 5e 72 8d 3e 57 69 0b 7c 21 80 2f a4 d5 12 |..^r.>Wi.|!./...| + 00000420 99 be 49 6e f3 0b 57 e5 a8 1e 88 b6 7b 48 |..In..W.....{H| +# --- +# name: test_v1_device [mqtt >] 00000000 10 29 00 04 4d 51 54 54 05 c2 00 3c 00 00 00 00 |.)..MQTT...<....| 00000010 08 31 39 36 34 38 66 39 34 00 10 32 33 34 36 37 |.19648f94..23467| diff --git a/tests/e2e/test_device_manager.py b/tests/e2e/test_device_manager.py index 6971df9b..083775e4 100644 --- a/tests/e2e/test_device_manager.py +++ b/tests/e2e/test_device_manager.py @@ -4,7 +4,7 @@ mock out the lower level socket connections to simulate a broker which gets us close to an "end to end" test without needing an actual MQTT broker server. -These are higher level tests that the similar tests in tests/mqtt/test_roborock_session.py +These are higher level tests than the similar tests in tests/mqtt/test_roborock_session.py which use mocks to verify specific behaviors. """ @@ -16,6 +16,7 @@ import pytest import syrupy +from roborock.data.containers import UserData from roborock.devices.cache import Cache, InMemoryCache from roborock.devices.device_manager import DeviceManager, UserParams, create_device_manager from roborock.protocol import MessageParser @@ -104,14 +105,10 @@ def __init__(self) -> None: def build( self, payload: bytes, - seq: int | None = None, protocol: RoborockMessageProtocol | None = None, ) -> bytes: """Build an encoded response message.""" - if seq is not None: - self.seq_counter = seq - else: - self.seq_counter += 1 + self.seq_counter += 1 return MessageParser.build( RoborockMessage( protocol=protocol if protocol is not None else self.protocol, @@ -145,7 +142,7 @@ def build_rpc( ) -async def test_device_manager( +async def test_v1_device( mock_rest: Any, push_mqtt_response: Callable[[bytes], None], local_response_queue: asyncio.Queue[bytes], @@ -154,7 +151,7 @@ async def test_device_manager( snapshot: syrupy.SnapshotAssertion, device_manager_factory: Callable[[UserParams], Awaitable[DeviceManager]], ) -> None: - """Test the device manager end to end flow.""" + """Test the device manager end to end flow with a v1 device.""" # Simulate the login flow to get user params web_api = RoborockApiClient(username=TEST_USERNAME) @@ -177,9 +174,10 @@ async def test_device_manager( push_mqtt_response(response) # Prepare local device responses. The ids are deterministic based on deterministic_message_fixtures + response_builder.seq_counter = 0 local_responses: list[bytes] = [ # Queue HELLO response - response_builder.build(protocol=RoborockMessageProtocol.HELLO_RESPONSE, seq=1, payload=b"ok"), + response_builder.build(protocol=RoborockMessageProtocol.HELLO_RESPONSE, payload=b"ok"), # Feature discovery part 1 & 2 response_builder.build_rpc(data={"id": 9094, "result": [mock_data.APP_GET_INIT_STATUS]}), response_builder.build_rpc(data={"id": 9097, "result": [mock_data.STATUS]}), @@ -231,8 +229,9 @@ async def test_device_manager( push_mqtt_response(response) # Prepare local device responses. + response_builder.seq_counter = 0 local_response_queue.put_nowait( - response_builder.build(protocol=RoborockMessageProtocol.HELLO_RESPONSE, seq=1, payload=b"ok") + response_builder.build(protocol=RoborockMessageProtocol.HELLO_RESPONSE, payload=b"ok") ) device_manager = await device_manager_factory(user_params) @@ -268,3 +267,81 @@ async def test_device_manager( assert device.v1_properties.status.state_name == "charging" assert snapshot == log + + +async def test_l01_device( + mock_rest: Any, + push_mqtt_response: Callable[[bytes], None], + local_response_queue: asyncio.Queue[bytes], + local_received_requests: asyncio.Queue[bytes], + log: CapturedRequestLog, + snapshot: syrupy.SnapshotAssertion, + device_manager_factory: Callable[[UserParams], Awaitable[DeviceManager]], +) -> None: + """Test the device manager end to end flow with a l01 device.""" + # Prepare MQTT requests + mqtt_response_builder = ResponseBuilder() + mqtt_responses: list[bytes] = [ + # MQTT connection response + mqtt_packet.gen_connack(rc=0, flags=2), + # ACK the request to subscribe to the topic + mqtt_packet.gen_suback(mid=1), + # ACK the GET_NETWORK_INFO call. id is deterministic based on deterministic_message_fixtures + mqtt_packet.gen_publish( + TEST_TOPIC, mid=2, payload=mqtt_response_builder.build_rpc(data={"id": 9090, "result": NETWORK_INFO}) + ), + ] + for response in mqtt_responses: + push_mqtt_response(response) + + # Prepare local device responses. The ids are deterministic based on deterministic_message_fixtures + local_response_builder = ResponseBuilder() + local_response_builder.version = LocalProtocolVersion.L01 + local_response_builder.connect_nonce = 9093 + local_responses: list[bytes] = [ + # Initial V01 Hello request will fail and cause a retry with L01 + b"\x00", + # Queue HELLO response with L01 + local_response_builder.build(protocol=RoborockMessageProtocol.HELLO_RESPONSE, payload=b"ok"), + ] + # Feature discovery requests are sent with an ack nonce based on the random sent in HELLO_RESPONSE + local_response_builder.ack_nonce = TEST_RANDOM + local_responses.extend( + [ + local_response_builder.build_rpc(data={"id": 9094, "result": [mock_data.APP_GET_INIT_STATUS]}), + local_response_builder.build_rpc(data={"id": 9097, "result": [mock_data.STATUS]}), + ] + ) + for payload in local_responses: + local_response_queue.put_nowait(payload) + + # Create the device manager + user_params = UserParams( + username=TEST_USERNAME, + user_data=UserData.from_dict(mock_data.USER_DATA), + base_url=mock_data.BASE_URL, + ) + device_manager = await device_manager_factory(user_params) + + # The mocked Home Data API returns a single v1 device + devices = await device_manager.get_devices() + assert len(devices) == 1 + device = devices[0] + assert device.duid == "abc123" + assert device.name == "Roborock S7 MaxV" + assert device.is_connected + assert device.is_local_connected + + # Verify GET_STATUS response based on mock_data.STATUS + assert device.v1_properties + assert device.v1_properties.status + assert device.v1_properties.status.state_name == "charging" + assert device.v1_properties.status.battery == 100 + assert device.v1_properties.status.clean_time == 1176 + + # Verify arbitrary device features + assert device.v1_properties.device_features.is_show_clean_finish_reason_supported + assert device.v1_properties.device_features.is_customized_clean_supported + assert not device.v1_properties.device_features.is_matter_supported + + assert snapshot == log