Process a line of output, extracting JSON-RPC responses. Args: line: Line of text from serial output Returns: Parsed JSON object if line contains valid RPC response, None otherwise
(self, line: str)
| 27 | self.raw_lines: list[str] = [] |
| 28 | |
| 29 | def process_line(self, line: str) -> dict[str, Any] | None: |
| 30 | """Process a line of output, extracting JSON-RPC responses. |
| 31 | |
| 32 | Args: |
| 33 | line: Line of text from serial output |
| 34 | |
| 35 | Returns: |
| 36 | Parsed JSON object if line contains valid RPC response, None otherwise |
| 37 | """ |
| 38 | # Check if line starts with REMOTE: prefix |
| 39 | if not line.startswith(self.REMOTE_PREFIX): |
| 40 | return None |
| 41 | |
| 42 | # Extract JSON portion (everything after prefix) |
| 43 | json_str = line[len(self.REMOTE_PREFIX) :].strip() |
| 44 | self.raw_lines.append(json_str) |
| 45 | |
| 46 | # Parse JSON |
| 47 | try: |
| 48 | response = json.loads(json_str) |
| 49 | self.responses.append(response) |
| 50 | return response |
| 51 | except json.JSONDecodeError as e: |
| 52 | print(f"⚠️ Warning: Failed to parse REMOTE JSON: {e}") |
| 53 | print(f" Raw line: {json_str}") |
| 54 | return None |
| 55 | |
| 56 | def get_responses(self) -> list[dict[str, Any]]: |
| 57 | """Get all parsed JSON-RPC responses. |
no test coverage detected