trezor: refactor transport enumeration a bit
This commit is contained in:
parent
66e3e60370
commit
e90bd0cd81
@ -5,5 +5,10 @@
|
||||
from keepkeylib.client import CallException, PinException
|
||||
from keepkeylib.client import KeepKeyClient as Client
|
||||
from keepkeylib.messages_pb2 import PassphraseAck, PinMatrixAck
|
||||
from keepkeylib.transport_hid import HidTransport as Transport
|
||||
from keepkeylib.transport_hid import HidTransport
|
||||
from keepkeylib.types_pb2 import IdentityType
|
||||
|
||||
|
||||
def enumerate_transports():
|
||||
"""Returns USB HID transports."""
|
||||
return [HidTransport(p) for p in HidTransport.enumerate()]
|
||||
|
@ -115,14 +115,14 @@ class Trezor(interface.Device):
|
||||
current_version))
|
||||
|
||||
def connect(self):
|
||||
"""Enumerate and connect to the first USB HID interface."""
|
||||
transport = self._defs.TrezorDevice.enumerate()
|
||||
if not transport:
|
||||
"""Enumerate and connect to the first available interface."""
|
||||
transports = self._defs.enumerate_transports()
|
||||
if not transports:
|
||||
raise interface.NotFoundError('{} not connected'.format(self))
|
||||
|
||||
log.debug('transports: %s', transport)
|
||||
log.debug('transports: %s', transports)
|
||||
for _ in range(5):
|
||||
connection = self._defs.Client(transport[0])
|
||||
connection = self._defs.Client(transports[0])
|
||||
self._override_pin_handler(connection)
|
||||
self._override_passphrase_handler(connection)
|
||||
self._verify_version(connection)
|
||||
|
@ -6,3 +6,8 @@ from trezorlib.client import CallException, PinException
|
||||
from trezorlib.client import TrezorClient as Client
|
||||
from trezorlib.messages import IdentityType, PassphraseAck, PinMatrixAck
|
||||
from trezorlib.device import TrezorDevice
|
||||
|
||||
|
||||
def enumerate_transports():
|
||||
"""Returns all available transports."""
|
||||
return TrezorDevice.enumerate()
|
||||
|
Loading…
Reference in New Issue
Block a user