Skip to content

Commit

Permalink
Add features parsing for the zapxml python parser (#33853)
Browse files Browse the repository at this point in the history
* Update zapxml parsing to support features

* Restyle
  • Loading branch information
andy31415 authored and pull[bot] committed Jun 27, 2024
1 parent b741bc7 commit 2115158
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
34 changes: 34 additions & 0 deletions scripts/py_matter_idl/matter_idl/test_zapxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,40 @@ def testEnum(self):
Cluster(name='Test2', code=20, enums=[e3])],
))

def testFeatures(self):
idl = XmlToIdl('''<?xml version="1.0"?>
<configurator>
<cluster>
<name>TestFeatures</name>
<code>20</code>
<features>
<feature bit="0" code="DEPONOFF" name="OnOff" summary="Test">
<optionalConform/>
</feature>
<feature bit="1" code="TEST" name="TestFeature" summary="Test2">
<optionalConform/>
</feature>
<feature bit="2" code="XYZ" name="AnotherTest" summary="Test2">
<optionalConform/>
</feature>
</features>
</cluster>
</configurator>
''')
bitmap = Bitmap(
name='Feature',
base_type='bitmap32',
entries=[
ConstantEntry(name='OnOff', code=1),
ConstantEntry(name='TestFeature', code=2),
ConstantEntry(name='AnotherTest', code=4),
])
self.assertEqual(idl,
Idl(clusters=[
Cluster(name='TestFeatures', code=20, bitmaps=[bitmap])
])),

def testStruct(self):
idl = XmlToIdl('''<?xml version="1.0"?>
<configurator>
Expand Down
29 changes: 29 additions & 0 deletions scripts/py_matter_idl/matter_idl/zapxml/handlers/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,33 @@ def EndProcessing(self):
self.context.AddIdlPostProcessor(self)


class FeaturesHandler(BaseHandler):
"""Handles .../features
Attaches a "Feature" bitmap to the given structure
"""

def __init__(self, context: Context, cluster: Cluster):
super().__init__(context)
self._features = Bitmap(name='Feature', base_type="bitmap32", entries=[])
self._cluster = cluster

def GetNextProcessor(self, name, attrs):
if name.lower() == 'feature':
self._features.entries.append(ConstantEntry(
name=attrs['name'],
code=1 << ParseInt(attrs['bit']),
))

# Sub-elements are conformance which is not representable in IDL
return BaseHandler(self.context, handled=HandledDepth.ENTIRE_TREE)
return BaseHandler(self.context)

def EndProcessing(self):
if self._features.entries:
self._cluster.bitmaps.append(self._features)


class DescriptionHandler(BaseHandler):
"""Handles .../description text elements
Expand Down Expand Up @@ -511,6 +538,8 @@ def GetNextProcessor(self, name: str, attrs):
return CommandHandler(self.context, self._cluster, attrs)
elif name.lower() == 'description':
return DescriptionHandler(self.context, self._cluster)
elif name.lower() == 'features':
return FeaturesHandler(self.context, self._cluster)
elif name.lower() in ['define', 'domain', 'tag', 'client', 'server']:
# NOTE: we COULD use client and server to create separate definitions
# of each, but the usefulness of this is unclear as the definitions are
Expand Down

0 comments on commit 2115158

Please sign in to comment.