python(debuglink): implement from_internal_name
What changed, and why it matters
This is a small, safe code cleanup in Trezor's Python debug tooling. It splits an existing lookup function into two so developers can resolve a device's screen layout type from just its internal model name, without needing a full model object. There is no security issue visible in the change.
No security action required. Review as normal code-quality change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors LayoutType.from_model in python/src/trezorlib/debuglink.py by extracting a new classmethod LayoutType.from_internal_name. The new method performs the same mapping (T2T1→Bolt, T2B1/T3B1→Caesar, T3T1→Delizia, T3W1→Eckhart, T1B1→T1) that was already present in from_model, now reachable directly from a string. from_model is updated to delegate to from_internal_name as a fallback. No cryptographic, transport, or privileged behavior is modified; this is a pure helper refactor in debug/test infrastructure.
Changed components
python/src/trezorlib/debuglink.pyInspect captured patch +17 / −0
diff --git a/python/src/trezorlib/debuglink.py b/python/src/trezorlib/debuglink.py
index c0ac25f4..fe588803 100644
--- a/python/src/trezorlib/debuglink.py
+++ b/python/src/trezorlib/debuglink.py
@@ -91,8 +91,25 @@ class LayoutType(Enum):
return cls.Eckhart
if model in (models.T1B1,):
return cls.T1
+ internal_name = getattr(model, "internal_name", None)
+ if internal_name:
+ return cls.from_internal_name(internal_name)
raise ValueError(f"Unknown model: {model}")
+ @classmethod
+ def from_internal_name(cls, internal_name: str) -> "LayoutType":
+ if internal_name in (models.T2T1.internal_name,):
+ return cls.Bolt
+ if internal_name in (models.T2B1.internal_name, models.T3B1.internal_name):
+ return cls.Caesar
+ if internal_name in (models.T3T1.internal_name,):
+ return cls.Delizia
+ if internal_name in (models.T3W1.internal_name,):
+ return cls.Eckhart
+ if internal_name in (models.T1B1.internal_name,):
+ return cls.T1
+ raise ValueError(f"Unknown internal name: {internal_name}")
+
def __str__(self) -> str:
return self.name
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.