refactor(core): differentiate models by internal name in python

[no changelog]
pull/3219/head
tychovrahe 10 months ago committed by TychoVrahe
parent a41a8c5f87
commit 5a86add884

@ -1,5 +1,5 @@
#ifndef MODELS_MODEL_T2T1_H_
#define MODELS_MODEL_T2T1_H_
#ifndef MODELS_MODEL_D001_H_
#define MODELS_MODEL_D001_H_
#define MODEL_NAME "T"
#define MODEL_INTERNAL_NAME "D001"

@ -69,7 +69,7 @@ def get_features() -> Features:
unit_btconly=utils.unit_btconly(),
)
if utils.MODEL in ("1", "R"):
if utils.INTERNAL_MODEL in ("T1B1", "T2B1"):
f.homescreen_format = HomescreenFormat.ToiG
else:
f.homescreen_format = HomescreenFormat.Jpeg

@ -173,10 +173,10 @@ if __debug__:
debug_events.last_event += 1
# TT click on specific coordinates, with possible hold
if x is not None and y is not None and utils.MODEL in ("T", "DISC1"):
if x is not None and y is not None and utils.INTERNAL_MODEL in ("T2T1", "D001"):
click_chan.publish((debug_events.last_event, x, y, msg.hold_ms))
# TR press specific button
elif msg.physical_button is not None and utils.MODEL in ("R",):
elif msg.physical_button is not None and utils.INTERNAL_MODEL in ("T2B1",):
button_chan.publish(
(debug_events.last_event, msg.physical_button, msg.hold_ms)
)

@ -14,7 +14,7 @@ if TYPE_CHECKING:
BRT_PROTECT_CALL = ButtonRequestType.ProtectCall # CACHE
if utils.MODEL in ("1", "R"):
if utils.INTERNAL_MODEL in ("T1B1", "T2B1"):
def _validate_homescreen_model_specific(homescreen: bytes) -> None:
from trezor.ui import WIDTH, HEIGHT

@ -65,7 +65,7 @@ async def _continue_recovery_process() -> Success:
# If we are starting recovery, ask for word count first...
# _request_word_count
# For TT, just continuing straight to word count keyboard
if utils.MODEL == "R":
if utils.INTERNAL_MODEL == "T2B1":
await layout.homescreen_dialog(
"Continue", "Select the number of words in your backup."
)

@ -52,7 +52,7 @@ def _find_message_handler_module(msg_type: int) -> str:
if msg_type == MessageType.RebootToBootloader:
return "apps.management.reboot_to_bootloader"
if utils.MODEL in ("R",) and msg_type == MessageType.ShowDeviceTutorial:
if utils.INTERNAL_MODEL in ("T2B1",) and msg_type == MessageType.ShowDeviceTutorial:
return "apps.management.show_tutorial"
if utils.USE_SD_CARD and msg_type == MessageType.SdProtect:

@ -39,7 +39,7 @@ else:
# in both debug and production, emulator needs to draw the screen explicitly
if utils.EMULATOR or utils.MODEL in ("1", "R"):
if utils.EMULATOR or utils.INTERNAL_MODEL in ("T1B1", "T2B1"):
loop.after_step_hook = refresh
@ -120,7 +120,7 @@ class Component:
def __init__(self) -> None:
self.repaint = True
if utils.MODEL in ("T", "DISC1"):
if utils.INTERNAL_MODEL in ("T2T1", "D001"):
def dispatch(self, event: int, x: int, y: int) -> None:
if event is RENDER:
@ -143,7 +143,7 @@ class Component:
def on_touch_end(self, x: int, y: int) -> None:
pass
elif utils.MODEL in ("1", "R"):
elif utils.INTERNAL_MODEL in ("T1B1", "T2B1"):
def dispatch(self, event: int, x: int, y: int) -> None:
if event is RENDER:
@ -255,7 +255,7 @@ class Layout(Component):
Usually overridden to add another tasks to the list."""
return self.handle_input(), self.handle_rendering()
if utils.MODEL in ("T", "DISC1"):
if utils.INTERNAL_MODEL in ("T2T1", "D001"):
def handle_input(self) -> Generator:
"""Task that is waiting for the user input."""
@ -269,7 +269,7 @@ class Layout(Component):
# way to get the lowest input-to-render latency.
self.dispatch(RENDER, 0, 0)
elif utils.MODEL in ("1", "R"):
elif utils.INTERNAL_MODEL in ("T1B1", "T2B1"):
def handle_input(self) -> Generator:
"""Task that is waiting for the user input."""

@ -4,9 +4,9 @@ from .common import * # noqa: F401,F403
# NOTE: using any import magic probably causes mypy not to check equivalence of
# layout type signatures across models
if utils.MODEL in ("1", "R"):
if utils.INTERNAL_MODEL in ("T1B1", "T2B1"):
from .tr import * # noqa: F401,F403
elif utils.MODEL in ("T", "DISC1"):
elif utils.INTERNAL_MODEL in ("T2T1", "D001"):
from .tt_v2 import * # noqa: F401,F403
else:
raise ValueError("Unknown Trezor model")

@ -1,6 +1,6 @@
from trezor import utils
if utils.MODEL in ("T", "DISC1"):
if utils.INTERNAL_MODEL in ("T2T1", "D001"):
from .tt_v2.fido import * # noqa: F401,F403
elif utils.MODEL in ("R",):
elif utils.INTERNAL_MODEL in ("T2B1",):
from .tr.fido import * # noqa: F401,F403

@ -1,6 +1,6 @@
from trezor import utils
if utils.MODEL in ("T", "DISC1"):
if utils.INTERNAL_MODEL in ("T2T1", "D001"):
from .tt_v2.homescreen import * # noqa: F401,F403
elif utils.MODEL in ("R",):
elif utils.INTERNAL_MODEL in ("T2B1",):
from .tr.homescreen import * # noqa: F401,F403

@ -1,6 +1,6 @@
from trezor import utils
if utils.MODEL in ("T", "DISC1"):
if utils.INTERNAL_MODEL in ("T2T1", "D001"):
from .tt_v2.progress import * # noqa: F401,F403
elif utils.MODEL in ("R",):
elif utils.INTERNAL_MODEL in ("T2B1",):
from .tr.progress import * # noqa: F401,F403

@ -1,6 +1,6 @@
from trezor import utils
if utils.MODEL in ("T", "DISC1"):
if utils.INTERNAL_MODEL in ("T2T1", "D001"):
from .tt_v2.recovery import * # noqa: F401,F403
elif utils.MODEL in ("R",):
elif utils.INTERNAL_MODEL in ("T2B1",):
from .tr.recovery import * # noqa: F401,F403

@ -1,6 +1,6 @@
from trezor import utils
if utils.MODEL in ("T", "DISC1"):
if utils.INTERNAL_MODEL in ("T2T1", "D001"):
from .tt_v2.reset import * # noqa: F401,F403
elif utils.MODEL in ("R",):
elif utils.INTERNAL_MODEL in ("T2B1",):
from .tr.reset import * # noqa: F401,F403

@ -266,7 +266,9 @@ class TrezorClient(Generic[UI]):
if not self.model:
# Trezor Model One bootloader 1.8.0 or older does not send model name
self.model = models.by_name(features.model or "1")
self.model = models.by_internal_name(features.internal_model)
if self.model is None:
self.model = models.by_name(features.model or "1")
if self.model is None:
raise RuntimeError("Unsupported Trezor model")

@ -27,6 +27,7 @@ VENDORS = ("bitcointrezor.com", "trezor.io")
@dataclass(eq=True, frozen=True)
class TrezorModel:
name: str
internal_name: str
minimum_version: Tuple[int, int, int]
vendors: Collection[str]
usb_ids: Collection[UsbId]
@ -35,6 +36,7 @@ class TrezorModel:
TREZOR_ONE = TrezorModel(
name="1",
internal_name="T1B1",
minimum_version=(1, 8, 0),
vendors=VENDORS,
usb_ids=((0x534C, 0x0001),),
@ -43,6 +45,7 @@ TREZOR_ONE = TrezorModel(
TREZOR_T = TrezorModel(
name="T",
internal_name="T2T1",
minimum_version=(2, 1, 0),
vendors=VENDORS,
usb_ids=((0x1209, 0x53C1), (0x1209, 0x53C0)),
@ -51,6 +54,7 @@ TREZOR_T = TrezorModel(
TREZOR_R = TrezorModel(
name="R",
internal_name="T2B1",
minimum_version=(2, 1, 0),
vendors=VENDORS,
usb_ids=((0x1209, 0x53C1), (0x1209, 0x53C0)),
@ -59,6 +63,7 @@ TREZOR_R = TrezorModel(
TREZOR_DISC1 = TrezorModel(
name="DISC1",
internal_name="D001",
minimum_version=(2, 1, 0),
vendors=VENDORS,
usb_ids=((0x1209, 0x53C1), (0x1209, 0x53C0)),
@ -75,3 +80,12 @@ def by_name(name: Optional[str]) -> Optional[TrezorModel]:
if model.name == name:
return model
return None
def by_internal_name(name: Optional[str]) -> Optional[TrezorModel]:
if name is None:
return None
for model in TREZORS:
if model.internal_name == name:
return model
return None

Loading…
Cancel
Save