Skip to content

Commit

Permalink
Handle value specified as bytes received as integer (#684)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelveldt committed May 1, 2024
1 parent b021322 commit 5fc265a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 7 additions & 0 deletions matter_server/common/helpers/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
5 changes: 4 additions & 1 deletion tests/common/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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""

0 comments on commit 5fc265a

Please sign in to comment.