diff --git a/scripts/idl/matter_grammar.lark b/scripts/idl/matter_grammar.lark index cbaf0c0249d4f8..335a853b0ce8a4 100644 --- a/scripts/idl/matter_grammar.lark +++ b/scripts/idl/matter_grammar.lark @@ -7,8 +7,9 @@ event: event_priority "event"i id "=" number "{" struct_field* "}" | "info"i -> info_priority | "debug"i -> debug_priority -attribute: attribute_access? "attribute"i field -attribute_access: "readonly"i -> readonly +attribute: attribute_tag* "attribute"i field +attribute_tag: "readonly"i -> attr_readonly + | "global"i -> attr_global request_struct: "request"i struct response_struct: "response"i struct diff --git a/scripts/idl/matter_idl_parser.py b/scripts/idl/matter_idl_parser.py index e8acaee9cff020..1ade381f5b2dc7 100755 --- a/scripts/idl/matter_idl_parser.py +++ b/scripts/idl/matter_idl_parser.py @@ -67,11 +67,11 @@ def optional(self, _): def nullable(self, _): return FieldAttribute.NULLABLE - def readonly(self, _): - return AttributeAccess.READONLY + def attr_readonly(self, _): + return AttributeTag.READABLE - def writable(self, _): - return AttributeAccess.READWRITE + def attr_global(self, _): + return AttributeTag.GLOBAL def critical_priority(self, _): return EventPriority.CRITICAL @@ -113,11 +113,15 @@ def event(self, args): return Event(priority=args[0], name=args[1], code=args[2], fields=args[3:], ) def attribute(self, args): - access = AttributeAccess.READWRITE # default - if len(args) > 1: - access = args[0] - - return Attribute(access=access, definition=args[-1]) + tags = set(args[:-1]) + # until we support write only (and need a bit of a reshuffle) + # if the 'attr_readonly == READABLE' is not in the list, we make things + # read/write + if AttributeTag.READABLE not in tags: + tags.add(AttributeTag.READABLE) + tags.add(AttributeTag.WRITABLE) + + return Attribute(definition=args[-1], tags=tags) @v_args(inline=True) def struct(self, id, *fields): diff --git a/scripts/idl/matter_idl_types.py b/scripts/idl/matter_idl_types.py index 89dd63b0ad614c..7ebc5b7cadb25e 100644 --- a/scripts/idl/matter_idl_types.py +++ b/scripts/idl/matter_idl_types.py @@ -9,9 +9,10 @@ class FieldAttribute(enum.Enum): NULLABLE = enum.auto() -class AttributeAccess(enum.Enum): - READONLY = enum.auto() - READWRITE = enum.auto() +class AttributeTag(enum.Enum): + READABLE = enum.auto() + WRITABLE = enum.auto() + GLOBAL = enum.auto() class EventPriority(enum.Enum): @@ -46,8 +47,20 @@ class Field: @dataclass class Attribute: - access: AttributeAccess definition: Field + tags: Set[AttributeTag] = field(default_factory=set()) + + @property + def is_readable(self): + return AttributeTag.READABLE in self.tags + + @property + def is_writable(self): + return AttributeTag.WRITABLE in self.tags + + @property + def is_global(self): + return AttributeTag.GLOBAL in self.tags @dataclass diff --git a/scripts/idl/test_matter_idl_parser.py b/scripts/idl/test_matter_idl_parser.py index 23e1d691f9d81b..19c6d676364750 100755 --- a/scripts/idl/test_matter_idl_parser.py +++ b/scripts/idl/test_matter_idl_parser.py @@ -91,6 +91,8 @@ def test_cluster_attribute(self): server cluster MyCluster = 0x321 { readonly attribute int8u roAttr = 1; attribute int32u rwAttr[] = 123; + global attribute int32u grwAttr[] = 124; + readonly global attribute int32u groAttr[] = 125; } """) @@ -99,10 +101,14 @@ def test_cluster_attribute(self): name="MyCluster", code=0x321, attributes=[ - Attribute(access=AttributeAccess.READONLY, definition=Field( + Attribute(tags=set([AttributeTag.READABLE]), definition=Field( data_type="int8u", code=1, name="roAttr")), - Attribute(access=AttributeAccess.READWRITE, definition=Field( + Attribute(tags=set([AttributeTag.READABLE, AttributeTag.WRITABLE]), definition=Field( data_type="int32u", code=123, name="rwAttr", is_list=True)), + Attribute(tags=set([AttributeTag.GLOBAL, AttributeTag.READABLE, AttributeTag.WRITABLE]), definition=Field( + data_type="int32u", code=124, name="grwAttr", is_list=True)), + Attribute(tags=set([AttributeTag.GLOBAL, AttributeTag.READABLE]), definition=Field( + data_type="int32u", code=125, name="groAttr", is_list=True)), ] )]) self.assertEqual(actual, expected)