Skip to content

Commit

Permalink
InteractionModelRevision
Browse files Browse the repository at this point in the history
  • Loading branch information
tannewt committed Oct 3, 2024
1 parent 4a0c4b6 commit ede6818
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
12 changes: 8 additions & 4 deletions circuitmatter/interaction_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,11 @@ class AttributeReportIB(tlv.Structure):
AttributeData = tlv.StructMember(1, AttributeDataIB, optional=True)


class ReadRequestMessage(tlv.Structure):
class InteractionModelMessage(tlv.Structure):
InteractionModelRevision = tlv.IntMember(0xFF, signed=False, octets=1, default=11)


class ReadRequestMessage(InteractionModelMessage):
AttributeRequests = tlv.ArrayMember(0, AttributePathIB)
EventRequests = tlv.ArrayMember(1, EventPathIB)
EventFilters = tlv.ArrayMember(2, EventFilterIB)
Expand Down Expand Up @@ -157,7 +161,7 @@ class EventReportIB(tlv.Structure):
EventData = tlv.StructMember(1, EventDataIB)


class ReportDataMessage(tlv.Structure):
class ReportDataMessage(InteractionModelMessage):
SubscriptionId = tlv.IntMember(0, signed=False, octets=4, optional=True)
AttributeReports = tlv.ArrayMember(1, AttributeReportIB, optional=True)
EventReports = tlv.ArrayMember(2, EventReportIB, optional=True)
Expand Down Expand Up @@ -188,13 +192,13 @@ class InvokeResponseIB(tlv.Structure):
Status = tlv.StructMember(1, CommandStatusIB, optional=True)


class InvokeRequestMessage(tlv.Structure):
class InvokeRequestMessage(InteractionModelMessage):
SuppressResponse = tlv.BoolMember(0)
TimedRequest = tlv.BoolMember(1)
InvokeRequests = tlv.ArrayMember(2, CommandDataIB)


class InvokeResponseMessage(tlv.Structure):
class InvokeResponseMessage(InteractionModelMessage):
SuppressResponse = tlv.BoolMember(0)
InvokeResponses = tlv.ArrayMember(1, InvokeResponseIB)
MoreChunkedMessages = tlv.BoolMember(2, optional=True)
3 changes: 3 additions & 0 deletions circuitmatter/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ def __init__(self, random_source, socket, local_session_id):
self.socket = socket
self.node_ipaddress = None

def __str__(self):
return f"Secure Session #{self.local_session_id} with {self.peer_node_id:x}"

@property
def peer_active(self):
return (time.monotonic() - self.active_timestamp) < self.session_active_interval
Expand Down
11 changes: 8 additions & 3 deletions circuitmatter/tlv.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,10 @@ def max_length(cls):

@classmethod
def _members(cls) -> Iterable[tuple[str, Member]]:
for field_name, descriptor in vars(cls).items():
if not field_name.startswith("_") and isinstance(descriptor, Member):
yield field_name, descriptor
for superclass in cls.__mro__:
for field_name, descriptor in vars(superclass).items():
if not field_name.startswith("_") and isinstance(descriptor, Member):
yield field_name, descriptor

@classmethod
def _members_by_tag(cls) -> dict[int, tuple[str, Member]]:
Expand Down Expand Up @@ -175,11 +176,15 @@ def decode(cls, control_octet, buffer, offset=0, depth=0) -> tuple[dict, int]:
return cls.from_value(values), offset

def construct_containers(self):
tags = set(self.values.keys())
for name, member_class in self._members():
tag = member_class.tag
if tag not in self.values:
continue
tags.remove(tag)
self.values[tag] = member_class.from_value(self.values[tag])
if tags:
raise RuntimeError(f"Unknown tags {tags}")

@classmethod
def from_value(cls, value):
Expand Down

0 comments on commit ede6818

Please sign in to comment.