Skip to content

Commit 069d05a

Browse files
committed
Merge branch 'simulatorparams'
2 parents 43967c8 + cbd2a99 commit 069d05a

File tree

3 files changed

+23
-19
lines changed

3 files changed

+23
-19
lines changed

py/bitbox02/bitbox02/communication/bitbox_api_protocol.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -526,24 +526,34 @@ class BitBoxCommonAPI:
526526

527527
# pylint: disable=too-many-public-methods,too-many-arguments
528528
def __init__(
529-
self, transport: TransportLayer, device_info: DeviceInfo, noise_config: BitBoxNoiseConfig
529+
self,
530+
transport: TransportLayer,
531+
device_info: Optional[DeviceInfo],
532+
noise_config: BitBoxNoiseConfig,
530533
):
531534
"""
532535
Can raise LibraryVersionOutdatedException. check_min_version() should be called following
533536
the instantiation.
537+
If device_info is None, it is infered using the OP_INFO API call, available since
538+
firmware version v5.0.0.
534539
"""
535540
self.debug = False
536-
serial_number = device_info["serial_number"]
537541

538-
if device_info["product_string"] == BITBOX02MULTI:
539-
self.edition = BitBox02Edition.MULTI
540-
elif device_info["product_string"] == BITBOX02BTC:
541-
self.edition = BitBox02Edition.BTCONLY
542+
if device_info is not None:
543+
version = device_info["serial_number"]
544+
if device_info["product_string"] == BITBOX02MULTI:
545+
edition = BitBox02Edition.MULTI
546+
elif device_info["product_string"] == BITBOX02BTC:
547+
edition = BitBox02Edition.BTCONLY
548+
else:
549+
version, _, edition, _ = self.get_info(transport)
542550

543-
self.version = parse_device_version(serial_number)
544-
if self.version is None:
551+
self.edition = edition
552+
try:
553+
self.version = parse_device_version(version)
554+
except:
545555
transport.close()
546-
raise ValueError(f"Could not parse version from {serial_number}")
556+
raise
547557

548558
# Delete the prelease part, as it messes with the comparison (e.g. 3.0.0-pre < 3.0.0 is
549559
# True, but the 3.0.0-pre has already the same API breaking changes like 3.0.0...).

py/bitbox02/bitbox02/communication/devices.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,9 @@ def get_any_bitbox02_bootloader() -> DeviceInfo:
157157
return devices[0]
158158

159159

160-
def parse_device_version(serial_number: str) -> semver.VersionInfo:
161-
match = re.search(r"v([0-9]+\.[0-9]+\.[0-9]+.*)", serial_number)
160+
def parse_device_version(version: str) -> semver.VersionInfo:
161+
match = re.search(r"v([0-9]+\.[0-9]+\.[0-9]+.*)", version)
162162
if match is None:
163-
raise Exception(f"Could not parse version string from serial_number: {serial_number}")
163+
raise ValueError(f"Could not parse version string from string: {version}")
164164

165165
return semver.VersionInfo.parse(match.group(1))

py/send_message.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1604,16 +1604,10 @@ def __del__(self) -> None:
16041604
self.client_socket.close()
16051605

16061606
simulator = Simulator()
1607-
1608-
device_info: devices.DeviceInfo = {
1609-
"serial_number": "v9.16.0",
1610-
"path": b"",
1611-
"product_string": "BitBox02BTC",
1612-
}
16131607
noise_config = bitbox_api_protocol.BitBoxNoiseConfig()
16141608
bitbox_connection = bitbox02.BitBox02(
16151609
transport=u2fhid.U2FHid(simulator),
1616-
device_info=device_info,
1610+
device_info=None,
16171611
noise_config=noise_config,
16181612
)
16191613
try:

0 commit comments

Comments
 (0)