@@ -236,8 +236,8 @@ def check_device_properties(
236
236
237
237
if properties .get ('ident' , expected .ident ) != expected .ident :
238
238
raise UnexpectedDeviceProperty (
239
- f"Got device with id : { properties ['ident' ]} "
240
- f"when expected id : { expected .ident } ." )
239
+ f"Got device from port : { properties ['ident' ]} "
240
+ f"when expected port : { expected .ident } ." )
241
241
properties ['ident' ] = expected .ident
242
242
243
243
if properties .get ('devclass' , expected .devclass ) != expected .devclass :
@@ -679,12 +679,16 @@ def deserialize(
679
679
"""
680
680
Recovers a serialized object, see: :py:meth:`serialize`.
681
681
"""
682
- ident , _ , rest = serialization .partition (b' ' )
683
- ident = ident .decode ('ascii' , errors = 'ignore' )
682
+ identity , _ , rest = serialization .partition (b' ' )
683
+ identity = identity .decode ('ascii' , errors = 'ignore' )
684
+ ident , devid = identity .split (':' , 1 )
685
+ if devid == 'None' : # TODO
686
+ devid = None
684
687
device = UnknownDevice (
685
688
backend_domain = expected_backend_domain ,
686
689
ident = ident ,
687
690
devclass = expected_devclass ,
691
+ self_identity = devid
688
692
)
689
693
690
694
try :
@@ -699,27 +703,34 @@ def deserialize(
699
703
def _deserialize (
700
704
cls ,
701
705
untrusted_serialization : bytes ,
702
- expected_port : Port
706
+ expected_device : 'DeviceInfo'
703
707
) -> 'DeviceInfo' :
704
708
"""
705
709
Actually deserializes the object.
706
710
"""
707
711
properties , options = cls .unpack_properties (untrusted_serialization )
708
712
properties .update (options )
709
713
710
- cls .check_device_properties (expected_port , properties )
714
+ cls .check_device_properties (expected_device , properties )
711
715
712
716
if 'attachment' not in properties or not properties ['attachment' ]:
713
717
properties ['attachment' ] = None
714
718
else :
715
- app = expected_port .backend_domain .app
719
+ app = expected_device .backend_domain .app
716
720
properties ['attachment' ] = app .domains .get_blind (
717
721
properties ['attachment' ])
718
722
719
- if properties ['devclass' ] != expected_port .devclass :
723
+ if properties ['devclass' ] != expected_device .devclass :
720
724
raise UnexpectedDeviceProperty (
721
725
f"Got { properties ['devclass' ]} device "
722
- f"when expected { expected_port .devclass } ." )
726
+ f"when expected { expected_device .devclass } ." )
727
+
728
+ if (expected_device .self_identity is not None and
729
+ properties ['self_identity' ] != expected_device .self_identity ):
730
+ raise UnexpectedDeviceProperty (
731
+ f"Unrecognized device identity '{ properties ['self_identity' ]} ' "
732
+ f"expected '{ expected_device .self_identity } '"
733
+ )
723
734
724
735
if 'interfaces' in properties :
725
736
interfaces = properties ['interfaces' ]
@@ -730,7 +741,7 @@ def _deserialize(
730
741
731
742
if 'parent_ident' in properties :
732
743
properties ['parent' ] = Port (
733
- backend_domain = expected_port .backend_domain ,
744
+ backend_domain = expected_device .backend_domain ,
734
745
ident = properties ['parent_ident' ],
735
746
devclass = properties ['parent_devclass' ],
736
747
)
@@ -986,12 +997,14 @@ def deserialize(
986
997
cls ,
987
998
serialization : bytes ,
988
999
expected_port : Port ,
1000
+ expected_identity : Optional [str ],
989
1001
) -> 'DeviceAssignment' :
990
1002
"""
991
1003
Recovers a serialized object, see: :py:meth:`serialize`.
992
1004
"""
993
1005
try :
994
- result = cls ._deserialize (serialization , expected_port )
1006
+ result = cls ._deserialize (
1007
+ serialization , expected_port , expected_identity )
995
1008
except Exception as exc :
996
1009
raise ProtocolError () from exc
997
1010
return result
@@ -1001,16 +1014,24 @@ def _deserialize(
1001
1014
cls ,
1002
1015
untrusted_serialization : bytes ,
1003
1016
expected_port : Port ,
1017
+ expected_identity : Optional [str ],
1004
1018
) -> 'DeviceAssignment' :
1005
1019
"""
1006
1020
Actually deserializes the object.
1007
1021
"""
1008
1022
properties , options = cls .unpack_properties (untrusted_serialization )
1009
1023
properties ['options' ] = options
1024
+ import sys ; print (f'{ expected_identity = } ' , f'{ expected_port = } ' , file = sys .stderr ) # TODO debug
1010
1025
1011
1026
cls .check_device_properties (expected_port , properties )
1012
1027
del properties ['backend_domain' ]
1013
1028
del properties ['ident' ]
1014
1029
del properties ['devclass' ]
1015
1030
1016
- return cls (expected_port , ** properties )
1031
+ assignment = cls (expected_port , ** properties )
1032
+ if (expected_identity
1033
+ and assignment .device .self_identity != expected_identity ):
1034
+ raise UnexpectedDeviceProperty (
1035
+ f"Got device with identity { assignment .device .self_identity } "
1036
+ f"when expected devices with identity { expected_identity } ." )
1037
+ return assignment
0 commit comments