Skip to content

Commit 5fc265a

Browse files
authored
Handle value specified as bytes received as integer (#684)
1 parent b021322 commit 5fc265a

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

matter_server/common/helpers/util.py

+7
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,13 @@ def parse_value(
221221
# as it is not super important we ignore it (for now)
222222
return b""
223223

224+
# handle NOCStruct.noc which is typed/specified as bytes but parsed
225+
# as integer in the tlv parser somehow.
226+
# https://github.com/home-assistant/core/issues/113279
227+
# https://github.com/home-assistant/core/issues/116304
228+
if name == "NOCStruct.noc" and not isinstance(value, bytes):
229+
return b""
230+
224231
# Matter SDK specific types
225232
if value_type is uint and (
226233
isinstance(value, int) or (isinstance(value, str) and value.isnumeric())

tests/common/test_parser.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import pytest
99

10-
from matter_server.common.helpers.util import dataclass_from_dict
10+
from matter_server.common.helpers.util import dataclass_from_dict, parse_value
1111

1212

1313
class MatterIntEnum(IntEnum):
@@ -107,3 +107,6 @@ def test_dataclass_from_dict():
107107
# test extra keys not silently ignored in strict mode
108108
with pytest.raises(KeyError):
109109
dataclass_from_dict(BasicModel, raw2, strict=True)
110+
# test NOCStruct.noc edge case
111+
res = parse_value("NOCStruct.noc", 5, bytes)
112+
assert res == b""

0 commit comments

Comments
 (0)