diff --git a/lib/logitech/unifying_receiver/api.py b/lib/logitech/unifying_receiver/api.py index 8b65b542..eb136be4 100644 --- a/lib/logitech/unifying_receiver/api.py +++ b/lib/logitech/unifying_receiver/api.py @@ -297,15 +297,15 @@ def get_device_firmware(handle, device, features_array=None): def get_device_type(handle, device, features_array=None): """Reads a device's type. - :see DEVICE_TYPES: + :see DEVICE_TYPE: :returns: a string describing the device type, or ``None`` if the device is not available or does not support the ``NAME`` feature. """ d_type = request(handle, device, FEATURE.NAME, function=b'\x20', features_array=features_array) if d_type: d_type = ord(d_type[:1]) - _l.log(_LOG_LEVEL, "(%d,%d) device type %d = %s", handle, device, d_type, DEVICE_TYPES[d_type]) - return DEVICE_TYPES[d_type] + _l.log(_LOG_LEVEL, "(%d,%d) device type %d = %s", handle, device, d_type, DEVICE_TYPE[d_type]) + return DEVICE_TYPE[d_type] def get_device_name(handle, device, features_array=None): @@ -339,7 +339,7 @@ def get_device_battery_level(handle, device, features_array=None): if battery: discharge, dischargeNext, status = struct.unpack('!BBB', battery[:3]) _l.log(_LOG_LEVEL, "(%d:%d) battery %d%% charged, next level %d%% charge, status %d = %s", discharge, dischargeNext, status, BATTERY_STATUSE[status]) - return (discharge, dischargeNext, BATTERY_STATUSE[status]) + return (discharge, dischargeNext, BATTERY_STATUS[status]) def get_device_keys(handle, device, features_array=None): diff --git a/lib/logitech/unifying_receiver/base.py b/lib/logitech/unifying_receiver/base.py index 6984cc7f..1e1aa30f 100644 --- a/lib/logitech/unifying_receiver/base.py +++ b/lib/logitech/unifying_receiver/base.py @@ -186,7 +186,8 @@ def read(handle, timeout=DEFAULT_TIMEOUT): _l.warn("(%d,*) => r[%s] read packet too short: %d bytes", handle, hexlify(data), len(data)) if len(data) > _MAX_REPLY_SIZE: _l.warn("(%d,*) => r[%s] read packet too long: %d bytes", handle, hexlify(data), len(data)) - code, device = struct.unpack('!BB', data[:2]) + code = ord(data[:1]) + device = ord(data[1:2]) return code, device, data[2:] _l.log(_LOG_LEVEL, "(%d,*) => r[]", handle) @@ -224,7 +225,7 @@ def request(handle, device, feature_index_function, params=b'', features_array=N if reply_device != device: # this message not for the device we're interested in - _l.log(_LOG_LEVEL, "(%d,%d) request got reply for unexpected device %d: [%s]", handle, device, hexlify(reply_device), hexlify(reply_data)) + _l.log(_LOG_LEVEL, "(%d,%d) request got reply for unexpected device %d: [%s]", handle, device, reply_device, hexlify(reply_data)) # worst case scenario, this is a reply for a concurrent request # on this receiver _unhandled._publish(reply_code, reply_device, reply_data) @@ -243,7 +244,7 @@ def request(handle, device, feature_index_function, params=b'', features_array=N if reply_code == 0x11 and reply_data[0] == b'\xFF' and reply_data[1:3] == feature_index_function: # an error returned from the device error_code = ord(reply_data[3]) - _l.warn("(%d,%d) request feature call error %d = %s: %s", handle, device, error_code, ERROR_NAME(error_code), hexlify(reply_data)) + _l.warn("(%d,%d) request feature call error %d = %s: %s", handle, device, error_code, ERROR_NAME[error_code], hexlify(reply_data)) feature_index = ord(feature_index_function[:1]) feature_function = feature_index_function[1:2] feature = None if features_array is None else features_array[feature_index] diff --git a/lib/logitech/unifying_receiver/constants.py b/lib/logitech/unifying_receiver/constants.py index 5d44dc74..a952f5a8 100644 --- a/lib/logitech/unifying_receiver/constants.py +++ b/lib/logitech/unifying_receiver/constants.py @@ -45,10 +45,12 @@ FEATURE_NAME[FEATURE.WIRELESS_STATUS] = 'WIRELESS_STATUS' FEATURE_NAME[FEATURE.SOLAR_CHARGE] = 'SOLAR_CHARGE' -"""Possible types of devices connected to an UR.""" -DEVICE_TYPES = ('Keyboard', 'Remote Control', 'NUMPAD', 'Mouse', +_DEVICE_TYPES = ('Keyboard', 'Remote Control', 'NUMPAD', 'Mouse', 'Touchpad', 'Trackball', 'Presenter', 'Receiver') +"""Possible types of devices connected to an UR.""" +DEVICE_TYPE = FallbackDict(lambda x: 'unknown', list2dict(_DEVICE_TYPES)) + _FIRMWARE_TYPES = ('Main (HID)', 'Bootloader', 'Hardware', 'Other')