Skip to content

Commit 2216237

Browse files
andy31415restyled-commits
authored andcommitted
Add global item support to the python zapxml parser. (#34603)
* ZapXML support for global items * Fix typo * Add a unit test for enum too * Restyled by autopep8 --------- Co-authored-by: Restyled.io <commits@restyled.io>
1 parent 3ef4ef2 commit 2216237

File tree

2 files changed

+57
-8
lines changed

2 files changed

+57
-8
lines changed

scripts/py_matter_idl/matter_idl/test_zapxml.py

+52
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,36 @@ def testFabricScopedAndSensitive(self):
234234
qualities=StructQuality.FABRIC_SCOPED)],
235235
)]))
236236

237+
def testGlobalEnum(self):
238+
idl = XmlToIdl('''<?xml version="1.0"?>
239+
<configurator>
240+
<enum name="One" type="ENUM8">
241+
<item value="3" name="Three" />
242+
</enum>
243+
244+
<enum name="Two" type="ENUM8">
245+
<item value="100" name="Big" />
246+
<item value="2000" name="Bigger" />
247+
</enum>
248+
</configurator>
249+
''')
250+
e1 = Enum(
251+
name='One',
252+
base_type="ENUM8",
253+
entries=[
254+
ConstantEntry(name="Three", code=3),
255+
]
256+
)
257+
e2 = Enum(
258+
name='Two',
259+
base_type="ENUM8",
260+
entries=[
261+
ConstantEntry(name="Big", code=100),
262+
ConstantEntry(name="Bigger", code=2000),
263+
]
264+
)
265+
self.assertEqual(idl, Idl(global_enums=[e1, e2]))
266+
237267
def testEnum(self):
238268
idl = XmlToIdl('''<?xml version="1.0"?>
239269
<configurator>
@@ -308,6 +338,28 @@ def testFeatures(self):
308338
Cluster(name='TestFeatures', code=20, bitmaps=[bitmap])
309339
])),
310340

341+
def testGlobalStruct(self):
342+
idl = XmlToIdl('''<?xml version="1.0"?>
343+
<configurator>
344+
<struct name="SomeStruct" isFabricScoped="true">
345+
<item name="FirstMember" type="int16u" />
346+
<item name="SecondMember" type="int32u" />
347+
</struct>
348+
349+
</configurator>
350+
''')
351+
struct = Struct(
352+
name='SomeStruct',
353+
qualities=StructQuality.FABRIC_SCOPED,
354+
fields=[
355+
Field(data_type=DataType(name='int16u'),
356+
code=0, name='FirstMember'),
357+
Field(data_type=DataType(name='int32u'),
358+
code=1, name='SecondMember')
359+
]
360+
)
361+
self.assertEqual(idl, Idl(global_structs=[struct]))
362+
311363
def testStruct(self):
312364
idl = XmlToIdl('''<?xml version="1.0"?>
313365
<configurator>

scripts/py_matter_idl/matter_idl/zapxml/handlers/handlers.py

+5-8
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ def FinalizeProcessing(self, idl: Idl):
225225
# - inside a cluster if a code exists
226226
# - inside top level if no codes were associated
227227
if not self._cluster_codes:
228-
LOGGER.error('Struct %s has no cluster codes' % self._struct.name)
228+
idl.global_structs.append(self._struct)
229229
return
230230

231231
for code in self._cluster_codes:
@@ -270,9 +270,9 @@ def GetNextProcessor(self, name, attrs):
270270

271271
def FinalizeProcessing(self, idl: Idl):
272272
if not self._cluster_codes:
273-
LOGGER.error("Found enum without a cluster code: %s" %
274-
(self._enum.name))
273+
idl.global_enums.append(self._enum)
275274
return
275+
276276
found = set()
277277
for c in idl.clusters:
278278
if c.code in self._cluster_codes:
@@ -313,14 +313,11 @@ def GetNextProcessor(self, name, attrs):
313313
return BaseHandler(self.context)
314314

315315
def FinalizeProcessing(self, idl: Idl):
316-
# We have two choices of adding an enum:
316+
# We have two choices of adding a bitmap:
317317
# - inside a cluster if a code exists
318318
# - inside top level if a code does not exist
319319
if not self._cluster_codes:
320-
# Log only instead of critical, as not our XML is well formed.
321-
# For example at the time of writing this, SwitchFeature in switch-cluster.xml
322-
# did not have a code associated with it.
323-
LOGGER.error("Bitmap %r has no cluster codes" % self._bitmap)
320+
idl.global_bitmaps.append(self._bitmap)
324321
return
325322

326323
for code in self._cluster_codes:

0 commit comments

Comments
 (0)