@@ -217,7 +217,22 @@ function generateClusterInterface(cluster) {
217217 * }>} clusterDefinitions - Array of CLUSTER definitions used to generate typed CLUSTER exports
218218 * @returns {string } Complete TypeScript definitions file
219219 */
220- function generateTypesFile ( clusters , clusterDefinitions ) {
220+ function generateConstantObject ( obj , indent = 2 ) {
221+ const lines = [ ] ;
222+ const pad = ' ' . repeat ( indent ) ;
223+ for ( const [ key , value ] of Object . entries ( obj ) ) {
224+ if ( typeof value === 'object' && value !== null ) {
225+ lines . push ( `${ pad } ${ key } : {` ) ;
226+ lines . push ( generateConstantObject ( value , indent + 2 ) ) ;
227+ lines . push ( `${ pad } };` ) ;
228+ } else {
229+ lines . push ( `${ pad } ${ key } : ${ typeof value === 'number' ? value : JSON . stringify ( value ) } ;` ) ;
230+ }
231+ }
232+ return lines . join ( '\n' ) ;
233+ }
234+
235+ function generateTypesFile ( clusters , clusterDefinitions , constants ) {
221236 const lines = [ ] ;
222237
223238 // Header
@@ -400,6 +415,16 @@ export const CLUSTER: {
400415 lines . push ( '};' ) ;
401416 }
402417
418+ // Export constants
419+ if ( constants ) {
420+ for ( const [ name , value ] of Object . entries ( constants ) ) {
421+ lines . push ( '' ) ;
422+ lines . push ( `export const ${ name } : {` ) ;
423+ lines . push ( generateConstantObject ( value ) ) ;
424+ lines . push ( '};' ) ;
425+ }
426+ }
427+
403428 lines . push ( '' ) ;
404429 lines . push ( 'declare const _default: {' ) ;
405430 lines . push ( ' ZCLNode: typeof ZCLNode;' ) ;
@@ -408,6 +433,11 @@ export const CLUSTER: {
408433 const exportName = cluster . exportName || toInterfaceName ( cluster ) ;
409434 lines . push ( ` ${ exportName } : typeof ${ exportName } ;` ) ;
410435 }
436+ if ( constants ) {
437+ for ( const name of Object . keys ( constants ) ) {
438+ lines . push ( ` ${ name } : typeof ${ name } ;` ) ;
439+ }
440+ }
411441 lines . push ( '};' ) ;
412442 lines . push ( 'export default _default;' ) ;
413443
@@ -448,8 +478,12 @@ function main() {
448478 } ) )
449479 . sort ( ( a , b ) => a . constantName . localeCompare ( b . constantName ) ) ;
450480
481+ // Load constants
482+ const { ZIGBEE_PROFILE_ID , ZIGBEE_DEVICE_ID , IAS_ZONE_TYPE } = require ( '../lib/constants' ) ;
483+ const constants = { ZIGBEE_PROFILE_ID , ZIGBEE_DEVICE_ID , IAS_ZONE_TYPE } ;
484+
451485 console . log ( `\nGenerating ${ OUTPUT_FILE } ...` ) ;
452- const output = generateTypesFile ( clusters , clusterDefinitions ) ;
486+ const output = generateTypesFile ( clusters , clusterDefinitions , constants ) ;
453487 fs . writeFileSync ( OUTPUT_FILE , output ) ;
454488
455489 console . log ( `Done! Generated types for ${ clusters . length } clusters.` ) ;
0 commit comments