Skip to content

Commit 6eca458

Browse files
committed
Add device model clients and use them
1 parent 0f48aba commit 6eca458

File tree

4 files changed

+35
-6
lines changed

4 files changed

+35
-6
lines changed

hwilib/commands.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,17 @@
1212
from .devices import __all__ as all_devs
1313

1414
def get_client_class(device_type):
15-
device_type = device_type.split('_')[0]
16-
class_name = device_type.capitalize()
17-
module = device_type.lower()
15+
device_type_split = device_type.split('_')
16+
if device_type_split[-1].lower() == 'simulator':
17+
del device_type_split[-1]
18+
device_type_split = [x.capitalize() for x in device_type_split]
19+
device_model = ''.join(device_type_split)
20+
module = device_type_split[0].lower()
1821

1922
try:
2023
imported_dev = importlib.import_module('.devices.' + module, __package__)
21-
client_constructor = getattr(imported_dev, class_name + 'Client')
22-
except ImportError:
24+
client_constructor = getattr(imported_dev, device_model + 'Client')
25+
except (ImportError, AttributeError):
2326
raise UnknownDeviceError('Unknown device type specified')
2427

2528
return client_constructor
@@ -57,7 +60,7 @@ def find_device(password='', device_type=None, fingerprint=None, expert=False):
5760
continue
5861
client = None
5962
try:
60-
client = get_client(d['type'], d['path'], password, expert)
63+
client = get_client(d['model'], d['path'], password, expert)
6164

6265
master_fpr = d.get('fingerprint', None)
6366
if master_fpr is None:

hwilib/devices/digitalbitbox.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,11 @@ def prompt_pin(self):
583583
def send_pin(self, pin):
584584
raise UnavailableActionError('The Digital Bitbox does not need a PIN sent from the host')
585585

586+
class Digitalbitbox01Client(DigitalbitboxClient):
587+
def __init__(self, path, password='', expert=False):
588+
super(Digitalbitbox01Client, self).__init__(path, password, expert)
589+
self.type = 'Digital BitBox01'
590+
586591
def enumerate(password=''):
587592
results = []
588593
devices = hid.enumerate(DBB_VENDOR_ID, DBB_DEVICE_ID)

hwilib/devices/ledger.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class LedgerClient(HardwareWalletClient):
7474

7575
def __init__(self, path, password='', expert=False):
7676
super(LedgerClient, self).__init__(path, password, expert)
77+
self.type = 'Ledger Nano S and X'
7778

7879
if path.startswith('tcp'):
7980
split_path = path.split(':')
@@ -354,6 +355,16 @@ def prompt_pin(self):
354355
def send_pin(self, pin):
355356
raise UnavailableActionError('The Ledger Nano S and X do not need a PIN sent from the host')
356357

358+
class LedgerNanoSClient(LedgerClient):
359+
def __init__(self, path, password='', expert=False):
360+
super(LedgerNanoSClient, self).__init__(path, password, expert)
361+
self.type = 'Ledger Nano S'
362+
363+
class LedgerNanoXClient(LedgerClient):
364+
def __init__(self, path, password='', expert=False):
365+
super(LedgerNanoXClient, self).__init__(path, password, expert)
366+
self.type = 'Ledger Nano X'
367+
357368
def enumerate(password=''):
358369
results = []
359370
devices = []

hwilib/devices/trezor.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,16 @@ def send_pin(self, pin):
434434
return {'success': False}
435435
return {'success': True}
436436

437+
class Trezor1Client(TrezorClient):
438+
def __init__(self, path, password='', expert=False):
439+
super(Trezor1Client, self).__init__(path, password, expert)
440+
self.type = 'Trezor 1'
441+
442+
class TrezorTClient(TrezorClient):
443+
def __init__(self, path, password='', expert=False):
444+
super(TrezorTClient, self).__init__(path, password, expert)
445+
self.type = 'Trezor T'
446+
437447
def enumerate(password=''):
438448
results = []
439449
for dev in enumerate_devices():

0 commit comments

Comments
 (0)