mirror of
https://github.com/romanz/amodem.git
synced 2026-04-18 20:25:59 +08:00
trezor: better logging and exception handling
This commit is contained in:
16
trezor.py
16
trezor.py
@@ -1,6 +1,7 @@
|
|||||||
import io
|
import io
|
||||||
import base64
|
import base64
|
||||||
import logging
|
import logging
|
||||||
|
import binascii
|
||||||
|
|
||||||
from trezorlib.client import TrezorClient
|
from trezorlib.client import TrezorClient
|
||||||
from trezorlib.transport_hid import HidTransport
|
from trezorlib.transport_hid import HidTransport
|
||||||
@@ -59,9 +60,18 @@ class Client(object):
|
|||||||
proto = 'ssh'
|
proto = 'ssh'
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
device, = HidTransport.enumerate()
|
devices = HidTransport.enumerate()
|
||||||
client = TrezorClient(HidTransport(device))
|
if len(devices) != 1:
|
||||||
log.debug('connected to Trezor #%s', client.get_device_id())
|
raise ValueError('{:d} Trezor devices found'.format(len(devices)))
|
||||||
|
client = TrezorClient(HidTransport(devices[0]))
|
||||||
|
f = client.features
|
||||||
|
log.info('connected to Trezor')
|
||||||
|
log.debug('ID : {}'.format(f.device_id))
|
||||||
|
log.debug('label : {}'.format(f.label))
|
||||||
|
log.debug('vendor : {}'.format(f.vendor))
|
||||||
|
version = [f.major_version, f.minor_version, f.patch_version]
|
||||||
|
log.debug('version : {}'.format('.'.join(map(str, version))))
|
||||||
|
log.debug('revision : {}'.format(binascii.hexlify(f.revision)))
|
||||||
self.client = client
|
self.client = client
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user