|
13 | 13 | from roborock.roborock_typing import RoborockCommand
|
14 | 14 | from roborock.util import get_next_int
|
15 | 15 |
|
16 |
| -# All mqtt commands are sent securely. Only local commands in this list are secured. |
17 |
| -COMMANDS_SECURED = { |
18 |
| - RoborockCommand.GET_MAP_V1, |
19 |
| - RoborockCommand.GET_MULTI_MAP, |
20 |
| -} |
21 |
| - |
22 | 16 | CommandType = RoborockCommand | str
|
23 | 17 | ParamsType = list | dict | int | None
|
24 | 18 |
|
@@ -79,24 +73,19 @@ def _get_payload(method: CommandType, params: ParamsType) -> RoborockMessage:
|
79 | 73 | return _get_payload
|
80 | 74 |
|
81 | 75 |
|
82 |
| -def create_local_payload_encoder(security_data: SecurityData) -> Callable[[CommandType, ParamsType], RoborockMessage]: |
83 |
| - """Create a payload encoder for V1 commands over local connection.""" |
84 |
| - |
85 |
| - def _get_payload(method: CommandType, params: ParamsType) -> RoborockMessage: |
86 |
| - """Build the payload for a V1 command.""" |
87 |
| - request = RequestMessage(method=method, params=params) |
88 |
| - is_secured = request.method in COMMANDS_SECURED |
89 |
| - payload = request.as_payload(security_data if is_secured else None) |
| 76 | +def encode_local_payload(method: CommandType, params: ParamsType) -> RoborockMessage: |
| 77 | + """Encode payload for V1 commands over local connection.""" |
90 | 78 |
|
91 |
| - message_retry: MessageRetry | None = None |
92 |
| - if method == RoborockCommand.RETRY_REQUEST and isinstance(params, dict): |
93 |
| - message_retry = MessageRetry(method=method, retry_id=params["retry_id"]) |
| 79 | + request = RequestMessage(method=method, params=params) |
| 80 | + payload = request.as_payload(security_data=None) |
94 | 81 |
|
95 |
| - return RoborockMessage( |
96 |
| - timestamp=request.timestamp, |
97 |
| - protocol=RoborockMessageProtocol.GENERAL_REQUEST, |
98 |
| - payload=payload, |
99 |
| - message_retry=message_retry, |
100 |
| - ) |
| 82 | + message_retry: MessageRetry | None = None |
| 83 | + if method == RoborockCommand.RETRY_REQUEST and isinstance(params, dict): |
| 84 | + message_retry = MessageRetry(method=method, retry_id=params["retry_id"]) |
101 | 85 |
|
102 |
| - return _get_payload |
| 86 | + return RoborockMessage( |
| 87 | + timestamp=request.timestamp, |
| 88 | + protocol=RoborockMessageProtocol.GENERAL_REQUEST, |
| 89 | + payload=payload, |
| 90 | + message_retry=message_retry, |
| 91 | + ) |
0 commit comments