@@ -161,7 +161,7 @@ def parse_basic_device_properties(
161
161
f"when expected port: { expected .port_id } ." )
162
162
properties .pop ('port_id' , None )
163
163
164
- if expected .devclass == 'peripheral' :
164
+ if not expected .has_devclass :
165
165
expected = Port (
166
166
expected .backend_domain ,
167
167
expected .port_id ,
@@ -339,14 +339,18 @@ def devclass(self) -> str:
339
339
return self .__devclass
340
340
return "peripheral"
341
341
342
+ @property
343
+ def has_devclass (self ):
344
+ return self .__devclass is not None
345
+
342
346
343
347
class VirtualDevice :
344
348
"""
345
349
Class of a device connected to *port*.
346
350
347
351
Attributes:
348
- port (Port): A unique identifier for the port within the backend domain .
349
- device_id (str): A unique identifier for the device.
352
+ port (Port): Peripheral device port exposed by vm .
353
+ device_id (str): An identifier for the device.
350
354
"""
351
355
def __init__ (
352
356
self ,
@@ -553,10 +557,8 @@ def serialize(self) -> bytes:
553
557
for key , value in (
554
558
('device_id' , self .device_id ),
555
559
('port_id' , self .port_id ),
556
- ('devclass' , self .devclass )))
557
-
558
- properties += b' ' + DeviceSerializer .pack_property (
559
- 'backend_domain' , self .backend_name )
560
+ ('devclass' , self .devclass ),
561
+ ('backend_domain' , self .backend_name )))
560
562
561
563
return properties
562
564
@@ -919,7 +921,8 @@ def subdevices(self) -> List[VirtualDevice]:
919
921
If the device has subdevices (e.g., partitions of a USB stick),
920
922
the subdevices id should be here.
921
923
"""
922
- return [dev for dev in self .backend_domain .devices [self .devclass ]
924
+ return [dev for devclass in self .backend_domain .devices .keys ()
925
+ for dev in self .backend_domain .devices [devclass ]
923
926
if dev .parent_device .port .port_id == self .port_id ]
924
927
925
928
@property
@@ -933,7 +936,7 @@ def serialize(self) -> bytes:
933
936
"""
934
937
Serialize an object to be transmitted via Qubes API.
935
938
"""
936
- properties = VirtualDevice .serialize (self )
939
+ properties = super () .serialize ()
937
940
# 'attachment', 'interfaces', 'data', 'parent_device'
938
941
# are not string, so they need special treatment
939
942
default = DeviceInfo (self .port )
@@ -1192,7 +1195,7 @@ def device(self) -> DeviceInfo:
1192
1195
return devices [0 ]
1193
1196
if len (devices ) > 1 :
1194
1197
raise ProtocolError ("Too many devices matches to assignment" )
1195
- raise ProtocolError ("Any devices matches to assignment" )
1198
+ raise ProtocolError ("No devices matches to assignment" )
1196
1199
1197
1200
@property
1198
1201
def port (self ) -> Port :
@@ -1309,7 +1312,7 @@ def _deserialize(
1309
1312
device_id = properties ['device_id' ])
1310
1313
# we do not need port, we need device
1311
1314
del properties ['port' ]
1312
- properties . pop ( 'device_id' , None )
1315
+ del properties [ 'device_id' ]
1313
1316
properties ['device' ] = expected_device
1314
1317
1315
1318
return cls (** properties )
0 commit comments