Skip to content

Commit 875dd2f

Browse files
committed
Add device model clients and use them
1 parent ac71764 commit 875dd2f

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
@@ -587,6 +587,11 @@ def send_pin(self, pin):
587587
def toggle_passphrase(self):
588588
raise UnavailableActionError('The Digital Bitbox does not support toggling passphrase from the host')
589589

590+
class Digitalbitbox01Client(DigitalbitboxClient):
591+
def __init__(self, path, password='', expert=False):
592+
super(Digitalbitbox01Client, self).__init__(path, password, expert)
593+
self.type = 'Digital BitBox01'
594+
590595
def enumerate(password=''):
591596
results = []
592597
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
@@ -73,6 +73,7 @@ class LedgerClient(HardwareWalletClient):
7373

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

7778
if path.startswith('tcp'):
7879
split_path = path.split(':')
@@ -357,6 +358,16 @@ def send_pin(self, pin):
357358
def toggle_passphrase(self):
358359
raise UnavailableActionError('The Ledger Nano S and X do not support toggling passphrase from the host')
359360

361+
class LedgerNanoSClient(LedgerClient):
362+
def __init__(self, path, password='', expert=False):
363+
super(LedgerNanoSClient, self).__init__(path, password, expert)
364+
self.type = 'Ledger Nano S'
365+
366+
class LedgerNanoXClient(LedgerClient):
367+
def __init__(self, path, password='', expert=False):
368+
super(LedgerNanoXClient, self).__init__(path, password, expert)
369+
self.type = 'Ledger Nano X'
370+
360371
def enumerate(password=''):
361372
results = []
362373
devices = []

hwilib/devices/trezor.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,16 @@ def toggle_passphrase(self):
440440
self._check_unlocked()
441441
return device.apply_settings(self.client, use_passphrase=not self.client.features.passphrase_protection)
442442

443+
class Trezor1Client(TrezorClient):
444+
def __init__(self, path, password='', expert=False):
445+
super(Trezor1Client, self).__init__(path, password, expert)
446+
self.type = 'Trezor 1'
447+
448+
class TrezorTClient(TrezorClient):
449+
def __init__(self, path, password='', expert=False):
450+
super(TrezorTClient, self).__init__(path, password, expert)
451+
self.type = 'Trezor T'
452+
443453
def enumerate(password=''):
444454
results = []
445455
for dev in enumerate_devices():

0 commit comments

Comments
 (0)