diff --git a/matter_server/common/helpers/util.py b/matter_server/common/helpers/util.py index c42e20a1..c38fdae4 100644 --- a/matter_server/common/helpers/util.py +++ b/matter_server/common/helpers/util.py @@ -221,6 +221,13 @@ def parse_value( # as it is not super important we ignore it (for now) return b"" + # handle NOCStruct.noc which is typed/specified as bytes but parsed + # as integer in the tlv parser somehow. + # https://github.com/home-assistant/core/issues/113279 + # https://github.com/home-assistant/core/issues/116304 + if name == "NOCStruct.noc" and not isinstance(value, bytes): + return b"" + # Matter SDK specific types if value_type is uint and ( isinstance(value, int) or (isinstance(value, str) and value.isnumeric()) diff --git a/tests/common/test_parser.py b/tests/common/test_parser.py index e3c4a519..41f9a44e 100644 --- a/tests/common/test_parser.py +++ b/tests/common/test_parser.py @@ -7,7 +7,7 @@ import pytest -from matter_server.common.helpers.util import dataclass_from_dict +from matter_server.common.helpers.util import dataclass_from_dict, parse_value class MatterIntEnum(IntEnum): @@ -107,3 +107,6 @@ def test_dataclass_from_dict(): # test extra keys not silently ignored in strict mode with pytest.raises(KeyError): dataclass_from_dict(BasicModel, raw2, strict=True) + # test NOCStruct.noc edge case + res = parse_value("NOCStruct.noc", 5, bytes) + assert res == b""