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

Add features parsing for the zapxml python parser #33853

Merged
merged 2 commits into from
Jun 13, 2024
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
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
Loading