Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Python] TLV schema tag should start from 1 #12347

Merged
merged 3 commits into from
Nov 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/controller/python/chip/ChipReplStartup.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,19 @@ def ReplInit():
def matterhelp(classOrObj=None):
if (classOrObj == None):
inspect(builtins.devCtrl, methods=True, help=True, private=False)
inspect(mattersetlog)
inspect(mattersetdebug)
else:
inspect(classOrObj, methods=True, help=True, private=False)


def mattersetlog(level):
logging.getLogger().setLevel(level)


def mattersetdebug(enableDebugMode: bool = True):
''' Enables debug mode that is utilized by some Matter modules
to better facilitate debugging of failures (e.g throwing exceptions instead
of returning well-formatted results).
'''
builtins.enableDebugMode = enableDebugMode
3 changes: 3 additions & 0 deletions src/controller/python/chip/ChipStack.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
from ctypes import *
from .ChipUtility import ChipUtility
from .exceptions import *
import builtins

__all__ = [
"DeviceStatusStruct",
Expand Down Expand Up @@ -160,6 +161,8 @@ def Wait(self):
@_singleton
class ChipStack(object):
def __init__(self, installDefaultLogHandler=True, bluetoothAdapter=0):
builtins.enableDebugMode = False

self.networkLock = Lock()
self.completeEvent = Event()
self.commissioningCompleteEvent = Event()
Expand Down
29 changes: 24 additions & 5 deletions src/controller/python/chip/clusters/Attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import sys
import logging
import threading
import builtins


@dataclass
Expand Down Expand Up @@ -97,6 +98,16 @@ class AttributeReadResult(AttributeStatus):
Data: Any = None


@dataclass
class ValueDecodeFailure:
''' Encapsulates a failure to decode a TLV value into a cluster object.
Some exceptions have custom fields, so run str(ReasonException) to get more info.
'''

TLVValue: Any = None
Reason: Exception = None


_AttributeIndex = {}


Expand Down Expand Up @@ -199,21 +210,29 @@ def _handleAttributeData(self, path: AttributePathWithListIndex, status: int, da
attributeType = _AttributeIndex.get(str(AttributePath(
ClusterId=path.ClusterId, AttributeId=path.AttributeId)), None)
attributeValue = None
tlvData = chip.tlv.TLVReader(data).get().get("Any", {})
if attributeType is None:
attributeValue = chip.tlv.TLVReader(data).get().get("Any", {})
attributeValue = ValueDecodeFailure(
tlvData, LookupError("attribute schema not found"))
else:
try:
attributeValue = attributeType.FromTLV(data)
except:
attributeValue = attributeType(attributeType.FromTLV(data))
except Exception as ex:
logging.error(
f"Error convering TLV to Cluster Object for path: Endpoint = {path.EndpointId}/Cluster = {path.ClusterId}/Attribute = {path.AttributeId}")
logging.error(
f"Failed Cluster Object: {str(attributeType)}")
raise
logging.error(ex)
attributeValue = ValueDecodeFailure(
mrjerryjohns marked this conversation as resolved.
Show resolved Hide resolved
mrjerryjohns marked this conversation as resolved.
Show resolved Hide resolved
tlvData, ex)

# If we're in debug mode, raise the exception so that we can better debug what's happening.
if (builtins.enableDebugMode):
raise

with self._resLock:
self._res[path] = AttributeReadResult(
Path=path, Status=imStatus, Data=attributeType(attributeValue))
Path=path, Status=imStatus, Data=attributeValue)
if self._subscription_handler is not None:
self._subscription_handler.OnUpdate(
path, attributeType(attributeValue))
Expand Down
Loading