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,
)
|