diff --git a/circuitmatter/session.py b/circuitmatter/session.py index eb5a657..247f3fc 100644 --- a/circuitmatter/session.py +++ b/circuitmatter/session.py @@ -140,7 +140,8 @@ def decode(self, buffer): ) self.general_code = GeneralCode(self.general_code) self.protocol_data = buffer[8:] - self.protocol_id = protocol.ProtocolId(self.protocol_id) + if self.protocol_id in protocol.ProtocolId: + self.protocol_id = protocol.ProtocolId(self.protocol_id) if self.protocol_id == protocol.ProtocolId.SECURE_CHANNEL: self.protocol_code = SecureChannelProtocolCode(self.protocol_code) diff --git a/tests/test_message_reception_state.py b/tests/test_message_reception_state.py index 43fa254..71b191e 100644 --- a/tests/test_message_reception_state.py +++ b/tests/test_message_reception_state.py @@ -1,4 +1,4 @@ -from circuitmatter import MessageReceptionState +from circuitmatter.session import MessageReceptionState def test_basics(): diff --git a/tests/test_status_report.py b/tests/test_status_report.py index 24ab7e9..32f6180 100644 --- a/tests/test_status_report.py +++ b/tests/test_status_report.py @@ -1,4 +1,5 @@ -from circuitmatter import StatusReport, GeneralCode, ProtocolId +from circuitmatter.session import StatusReport, GeneralCode +from circuitmatter.protocol import ProtocolId def test_example1(): diff --git a/tests/test_tlv.py b/tests/test_tlv.py index 3b4a8c2..74132d5 100644 --- a/tests/test_tlv.py +++ b/tests/test_tlv.py @@ -111,7 +111,7 @@ def test_signed_int_negative_17_encode(self): def test_signed_int_42_two_octet_encode(self): s = SignedIntTwoOctet() s.i = 42 - assert s.encode().tobytes() == b"\x15\x21\x00\x2a\x00\x18" + assert s.encode().tobytes() == b"\x15\x20\x00\x2a\x18" def test_signed_int_negative_170000_encode(self): s = SignedIntFourOctet() @@ -547,10 +547,7 @@ def test_inner_struct_encode(self): inner.a = 42 inner.b = -17 s.s = inner - assert ( - s.encode().tobytes() - == b"\x15\x35\x00\x22\x00\x2a\x00\x00\x00\x22\x01\xef\xff\xff\xff\x18\x18" - ) + assert s.encode().tobytes() == b"\x15\x35\x00\x20\x00\x2a\x20\x01\xef\x18\x18" def test_inner_struct_encode_empty(self): s = OuterStruct() @@ -581,7 +578,7 @@ def test_encode(self): s.b = -17 assert ( s.encode().tobytes() - == b"\x15\xc2\xda\x0a\x00\x0f\x23\x01\x2a\x00\x00\x00\xe2\xda\x0a\x00\x0f\x45\x23\x01\x00\xef\xff\xff\xff\x18" + == b"\x15\xc0\xda\x0a\x00\x0f\x23\x01\x2a\xe0\xda\x0a\x00\x0f\x45\x23\x01\x00\xef\x18" ) @@ -601,10 +598,7 @@ def test_encode(self): inner.a = 42 inner.b = -17 s.sublist = inner - assert ( - s.encode().tobytes() - == b"\x15\x37\x00\x22\x00\x2a\x00\x00\x00\x22\x01\xef\xff\xff\xff\x18\x18" - ) + assert s.encode().tobytes() == b"\x15\x37\x00\x20\x00\x2a\x20\x01\xef\x18\x18" class OuterStructArray(tlv.Structure): @@ -620,7 +614,7 @@ def test_encode(self): s.a = [inner] assert ( s.encode().tobytes() - == b"\x15\x36\x00\x17\x22\x00\x2a\x00\x00\x00\x22\x01\xef\xff\xff\xff\x18\x18\x18" + == b"\x15\x36\x00\x17\x20\x00\x2a\x20\x01\xef\x18\x18\x18" ) def test_encode2(self): @@ -631,5 +625,5 @@ def test_encode2(self): s.a = [inner, inner] assert ( s.encode().tobytes() - == b"\x15\x36\x00\x17\x22\x00\x2a\x00\x00\x00\x22\x01\xef\xff\xff\xff\x18\x17\x22\x00\x2a\x00\x00\x00\x22\x01\xef\xff\xff\xff\x18\x18\x18" + == b"\x15\x36\x00\x17\x20\x00\x2a\x20\x01\xef\x18\x17\x20\x00\x2a\x20\x01\xef\x18\x18\x18" )