1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-21 23:18:13 +00:00

feat(python/debuglink): introduce layout type awareness

[no changelog]
This commit is contained in:
matejcik 2024-09-02 12:59:56 +02:00 committed by matejcik
parent 37d8649d5d
commit 6506b02e2e

View File

@ -21,7 +21,7 @@ import textwrap
import time import time
from copy import deepcopy from copy import deepcopy
from datetime import datetime from datetime import datetime
from enum import IntEnum from enum import Enum, IntEnum, auto
from itertools import zip_longest from itertools import zip_longest
from pathlib import Path from pathlib import Path
from typing import ( from typing import (
@ -65,6 +65,25 @@ EXPECTED_RESPONSES_CONTEXT_LINES = 3
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
class LayoutType(Enum):
T1 = auto()
TT = auto()
TR = auto()
Mercury = auto()
@classmethod
def from_model(cls, model: models.TrezorModel) -> "LayoutType":
if model in (models.T2T1,):
return cls.TT
if model in (models.T2B1, models.T3B1):
return cls.TR
if model in (models.T3T1,):
return cls.Mercury
if model in (models.T1B1,):
return cls.T1
raise ValueError(f"Unknown model: {model}")
class UnstructuredJSONReader: class UnstructuredJSONReader:
"""Contains data-parsing helpers for JSON data that have unknown structure.""" """Contains data-parsing helpers for JSON data that have unknown structure."""
@ -404,6 +423,11 @@ class DebugLink:
"""Differences in handling debug events and LayoutContent.""" """Differences in handling debug events and LayoutContent."""
return self.version < (2, 6, 1) return self.version < (2, 6, 1)
@property
def layout_type(self) -> LayoutType:
assert self.model is not None
return LayoutType.from_model(self.model)
def set_screen_text_file(self, file_path: Optional[Path]) -> None: def set_screen_text_file(self, file_path: Optional[Path]) -> None:
if file_path is not None: if file_path is not None:
file_path.write_bytes(b"") file_path.write_bytes(b"")
@ -995,6 +1019,10 @@ class TrezorClientDebugLink(TrezorClient):
self.debug.model = self.model self.debug.model = self.model
self.debug.version = self.version self.debug.version = self.version
@property
def layout_type(self) -> LayoutType:
return self.debug.layout_type
def reset_debug_features(self) -> None: def reset_debug_features(self) -> None:
"""Prepare the debugging client for a new testcase. """Prepare the debugging client for a new testcase.