@@ -112,6 +112,8 @@ class Port:
112112 USB port representation from uhubctl
113113 """
114114
115+ PORT_PATTERN = re .compile (r" Port (?P<port>\d): \d{4} (?P<status>[a-z ]+)\w?(\[(?:(?P<vid>[a-f0-9]{4}):(?P<pid>[a-f0-9]{4})(?P<description>.*)?)\])?" )
116+
115117 def __init__ (self , hub : Hub , port_number : int ):
116118 """
117119 Create new port instance
@@ -130,14 +132,15 @@ def status(self) -> bool:
130132 Port power status
131133 """
132134 status = None
133- pattern = re .compile (rf" Port { self .port_number } : \d{{4}} (power|off|indicator)" )
134135
135136 args = ["-l" , self .hub .path , "-p" , str (self .port_number )]
136137 for line in UHubCtl .exec (args ):
137- reg = pattern .match (line )
138+ reg = self . PORT_PATTERN .match (line )
138139
139140 if reg :
140- status = reg .group (1 ) == "power"
141+ if reg .group ("port" ) != self .port_number :
142+ continue
143+ status = "power" in reg .group ("status" )
141144
142145 if status is None :
143146 raise Exception ()
@@ -155,6 +158,26 @@ def status(self, status: bool) -> None:
155158
156159 UHubCtl .exec (args )
157160
161+ @property
162+ def name (self ) -> str :
163+ """
164+ Attached device name
165+ """
166+
167+ args = ["-l" , self .hub .path , "-p" , str (self .port_number )]
168+ for line in UHubCtl .exec (args ):
169+ reg = self .PORT_PATTERN .match (line )
170+
171+ print (line )
172+
173+ if reg :
174+ if reg .group ("port" ) != self .port_number :
175+ continue
176+
177+ return reg .group ("description" )
178+
179+ # raise Exception("could not determine name")
180+
158181 @staticmethod
159182 def from_path (path : str ):
160183 """
0 commit comments