Skip to content

Commit 4905e06

Browse files
committed
fix: make port handling more robust
The old approach of port discovery and status handling relies on a certain format of uhubctl output. It turned out that this is kinda fragile, because it does not always contain the keyword 'off' for a disabled port (eg. when indicator status is present). Fix this by removing the status from discovery and adding 'indicator' to status handling. Signed-off-by: Nicolai Buchwitz <nb@tipi-net.de>
1 parent d89279c commit 4905e06

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

uhubctl/usb.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def discover_ports(self) -> None:
9494
"""
9595
Discover ports for this hub instance
9696
"""
97-
pattern = re.compile(r" Port (\d+): \d{4} (power|off)")
97+
pattern = re.compile(r" Port (\d+): \d{4} ")
9898

9999
for line in _uhubctl(["-l", self.path]):
100100
regex = pattern.match(line)
@@ -131,7 +131,7 @@ def status(self) -> bool:
131131
"""
132132
status = None
133133
pattern = re.compile(
134-
fr" Port {self.port_number}: \d{{4}} (power|off)")
134+
fr" Port {self.port_number}: \d{{4}} (power|off|indicator)")
135135

136136
args = ["-l", self.hub.path, "-p", str(self.port_number)]
137137
for line in _uhubctl(args):

0 commit comments

Comments
 (0)