File: common.py

package info (click to toggle)
python-roborock 4.12.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,480 kB
  • sloc: python: 16,602; makefile: 17; sh: 6
file content (26 lines) | stat: -rw-r--r-- 716 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
"""Common test utils for the protocols package."""

import json
from typing import Any

from Crypto.Cipher import AES
from Crypto.Util.Padding import pad

from roborock.roborock_message import RoborockMessage, RoborockMessageProtocol


def build_a01_message(message: dict[Any, Any], seq: int = 2020) -> RoborockMessage:
    """Build an encoded A01 RPC response message."""
    return RoborockMessage(
        protocol=RoborockMessageProtocol.RPC_RESPONSE,
        payload=pad(
            json.dumps(
                {
                    "dps": message,  # {10000: json.dumps(message)},
                }
            ).encode(),
            AES.block_size,
        ),
        version=b"A01",
        seq=seq,
    )