@@ -96,11 +96,12 @@ def discover_ports(self) -> None:
9696 """
9797 pattern = re .compile (r" Port (\d+): \d{4} " )
9898
99- for line in UHubCtl .exec (["-l" , self .path ]):
99+ for line in UHubCtl .exec (["-l" , self .path ], description = True ):
100100 regex = pattern .match (line )
101101
102102 if regex :
103- port = Port (self , regex .group (1 ))
103+ # create Port object and pre-populate cache with line from autodiscovery
104+ port = Port (self , regex .group (1 ), cache = line )
104105 self .ports .append (port )
105106
106107 def __str__ (self ) -> str :
@@ -116,7 +117,7 @@ class Port:
116117 r" Port (?P<port>\d): \d{4} (?P<status>[a-z ]+)\s?(\[(?:(?P<vid>[a-f0-9]{4}):(?P<pid>[a-f0-9]{4})\s?(?P<description>.*)?)\])?"
117118 )
118119
119- def __init__ (self , hub : Hub , port_number : int ):
120+ def __init__ (self , hub : Hub , port_number : int , cache : str = None ):
120121 """
121122 Create new port instance
122123
@@ -127,7 +128,7 @@ def __init__(self, hub: Hub, port_number: int):
127128 """
128129 self .hub = hub
129130 self .port_number = int (port_number )
130- self .__cache = None
131+ self ._cache = cache
131132
132133 @property
133134 def status (self ) -> bool :
@@ -170,8 +171,8 @@ def __attribute(self, name: str, cache: bool = True, result_filter: callable = N
170171 raise AttributeError (name )
171172
172173 # use cache for port details if possible (fetching is slow)
173- if cache and self .__cache is not None :
174- lines = [self .__cache ]
174+ if cache and self ._cache is not None :
175+ lines = [self ._cache ]
175176 else :
176177 args = ["-l" , self .hub .path , "-p" , str (self .port_number )]
177178 lines = UHubCtl .exec (args , description = True )
@@ -183,7 +184,7 @@ def __attribute(self, name: str, cache: bool = True, result_filter: callable = N
183184 if int (reg .group ("port" )) != self .port_number :
184185 continue
185186
186- self .__cache = line
187+ self ._cache = line
187188
188189 if callable (result_filter ):
189190 return result_filter (reg .group (name ))
0 commit comments