Skip to content

Commit 4318e9c

Browse files
committed
replace DeviceInfo with a namedtuple
1 parent d928ebd commit 4318e9c

File tree

1 file changed

+7
-24
lines changed

1 file changed

+7
-24
lines changed

evdev/device.py

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,9 @@
77
from evdev.events import InputEvent
88

99

10-
class DeviceInfo(object):
11-
__slots__ = 'bustype', 'product', 'vendor', 'version'
12-
13-
def __init__(self, bustype, vendor, product, version):
14-
self.bustype = bustype
15-
self.vendor = vendor
16-
self.product = product
17-
self.version = version
18-
19-
def __str__(self):
20-
msg = 'bus: {:04x}, product {:04x}, vendor {:04x}, version {:04x}'
21-
return msg.format(self.bustype, self.product, self.vendor, self.version)
22-
23-
def __repr__(s):
24-
msg = (s.__class__.__name__, s.bustype, s.vendor, s.product, s.version)
25-
return '{}({:04x}, {:04x}, {:04x}, {:04x})'.format(*msg)
26-
27-
def __eq__(self, o):
28-
return self.bustype == o.bustype \
29-
and self.vendor == o.vendor \
30-
and self.product == o.product \
31-
and self.version == o.version
32-
33-
3410
_AbsInfo = namedtuple('AbsInfo', ['value', 'min', 'max', 'fuzz', 'flat', 'resolution'])
3511
_KbdInfo = namedtuple('KbdInfo', ['repeat', 'delay'])
12+
_DeviceInfo = namedtuple('DeviceInfo', ['bustype', 'product', 'vendor', 'version'])
3613

3714

3815
class AbsInfo(_AbsInfo):
@@ -89,6 +66,12 @@ def __str__(self):
8966
return 'repeat {}, delay {}'.format(*self)
9067

9168

69+
class DeviceInfo(_DeviceInfo):
70+
def __str__(self):
71+
msg = 'bus: {:04x}, product {:04x}, vendor {:04x}, version {:04x}'
72+
return msg.format(*self)
73+
74+
9275
class InputDevice(object):
9376
'''
9477
A linux input device from which input events can be read.

0 commit comments

Comments
 (0)