@@ -37,7 +37,7 @@ public static void Generate()
3737 if ( cluster == null )
3838 throw new IOException ( "Failed to parse cluster " + clusterxml ) ;
3939 if ( ! string . IsNullOrEmpty ( cluster . clusterIds . clusterId . id ) )
40- clusterBase . WriteLine ( $ " case { cluster . name . Replace ( " " , "" ) . Replace ( '/' , '_' ) } .CLUSTER_ID:\n return new { cluster . name . Replace ( " " , "" ) . Replace ( '/' , '_' ) } (endPoint);") ;
40+ clusterBase . WriteLine ( $ " case { GeneratorUtil . SanitizeClassName ( cluster . name ) } .CLUSTER_ID:\n return new { GeneratorUtil . SanitizeClassName ( cluster . name ) } (endPoint);") ;
4141 WriteClass ( cluster ) ;
4242 }
4343 }
@@ -95,7 +95,7 @@ private static void WriteClass(Cluster cluster, TextWriter writer)
9595 if ( string . IsNullOrEmpty ( cluster . classification . baseCluster ) && ! string . IsNullOrEmpty ( cluster . clusterIds . clusterId . id ) )
9696 writer . WriteLine ( $ " /// <inheritdoc />\n protected { GeneratorUtil . SanitizeClassName ( cluster . name ) } (uint cluster, ushort endPoint) : base(cluster, endPoint) {{ }}") ;
9797 writer . WriteLine ( ) ;
98- if ( cluster . dataTypes ? . @enum != null || ( cluster . features != null && cluster . features . Length > 0 ) )
98+ if ( cluster . dataTypes ? . @enum != null || cluster . dataTypes ? . bitmap != null || ( cluster . features != null && cluster . features . Length > 0 ) )
9999 {
100100 writer . WriteLine ( " #region Enums" ) ;
101101 bool firstEnum = true ;
@@ -174,7 +174,7 @@ private static void WriteClass(Cluster cluster, TextWriter writer)
174174 WriteCommands ( cluster , writer ) ;
175175 }
176176
177- if ( cluster . attributes . Length > 0 || ( cluster . features != null && cluster . features . Length > 0 ) )
177+ if ( ( cluster . attributes != null && cluster . attributes . Length > 0 ) || ( cluster . features != null && cluster . features . Length > 0 ) )
178178 {
179179 writer . WriteLine ( " #region Attributes" ) ;
180180 bool firstAttribute = true ;
@@ -183,15 +183,18 @@ private static void WriteClass(Cluster cluster, TextWriter writer)
183183 firstAttribute = false ;
184184 WriteFeatureFunctions ( writer ) ;
185185 }
186- foreach ( var attribute in cluster . attributes )
186+ if ( cluster . attributes != null && cluster . attributes . Length > 0 )
187187 {
188- if ( attribute . type != null )
188+ foreach ( var attribute in cluster . attributes )
189189 {
190- if ( firstAttribute )
191- firstAttribute = false ;
192- else
193- writer . WriteLine ( ) ;
194- WriteAttribute ( cluster , attribute , writer ) ;
190+ if ( attribute . type != null && attribute ? . mandatoryConform ? . condition ? . name != "Zigbee" )
191+ {
192+ if ( firstAttribute )
193+ firstAttribute = false ;
194+ else
195+ writer . WriteLine ( ) ;
196+ WriteAttribute ( cluster , attribute , writer ) ;
197+ }
195198 }
196199 }
197200 writer . WriteLine ( " #endregion Attributes" ) ;
@@ -231,7 +234,7 @@ private static void WriteStruct(clusterCommand command, bool toServer, TextWrite
231234 if ( field . type . EndsWith ( "Enum" ) )
232235 writer . WriteLine ( " = " + field . type + "." + field . @default + ";" ) ;
233236 else
234- writer . WriteLine ( " = " + SanitizeDefault ( field . @default , field . type ) + ";" ) ;
237+ writer . WriteLine ( " = " + SanitizeDefault ( field . @default , field . type , field . entry ? . type ) + ";" ) ;
235238 }
236239 else
237240 writer . WriteLine ( ) ;
@@ -375,6 +378,7 @@ private static void WriteStructType(bool optional, bool nullable, string type, s
375378 case "namespace" :
376379 case "fabric-idx" :
377380 case "action-id" :
381+ case "percent" :
378382 writer . Write ( $ "{ totalIndent } writer.WriteByte({ id } , { name } ") ;
379383 if ( to != null )
380384 writer . Write ( $ ", { to . Value } ") ;
@@ -521,11 +525,13 @@ private static void WriteStructType(bool optional, bool nullable, string type, s
521525 case "ref_IpAdr" :
522526 case "ref_Ipv4Adr" :
523527 case "ref_Ipv6Adr" :
528+ case "ipv6adr" :
524529 if ( nullable && ! optional )
525530 writer . Write ( $ "{ totalIndent } if ({ name } == null)\n { totalIndent } writer.WriteNull({ id } );\n { totalIndent } else\n ") ;
526531 writer . WriteLine ( $ "{ totalIndent } writer.WriteBytes({ id } , { name } .GetAddressBytes());") ;
527532 return ;
528533 case "Hardware Address" :
534+ case "hwadr" :
529535 if ( nullable && ! optional )
530536 writer . Write ( $ "{ totalIndent } if ({ name } == null)\n { totalIndent } writer.WriteNull({ id } );\n { totalIndent } else\n ") ;
531537 writer . WriteLine ( $ "{ totalIndent } writer.WriteBytes({ id } , { name } .GetAddressBytes());") ;
@@ -623,6 +629,7 @@ private static void WriteFieldReader(bool optional, bool nullable, string type,
623629 case "namespace" :
624630 case "fabric-idx" :
625631 case "action-id" :
632+ case "percent" :
626633 writer . Write ( $ "reader.GetByte({ id } ") ;
627634 break ;
628635 case "uint16" :
@@ -672,9 +679,11 @@ private static void WriteFieldReader(bool optional, bool nullable, string type,
672679 writer . WriteLine ( $ "new IPAddress(reader.GetBytes({ id } , { ( optional ? "true" : "false" ) } , 4, 4{ ( id == "-1" || id == "i" ? ")!))" : ")!)" ) } ;") ;
673680 return ;
674681 case "ref_Ipv6Adr" :
682+ case "ipv6adr" :
675683 writer . WriteLine ( $ "new IPAddress(reader.GetBytes({ id } , { ( optional ? "true" : "false" ) } , 16, 16{ ( id == "-1" || id == "i" ? ")!))" : ")!)" ) } ;") ;
676684 return ;
677685 case "Hardware Address" :
686+ case "hwadr" :
678687 writer . WriteLine ( $ "new PhysicalAddress(reader.GetBytes({ id } , { ( optional ? "true" : "false" ) } , 8, 6{ ( id == "-1" || id == "i" ? ")!))" : ")!)" ) } ;") ;
679688 return ;
680689 case "epoch-s" :
@@ -764,7 +773,7 @@ private static void WriteFieldReader(bool optional, bool nullable, string type,
764773 else if ( id == "i" )
765774 writer . WriteLine ( "(reader.GetStruct(i)!));" ) ;
766775 else
767- writer . WriteLine ( $ "fields[{ id } ]);") ;
776+ writer . WriteLine ( $ "((object[]) fields[{ id } ]);") ;
768777 }
769778 return ;
770779 }
@@ -786,7 +795,7 @@ private static void WriteFieldReader(bool optional, bool nullable, string type,
786795
787796 private static bool HasEnum ( Cluster cluster , string name )
788797 {
789- if ( cluster . dataTypes . @enum == null )
798+ if ( cluster . dataTypes ? . @enum == null )
790799 return false ;
791800 foreach ( clusterDataTypesEnum enumType in cluster . dataTypes . @enum )
792801 {
@@ -798,7 +807,7 @@ private static bool HasEnum(Cluster cluster, string name)
798807
799808 private static bool HasEnumValue ( Cluster cluster , string name , string value )
800809 {
801- if ( cluster . dataTypes . @enum == null )
810+ if ( cluster . dataTypes ? . @enum == null )
802811 return false ;
803812 foreach ( clusterDataTypesEnum enumType in cluster . dataTypes . @enum )
804813 {
@@ -816,7 +825,7 @@ private static bool HasEnumValue(Cluster cluster, string name, string value)
816825
817826 private static bool HasBitmap ( Cluster cluster , string name )
818827 {
819- if ( cluster . dataTypes . bitmap == null )
828+ if ( cluster . dataTypes ? . bitmap == null )
820829 return false ;
821830 foreach ( clusterDataTypesBitfield bitfieldType in cluster . dataTypes . bitmap )
822831 {
@@ -828,7 +837,7 @@ private static bool HasBitmap(Cluster cluster, string name)
828837
829838 private static bool HasBitmapValue ( Cluster cluster , string name , string value )
830839 {
831- if ( cluster . dataTypes . bitmap == null )
840+ if ( cluster . dataTypes ? . bitmap == null )
832841 return false ;
833842 foreach ( clusterDataTypesBitfield bitfieldType in cluster . dataTypes . bitmap )
834843 {
@@ -846,7 +855,7 @@ private static bool HasBitmapValue(Cluster cluster, string name, string value)
846855
847856 private static bool HasStruct ( Cluster cluster , string name )
848857 {
849- if ( cluster . dataTypes . @struct == null )
858+ if ( cluster . dataTypes ? . @struct == null )
850859 return false ;
851860 foreach ( clusterDataTypesStruct structType in cluster . dataTypes . @struct )
852861 {
@@ -1024,7 +1033,7 @@ private static void WriteRecord(clusterDataTypesStruct structType, Cluster clust
10241033 if ( HasEnum ( cluster , field . type ) || HasBitmap ( cluster , field . type ) )
10251034 writer . WriteLine ( " = " + field . type + "." + field . @default + ";" ) ;
10261035 else
1027- writer . WriteLine ( " = " + SanitizeDefault ( field . @default ! , field . type ) + ";" ) ;
1036+ writer . WriteLine ( " = " + SanitizeDefault ( field . @default ! , field . type , field . entry ? . type ) + ";" ) ;
10281037 }
10291038 else
10301039 writer . WriteLine ( ) ;
@@ -1079,9 +1088,12 @@ private static void WriteEnum(clusterDataTypesEnum enumType, TextWriter writer)
10791088 writer . WriteLine ( " public enum " + GeneratorUtil . SanitizeName ( enumType . name ) + " {" ) ;
10801089 foreach ( clusterDataTypesEnumItem item in enumType . item )
10811090 {
1082- if ( item . summary != null )
1083- writer . WriteLine ( " /// <summary>\n /// " + item . summary . Replace ( "[[ref_" , "<see cref=\" " ) . Replace ( "]]" , "\" />" ) + "\n /// </summary>" ) ;
1084- writer . WriteLine ( " " + item . name + " = " + item . value + "," ) ;
1091+ if ( ! string . IsNullOrWhiteSpace ( item . value ) )
1092+ {
1093+ if ( item . summary != null )
1094+ writer . WriteLine ( " /// <summary>\n /// " + item . summary . Replace ( "[[ref_" , "<see cref=\" " ) . Replace ( "]]" , "\" />" ) + "\n /// </summary>" ) ;
1095+ writer . WriteLine ( " " + GeneratorUtil . SanitizeName ( item . name ) + " = " + item . value + "," ) ;
1096+ }
10851097 }
10861098 writer . WriteLine ( " }" ) ;
10871099 }
@@ -1097,7 +1109,7 @@ private static void WriteBitfield(clusterDataTypesBitfield enumType, TextWriter
10971109 {
10981110 if ( item . summary != null )
10991111 writer . WriteLine ( " /// <summary>\n /// " + item . summary . Replace ( "[[ref_" , "<see cref=\" " ) . Replace ( "]]" , "\" />" ) + "\n /// </summary>" ) ;
1100- writer . WriteLine ( " " + item . name + " = " + ( 1 << item . bit ) + "," ) ;
1112+ writer . WriteLine ( " " + GeneratorUtil . SanitizeName ( item . name ) + " = " + ( 1 << item . bit ) + "," ) ;
11011113 }
11021114 writer . WriteLine ( " }" ) ;
11031115 }
@@ -1194,7 +1206,7 @@ private static void WriteAttribute(Cluster cluster, clusterAttribute attribute,
11941206 writer . WriteLine ( ";" ) ;
11951207 writer . WriteLine ( " }" ) ;
11961208 }
1197- if ( attribute ? . access ? . write == true )
1209+ if ( attribute ? . access ? . write == " true" || attribute ? . access ? . write == "optional" )
11981210 {
11991211 if ( attribute . access . read )
12001212 writer . WriteLine ( ) ;
@@ -1233,6 +1245,7 @@ private static void WriteType(string type, string? entryType, TextWriter writer)
12331245 case "namespace" :
12341246 case "fabric-idx" :
12351247 case "action-id" :
1248+ case "percent" :
12361249 writer . Write ( "byte" ) ;
12371250 break ;
12381251 case "uint16" :
@@ -1317,10 +1330,12 @@ private static void WriteType(string type, string? entryType, TextWriter writer)
13171330 case "ref_IpAdr" :
13181331 case "ref_Ipv4Adr" :
13191332 case "ref_Ipv6Adr" :
1333+ case "ipv6adr" :
13201334 includes . Add ( "System.Net" ) ;
13211335 writer . Write ( "IPAddress" ) ;
13221336 break ;
13231337 case "Hardware Address" :
1338+ case "hwadr" : //This is the most non-standard standard i've ever worked with
13241339 includes . Add ( "System.Net.NetworkInformation" ) ;
13251340 writer . Write ( "PhysicalAddress" ) ;
13261341 break ;
@@ -1349,7 +1364,7 @@ private static void WriteType(string type, string? entryType, TextWriter writer)
13491364 }
13501365 }
13511366
1352- private static string SanitizeDefault ( string value , string ? type = null , string ? listType = null )
1367+ private static string SanitizeDefault ( string value , string ? type , string ? listType )
13531368 {
13541369 if ( value == "\" " )
13551370 return "\" \" " ;
@@ -1374,6 +1389,8 @@ private static string SanitizeDefault(string value, string? type = null, string?
13741389 return value ;
13751390 if ( value == "0" && ( type == "epoch-s" || type == "epoch-us" ) )
13761391 return "TimeUtil.EPOCH" ;
1392+ if ( type == "elapsed-s" )
1393+ return $ "TimeSpan.FromSeconds({ value } )";
13771394 return value . ToLowerInvariant ( ) ;
13781395 }
13791396
@@ -1385,6 +1402,8 @@ private static bool DefaultValid(string value)
13851402 return false ;
13861403 if ( value == "-" )
13871404 return false ;
1405+ if ( value == "PhysicalMinLevel" || value == "PhysicalMaxLevel" )
1406+ return false ;
13881407 return true ;
13891408 }
13901409 }
0 commit comments