Skip to content

Commit

Permalink
Handle energy type naming in data model xml handlers (#31344)
Browse files Browse the repository at this point in the history
* Correct case names for enerty types in data model handlers.

* Add unit test

* restyle
  • Loading branch information
andy31415 authored Jan 15, 2024
1 parent 970e9db commit dbbb79b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ def NormalizeDataType(t: str) -> str:
}


# Handle odd casing and naming
_CASE_RENAMES_MAPPING = {
"power_mW": "power_mw",
"energy_mWh": "energy_mwh"
}


def ParseType(t: str) -> ParsedType:
"""Parse a data type entry.
Expand All @@ -123,6 +130,9 @@ def ParseType(t: str) -> ParsedType:
if t in _REF_NAME_MAPPING:
t = _REF_NAME_MAPPING[t]

if t in _CASE_RENAMES_MAPPING:
t = _CASE_RENAMES_MAPPING[t]

return ParsedType(name=NormalizeDataType(t), is_list=is_list)


Expand Down
16 changes: 16 additions & 0 deletions scripts/py_matter_idl/matter_idl/test_data_model_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,19 @@ def testXmlNameWorkarounds(self):
<access read="true" write="true"/>
<mandatoryConform/>
</field>
<field id="3" name="NominalPower" type="power-mW">
<access read="true" write="true"/>
<mandatoryConform>
<feature name="PFR"/>
</mandatoryConform>
<constraint type="desc"/>
</field>
<field id="4" name="MaximumEnergy" type="energy-mWh">
<access read="true" write="true"/>
<mandatoryConform>
<feature name="PFR"/>
</mandatoryConform>
</field>
</struct>
</dataTypes>
<attributes>
Expand Down Expand Up @@ -443,11 +456,14 @@ def testXmlNameWorkarounds(self):
char_string id = 0;
int8u items[] = 1;
endpoint_no endpoints[] = 2;
optional power_mw nominalPower = 3;
optional energy_mwh maximumEnergy = 4;
}
readonly attribute OutputInfoStruct outputList[] = 0;
readonly attribute optional enum8 testConform = 1;
readonly attribute attrib_id attributeList[] = 65531;
readonly attribute event_id eventList[] = 65530;
readonly attribute command_id acceptedCommandList[] = 65529;
Expand Down

0 comments on commit dbbb79b

Please sign in to comment.