Skip to content

Commit

Permalink
Update pyusbmux.py to handle devices > 30 (#11)
Browse files Browse the repository at this point in the history
* Update pyusbmux.py to handle devices > 30

* use Listen instead of ListDevices

---------

Co-authored-by: 孙圣翔²⁰₂₁ <[email protected]>
  • Loading branch information
codeskyblue and 孙圣翔²⁰₂₁ authored Sep 22, 2024
1 parent 6a962e9 commit b89c704
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions wdapy/usbmux/pyusbmux.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,15 +369,29 @@ def get_pair_record(self, serial: str) -> Mapping:
def get_device_list(self, timeout: float = None) -> None:
""" get device list synchronously without waiting the timeout """
self.devices = []
self._send({'MessageType': 'ListDevices'})
for response in self._receive(self._tag - 1)['DeviceList']:
if response['MessageType'] == 'Attached':
super()._add_device(MuxDevice(response['DeviceID'], response['Properties']['SerialNumber'],
response['Properties']['ConnectionType']))
elif response['MessageType'] == 'Detached':
super()._remove_device(response['DeviceID'])
else:
raise MuxError(f'Invalid packet type received: {response}')
self._send_receive({'MessageType': 'Listen'})
end = time.time() + timeout
self._sock.settimeout(timeout)
while time.time() < end:
try:
response = self._receive()
if response['MessageType'] == 'Attached':
super()._add_device(MuxDevice(response['DeviceID'], response['Properties']['SerialNumber'],
response['Properties']['ConnectionType']))
elif response['MessageType'] == 'Detached':
super()._remove_device(response['DeviceID'])
else:
raise MuxError(f'Invalid packet type received: {response}')
except (BlockingIOError, StreamError):
continue
except IOError:
try:
self._sock.setblocking(True)
self.close()
except OSError:
pass
raise MuxError('Exception in listener socket')


def get_buid(self) -> str:
""" get SystemBUID """
Expand Down Expand Up @@ -482,4 +496,4 @@ def __enter__(self) -> HTTPConnection:
return self

def __exit__(self, exc_type, exc_value, traceback):
self.close()
self.close()

0 comments on commit b89c704

Please sign in to comment.