@zwave-js/cc 14.0.0 → 14.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. package/build/cjs/cc/AssociationCC.js +1 -1
  2. package/build/cjs/cc/AssociationCC.js.map +1 -1
  3. package/build/cjs/cc/CentralSceneCC.js +2 -3
  4. package/build/cjs/cc/CentralSceneCC.js.map +2 -2
  5. package/build/cjs/cc/ClimateControlScheduleCC.js +5 -6
  6. package/build/cjs/cc/ClimateControlScheduleCC.js.map +2 -2
  7. package/build/cjs/cc/ClockCC.js +2 -3
  8. package/build/cjs/cc/ClockCC.js.map +2 -2
  9. package/build/cjs/cc/ColorSwitchCC.js +2 -2
  10. package/build/cjs/cc/ColorSwitchCC.js.map +1 -1
  11. package/build/cjs/cc/ConfigurationCC.js +4 -6
  12. package/build/cjs/cc/ConfigurationCC.js.map +2 -2
  13. package/build/cjs/cc/DoorLockCC.js +1 -1
  14. package/build/cjs/cc/DoorLockCC.js.map +1 -1
  15. package/build/cjs/cc/IndicatorCC.js +2 -2
  16. package/build/cjs/cc/IndicatorCC.js.map +1 -1
  17. package/build/cjs/cc/IrrigationCC.js +7 -8
  18. package/build/cjs/cc/IrrigationCC.js.map +2 -2
  19. package/build/cjs/cc/MultiChannelCC.js +1 -1
  20. package/build/cjs/cc/MultiChannelCC.js.map +1 -1
  21. package/build/cjs/cc/NotificationCC.js +1 -1
  22. package/build/cjs/cc/NotificationCC.js.map +1 -1
  23. package/build/cjs/cc/ProtectionCC.js +1 -2
  24. package/build/cjs/cc/ProtectionCC.js.map +2 -2
  25. package/build/cjs/cc/Security2CC.js +2 -2
  26. package/build/cjs/cc/Security2CC.js.map +1 -1
  27. package/build/cjs/cc/SecurityCC.js +1 -1
  28. package/build/cjs/cc/SecurityCC.js.map +1 -1
  29. package/build/cjs/cc/SoundSwitchCC.js +1 -1
  30. package/build/cjs/cc/SoundSwitchCC.js.map +1 -1
  31. package/build/cjs/cc/ThermostatSetbackCC.js +6 -8
  32. package/build/cjs/cc/ThermostatSetbackCC.js.map +2 -2
  33. package/build/cjs/cc/TimeCC.js +2 -3
  34. package/build/cjs/cc/TimeCC.js.map +2 -2
  35. package/build/cjs/cc/WakeUpCC.js +1 -1
  36. package/build/cjs/cc/WakeUpCC.js.map +1 -1
  37. package/build/cjs/cc/manufacturerProprietary/FibaroCC.js +1 -1
  38. package/build/cjs/cc/manufacturerProprietary/FibaroCC.js.map +1 -1
  39. package/build/cjs/index_browser.d.ts +8 -0
  40. package/build/cjs/index_browser.js +40 -0
  41. package/build/cjs/index_browser.js.map +7 -0
  42. package/build/cjs/lib/API.js +1 -1
  43. package/build/cjs/lib/API.js.map +1 -1
  44. package/build/cjs/lib/CommandClass.js +1 -1
  45. package/build/cjs/lib/CommandClass.js.map +1 -1
  46. package/build/cjs/lib/EncapsulatingCommandClass.js +1 -1
  47. package/build/cjs/lib/EncapsulatingCommandClass.js.map +1 -1
  48. package/build/cjs/lib/Values.d.ts +2 -2
  49. package/build/cjs/lib/Values.js +9 -9
  50. package/build/cjs/lib/Values.js.map +3 -3
  51. package/build/cjs/lib/serializers.d.ts +2 -2
  52. package/build/cjs/lib/serializers.js +19 -10
  53. package/build/cjs/lib/serializers.js.map +2 -2
  54. package/build/cjs/lib/utils.js +1 -1
  55. package/build/cjs/lib/utils.js.map +1 -1
  56. package/build/esm/cc/AssociationCC.js +1 -1
  57. package/build/esm/cc/AssociationCC.js.map +1 -1
  58. package/build/esm/cc/CentralSceneCC.d.ts.map +1 -1
  59. package/build/esm/cc/CentralSceneCC.js +2 -3
  60. package/build/esm/cc/CentralSceneCC.js.map +1 -1
  61. package/build/esm/cc/ClimateControlScheduleCC.d.ts.map +1 -1
  62. package/build/esm/cc/ClimateControlScheduleCC.js +7 -7
  63. package/build/esm/cc/ClimateControlScheduleCC.js.map +1 -1
  64. package/build/esm/cc/ClockCC.d.ts.map +1 -1
  65. package/build/esm/cc/ClockCC.js +2 -3
  66. package/build/esm/cc/ClockCC.js.map +1 -1
  67. package/build/esm/cc/ColorSwitchCC.js +2 -2
  68. package/build/esm/cc/ColorSwitchCC.js.map +1 -1
  69. package/build/esm/cc/ConfigurationCC.d.ts.map +1 -1
  70. package/build/esm/cc/ConfigurationCC.js +4 -6
  71. package/build/esm/cc/ConfigurationCC.js.map +1 -1
  72. package/build/esm/cc/DoorLockCC.js +1 -1
  73. package/build/esm/cc/DoorLockCC.js.map +1 -1
  74. package/build/esm/cc/IndicatorCC.js +2 -2
  75. package/build/esm/cc/IndicatorCC.js.map +1 -1
  76. package/build/esm/cc/IrrigationCC.d.ts.map +1 -1
  77. package/build/esm/cc/IrrigationCC.js +7 -8
  78. package/build/esm/cc/IrrigationCC.js.map +1 -1
  79. package/build/esm/cc/MultiChannelCC.js +1 -1
  80. package/build/esm/cc/MultiChannelCC.js.map +1 -1
  81. package/build/esm/cc/NotificationCC.js +1 -1
  82. package/build/esm/cc/NotificationCC.js.map +1 -1
  83. package/build/esm/cc/ProtectionCC.d.ts.map +1 -1
  84. package/build/esm/cc/ProtectionCC.js +1 -2
  85. package/build/esm/cc/ProtectionCC.js.map +1 -1
  86. package/build/esm/cc/Security2CC.js +2 -2
  87. package/build/esm/cc/Security2CC.js.map +1 -1
  88. package/build/esm/cc/SecurityCC.js +1 -1
  89. package/build/esm/cc/SecurityCC.js.map +1 -1
  90. package/build/esm/cc/SoundSwitchCC.js +1 -1
  91. package/build/esm/cc/SoundSwitchCC.js.map +1 -1
  92. package/build/esm/cc/ThermostatSetbackCC.d.ts.map +1 -1
  93. package/build/esm/cc/ThermostatSetbackCC.js +10 -12
  94. package/build/esm/cc/ThermostatSetbackCC.js.map +1 -1
  95. package/build/esm/cc/TimeCC.d.ts.map +1 -1
  96. package/build/esm/cc/TimeCC.js +2 -3
  97. package/build/esm/cc/TimeCC.js.map +1 -1
  98. package/build/esm/cc/WakeUpCC.js +1 -1
  99. package/build/esm/cc/WakeUpCC.js.map +1 -1
  100. package/build/esm/cc/manufacturerProprietary/FibaroCC.js +1 -1
  101. package/build/esm/cc/manufacturerProprietary/FibaroCC.js.map +1 -1
  102. package/build/esm/index_browser.d.ts +8 -0
  103. package/build/esm/index_browser.d.ts.map +1 -0
  104. package/build/esm/index_browser.js +8 -0
  105. package/build/esm/index_browser.js.map +1 -0
  106. package/build/esm/lib/API.js +1 -1
  107. package/build/esm/lib/API.js.map +1 -1
  108. package/build/esm/lib/CommandClass.js +1 -1
  109. package/build/esm/lib/CommandClass.js.map +1 -1
  110. package/build/esm/lib/EncapsulatingCommandClass.js +1 -1
  111. package/build/esm/lib/EncapsulatingCommandClass.js.map +1 -1
  112. package/build/esm/lib/Values.d.ts +2 -2
  113. package/build/esm/lib/Values.d.ts.map +1 -1
  114. package/build/esm/lib/Values.js +1 -1
  115. package/build/esm/lib/Values.js.map +1 -1
  116. package/build/esm/lib/serializers.d.ts +2 -2
  117. package/build/esm/lib/serializers.d.ts.map +1 -1
  118. package/build/esm/lib/serializers.js +20 -10
  119. package/build/esm/lib/serializers.js.map +1 -1
  120. package/build/esm/lib/utils.js +1 -1
  121. package/build/esm/lib/utils.js.map +1 -1
  122. package/package.json +8 -7
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/lib/Values.ts"],
4
- "sourcesContent": ["import {\n\ttype CommandClasses,\n\ttype EndpointId,\n\ttype ValueID,\n\tValueMetadata,\n} from \"@zwave-js/core\";\nimport type { GetDeviceConfig, GetValueDB } from \"@zwave-js/host\";\nimport {\n\ttype FnOrStatic,\n\ttype ReturnTypeOrStatic,\n\tevalOrStatic,\n} from \"@zwave-js/shared/safe\";\nimport type { Overwrite } from \"alcalzone-shared/types/index.js\";\nimport type { ValueIDProperties } from \"./API.js\";\n\n// HINT: To fully view types for definitions created by this, open\n// node_modules/typescript/lib/tsserver.js and change the definition of\n// ts.defaultMaximumTruncationLength = 160\n// to something higher like\n// ts.defaultMaximumTruncationLength = 1000\n// Then restart TS Server\n\nexport interface CCValueOptions {\n\t/**\n\t * Whether the CC value is internal. Internal values are not exposed to the user.\n\t */\n\tinternal?: boolean;\n\t/**\n\t * The minimum CC version required for this value to exist.\n\t */\n\tminVersion?: number;\n\t/**\n\t * Whether this value represents a state (`true`) or a notification/event (`false`). Default: `true`\n\t */\n\tstateful?: boolean;\n\t/**\n\t * Omit this value from value logs. Default: `false`\n\t */\n\tsecret?: boolean;\n\n\t/** Whether the CC value may exist on endpoints. Default: `true` */\n\tsupportsEndpoints?: boolean;\n\n\t/**\n\t * Can be used to dynamically decide if this value should be created automatically.\n\t * This is ignored for dynamic values and defaults to `true` if not given.\n\t */\n\tautoCreate?:\n\t\t| boolean\n\t\t| ((\n\t\t\tctx: GetValueDB & GetDeviceConfig,\n\t\t\tendpoint: EndpointId,\n\t\t) => boolean);\n}\n\nexport const defaultCCValueOptions = {\n\tinternal: false,\n\tminVersion: 1,\n\tsecret: false,\n\tstateful: true,\n\tsupportsEndpoints: true,\n\tautoCreate: true,\n} as const;\n\ntype DefaultOptions = typeof defaultCCValueOptions;\n\n// expands object types recursively\nexport type ExpandRecursively<T> =\n\t// Split functions with properties into the function and object parts\n\tT extends (...args: infer A) => infer R\n\t\t? [keyof T] extends [never] ? (...args: A) => ExpandRecursively<R>\n\t\t:\n\t\t\t& ((...args: A) => ExpandRecursively<R>)\n\t\t\t& {\n\t\t\t\t[P in keyof T]: ExpandRecursively<T[P]>;\n\t\t\t}\n\t\t// Expand object types\n\t\t: T extends object\n\t\t\t? T extends infer O ? { [K in keyof O]: ExpandRecursively<O[K]> }\n\t\t\t: never\n\t\t// Fallback to the type itself if no match\n\t\t: T;\n\nexport type ExpandRecursivelySkipMeta<T> =\n\t// Split functions with properties into the function and object parts\n\tT extends (...args: infer A) => infer R\n\t\t? [keyof T] extends [never]\n\t\t\t? (...args: A) => ExpandRecursivelySkipMeta<R>\n\t\t:\n\t\t\t& ((...args: A) => ExpandRecursivelySkipMeta<R>)\n\t\t\t& {\n\t\t\t\t[P in keyof T]: ExpandRecursivelySkipMeta<T[P]>;\n\t\t\t}\n\t\t// Ignore the ValueMetadata type\n\t\t: T extends ValueMetadata ? T\n\t\t// Expand object types\n\t\t: T extends object\n\t\t\t? T extends infer O\n\t\t\t\t? { [K in keyof O]: ExpandRecursivelySkipMeta<O[K]> }\n\t\t\t: never\n\t\t// Fallback to the type itself if no match\n\t\t: T;\n\ntype InferValueIDBase<\n\tTCommandClass extends CommandClasses,\n\tTBlueprint extends CCValueBlueprint,\n\tTWorker = {\n\t\tcommandClass: TCommandClass;\n\t} & Pick<TBlueprint, \"property\" | \"propertyKey\">,\n> = {\n\t[K in keyof TWorker as unknown extends TWorker[K] ? never : K]: TWorker[K];\n};\n\ntype ToStaticCCValues<\n\tTCommandClass extends CommandClasses,\n\tTValues extends Record<keyof TValues, CCValueBlueprint>,\n> = Readonly<\n\t{\n\t\t[K in keyof TValues]: ExpandRecursively<\n\t\t\tInferStaticCCValue<TCommandClass, TValues[K]>\n\t\t>;\n\t}\n>;\n\ntype ToDynamicCCValues<\n\tTCommandClass extends CommandClasses,\n\tTValues extends Record<keyof TValues, DynamicCCValueBlueprint<any>>,\n> = Readonly<\n\t{\n\t\t[K in keyof TValues]: ExpandRecursively<\n\t\t\tInferDynamicCCValue<TCommandClass, TValues[K]>\n\t\t>;\n\t}\n>;\n\ntype InferArgs<T extends FnOrStatic<any, any>[]> = T extends [\n\t(...args: infer A) => any,\n\t...any,\n] ? A\n\t: T extends [any, ...infer R] ? InferArgs<R>\n\t: [];\n\n/** Defines a single static CC values that belong to a CC */\nfunction defineStaticCCValue<\n\tTCommandClass extends CommandClasses,\n\tTBlueprint extends CCValueBlueprint,\n>(\n\tcommandClass: TCommandClass,\n\tblueprint: TBlueprint,\n): ExpandRecursively<InferStaticCCValue<TCommandClass, TBlueprint>> {\n\t// Normalize value options\n\tconst _blueprint = {\n\t\t...blueprint,\n\t\toptions: {\n\t\t\t...defaultCCValueOptions,\n\t\t\t...blueprint.options,\n\t\t},\n\t};\n\n\tconst valueId = {\n\t\tcommandClass,\n\t\tproperty: _blueprint.property,\n\t\tpropertyKey: _blueprint.propertyKey,\n\t};\n\tif (valueId.propertyKey === undefined) delete valueId.propertyKey;\n\n\tconst ret: InferStaticCCValue<TCommandClass, TBlueprint> = {\n\t\tget id() {\n\t\t\treturn { ...valueId };\n\t\t},\n\t\tendpoint: (endpoint: number = 0) => {\n\t\t\tif (!_blueprint.options.supportsEndpoints) endpoint = 0;\n\t\t\treturn { ...valueId, endpoint } as any;\n\t\t},\n\t\tis: (testValueId) => {\n\t\t\treturn (\n\t\t\t\tvalueId.commandClass === testValueId.commandClass\n\t\t\t\t&& valueId.property === testValueId.property\n\t\t\t\t&& valueId.propertyKey === testValueId.propertyKey\n\t\t\t);\n\t\t},\n\t\tget meta() {\n\t\t\treturn { ...ValueMetadata.Any, ..._blueprint.meta } as any;\n\t\t},\n\t\tget options() {\n\t\t\treturn { ..._blueprint.options } as any;\n\t\t},\n\t};\n\n\treturn ret as any;\n}\n\n/** Defines a single CC value which depends on one or more parameters */\nfunction defineDynamicCCValue<\n\tTCommandClass extends CommandClasses,\n\tTBlueprint extends DynamicCCValueBlueprint<any[]>,\n>(\n\tcommandClass: TCommandClass,\n\tblueprint: TBlueprint,\n): ExpandRecursively<InferDynamicCCValue<TCommandClass, TBlueprint>> {\n\tconst options = {\n\t\t...defaultCCValueOptions,\n\t\t...blueprint.options,\n\t};\n\n\tconst ret: ExpandRecursively<\n\t\tInferDynamicCCValue<TCommandClass, TBlueprint>\n\t> = ((...args: Parameters<TBlueprint>) => {\n\t\tconst _blueprint = blueprint(...args);\n\n\t\t// Normalize value options\n\t\tconst actualBlueprint = {\n\t\t\t..._blueprint,\n\t\t};\n\n\t\tconst valueId = {\n\t\t\tcommandClass,\n\t\t\tproperty: actualBlueprint.property,\n\t\t\tpropertyKey: actualBlueprint.propertyKey,\n\t\t};\n\t\tif (valueId.propertyKey === undefined) delete valueId.propertyKey;\n\n\t\tconst value: Omit<\n\t\t\tInferStaticCCValue<TCommandClass, ReturnType<TBlueprint>>,\n\t\t\t\"options\" | \"is\"\n\t\t> = {\n\t\t\tget id() {\n\t\t\t\treturn { ...valueId };\n\t\t\t},\n\t\t\tendpoint: (endpoint: number = 0) => {\n\t\t\t\tif (!options.supportsEndpoints) endpoint = 0;\n\t\t\t\treturn { ...valueId, endpoint } as any;\n\t\t\t},\n\t\t\tget meta() {\n\t\t\t\treturn { ...ValueMetadata.Any, ...actualBlueprint.meta } as any;\n\t\t\t},\n\t\t};\n\n\t\treturn value;\n\t}) as any;\n\n\tObject.defineProperty(ret, \"options\", {\n\t\tconfigurable: false,\n\t\tenumerable: true,\n\t\tget() {\n\t\t\treturn { ...options };\n\t\t},\n\t});\n\n\tObject.defineProperty(ret, \"is\", {\n\t\tconfigurable: false,\n\t\tenumerable: false,\n\t\twritable: false,\n\t\tvalue: (id: ValueID) =>\n\t\t\tid.commandClass === commandClass && blueprint.is(id),\n\t});\n\n\treturn ret;\n}\n\n// Namespace for utilities to define CC values\nexport const V = {\n\t/** Defines multiple static CC values that belong to the same CC */\n\tdefineStaticCCValues<\n\t\tTCommandClass extends CommandClasses,\n\t\tTValues extends Record<keyof TValues, CCValueBlueprint>,\n\t>(\n\t\tcommandClass: TCommandClass,\n\t\tvalues: TValues,\n\t): TValues extends Record<keyof TValues, CCValueBlueprint>\n\t\t? ExpandRecursively<ToStaticCCValues<TCommandClass, TValues>>\n\t\t: never\n\t{\n\t\treturn Object.fromEntries(\n\t\t\tObject.entries<CCValueBlueprint>(values).map(([key, blueprint]) => [\n\t\t\t\tkey,\n\t\t\t\tdefineStaticCCValue(commandClass, blueprint),\n\t\t\t]),\n\t\t) as any;\n\t},\n\n\t/** Defines multiple static CC values that belong to the same CC */\n\tdefineDynamicCCValues<\n\t\tTCommandClass extends CommandClasses,\n\t\tTValues extends Record<keyof TValues, DynamicCCValueBlueprint<any>>,\n\t>(\n\t\tcommandClass: TCommandClass,\n\t\tvalues: TValues,\n\t): TValues extends Record<keyof TValues, DynamicCCValueBlueprint<any>>\n\t\t? ExpandRecursively<ToDynamicCCValues<TCommandClass, TValues>>\n\t\t: never\n\t{\n\t\treturn Object.fromEntries(\n\t\t\tObject.entries<DynamicCCValueBlueprint<any>>(values).map(\n\t\t\t\t([key, blueprint]) => [\n\t\t\t\t\tkey,\n\t\t\t\t\tdefineDynamicCCValue(commandClass, blueprint),\n\t\t\t\t],\n\t\t\t),\n\t\t) as any;\n\t},\n\n\t/** Returns a CC value definition that is named like the value `property` */\n\tstaticProperty<\n\t\tTProp extends string | number,\n\t\tTMeta extends ValueMetadata,\n\t\tTOptions extends CCValueOptions,\n\t>(\n\t\tproperty: TProp,\n\t\tmeta?: TMeta,\n\t\toptions?: TOptions,\n\t): {\n\t\t[K in TProp]: {\n\t\t\tproperty: TProp;\n\t\t\tmeta: TMeta;\n\t\t\toptions: TOptions;\n\t\t};\n\t} {\n\t\treturn {\n\t\t\t[property]: {\n\t\t\t\tproperty,\n\t\t\t\tmeta,\n\t\t\t\toptions,\n\t\t\t},\n\t\t} as any;\n\t},\n\n\t/** Returns a CC value definition with the given name and `property` */\n\tstaticPropertyWithName<\n\t\tTName extends string,\n\t\tTProp extends string | number,\n\t\tTMeta extends ValueMetadata,\n\t\tTOptions extends CCValueOptions,\n\t>(\n\t\tname: TName,\n\t\tproperty: TProp,\n\t\tmeta?: TMeta,\n\t\toptions?: TOptions,\n\t): {\n\t\t[K in TName]: {\n\t\t\tproperty: TProp;\n\t\t\tmeta: TMeta;\n\t\t\toptions: TOptions;\n\t\t};\n\t} {\n\t\treturn {\n\t\t\t[name]: {\n\t\t\t\tproperty,\n\t\t\t\tmeta,\n\t\t\t\toptions,\n\t\t\t},\n\t\t} as any;\n\t},\n\n\t/** Returns a CC value definition with the given name, `property` and `propertyKey` */\n\tstaticPropertyAndKeyWithName<\n\t\tTName extends string,\n\t\tTProp extends string | number,\n\t\tTKey extends string | number,\n\t\tTMeta extends ValueMetadata,\n\t\tTOptions extends CCValueOptions,\n\t>(\n\t\tname: TName,\n\t\tproperty: TProp,\n\t\tpropertyKey: TKey,\n\t\tmeta?: TMeta,\n\t\toptions?: TOptions,\n\t): {\n\t\t[K in TName]: {\n\t\t\tproperty: TProp;\n\t\t\tpropertyKey: TKey;\n\t\t\tmeta: TMeta;\n\t\t\toptions: TOptions;\n\t\t};\n\t} {\n\t\treturn {\n\t\t\t[name]: {\n\t\t\t\tproperty,\n\t\t\t\tpropertyKey,\n\t\t\t\tmeta,\n\t\t\t\toptions,\n\t\t\t},\n\t\t} as any;\n\t},\n\n\t/** Returns a CC value definition with the given name and a dynamic `property` */\n\tdynamicPropertyWithName<\n\t\tTName extends string,\n\t\tTProp extends FnOrStatic<any[], ValueIDProperties[\"property\"]>,\n\t\tTMeta extends FnOrStatic<any[], ValueMetadata> = ValueMetadata,\n\t\tTOptions extends CCValueOptions = CCValueOptions,\n\t>(\n\t\tname: TName,\n\t\tproperty: TProp,\n\t\tis: PartialCCValuePredicate,\n\t\tmeta?: TMeta,\n\t\toptions?: TOptions,\n\t): {\n\t\t[K in TName]: {\n\t\t\t(...args: InferArgs<[TProp, TMeta]>): {\n\t\t\t\tproperty: ReturnTypeOrStatic<TProp>;\n\t\t\t\tmeta: ReturnTypeOrStatic<TMeta>;\n\t\t\t};\n\t\t\tis: PartialCCValuePredicate;\n\t\t\toptions: TOptions;\n\t\t};\n\t} {\n\t\treturn {\n\t\t\t[name]: Object.assign(\n\t\t\t\t(...args: InferArgs<[TProp, TMeta]>) => ({\n\t\t\t\t\tproperty: evalOrStatic(property, ...args),\n\t\t\t\t\tmeta: evalOrStatic(meta, ...args),\n\t\t\t\t}),\n\t\t\t\t{ is, options },\n\t\t\t),\n\t\t} as any;\n\t},\n\n\t/** Returns a CC value definition with the given name and a dynamic `property` */\n\tdynamicPropertyAndKeyWithName<\n\t\tTName extends string,\n\t\tTProp extends FnOrStatic<any[], ValueIDProperties[\"property\"]>,\n\t\tTKey extends FnOrStatic<any[], ValueIDProperties[\"propertyKey\"]>,\n\t\tTMeta extends FnOrStatic<any[], ValueMetadata> = ValueMetadata,\n\t\tTOptions extends FnOrStatic<any[], CCValueOptions> = CCValueOptions,\n\t>(\n\t\tname: TName,\n\t\tproperty: TProp,\n\t\tpropertyKey: TKey,\n\t\tis: PartialCCValuePredicate,\n\t\tmeta?: TMeta,\n\t\toptions?: TOptions,\n\t): {\n\t\t[K in TName]: {\n\t\t\t(...args: InferArgs<[TProp, TKey, TMeta]>): {\n\t\t\t\tproperty: ReturnTypeOrStatic<TProp>;\n\t\t\t\tpropertyKey: ReturnTypeOrStatic<TKey>;\n\t\t\t\tmeta: ReturnTypeOrStatic<TMeta>;\n\t\t\t};\n\t\t\tis: PartialCCValuePredicate;\n\t\t\toptions: TOptions;\n\t\t};\n\t} {\n\t\treturn {\n\t\t\t[name]: Object.assign(\n\t\t\t\t(...args: any[]) => {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tproperty: evalOrStatic(property, ...args),\n\t\t\t\t\t\tpropertyKey: evalOrStatic(propertyKey, ...args),\n\t\t\t\t\t\tmeta: evalOrStatic(meta, ...args),\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t\t\t{ is, options },\n\t\t\t),\n\t\t} as any;\n\t},\n};\n\nexport interface CCValueBlueprint extends Readonly<ValueIDProperties> {\n\treadonly meta?: Readonly<ValueMetadata>;\n\treadonly options?: Readonly<CCValueOptions>;\n}\n\nexport type CCValuePredicate = (valueId: ValueID) => boolean;\nexport type PartialCCValuePredicate = (\n\tproperties: ValueIDProperties,\n) => boolean;\n\n/** A blueprint for a CC value which depends on one or more parameters */\nexport interface DynamicCCValueBlueprint<TArgs extends any[]> {\n\t(...args: TArgs): Omit<CCValueBlueprint, \"options\">;\n\tis: PartialCCValuePredicate;\n\treadonly options?: Readonly<CCValueOptions>;\n}\n\ntype DropOptional<T> = {\n\t[K in keyof T as [undefined] extends [T[K]] ? never : K]: T[K];\n};\n\ntype MergeOptions<TOptions extends CCValueOptions> = DropOptional<\n\tCCValueOptions extends TOptions\n\t\t// When the type cannot be inferred exactly (not given), default to DefaultOptions\n\t\t? DefaultOptions\n\t\t: Overwrite<DefaultOptions, TOptions>\n>;\n\ntype MergeMeta<TMeta extends ValueMetadata> = DropOptional<\n\tValueMetadata extends TMeta\n\t\t// When the type cannot be inferred exactly (not given), default to ValueMetadata.Any\n\t\t? (typeof ValueMetadata)[\"Any\"]\n\t\t: Overwrite<(typeof ValueMetadata)[\"Any\"], TMeta>\n>;\n\n/** The common base type of all CC value definitions */\nexport interface CCValue {\n\treadonly id: Omit<ValueID, \"endpoint\">;\n\tendpoint(endpoint?: number): ValueID;\n\treadonly meta: ValueMetadata;\n}\n\ntype AddCCValueProperties<\n\tTCommandClass extends CommandClasses,\n\tTBlueprint extends CCValueBlueprint,\n\tValueIDBase extends Record<string, any> = InferValueIDBase<\n\t\tTCommandClass,\n\t\tTBlueprint\n\t>,\n> = {\n\t/** Returns the value ID of this CC value, without endpoint information */\n\tget id(): ValueIDBase;\n\n\t/** Returns the value ID, specialized to the given endpoint */\n\tendpoint(\n\t\tendpoint?: number,\n\t): Readonly<\n\t\t& Pick<ValueIDBase, \"commandClass\">\n\t\t& { endpoint: number }\n\t\t& Omit<\n\t\t\tValueIDBase,\n\t\t\t\"commandClass\"\n\t\t>\n\t>;\n\n\t/** Whether the given value ID matches this value definition */\n\tis: CCValuePredicate;\n\n\t/** Returns the metadata for this value ID */\n\tget meta(): Readonly<MergeMeta<NonNullable<TBlueprint[\"meta\"]>>>;\n\t/** Returns the value options for this value ID */\n\tget options(): Readonly<MergeOptions<NonNullable<TBlueprint[\"options\"]>>>;\n};\n\n/** A CC value definition which depends on one or more parameters, transparently inferred from its arguments */\nexport type InferDynamicCCValue<\n\tTCommandClass extends CommandClasses,\n\tTBlueprint extends DynamicCCValueBlueprint<any[]>,\n> = TBlueprint extends DynamicCCValueBlueprint<infer TArgs> ? {\n\t\t(...args: TArgs): Omit<\n\t\t\tInferStaticCCValue<TCommandClass, ReturnType<TBlueprint>>,\n\t\t\t\"options\" | \"is\"\n\t\t>;\n\n\t\t/** Whether the given value ID matches this value definition */\n\t\tis: CCValuePredicate;\n\n\t\treadonly options: InferStaticCCValue<\n\t\t\tTCommandClass,\n\t\t\tReturnType<TBlueprint> & { options: TBlueprint[\"options\"] }\n\t\t>[\"options\"];\n\t}\n\t: never;\n\n/** A static or evaluated CC value definition, transparently inferred from its arguments */\nexport type InferStaticCCValue<\n\tTCommandClass extends CommandClasses,\n\tTBlueprint extends CCValueBlueprint,\n> = Readonly<AddCCValueProperties<TCommandClass, TBlueprint>>;\n\n/** The generic variant of {@link InferStaticCCValue}, without inferring arguments */\nexport interface StaticCCValue extends CCValue {\n\t/** Whether the given value ID matches this value definition */\n\tis: CCValuePredicate;\n\treadonly options: Required<CCValueOptions>;\n}\n\n/** The generic variant of {@link InferDynamicCCValue}, without inferring arguments */\nexport type DynamicCCValue<TArgs extends any[] = any[]> =\n\t& ExpandRecursivelySkipMeta<(...args: TArgs) => CCValue>\n\t& {\n\t\t/** Whether the given value ID matches this value definition */\n\t\tis: CCValuePredicate;\n\t\treadonly options: Required<CCValueOptions>;\n\t};\n\nexport type StaticCCValueFactory<T> = (self: T) => StaticCCValue;\n\n// This interface is auto-generated by maintenance/generateCCValuesInterface.ts\n// Do not edit it by hand or your changes will be lost\nexport interface CCValues {\n\t// AUTO GENERATION BELOW\n\t\"Alarm Sensor\": typeof import(\"../cc/AlarmSensorCC.js\").AlarmSensorCCValues;\n\tAssociation: typeof import(\"../cc/AssociationCC.js\").AssociationCCValues;\n\t\"Association Group Information\":\n\t\ttypeof import(\"../cc/AssociationGroupInfoCC.js\").AssociationGroupInfoCCValues;\n\t\"Barrier Operator\":\n\t\ttypeof import(\"../cc/BarrierOperatorCC.js\").BarrierOperatorCCValues;\n\tBasic: typeof import(\"../cc/BasicCC.js\").BasicCCValues;\n\tBattery: typeof import(\"../cc/BatteryCC.js\").BatteryCCValues;\n\t\"Binary Sensor\":\n\t\ttypeof import(\"../cc/BinarySensorCC.js\").BinarySensorCCValues;\n\t\"Binary Switch\":\n\t\ttypeof import(\"../cc/BinarySwitchCC.js\").BinarySwitchCCValues;\n\t\"Central Scene\":\n\t\ttypeof import(\"../cc/CentralSceneCC.js\").CentralSceneCCValues;\n\t\"Climate Control Schedule\":\n\t\ttypeof import(\"../cc/ClimateControlScheduleCC.js\").ClimateControlScheduleCCValues;\n\t\"Color Switch\": typeof import(\"../cc/ColorSwitchCC.js\").ColorSwitchCCValues;\n\tConfiguration:\n\t\ttypeof import(\"../cc/ConfigurationCC.js\").ConfigurationCCValues;\n\t\"Door Lock\": typeof import(\"../cc/DoorLockCC.js\").DoorLockCCValues;\n\t\"Door Lock Logging\":\n\t\ttypeof import(\"../cc/DoorLockLoggingCC.js\").DoorLockLoggingCCValues;\n\t\"Energy Production\":\n\t\ttypeof import(\"../cc/EnergyProductionCC.js\").EnergyProductionCCValues;\n\t\"Entry Control\":\n\t\ttypeof import(\"../cc/EntryControlCC.js\").EntryControlCCValues;\n\t\"Firmware Update Meta Data\":\n\t\ttypeof import(\"../cc/FirmwareUpdateMetaDataCC.js\").FirmwareUpdateMetaDataCCValues;\n\t\"Humidity Control Mode\":\n\t\ttypeof import(\"../cc/HumidityControlModeCC.js\").HumidityControlModeCCValues;\n\t\"Humidity Control Operating State\":\n\t\ttypeof import(\"../cc/HumidityControlOperatingStateCC.js\").HumidityControlOperatingStateCCValues;\n\t\"Humidity Control Setpoint\":\n\t\ttypeof import(\"../cc/HumidityControlSetpointCC.js\").HumidityControlSetpointCCValues;\n\tIndicator: typeof import(\"../cc/IndicatorCC.js\").IndicatorCCValues;\n\tIrrigation: typeof import(\"../cc/IrrigationCC.js\").IrrigationCCValues;\n\tLanguage: typeof import(\"../cc/LanguageCC.js\").LanguageCCValues;\n\tLock: typeof import(\"../cc/LockCC.js\").LockCCValues;\n\t\"Manufacturer Specific\":\n\t\ttypeof import(\"../cc/ManufacturerSpecificCC.js\").ManufacturerSpecificCCValues;\n\tMeter: typeof import(\"../cc/MeterCC.js\").MeterCCValues;\n\t\"Multi Channel Association\":\n\t\ttypeof import(\"../cc/MultiChannelAssociationCC.js\").MultiChannelAssociationCCValues;\n\t\"Multi Channel\":\n\t\ttypeof import(\"../cc/MultiChannelCC.js\").MultiChannelCCValues;\n\t\"Multilevel Sensor\":\n\t\ttypeof import(\"../cc/MultilevelSensorCC.js\").MultilevelSensorCCValues;\n\t\"Multilevel Switch\":\n\t\ttypeof import(\"../cc/MultilevelSwitchCC.js\").MultilevelSwitchCCValues;\n\t\"Node Naming and Location\":\n\t\ttypeof import(\"../cc/NodeNamingCC.js\").NodeNamingAndLocationCCValues;\n\tNotification: typeof import(\"../cc/NotificationCC.js\").NotificationCCValues;\n\tProtection: typeof import(\"../cc/ProtectionCC.js\").ProtectionCCValues;\n\t\"Scene Activation\":\n\t\ttypeof import(\"../cc/SceneActivationCC.js\").SceneActivationCCValues;\n\t\"Scene Actuator Configuration\":\n\t\ttypeof import(\"../cc/SceneActuatorConfigurationCC.js\").SceneActuatorConfigurationCCValues;\n\t\"Scene Controller Configuration\":\n\t\ttypeof import(\"../cc/SceneControllerConfigurationCC.js\").SceneControllerConfigurationCCValues;\n\t\"Schedule Entry Lock\":\n\t\ttypeof import(\"../cc/ScheduleEntryLockCC.js\").ScheduleEntryLockCCValues;\n\t\"Sound Switch\": typeof import(\"../cc/SoundSwitchCC.js\").SoundSwitchCCValues;\n\tSupervision: typeof import(\"../cc/SupervisionCC.js\").SupervisionCCValues;\n\t\"Thermostat Fan Mode\":\n\t\ttypeof import(\"../cc/ThermostatFanModeCC.js\").ThermostatFanModeCCValues;\n\t\"Thermostat Fan State\":\n\t\ttypeof import(\"../cc/ThermostatFanStateCC.js\").ThermostatFanStateCCValues;\n\t\"Thermostat Mode\":\n\t\ttypeof import(\"../cc/ThermostatModeCC.js\").ThermostatModeCCValues;\n\t\"Thermostat Operating State\":\n\t\ttypeof import(\"../cc/ThermostatOperatingStateCC.js\").ThermostatOperatingStateCCValues;\n\t\"Thermostat Setpoint\":\n\t\ttypeof import(\"../cc/ThermostatSetpointCC.js\").ThermostatSetpointCCValues;\n\t\"Time Parameters\":\n\t\ttypeof import(\"../cc/TimeParametersCC.js\").TimeParametersCCValues;\n\t\"User Code\": typeof import(\"../cc/UserCodeCC.js\").UserCodeCCValues;\n\tVersion: typeof import(\"../cc/VersionCC.js\").VersionCCValues;\n\t\"Wake Up\": typeof import(\"../cc/WakeUpCC.js\").WakeUpCCValues;\n\t\"Window Covering\":\n\t\ttypeof import(\"../cc/WindowCoveringCC.js\").WindowCoveringCCValues;\n\t\"Z-Wave Plus Info\": typeof import(\"../cc/ZWavePlusCC.js\").ZWavePlusCCValues;\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;;;;;;AAAA,kBAKO;AAEP,kBAIO;AA4CA,MAAM,wBAAwB;EACpC,UAAU;EACV,YAAY;EACZ,QAAQ;EACR,UAAU;EACV,mBAAmB;EACnB,YAAY;;AAkFb,SAAS,oBAIR,cACA,WAAqB;AAGrB,QAAM,aAAa;IAClB,GAAG;IACH,SAAS;MACR,GAAG;MACH,GAAG,UAAU;;;AAIf,QAAM,UAAU;IACf;IACA,UAAU,WAAW;IACrB,aAAa,WAAW;;AAEzB,MAAI,QAAQ,gBAAgB;AAAW,WAAO,QAAQ;AAEtD,QAAM,MAAqD;IAC1D,IAAI,KAAE;AACL,aAAO,EAAE,GAAG,QAAO;IACpB;IACA,UAAU,CAAC,WAAmB,MAAK;AAClC,UAAI,CAAC,WAAW,QAAQ;AAAmB,mBAAW;AACtD,aAAO,EAAE,GAAG,SAAS,SAAQ;IAC9B;IACA,IAAI,CAAC,gBAAe;AACnB,aACC,QAAQ,iBAAiB,YAAY,gBAClC,QAAQ,aAAa,YAAY,YACjC,QAAQ,gBAAgB,YAAY;IAEzC;IACA,IAAI,OAAI;AACP,aAAO,EAAE,GAAG,0BAAc,KAAK,GAAG,WAAW,KAAI;IAClD;IACA,IAAI,UAAO;AACV,aAAO,EAAE,GAAG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AAkB;AAQlB,WAAO;MACN,CAAC,QAAQ,GAAG;QACX;QACA;QACA;;;EAGH;;EAGA,uBAMC,MACA,UACA,MACA,SAAkB;AAQlB,WAAO;MACN,CAAC,IAAI,GAAG;QACP;QACA;QACA;;;EAGH;;EAGA,6BAOC,MACA,UACA,aACA,MACA,SAAkB;AASlB,WAAO;MACN,CAAC,IAAI,GAAG;QACP;QACA;QACA;QACA;;;EAGH;;EAGA,wBAMC,MACA,UACA,IACA,MACA,SAAkB;AAWlB,WAAO;MACN,CAAC,IAAI,GAAG,OAAO,OACd,IAAI,UAAqC;QACxC,cAAU,0BAAa,UAAU,GAAG,IAAI;QACxC,UAAM,0BAAa,MAAM,GAAG,IAAI;UAEjC,EAAE,IAAI,QAAO,CAAE;;EAGlB;;EAGA,8BAOC,MACA,UACA,aACA,IACA,MACA,SAAkB;AAYlB,WAAO;MACN,CAAC,IAAI,GAAG,OAAO,OACd,IAAI,SAAe;AAClB,eAAO;UACN,cAAU,0BAAa,UAAU,GAAG,IAAI;UACxC,iBAAa,0BAAa,aAAa,GAAG,IAAI;UAC9C,UAAM,0BAAa,MAAM,GAAG,IAAI;;MAElC,GACA,EAAE,IAAI,QAAO,CAAE;;EAGlB;;",
6
- "names": []
4
+ "sourcesContent": ["import {\n\ttype CommandClasses,\n\ttype EndpointId,\n\ttype ValueID,\n\tValueMetadata,\n} from \"@zwave-js/core/safe\";\nimport type { GetDeviceConfig, GetValueDB } from \"@zwave-js/host\";\nimport {\n\ttype FnOrStatic,\n\ttype ReturnTypeOrStatic,\n\tevalOrStatic,\n} from \"@zwave-js/shared/safe\";\nimport type { Overwrite } from \"alcalzone-shared/types\";\nimport type { ValueIDProperties } from \"./API.js\";\n\n// HINT: To fully view types for definitions created by this, open\n// node_modules/typescript/lib/tsserver.js and change the definition of\n// ts.defaultMaximumTruncationLength = 160\n// to something higher like\n// ts.defaultMaximumTruncationLength = 1000\n// Then restart TS Server\n\nexport interface CCValueOptions {\n\t/**\n\t * Whether the CC value is internal. Internal values are not exposed to the user.\n\t */\n\tinternal?: boolean;\n\t/**\n\t * The minimum CC version required for this value to exist.\n\t */\n\tminVersion?: number;\n\t/**\n\t * Whether this value represents a state (`true`) or a notification/event (`false`). Default: `true`\n\t */\n\tstateful?: boolean;\n\t/**\n\t * Omit this value from value logs. Default: `false`\n\t */\n\tsecret?: boolean;\n\n\t/** Whether the CC value may exist on endpoints. Default: `true` */\n\tsupportsEndpoints?: boolean;\n\n\t/**\n\t * Can be used to dynamically decide if this value should be created automatically.\n\t * This is ignored for dynamic values and defaults to `true` if not given.\n\t */\n\tautoCreate?:\n\t\t| boolean\n\t\t| ((\n\t\t\tctx: GetValueDB & GetDeviceConfig,\n\t\t\tendpoint: EndpointId,\n\t\t) => boolean);\n}\n\nexport const defaultCCValueOptions = {\n\tinternal: false,\n\tminVersion: 1,\n\tsecret: false,\n\tstateful: true,\n\tsupportsEndpoints: true,\n\tautoCreate: true,\n} as const;\n\ntype DefaultOptions = typeof defaultCCValueOptions;\n\n// expands object types recursively\nexport type ExpandRecursively<T> =\n\t// Split functions with properties into the function and object parts\n\tT extends (...args: infer A) => infer R\n\t\t? [keyof T] extends [never] ? (...args: A) => ExpandRecursively<R>\n\t\t:\n\t\t\t& ((...args: A) => ExpandRecursively<R>)\n\t\t\t& {\n\t\t\t\t[P in keyof T]: ExpandRecursively<T[P]>;\n\t\t\t}\n\t\t// Expand object types\n\t\t: T extends object\n\t\t\t? T extends infer O ? { [K in keyof O]: ExpandRecursively<O[K]> }\n\t\t\t: never\n\t\t// Fallback to the type itself if no match\n\t\t: T;\n\nexport type ExpandRecursivelySkipMeta<T> =\n\t// Split functions with properties into the function and object parts\n\tT extends (...args: infer A) => infer R\n\t\t? [keyof T] extends [never]\n\t\t\t? (...args: A) => ExpandRecursivelySkipMeta<R>\n\t\t:\n\t\t\t& ((...args: A) => ExpandRecursivelySkipMeta<R>)\n\t\t\t& {\n\t\t\t\t[P in keyof T]: ExpandRecursivelySkipMeta<T[P]>;\n\t\t\t}\n\t\t// Ignore the ValueMetadata type\n\t\t: T extends ValueMetadata ? T\n\t\t// Expand object types\n\t\t: T extends object\n\t\t\t? T extends infer O\n\t\t\t\t? { [K in keyof O]: ExpandRecursivelySkipMeta<O[K]> }\n\t\t\t: never\n\t\t// Fallback to the type itself if no match\n\t\t: T;\n\ntype InferValueIDBase<\n\tTCommandClass extends CommandClasses,\n\tTBlueprint extends CCValueBlueprint,\n\tTWorker = {\n\t\tcommandClass: TCommandClass;\n\t} & Pick<TBlueprint, \"property\" | \"propertyKey\">,\n> = {\n\t[K in keyof TWorker as unknown extends TWorker[K] ? never : K]: TWorker[K];\n};\n\ntype ToStaticCCValues<\n\tTCommandClass extends CommandClasses,\n\tTValues extends Record<keyof TValues, CCValueBlueprint>,\n> = Readonly<\n\t{\n\t\t[K in keyof TValues]: ExpandRecursively<\n\t\t\tInferStaticCCValue<TCommandClass, TValues[K]>\n\t\t>;\n\t}\n>;\n\ntype ToDynamicCCValues<\n\tTCommandClass extends CommandClasses,\n\tTValues extends Record<keyof TValues, DynamicCCValueBlueprint<any>>,\n> = Readonly<\n\t{\n\t\t[K in keyof TValues]: ExpandRecursively<\n\t\t\tInferDynamicCCValue<TCommandClass, TValues[K]>\n\t\t>;\n\t}\n>;\n\ntype InferArgs<T extends FnOrStatic<any, any>[]> = T extends [\n\t(...args: infer A) => any,\n\t...any,\n] ? A\n\t: T extends [any, ...infer R] ? InferArgs<R>\n\t: [];\n\n/** Defines a single static CC values that belong to a CC */\nfunction defineStaticCCValue<\n\tTCommandClass extends CommandClasses,\n\tTBlueprint extends CCValueBlueprint,\n>(\n\tcommandClass: TCommandClass,\n\tblueprint: TBlueprint,\n): ExpandRecursively<InferStaticCCValue<TCommandClass, TBlueprint>> {\n\t// Normalize value options\n\tconst _blueprint = {\n\t\t...blueprint,\n\t\toptions: {\n\t\t\t...defaultCCValueOptions,\n\t\t\t...blueprint.options,\n\t\t},\n\t};\n\n\tconst valueId = {\n\t\tcommandClass,\n\t\tproperty: _blueprint.property,\n\t\tpropertyKey: _blueprint.propertyKey,\n\t};\n\tif (valueId.propertyKey === undefined) delete valueId.propertyKey;\n\n\tconst ret: InferStaticCCValue<TCommandClass, TBlueprint> = {\n\t\tget id() {\n\t\t\treturn { ...valueId };\n\t\t},\n\t\tendpoint: (endpoint: number = 0) => {\n\t\t\tif (!_blueprint.options.supportsEndpoints) endpoint = 0;\n\t\t\treturn { ...valueId, endpoint } as any;\n\t\t},\n\t\tis: (testValueId) => {\n\t\t\treturn (\n\t\t\t\tvalueId.commandClass === testValueId.commandClass\n\t\t\t\t&& valueId.property === testValueId.property\n\t\t\t\t&& valueId.propertyKey === testValueId.propertyKey\n\t\t\t);\n\t\t},\n\t\tget meta() {\n\t\t\treturn { ...ValueMetadata.Any, ..._blueprint.meta } as any;\n\t\t},\n\t\tget options() {\n\t\t\treturn { ..._blueprint.options } as any;\n\t\t},\n\t};\n\n\treturn ret as any;\n}\n\n/** Defines a single CC value which depends on one or more parameters */\nfunction defineDynamicCCValue<\n\tTCommandClass extends CommandClasses,\n\tTBlueprint extends DynamicCCValueBlueprint<any[]>,\n>(\n\tcommandClass: TCommandClass,\n\tblueprint: TBlueprint,\n): ExpandRecursively<InferDynamicCCValue<TCommandClass, TBlueprint>> {\n\tconst options = {\n\t\t...defaultCCValueOptions,\n\t\t...blueprint.options,\n\t};\n\n\tconst ret: ExpandRecursively<\n\t\tInferDynamicCCValue<TCommandClass, TBlueprint>\n\t> = ((...args: Parameters<TBlueprint>) => {\n\t\tconst _blueprint = blueprint(...args);\n\n\t\t// Normalize value options\n\t\tconst actualBlueprint = {\n\t\t\t..._blueprint,\n\t\t};\n\n\t\tconst valueId = {\n\t\t\tcommandClass,\n\t\t\tproperty: actualBlueprint.property,\n\t\t\tpropertyKey: actualBlueprint.propertyKey,\n\t\t};\n\t\tif (valueId.propertyKey === undefined) delete valueId.propertyKey;\n\n\t\tconst value: Omit<\n\t\t\tInferStaticCCValue<TCommandClass, ReturnType<TBlueprint>>,\n\t\t\t\"options\" | \"is\"\n\t\t> = {\n\t\t\tget id() {\n\t\t\t\treturn { ...valueId };\n\t\t\t},\n\t\t\tendpoint: (endpoint: number = 0) => {\n\t\t\t\tif (!options.supportsEndpoints) endpoint = 0;\n\t\t\t\treturn { ...valueId, endpoint } as any;\n\t\t\t},\n\t\t\tget meta() {\n\t\t\t\treturn { ...ValueMetadata.Any, ...actualBlueprint.meta } as any;\n\t\t\t},\n\t\t};\n\n\t\treturn value;\n\t}) as any;\n\n\tObject.defineProperty(ret, \"options\", {\n\t\tconfigurable: false,\n\t\tenumerable: true,\n\t\tget() {\n\t\t\treturn { ...options };\n\t\t},\n\t});\n\n\tObject.defineProperty(ret, \"is\", {\n\t\tconfigurable: false,\n\t\tenumerable: false,\n\t\twritable: false,\n\t\tvalue: (id: ValueID) =>\n\t\t\tid.commandClass === commandClass && blueprint.is(id),\n\t});\n\n\treturn ret;\n}\n\n// Namespace for utilities to define CC values\nexport const V = {\n\t/** Defines multiple static CC values that belong to the same CC */\n\tdefineStaticCCValues<\n\t\tTCommandClass extends CommandClasses,\n\t\tTValues extends Record<keyof TValues, CCValueBlueprint>,\n\t>(\n\t\tcommandClass: TCommandClass,\n\t\tvalues: TValues,\n\t): TValues extends Record<keyof TValues, CCValueBlueprint>\n\t\t? ExpandRecursively<ToStaticCCValues<TCommandClass, TValues>>\n\t\t: never\n\t{\n\t\treturn Object.fromEntries(\n\t\t\tObject.entries<CCValueBlueprint>(values).map(([key, blueprint]) => [\n\t\t\t\tkey,\n\t\t\t\tdefineStaticCCValue(commandClass, blueprint),\n\t\t\t]),\n\t\t) as any;\n\t},\n\n\t/** Defines multiple static CC values that belong to the same CC */\n\tdefineDynamicCCValues<\n\t\tTCommandClass extends CommandClasses,\n\t\tTValues extends Record<keyof TValues, DynamicCCValueBlueprint<any>>,\n\t>(\n\t\tcommandClass: TCommandClass,\n\t\tvalues: TValues,\n\t): TValues extends Record<keyof TValues, DynamicCCValueBlueprint<any>>\n\t\t? ExpandRecursively<ToDynamicCCValues<TCommandClass, TValues>>\n\t\t: never\n\t{\n\t\treturn Object.fromEntries(\n\t\t\tObject.entries<DynamicCCValueBlueprint<any>>(values).map(\n\t\t\t\t([key, blueprint]) => [\n\t\t\t\t\tkey,\n\t\t\t\t\tdefineDynamicCCValue(commandClass, blueprint),\n\t\t\t\t],\n\t\t\t),\n\t\t) as any;\n\t},\n\n\t/** Returns a CC value definition that is named like the value `property` */\n\tstaticProperty<\n\t\tTProp extends string | number,\n\t\tTMeta extends ValueMetadata,\n\t\tTOptions extends CCValueOptions,\n\t>(\n\t\tproperty: TProp,\n\t\tmeta?: TMeta,\n\t\toptions?: TOptions,\n\t): {\n\t\t[K in TProp]: {\n\t\t\tproperty: TProp;\n\t\t\tmeta: TMeta;\n\t\t\toptions: TOptions;\n\t\t};\n\t} {\n\t\treturn {\n\t\t\t[property]: {\n\t\t\t\tproperty,\n\t\t\t\tmeta,\n\t\t\t\toptions,\n\t\t\t},\n\t\t} as any;\n\t},\n\n\t/** Returns a CC value definition with the given name and `property` */\n\tstaticPropertyWithName<\n\t\tTName extends string,\n\t\tTProp extends string | number,\n\t\tTMeta extends ValueMetadata,\n\t\tTOptions extends CCValueOptions,\n\t>(\n\t\tname: TName,\n\t\tproperty: TProp,\n\t\tmeta?: TMeta,\n\t\toptions?: TOptions,\n\t): {\n\t\t[K in TName]: {\n\t\t\tproperty: TProp;\n\t\t\tmeta: TMeta;\n\t\t\toptions: TOptions;\n\t\t};\n\t} {\n\t\treturn {\n\t\t\t[name]: {\n\t\t\t\tproperty,\n\t\t\t\tmeta,\n\t\t\t\toptions,\n\t\t\t},\n\t\t} as any;\n\t},\n\n\t/** Returns a CC value definition with the given name, `property` and `propertyKey` */\n\tstaticPropertyAndKeyWithName<\n\t\tTName extends string,\n\t\tTProp extends string | number,\n\t\tTKey extends string | number,\n\t\tTMeta extends ValueMetadata,\n\t\tTOptions extends CCValueOptions,\n\t>(\n\t\tname: TName,\n\t\tproperty: TProp,\n\t\tpropertyKey: TKey,\n\t\tmeta?: TMeta,\n\t\toptions?: TOptions,\n\t): {\n\t\t[K in TName]: {\n\t\t\tproperty: TProp;\n\t\t\tpropertyKey: TKey;\n\t\t\tmeta: TMeta;\n\t\t\toptions: TOptions;\n\t\t};\n\t} {\n\t\treturn {\n\t\t\t[name]: {\n\t\t\t\tproperty,\n\t\t\t\tpropertyKey,\n\t\t\t\tmeta,\n\t\t\t\toptions,\n\t\t\t},\n\t\t} as any;\n\t},\n\n\t/** Returns a CC value definition with the given name and a dynamic `property` */\n\tdynamicPropertyWithName<\n\t\tTName extends string,\n\t\tTProp extends FnOrStatic<any[], ValueIDProperties[\"property\"]>,\n\t\tTMeta extends FnOrStatic<any[], ValueMetadata> = ValueMetadata,\n\t\tTOptions extends CCValueOptions = CCValueOptions,\n\t>(\n\t\tname: TName,\n\t\tproperty: TProp,\n\t\tis: PartialCCValuePredicate,\n\t\tmeta?: TMeta,\n\t\toptions?: TOptions,\n\t): {\n\t\t[K in TName]: {\n\t\t\t(...args: InferArgs<[TProp, TMeta]>): {\n\t\t\t\tproperty: ReturnTypeOrStatic<TProp>;\n\t\t\t\tmeta: ReturnTypeOrStatic<TMeta>;\n\t\t\t};\n\t\t\tis: PartialCCValuePredicate;\n\t\t\toptions: TOptions;\n\t\t};\n\t} {\n\t\treturn {\n\t\t\t[name]: Object.assign(\n\t\t\t\t(...args: InferArgs<[TProp, TMeta]>) => ({\n\t\t\t\t\tproperty: evalOrStatic(property, ...args),\n\t\t\t\t\tmeta: evalOrStatic(meta, ...args),\n\t\t\t\t}),\n\t\t\t\t{ is, options },\n\t\t\t),\n\t\t} as any;\n\t},\n\n\t/** Returns a CC value definition with the given name and a dynamic `property` */\n\tdynamicPropertyAndKeyWithName<\n\t\tTName extends string,\n\t\tTProp extends FnOrStatic<any[], ValueIDProperties[\"property\"]>,\n\t\tTKey extends FnOrStatic<any[], ValueIDProperties[\"propertyKey\"]>,\n\t\tTMeta extends FnOrStatic<any[], ValueMetadata> = ValueMetadata,\n\t\tTOptions extends FnOrStatic<any[], CCValueOptions> = CCValueOptions,\n\t>(\n\t\tname: TName,\n\t\tproperty: TProp,\n\t\tpropertyKey: TKey,\n\t\tis: PartialCCValuePredicate,\n\t\tmeta?: TMeta,\n\t\toptions?: TOptions,\n\t): {\n\t\t[K in TName]: {\n\t\t\t(...args: InferArgs<[TProp, TKey, TMeta]>): {\n\t\t\t\tproperty: ReturnTypeOrStatic<TProp>;\n\t\t\t\tpropertyKey: ReturnTypeOrStatic<TKey>;\n\t\t\t\tmeta: ReturnTypeOrStatic<TMeta>;\n\t\t\t};\n\t\t\tis: PartialCCValuePredicate;\n\t\t\toptions: TOptions;\n\t\t};\n\t} {\n\t\treturn {\n\t\t\t[name]: Object.assign(\n\t\t\t\t(...args: any[]) => {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tproperty: evalOrStatic(property, ...args),\n\t\t\t\t\t\tpropertyKey: evalOrStatic(propertyKey, ...args),\n\t\t\t\t\t\tmeta: evalOrStatic(meta, ...args),\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t\t\t{ is, options },\n\t\t\t),\n\t\t} as any;\n\t},\n};\n\nexport interface CCValueBlueprint extends Readonly<ValueIDProperties> {\n\treadonly meta?: Readonly<ValueMetadata>;\n\treadonly options?: Readonly<CCValueOptions>;\n}\n\nexport type CCValuePredicate = (valueId: ValueID) => boolean;\nexport type PartialCCValuePredicate = (\n\tproperties: ValueIDProperties,\n) => boolean;\n\n/** A blueprint for a CC value which depends on one or more parameters */\nexport interface DynamicCCValueBlueprint<TArgs extends any[]> {\n\t(...args: TArgs): Omit<CCValueBlueprint, \"options\">;\n\tis: PartialCCValuePredicate;\n\treadonly options?: Readonly<CCValueOptions>;\n}\n\ntype DropOptional<T> = {\n\t[K in keyof T as [undefined] extends [T[K]] ? never : K]: T[K];\n};\n\ntype MergeOptions<TOptions extends CCValueOptions> = DropOptional<\n\tCCValueOptions extends TOptions\n\t\t// When the type cannot be inferred exactly (not given), default to DefaultOptions\n\t\t? DefaultOptions\n\t\t: Overwrite<DefaultOptions, TOptions>\n>;\n\ntype MergeMeta<TMeta extends ValueMetadata> = DropOptional<\n\tValueMetadata extends TMeta\n\t\t// When the type cannot be inferred exactly (not given), default to ValueMetadata.Any\n\t\t? (typeof ValueMetadata)[\"Any\"]\n\t\t: Overwrite<(typeof ValueMetadata)[\"Any\"], TMeta>\n>;\n\n/** The common base type of all CC value definitions */\nexport interface CCValue {\n\treadonly id: Omit<ValueID, \"endpoint\">;\n\tendpoint(endpoint?: number): ValueID;\n\treadonly meta: ValueMetadata;\n}\n\ntype AddCCValueProperties<\n\tTCommandClass extends CommandClasses,\n\tTBlueprint extends CCValueBlueprint,\n\tValueIDBase extends Record<string, any> = InferValueIDBase<\n\t\tTCommandClass,\n\t\tTBlueprint\n\t>,\n> = {\n\t/** Returns the value ID of this CC value, without endpoint information */\n\tget id(): ValueIDBase;\n\n\t/** Returns the value ID, specialized to the given endpoint */\n\tendpoint(\n\t\tendpoint?: number,\n\t): Readonly<\n\t\t& Pick<ValueIDBase, \"commandClass\">\n\t\t& { endpoint: number }\n\t\t& Omit<\n\t\t\tValueIDBase,\n\t\t\t\"commandClass\"\n\t\t>\n\t>;\n\n\t/** Whether the given value ID matches this value definition */\n\tis: CCValuePredicate;\n\n\t/** Returns the metadata for this value ID */\n\tget meta(): Readonly<MergeMeta<NonNullable<TBlueprint[\"meta\"]>>>;\n\t/** Returns the value options for this value ID */\n\tget options(): Readonly<MergeOptions<NonNullable<TBlueprint[\"options\"]>>>;\n};\n\n/** A CC value definition which depends on one or more parameters, transparently inferred from its arguments */\nexport type InferDynamicCCValue<\n\tTCommandClass extends CommandClasses,\n\tTBlueprint extends DynamicCCValueBlueprint<any[]>,\n> = TBlueprint extends DynamicCCValueBlueprint<infer TArgs> ? {\n\t\t(...args: TArgs): Omit<\n\t\t\tInferStaticCCValue<TCommandClass, ReturnType<TBlueprint>>,\n\t\t\t\"options\" | \"is\"\n\t\t>;\n\n\t\t/** Whether the given value ID matches this value definition */\n\t\tis: CCValuePredicate;\n\n\t\treadonly options: InferStaticCCValue<\n\t\t\tTCommandClass,\n\t\t\tReturnType<TBlueprint> & { options: TBlueprint[\"options\"] }\n\t\t>[\"options\"];\n\t}\n\t: never;\n\n/** A static or evaluated CC value definition, transparently inferred from its arguments */\nexport type InferStaticCCValue<\n\tTCommandClass extends CommandClasses,\n\tTBlueprint extends CCValueBlueprint,\n> = Readonly<AddCCValueProperties<TCommandClass, TBlueprint>>;\n\n/** The generic variant of {@link InferStaticCCValue}, without inferring arguments */\nexport interface StaticCCValue extends CCValue {\n\t/** Whether the given value ID matches this value definition */\n\tis: CCValuePredicate;\n\treadonly options: Required<CCValueOptions>;\n}\n\n/** The generic variant of {@link InferDynamicCCValue}, without inferring arguments */\nexport type DynamicCCValue<TArgs extends any[] = any[]> =\n\t& ExpandRecursivelySkipMeta<(...args: TArgs) => CCValue>\n\t& {\n\t\t/** Whether the given value ID matches this value definition */\n\t\tis: CCValuePredicate;\n\t\treadonly options: Required<CCValueOptions>;\n\t};\n\nexport type StaticCCValueFactory<T> = (self: T) => StaticCCValue;\n\n// This interface is auto-generated by maintenance/generateCCValuesInterface.ts\n// Do not edit it by hand or your changes will be lost\nexport interface CCValues {\n\t// AUTO GENERATION BELOW\n\t\"Alarm Sensor\": typeof import(\"../cc/AlarmSensorCC.js\").AlarmSensorCCValues;\n\tAssociation: typeof import(\"../cc/AssociationCC.js\").AssociationCCValues;\n\t\"Association Group Information\":\n\t\ttypeof import(\"../cc/AssociationGroupInfoCC.js\").AssociationGroupInfoCCValues;\n\t\"Barrier Operator\":\n\t\ttypeof import(\"../cc/BarrierOperatorCC.js\").BarrierOperatorCCValues;\n\tBasic: typeof import(\"../cc/BasicCC.js\").BasicCCValues;\n\tBattery: typeof import(\"../cc/BatteryCC.js\").BatteryCCValues;\n\t\"Binary Sensor\":\n\t\ttypeof import(\"../cc/BinarySensorCC.js\").BinarySensorCCValues;\n\t\"Binary Switch\":\n\t\ttypeof import(\"../cc/BinarySwitchCC.js\").BinarySwitchCCValues;\n\t\"Central Scene\":\n\t\ttypeof import(\"../cc/CentralSceneCC.js\").CentralSceneCCValues;\n\t\"Climate Control Schedule\":\n\t\ttypeof import(\"../cc/ClimateControlScheduleCC.js\").ClimateControlScheduleCCValues;\n\t\"Color Switch\": typeof import(\"../cc/ColorSwitchCC.js\").ColorSwitchCCValues;\n\tConfiguration:\n\t\ttypeof import(\"../cc/ConfigurationCC.js\").ConfigurationCCValues;\n\t\"Door Lock\": typeof import(\"../cc/DoorLockCC.js\").DoorLockCCValues;\n\t\"Door Lock Logging\":\n\t\ttypeof import(\"../cc/DoorLockLoggingCC.js\").DoorLockLoggingCCValues;\n\t\"Energy Production\":\n\t\ttypeof import(\"../cc/EnergyProductionCC.js\").EnergyProductionCCValues;\n\t\"Entry Control\":\n\t\ttypeof import(\"../cc/EntryControlCC.js\").EntryControlCCValues;\n\t\"Firmware Update Meta Data\":\n\t\ttypeof import(\"../cc/FirmwareUpdateMetaDataCC.js\").FirmwareUpdateMetaDataCCValues;\n\t\"Humidity Control Mode\":\n\t\ttypeof import(\"../cc/HumidityControlModeCC.js\").HumidityControlModeCCValues;\n\t\"Humidity Control Operating State\":\n\t\ttypeof import(\"../cc/HumidityControlOperatingStateCC.js\").HumidityControlOperatingStateCCValues;\n\t\"Humidity Control Setpoint\":\n\t\ttypeof import(\"../cc/HumidityControlSetpointCC.js\").HumidityControlSetpointCCValues;\n\tIndicator: typeof import(\"../cc/IndicatorCC.js\").IndicatorCCValues;\n\tIrrigation: typeof import(\"../cc/IrrigationCC.js\").IrrigationCCValues;\n\tLanguage: typeof import(\"../cc/LanguageCC.js\").LanguageCCValues;\n\tLock: typeof import(\"../cc/LockCC.js\").LockCCValues;\n\t\"Manufacturer Specific\":\n\t\ttypeof import(\"../cc/ManufacturerSpecificCC.js\").ManufacturerSpecificCCValues;\n\tMeter: typeof import(\"../cc/MeterCC.js\").MeterCCValues;\n\t\"Multi Channel Association\":\n\t\ttypeof import(\"../cc/MultiChannelAssociationCC.js\").MultiChannelAssociationCCValues;\n\t\"Multi Channel\":\n\t\ttypeof import(\"../cc/MultiChannelCC.js\").MultiChannelCCValues;\n\t\"Multilevel Sensor\":\n\t\ttypeof import(\"../cc/MultilevelSensorCC.js\").MultilevelSensorCCValues;\n\t\"Multilevel Switch\":\n\t\ttypeof import(\"../cc/MultilevelSwitchCC.js\").MultilevelSwitchCCValues;\n\t\"Node Naming and Location\":\n\t\ttypeof import(\"../cc/NodeNamingCC.js\").NodeNamingAndLocationCCValues;\n\tNotification: typeof import(\"../cc/NotificationCC.js\").NotificationCCValues;\n\tProtection: typeof import(\"../cc/ProtectionCC.js\").ProtectionCCValues;\n\t\"Scene Activation\":\n\t\ttypeof import(\"../cc/SceneActivationCC.js\").SceneActivationCCValues;\n\t\"Scene Actuator Configuration\":\n\t\ttypeof import(\"../cc/SceneActuatorConfigurationCC.js\").SceneActuatorConfigurationCCValues;\n\t\"Scene Controller Configuration\":\n\t\ttypeof import(\"../cc/SceneControllerConfigurationCC.js\").SceneControllerConfigurationCCValues;\n\t\"Schedule Entry Lock\":\n\t\ttypeof import(\"../cc/ScheduleEntryLockCC.js\").ScheduleEntryLockCCValues;\n\t\"Sound Switch\": typeof import(\"../cc/SoundSwitchCC.js\").SoundSwitchCCValues;\n\tSupervision: typeof import(\"../cc/SupervisionCC.js\").SupervisionCCValues;\n\t\"Thermostat Fan Mode\":\n\t\ttypeof import(\"../cc/ThermostatFanModeCC.js\").ThermostatFanModeCCValues;\n\t\"Thermostat Fan State\":\n\t\ttypeof import(\"../cc/ThermostatFanStateCC.js\").ThermostatFanStateCCValues;\n\t\"Thermostat Mode\":\n\t\ttypeof import(\"../cc/ThermostatModeCC.js\").ThermostatModeCCValues;\n\t\"Thermostat Operating State\":\n\t\ttypeof import(\"../cc/ThermostatOperatingStateCC.js\").ThermostatOperatingStateCCValues;\n\t\"Thermostat Setpoint\":\n\t\ttypeof import(\"../cc/ThermostatSetpointCC.js\").ThermostatSetpointCCValues;\n\t\"Time Parameters\":\n\t\ttypeof import(\"../cc/TimeParametersCC.js\").TimeParametersCCValues;\n\t\"User Code\": typeof import(\"../cc/UserCodeCC.js\").UserCodeCCValues;\n\tVersion: typeof import(\"../cc/VersionCC.js\").VersionCCValues;\n\t\"Wake Up\": typeof import(\"../cc/WakeUpCC.js\").WakeUpCCValues;\n\t\"Window Covering\":\n\t\ttypeof import(\"../cc/WindowCoveringCC.js\").WindowCoveringCCValues;\n\t\"Z-Wave Plus Info\": typeof import(\"../cc/ZWavePlusCC.js\").ZWavePlusCCValues;\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;;;;;;AAAA,kBAKO;AAEP,IAAAA,eAIO;AA4CA,MAAM,wBAAwB;EACpC,UAAU;EACV,YAAY;EACZ,QAAQ;EACR,UAAU;EACV,mBAAmB;EACnB,YAAY;;AAkFb,SAAS,oBAIR,cACA,WAAqB;AAGrB,QAAM,aAAa;IAClB,GAAG;IACH,SAAS;MACR,GAAG;MACH,GAAG,UAAU;;;AAIf,QAAM,UAAU;IACf;IACA,UAAU,WAAW;IACrB,aAAa,WAAW;;AAEzB,MAAI,QAAQ,gBAAgB;AAAW,WAAO,QAAQ;AAEtD,QAAM,MAAqD;IAC1D,IAAI,KAAE;AACL,aAAO,EAAE,GAAG,QAAO;IACpB;IACA,UAAU,CAAC,WAAmB,MAAK;AAClC,UAAI,CAAC,WAAW,QAAQ;AAAmB,mBAAW;AACtD,aAAO,EAAE,GAAG,SAAS,SAAQ;IAC9B;IACA,IAAI,CAAC,gBAAe;AACnB,aACC,QAAQ,iBAAiB,YAAY,gBAClC,QAAQ,aAAa,YAAY,YACjC,QAAQ,gBAAgB,YAAY;IAEzC;IACA,IAAI,OAAI;AACP,aAAO,EAAE,GAAG,0BAAc,KAAK,GAAG,WAAW,KAAI;IAClD;IACA,IAAI,UAAO;AACV,aAAO,EAAE,GAAG,WAAW,QAAO;IAC/B;;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N,CAAC,QAAQ,GAAG;QACX;QACA;QACA;;;EAGH;;EAGA,uBAMC,MACA,UACA,MACA,SAAkB;AAQlB,WAAO;MACN,CAAC,IAAI,GAAG;QACP;QACA;QACA;;;EAGH;;EAGA,6BAOC,MACA,UACA,aACA,MACA,SAAkB;AASlB,WAAO;MACN,CAAC,IAAI,GAAG;QACP;QACA;QACA;QACA;;;EAGH;;EAGA,wBAMC,MACA,UACA,IACA,MACA,SAAkB;AAWlB,WAAO;MACN,CAAC,IAAI,GAAG,OAAO,OACd,IAAI,UAAqC;QACxC,cAAU,2BAAa,UAAU,GAAG,IAAI;QACxC,UAAM,2BAAa,MAAM,GAAG,IAAI;UAEjC,EAAE,IAAI,QAAO,CAAE;;EAGlB;;EAGA,8BAOC,MACA,UACA,aACA,IACA,MACA,SAAkB;AAYlB,WAAO;MACN,CAAC,IAAI,GAAG,OAAO,OACd,IAAI,SAAe;AAClB,eAAO;UACN,cAAU,2BAAa,UAAU,GAAG,IAAI;UACxC,iBAAa,2BAAa,aAAa,GAAG,IAAI;UAC9C,UAAM,2BAAa,MAAM,GAAG,IAAI;;MAElC,GACA,EAAE,IAAI,QAAO,CAAE;;EAGlB;;",
6
+ "names": ["import_safe"]
7
7
  }
@@ -5,12 +5,12 @@ export declare const setbackSpecialStateValues: Record<SetbackSpecialState, numb
5
5
  * @publicAPI
6
6
  * Encodes a setback state to use in a ThermostatSetbackCC
7
7
  */
8
- export declare function encodeSetbackState(state: SetbackState): number;
8
+ export declare function encodeSetbackState(state: SetbackState): Bytes;
9
9
  /**
10
10
  * @publicAPI
11
11
  * Decodes a setback state used in a ThermostatSetbackCC
12
12
  */
13
- export declare function decodeSetbackState(val: number): SetbackState | undefined;
13
+ export declare function decodeSetbackState(data: Uint8Array, offset?: number): SetbackState | undefined;
14
14
  /**
15
15
  * @publicAPI
16
16
  * Decodes a switch point used in a ClimateControlScheduleCC
@@ -29,19 +29,26 @@ __export(serializers_exports, {
29
29
  module.exports = __toCommonJS(serializers_exports);
30
30
  var import_core = require("@zwave-js/core");
31
31
  var import_safe = require("@zwave-js/shared/safe");
32
- var import_math = require("alcalzone-shared/math/index.js");
32
+ var import_math = require("alcalzone-shared/math");
33
33
  const setbackSpecialStateValues = {
34
34
  "Frost Protection": 121,
35
35
  "Energy Saving": 122,
36
36
  Unused: 127
37
37
  };
38
38
  function encodeSetbackState(state) {
39
- if (typeof state === "string")
40
- return setbackSpecialStateValues[state];
41
- state = (0, import_math.clamp)(state, -12.8, 12);
42
- return Math.round(state * 10);
39
+ let rawValue;
40
+ if (typeof state === "string") {
41
+ rawValue = setbackSpecialStateValues[state];
42
+ } else {
43
+ state = (0, import_math.clamp)(state, -12.8, 12);
44
+ rawValue = Math.round(state * 10);
45
+ }
46
+ const ret = new import_safe.Bytes(1);
47
+ ret.writeInt8(rawValue);
48
+ return ret;
43
49
  }
44
- function decodeSetbackState(val) {
50
+ function decodeSetbackState(data, offset = 0) {
51
+ const val = import_safe.Bytes.view(data).readInt8(offset);
45
52
  if (val > 120) {
46
53
  const foundEntry = Object.entries(setbackSpecialStateValues).find(([, v]) => val === v);
47
54
  if (!foundEntry)
@@ -55,16 +62,18 @@ function decodeSwitchpoint(data) {
55
62
  return {
56
63
  hour: data[0] & 31,
57
64
  minute: data[1] & 63,
58
- state: decodeSetbackState(data[2])
65
+ state: decodeSetbackState(data, 2)
59
66
  };
60
67
  }
61
68
  function encodeSwitchpoint(point) {
62
69
  if (point.state == void 0) {
63
70
  throw new import_core.ZWaveError("The given Switchpoint is not valid!", import_core.ZWaveErrorCodes.CC_Invalid);
64
71
  }
65
- return import_safe.Bytes.from([
66
- point.hour & 31,
67
- point.minute & 63,
72
+ return import_safe.Bytes.concat([
73
+ [
74
+ point.hour & 31,
75
+ point.minute & 63
76
+ ],
68
77
  encodeSetbackState(point.state)
69
78
  ]);
70
79
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/lib/serializers.ts"],
4
- "sourcesContent": ["import { ZWaveError, ZWaveErrorCodes } from \"@zwave-js/core\";\nimport { Bytes } from \"@zwave-js/shared/safe\";\nimport { clamp } from \"alcalzone-shared/math/index.js\";\nimport type {\n\tSetbackSpecialState,\n\tSetbackState,\n\tSwitchpoint,\n\tTimezone,\n} from \"./_Types.js\";\n\nexport const setbackSpecialStateValues: Record<SetbackSpecialState, number> = {\n\t\"Frost Protection\": 0x79,\n\t\"Energy Saving\": 0x7a,\n\tUnused: 0x7f,\n};\n\n/**\n * @publicAPI\n * Encodes a setback state to use in a ThermostatSetbackCC\n */\nexport function encodeSetbackState(state: SetbackState): number {\n\tif (typeof state === \"string\") return setbackSpecialStateValues[state];\n\tstate = clamp(state, -12.8, 12);\n\treturn Math.round(state * 10);\n}\n\n/**\n * @publicAPI\n * Decodes a setback state used in a ThermostatSetbackCC\n */\nexport function decodeSetbackState(val: number): SetbackState | undefined {\n\tif (val > 120) {\n\t\t// Special state, try to look it up\n\t\tconst foundEntry = Object.entries(setbackSpecialStateValues).find(\n\t\t\t([, v]) => val === v,\n\t\t);\n\t\tif (!foundEntry) return;\n\t\treturn foundEntry[0] as SetbackSpecialState;\n\t} else {\n\t\treturn val / 10;\n\t}\n}\n\n/**\n * @publicAPI\n * Decodes a switch point used in a ClimateControlScheduleCC\n */\nexport function decodeSwitchpoint(data: Uint8Array): Switchpoint {\n\treturn {\n\t\thour: data[0] & 0b000_11111,\n\t\tminute: data[1] & 0b00_111111,\n\t\tstate: decodeSetbackState(data[2]),\n\t};\n}\n\n/**\n * @publicAPI\n * Encodes a switch point to use in a ClimateControlScheduleCC\n */\nexport function encodeSwitchpoint(point: Switchpoint): Bytes {\n\tif (point.state == undefined) {\n\t\tthrow new ZWaveError(\n\t\t\t\"The given Switchpoint is not valid!\",\n\t\t\tZWaveErrorCodes.CC_Invalid,\n\t\t);\n\t}\n\treturn Bytes.from([\n\t\tpoint.hour & 0b000_11111,\n\t\tpoint.minute & 0b00_111111,\n\t\tencodeSetbackState(point.state),\n\t]);\n}\n\n/**\n * @publicAPI\n * Decodes timezone information used in time related CCs\n */\nexport function parseTimezone(data: Uint8Array): Timezone {\n\tconst hourSign = !!(data[0] & 0b1000_0000);\n\tconst hour = data[0] & 0b0111_1111;\n\tconst minute = data[1];\n\tconst standardOffset = (hourSign ? -1 : 1) * (hour * 60 + minute);\n\tconst deltaSign = !!(data[2] & 0b1000_0000);\n\tconst deltaMinutes = data[2] & 0b0111_1111;\n\tconst dstOffset = standardOffset + (deltaSign ? -1 : 1) * deltaMinutes;\n\n\treturn {\n\t\tstandardOffset,\n\t\tdstOffset,\n\t};\n}\n\n/**\n * @publicAPI\n * Decodes timezone information used in time related CCs\n */\nexport function encodeTimezone(tz: Timezone): Bytes {\n\tif (\n\t\tMath.abs(tz.standardOffset) >= 24 * 60\n\t\t|| Math.abs(tz.dstOffset) >= 24 * 60\n\t) {\n\t\tthrow new ZWaveError(\n\t\t\t\"The given timezone is not valid!\",\n\t\t\tZWaveErrorCodes.CC_Invalid,\n\t\t);\n\t}\n\tconst minutes = Math.abs(tz.standardOffset) % 60;\n\tconst hour = Math.floor(Math.abs(tz.standardOffset) / 60);\n\tconst hourSign = tz.standardOffset < 0 ? 1 : 0;\n\n\tconst delta = tz.dstOffset - tz.standardOffset;\n\tconst deltaMinutes = Math.abs(delta);\n\tconst deltaSign = delta < 0 ? 1 : 0;\n\n\treturn Bytes.from([\n\t\t(hourSign << 7) | (hour & 0b0111_1111),\n\t\tminutes,\n\t\t(deltaSign << 7) | (deltaMinutes & 0b0111_1111),\n\t]);\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;AAAA,kBAA4C;AAC5C,kBAAsB;AACtB,kBAAsB;AAQf,MAAM,4BAAiE;EAC7E,oBAAoB;EACpB,iBAAiB;EACjB,QAAQ;;AAOH,SAAU,mBAAmB,OAAmB;AACrD,MAAI,OAAO,UAAU;AAAU,WAAO,0BAA0B,KAAK;AACrE,cAAQ,mBAAM,OAAO,OAAO,EAAE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,MAAM,KAAK,IAAI,GAAG,cAAc,IAAI,EAAE;AACxD,QAAM,WAAW,GAAG,iBAAiB,IAAI,IAAI;AAE7C,QAAM,QAAQ,GAAG,YAAY,GAAG;AAChC,QAAM,eAAe,KAAK,IAAI,KAAK;AACnC,QAAM,YAAY,QAAQ,IAAI,IAAI;AAElC,SAAO,kBAAM,KAAK;IAChB,YAAY,IAAM,OAAO;IAC1B;IACC,aAAa,IAAM,eAAe;GACnC;AACF;",
4
+ "sourcesContent": ["import { ZWaveError, ZWaveErrorCodes } from \"@zwave-js/core\";\nimport { Bytes } from \"@zwave-js/shared/safe\";\nimport { clamp } from \"alcalzone-shared/math\";\nimport type {\n\tSetbackSpecialState,\n\tSetbackState,\n\tSwitchpoint,\n\tTimezone,\n} from \"./_Types.js\";\n\nexport const setbackSpecialStateValues: Record<SetbackSpecialState, number> = {\n\t\"Frost Protection\": 0x79,\n\t\"Energy Saving\": 0x7a,\n\tUnused: 0x7f,\n};\n\n/**\n * @publicAPI\n * Encodes a setback state to use in a ThermostatSetbackCC\n */\nexport function encodeSetbackState(state: SetbackState): Bytes {\n\tlet rawValue: number;\n\tif (typeof state === \"string\") {\n\t\trawValue = setbackSpecialStateValues[state];\n\t} else {\n\t\tstate = clamp(state, -12.8, 12);\n\t\trawValue = Math.round(state * 10);\n\t}\n\n\tconst ret = new Bytes(1);\n\tret.writeInt8(rawValue);\n\treturn ret;\n}\n\n/**\n * @publicAPI\n * Decodes a setback state used in a ThermostatSetbackCC\n */\nexport function decodeSetbackState(\n\tdata: Uint8Array,\n\toffset: number = 0,\n): SetbackState | undefined {\n\tconst val = Bytes.view(data).readInt8(offset);\n\tif (val > 120) {\n\t\t// Special state, try to look it up\n\t\tconst foundEntry = Object.entries(setbackSpecialStateValues).find(\n\t\t\t([, v]) => val === v,\n\t\t);\n\t\tif (!foundEntry) return;\n\t\treturn foundEntry[0] as SetbackSpecialState;\n\t} else {\n\t\treturn val / 10;\n\t}\n}\n\n/**\n * @publicAPI\n * Decodes a switch point used in a ClimateControlScheduleCC\n */\nexport function decodeSwitchpoint(data: Uint8Array): Switchpoint {\n\treturn {\n\t\thour: data[0] & 0b000_11111,\n\t\tminute: data[1] & 0b00_111111,\n\t\tstate: decodeSetbackState(data, 2),\n\t};\n}\n\n/**\n * @publicAPI\n * Encodes a switch point to use in a ClimateControlScheduleCC\n */\nexport function encodeSwitchpoint(point: Switchpoint): Bytes {\n\tif (point.state == undefined) {\n\t\tthrow new ZWaveError(\n\t\t\t\"The given Switchpoint is not valid!\",\n\t\t\tZWaveErrorCodes.CC_Invalid,\n\t\t);\n\t}\n\treturn Bytes.concat([\n\t\t[\n\t\t\tpoint.hour & 0b000_11111,\n\t\t\tpoint.minute & 0b00_111111,\n\t\t],\n\t\tencodeSetbackState(point.state),\n\t]);\n}\n\n/**\n * @publicAPI\n * Decodes timezone information used in time related CCs\n */\nexport function parseTimezone(data: Uint8Array): Timezone {\n\tconst hourSign = !!(data[0] & 0b1000_0000);\n\tconst hour = data[0] & 0b0111_1111;\n\tconst minute = data[1];\n\tconst standardOffset = (hourSign ? -1 : 1) * (hour * 60 + minute);\n\tconst deltaSign = !!(data[2] & 0b1000_0000);\n\tconst deltaMinutes = data[2] & 0b0111_1111;\n\tconst dstOffset = standardOffset + (deltaSign ? -1 : 1) * deltaMinutes;\n\n\treturn {\n\t\tstandardOffset,\n\t\tdstOffset,\n\t};\n}\n\n/**\n * @publicAPI\n * Decodes timezone information used in time related CCs\n */\nexport function encodeTimezone(tz: Timezone): Bytes {\n\tif (\n\t\tMath.abs(tz.standardOffset) >= 24 * 60\n\t\t|| Math.abs(tz.dstOffset) >= 24 * 60\n\t) {\n\t\tthrow new ZWaveError(\n\t\t\t\"The given timezone is not valid!\",\n\t\t\tZWaveErrorCodes.CC_Invalid,\n\t\t);\n\t}\n\tconst minutes = Math.abs(tz.standardOffset) % 60;\n\tconst hour = Math.floor(Math.abs(tz.standardOffset) / 60);\n\tconst hourSign = tz.standardOffset < 0 ? 1 : 0;\n\n\tconst delta = tz.dstOffset - tz.standardOffset;\n\tconst deltaMinutes = Math.abs(delta);\n\tconst deltaSign = delta < 0 ? 1 : 0;\n\n\treturn Bytes.from([\n\t\t(hourSign << 7) | (hour & 0b0111_1111),\n\t\tminutes,\n\t\t(deltaSign << 7) | (deltaMinutes & 0b0111_1111),\n\t]);\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;AAAA,kBAA4C;AAC5C,kBAAsB;AACtB,kBAAsB;AAQf,MAAM,4BAAiE;EAC7E,oBAAoB;EACpB,iBAAiB;EACjB,QAAQ;;AAOH,SAAU,mBAAmB,OAAmB;AACrD,MAAI;AACJ,MAAI,OAAO,UAAU,UAAU;AAC9B,eAAW,0BAA0B,KAAK;EAC3C,OAAO;AACN,gBAAQ,mBAAM,OAAO,OAAO,EAAE;AAC9B,eAAW,KAAK,MAAM,QAAQ,EAAE;EACjC;AAEA,QAAM,MAAM,IAAI,kBAAM,CAAC;AACvB,MAAI,UAAU,QAAQ;AACtB,SAAO;AACR;AAMM,SAAU,mBACf,MACA,SAAiB,GAAC;AAElB,QAAM,MAAM,kBAAM,KAAK,IAAI,EAAE,SAAS,MAAM;AAC5C,MAAI,MAAM,KAAK;AAEd,UAAM,aAAa,OAAO,QAAQ,yBAAyB,EAAE,KAC5D,CAAC,CAAC,EAAE,CAAC,MAAM,QAAQ,CAAC;AAErB,QAAI,CAAC;AAAY;AACjB,WAAO,WAAW,CAAC;EACpB,OAAO;AACN,WAAO,MAAM;EACd;AACD;AAMM,SAAU,kBAAkB,MAAgB;AACjD,SAAO;IACN,MAAM,KAAK,CAAC,IAAI;IAChB,QAAQ,KAAK,CAAC,IAAI;IAClB,OAAO,mBAAmB,MAAM,CAAC;;AAEnC;AAMM,SAAU,kBAAkB,OAAkB;AACnD,MAAI,MAAM,SAAS,QAAW;AAC7B,UAAM,IAAI,uBACT,uCACA,4BAAgB,UAAU;EAE5B;AACA,SAAO,kBAAM,OAAO;IACnB;MACC,MAAM,OAAO;MACb,MAAM,SAAS;;IAEhB,mBAAmB,MAAM,KAAK;GAC9B;AACF;AAMM,SAAU,cAAc,MAAgB;AAC7C,QAAM,WAAW,CAAC,EAAE,KAAK,CAAC,IAAI;AAC9B,QAAM,OAAO,KAAK,CAAC,IAAI;AACvB,QAAM,SAAS,KAAK,CAAC;AACrB,QAAM,kBAAkB,WAAW,KAAK,MAAM,OAAO,KAAK;AAC1D,QAAM,YAAY,CAAC,EAAE,KAAK,CAAC,IAAI;AAC/B,QAAM,eAAe,KAAK,CAAC,IAAI;AAC/B,QAAM,YAAY,kBAAkB,YAAY,KAAK,KAAK;AAE1D,SAAO;IACN;IACA;;AAEF;AAMM,SAAU,eAAe,IAAY;AAC1C,MACC,KAAK,IAAI,GAAG,cAAc,KAAK,KAAK,MACjC,KAAK,IAAI,GAAG,SAAS,KAAK,KAAK,IACjC;AACD,UAAM,IAAI,uBACT,oCACA,4BAAgB,UAAU;EAE5B;AACA,QAAM,UAAU,KAAK,IAAI,GAAG,cAAc,IAAI;AAC9C,QAAM,OAAO,KAAK,MAAM,KAAK,IAAI,GAAG,cAAc,IAAI,EAAE;AACxD,QAAM,WAAW,GAAG,iBAAiB,IAAI,IAAI;AAE7C,QAAM,QAAQ,GAAG,YAAY,GAAG;AAChC,QAAM,eAAe,KAAK,IAAI,KAAK;AACnC,QAAM,YAAY,QAAQ,IAAI,IAAI;AAElC,SAAO,kBAAM,KAAK;IAChB,YAAY,IAAM,OAAO;IAC1B;IACC,aAAa,IAAM,eAAe;GACnC;AACF;",
6
6
  "names": []
7
7
  }
@@ -33,7 +33,7 @@ __export(utils_exports, {
33
33
  module.exports = __toCommonJS(utils_exports);
34
34
  var import_safe = require("@zwave-js/core/safe");
35
35
  var import_safe2 = require("@zwave-js/shared/safe");
36
- var import_arrays = require("alcalzone-shared/arrays/index.js");
36
+ var import_arrays = require("alcalzone-shared/arrays");
37
37
  var import_AssociationCC = require("../cc/AssociationCC.js");
38
38
  var import_AssociationGroupInfoCC = require("../cc/AssociationGroupInfoCC.js");
39
39
  var import_MultiChannelAssociationCC = require("../cc/MultiChannelAssociationCC.js");
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/lib/utils.ts"],
4
- "sourcesContent": ["import type { AssociationConfig } from \"@zwave-js/config\";\nimport {\n\tCommandClasses,\n\ttype ControlsCC,\n\ttype EndpointId,\n\ttype GetAllEndpoints,\n\ttype GetEndpoint,\n\ttype MaybeNotKnown,\n\tNOT_KNOWN,\n\ttype NodeId,\n\ttype QuerySecurityClasses,\n\tSecurityClass,\n\ttype SupportsCC,\n\tZWaveError,\n\tZWaveErrorCodes,\n\tactuatorCCs,\n\tgetCCName,\n\tisActuatorCC,\n\tisLongRangeNodeId,\n\tisSensorCC,\n} from \"@zwave-js/core/safe\";\nimport {\n\ttype GetDeviceConfig,\n\ttype GetNode,\n\ttype GetValueDB,\n\ttype HostIDs,\n} from \"@zwave-js/host\";\nimport {\n\tObjectKeyMap,\n\ttype ReadonlyObjectKeyMap,\n\tgetEnumMemberName,\n} from \"@zwave-js/shared/safe\";\nimport { distinct } from \"alcalzone-shared/arrays/index.js\";\nimport { AssociationCC, AssociationCCValues } from \"../cc/AssociationCC.js\";\nimport { AssociationGroupInfoCC } from \"../cc/AssociationGroupInfoCC.js\";\nimport { MultiChannelAssociationCC } from \"../cc/MultiChannelAssociationCC.js\";\nimport { CCAPI, type CCAPIHost, type CCAPINode } from \"./API.js\";\nimport {\n\ttype AssociationAddress,\n\tAssociationCheckResult,\n\ttype AssociationGroup,\n\tAssociationGroupInfoProfile,\n\ttype EndpointAddress,\n} from \"./_Types.js\";\n\nexport function getAssociations(\n\tctx: GetValueDB,\n\tendpoint: EndpointId & SupportsCC,\n): ReadonlyMap<number, readonly AssociationAddress[]> {\n\tconst ret = new Map<number, readonly AssociationAddress[]>();\n\n\tif (endpoint.supportsCC(CommandClasses.Association)) {\n\t\tconst destinations = AssociationCC.getAllDestinationsCached(\n\t\t\tctx,\n\t\t\tendpoint,\n\t\t);\n\t\tfor (const [groupId, assocs] of destinations) {\n\t\t\tret.set(groupId, assocs);\n\t\t}\n\t} else {\n\t\tthrow new ZWaveError(\n\t\t\t`Node ${endpoint.nodeId}${\n\t\t\t\tendpoint.index > 0 ? `, endpoint ${endpoint.index}` : \"\"\n\t\t\t} does not support associations!`,\n\t\t\tZWaveErrorCodes.CC_NotSupported,\n\t\t);\n\t}\n\n\t// Merge the \"normal\" destinations with multi channel destinations\n\tif (endpoint.supportsCC(CommandClasses[\"Multi Channel Association\"])) {\n\t\tconst destinations = MultiChannelAssociationCC.getAllDestinationsCached(\n\t\t\tctx,\n\t\t\tendpoint,\n\t\t);\n\t\tfor (const [groupId, assocs] of destinations) {\n\t\t\tif (ret.has(groupId)) {\n\t\t\t\tconst normalAssociations = ret.get(groupId)!;\n\t\t\t\tret.set(groupId, [\n\t\t\t\t\t...normalAssociations,\n\t\t\t\t\t// Eliminate potential duplicates\n\t\t\t\t\t...assocs.filter(\n\t\t\t\t\t\t(a1) =>\n\t\t\t\t\t\t\t!normalAssociations.some(\n\t\t\t\t\t\t\t\t(a2) =>\n\t\t\t\t\t\t\t\t\ta1.nodeId === a2.nodeId\n\t\t\t\t\t\t\t\t\t&& a1.endpoint === a2.endpoint,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t),\n\t\t\t\t]);\n\t\t\t} else {\n\t\t\t\tret.set(groupId, assocs);\n\t\t\t}\n\t\t}\n\t}\n\n\treturn ret;\n}\n\nexport function getAllAssociations(\n\tctx: GetValueDB,\n\tnode: NodeId & GetAllEndpoints<EndpointId & SupportsCC>,\n): ReadonlyObjectKeyMap<\n\tAssociationAddress,\n\tReadonlyMap<number, readonly AssociationAddress[]>\n> {\n\tconst ret = new ObjectKeyMap<\n\t\tAssociationAddress,\n\t\tReadonlyMap<number, readonly AssociationAddress[]>\n\t>();\n\tfor (const endpoint of node.getAllEndpoints()) {\n\t\tconst address: AssociationAddress = {\n\t\t\tnodeId: node.id,\n\t\t\tendpoint: endpoint.index,\n\t\t};\n\t\tif (endpoint.supportsCC(CommandClasses.Association)) {\n\t\t\tret.set(address, getAssociations(ctx, endpoint));\n\t\t}\n\t}\n\treturn ret;\n}\n\nexport function checkAssociation(\n\tctx:\n\t\t& HostIDs\n\t\t& GetValueDB\n\t\t& GetNode<\n\t\t\t& NodeId\n\t\t\t& SupportsCC\n\t\t\t& GetEndpoint<EndpointId & SupportsCC>\n\t\t\t& QuerySecurityClasses\n\t\t>,\n\tendpoint: EndpointId & SupportsCC & ControlsCC,\n\tgroup: number,\n\tdestination: AssociationAddress,\n): AssociationCheckResult {\n\t// Check that the target endpoint exists except when adding an association to the controller\n\tconst targetNode = ctx.getNodeOrThrow(destination.nodeId);\n\tconst targetEndpoint = destination.nodeId === ctx.ownNodeId\n\t\t? targetNode\n\t\t: targetNode.getEndpointOrThrow(destination.endpoint ?? 0);\n\n\tif (\n\t\t!endpoint.supportsCC(CommandClasses.Association)\n\t\t&& !endpoint.supportsCC(CommandClasses[\"Multi Channel Association\"])\n\t) {\n\t\tthrow new ZWaveError(\n\t\t\t`Node ${endpoint.nodeId}${\n\t\t\t\tendpoint.index > 0 ? `, endpoint ${endpoint.index}` : \"\"\n\t\t\t} does not support associations!`,\n\t\t\tZWaveErrorCodes.CC_NotSupported,\n\t\t);\n\t}\n\n\t// Associations to and from ZWLR devices are not allowed\n\tif (isLongRangeNodeId(destination.nodeId)) {\n\t\treturn AssociationCheckResult.Forbidden_DestinationIsLongRange;\n\t} else if (isLongRangeNodeId(endpoint.nodeId)) {\n\t\t// Except the lifeline back to the host\n\t\tif (group !== 1 || destination.nodeId !== ctx.ownNodeId) {\n\t\t\treturn AssociationCheckResult.Forbidden_SourceIsLongRange;\n\t\t}\n\t}\n\n\t// The following checks don't apply to Lifeline associations\n\tif (destination.nodeId === ctx.ownNodeId) {\n\t\treturn AssociationCheckResult.OK;\n\t}\n\n\t// Disallow self-associations\n\tif (destination.nodeId === endpoint.nodeId) {\n\t\treturn AssociationCheckResult.Forbidden_SelfAssociation;\n\t}\n\n\t// For Association version 1 and version 2 / MCA version 1-3:\n\t// A controlling node MUST NOT associate Node A to a Node B destination\n\t// if Node A and Node B\u2019s highest Security Class are not identical.\n\t// For Association version 3 / MCA version 4:\n\t// A controlling node MUST NOT associate Node A to a Node B destination\n\t// if Node A was not granted Node B\u2019s highest Security Class.\n\n\tconst sourceNode = ctx.getNode(endpoint.nodeId)!;\n\tlet securityClassMustMatch: boolean;\n\tif (destination.endpoint == undefined) {\n\t\t// \"normal\" association\n\t\tconst sourceNodeCCVersion = endpoint.getCCVersion(\n\t\t\tCommandClasses.Association,\n\t\t);\n\t\tsecurityClassMustMatch = sourceNodeCCVersion < 3;\n\t} else {\n\t\t// multi channel association\n\t\tconst sourceNodeCCVersion = endpoint.getCCVersion(\n\t\t\tCommandClasses[\"Multi Channel Association\"],\n\t\t);\n\t\tsecurityClassMustMatch = sourceNodeCCVersion < 4;\n\t}\n\n\tconst sourceSecurityClass = sourceNode.getHighestSecurityClass();\n\tconst targetSecurityClass = targetNode.getHighestSecurityClass();\n\n\t// If the security classes are unknown, all bets are off\n\tif (sourceSecurityClass != undefined && targetSecurityClass != undefined) {\n\t\tif (\n\t\t\tsecurityClassMustMatch\n\t\t\t&& sourceSecurityClass !== targetSecurityClass\n\t\t) {\n\t\t\treturn AssociationCheckResult.Forbidden_SecurityClassMismatch;\n\t\t} else if (\n\t\t\t// Commands to insecure nodes are allowed\n\t\t\ttargetSecurityClass !== SecurityClass.None\n\t\t\t// Otherwise, the sender must know the target's highest key\n\t\t\t&& !securityClassMustMatch\n\t\t\t&& !sourceNode.hasSecurityClass(targetSecurityClass)\n\t\t) {\n\t\t\treturn AssociationCheckResult\n\t\t\t\t.Forbidden_DestinationSecurityClassNotGranted;\n\t\t}\n\t}\n\n\t// SDS14223:\n\t// A controlling node MUST NOT associate Node A to a Node B destination that does not support\n\t// the Command Class that the Node A will be controlling\n\t//\n\t// To determine this, the node must support the AGI CC or we have no way of knowing which\n\t// CCs the node will control\n\tif (!endpoint.supportsCC(CommandClasses[\"Association Group Information\"])) {\n\t\treturn AssociationCheckResult.OK;\n\t}\n\n\tconst groupCommandList = AssociationGroupInfoCC.getIssuedCommandsCached(\n\t\tctx,\n\t\tendpoint,\n\t\tgroup,\n\t);\n\tif (!groupCommandList || !groupCommandList.size) {\n\t\t// We don't know which CCs this group controls, just allow it\n\t\treturn AssociationCheckResult.OK;\n\t}\n\tconst groupCCs = [...groupCommandList.keys()];\n\n\t// A controlling node MAY create an association to a destination supporting an\n\t// actuator Command Class if the actual association group sends Basic Control Command Class.\n\tif (\n\t\tgroupCCs.includes(CommandClasses.Basic)\n\t\t&& actuatorCCs.some((cc) => targetEndpoint?.supportsCC(cc))\n\t) {\n\t\treturn AssociationCheckResult.OK;\n\t}\n\n\t// Enforce that at least one issued CC is supported\n\tif (groupCCs.some((cc) => targetEndpoint?.supportsCC(cc))) {\n\t\treturn AssociationCheckResult.OK;\n\t} else {\n\t\treturn AssociationCheckResult.Forbidden_NoSupportedCCs;\n\t}\n}\n\nexport function getAssociationGroups(\n\tctx: GetValueDB & GetDeviceConfig,\n\tendpoint: EndpointId & SupportsCC,\n): ReadonlyMap<number, AssociationGroup> {\n\t// Check whether we have multi channel support or not\n\tlet assocInstance: typeof AssociationCC;\n\tlet mcInstance: typeof MultiChannelAssociationCC | undefined;\n\tif (endpoint.supportsCC(CommandClasses.Association)) {\n\t\tassocInstance = AssociationCC;\n\t} else {\n\t\tthrow new ZWaveError(\n\t\t\t`Node ${endpoint.nodeId}${\n\t\t\t\tendpoint.index > 0 ? `, endpoint ${endpoint.index}` : \"\"\n\t\t\t} does not support associations!`,\n\t\t\tZWaveErrorCodes.CC_NotSupported,\n\t\t);\n\t}\n\tif (endpoint.supportsCC(CommandClasses[\"Multi Channel Association\"])) {\n\t\tmcInstance = MultiChannelAssociationCC;\n\t}\n\n\tconst assocGroupCount = assocInstance.getGroupCountCached(ctx, endpoint)\n\t\t?? 0;\n\tconst mcGroupCount = mcInstance?.getGroupCountCached(ctx, endpoint)\n\t\t?? 0;\n\tconst groupCount = Math.max(assocGroupCount, mcGroupCount);\n\n\tconst deviceConfig = ctx.getDeviceConfig?.(endpoint.nodeId);\n\n\tconst ret = new Map<number, AssociationGroup>();\n\n\tif (endpoint.supportsCC(CommandClasses[\"Association Group Information\"])) {\n\t\t// We can read all information we need from the AGI CC\n\t\tconst agiInstance = AssociationGroupInfoCC;\n\t\tfor (let group = 1; group <= groupCount; group++) {\n\t\t\tconst assocConfig = deviceConfig?.getAssociationConfigForEndpoint(\n\t\t\t\tendpoint.index,\n\t\t\t\tgroup,\n\t\t\t);\n\t\t\tconst multiChannel = !!mcInstance && group <= mcGroupCount;\n\t\t\tret.set(group, {\n\t\t\t\tmaxNodes: (multiChannel\n\t\t\t\t\t? mcInstance!\n\t\t\t\t\t: assocInstance).getMaxNodesCached(\n\t\t\t\t\t\tctx,\n\t\t\t\t\t\tendpoint,\n\t\t\t\t\t\tgroup,\n\t\t\t\t\t) || 1,\n\t\t\t\t// AGI implies Z-Wave+ where group 1 is the lifeline\n\t\t\t\tisLifeline: group === 1,\n\t\t\t\tlabel:\n\t\t\t\t\t// prefer the configured label if we have one\n\t\t\t\t\tassocConfig?.label\n\t\t\t\t\t\t// the ones reported by AGI are sometimes pretty bad\n\t\t\t\t\t\t?? agiInstance.getGroupNameCached(\n\t\t\t\t\t\t\tctx,\n\t\t\t\t\t\t\tendpoint,\n\t\t\t\t\t\t\tgroup,\n\t\t\t\t\t\t)\n\t\t\t\t\t\t// but still better than \"unnamed\"\n\t\t\t\t\t\t?? `Unnamed group ${group}`,\n\t\t\t\tmultiChannel,\n\t\t\t\tprofile: agiInstance.getGroupProfileCached(\n\t\t\t\t\tctx,\n\t\t\t\t\tendpoint,\n\t\t\t\t\tgroup,\n\t\t\t\t),\n\t\t\t\tissuedCommands: agiInstance.getIssuedCommandsCached(\n\t\t\t\t\tctx,\n\t\t\t\t\tendpoint,\n\t\t\t\t\tgroup,\n\t\t\t\t),\n\t\t\t});\n\t\t}\n\t} else {\n\t\t// we need to consult the device config\n\t\tfor (let group = 1; group <= groupCount; group++) {\n\t\t\tconst assocConfig = deviceConfig?.getAssociationConfigForEndpoint(\n\t\t\t\tendpoint.index,\n\t\t\t\tgroup,\n\t\t\t);\n\t\t\tconst multiChannel = !!mcInstance && group <= mcGroupCount;\n\t\t\tret.set(group, {\n\t\t\t\tmaxNodes: (multiChannel\n\t\t\t\t\t? mcInstance!\n\t\t\t\t\t: assocInstance).getMaxNodesCached(\n\t\t\t\t\t\tctx,\n\t\t\t\t\t\tendpoint,\n\t\t\t\t\t\tgroup,\n\t\t\t\t\t)\n\t\t\t\t\t|| assocConfig?.maxNodes\n\t\t\t\t\t|| 1,\n\t\t\t\tisLifeline: assocConfig?.isLifeline ?? group === 1,\n\t\t\t\tlabel: assocConfig?.label ?? `Unnamed group ${group}`,\n\t\t\t\tmultiChannel,\n\t\t\t});\n\t\t}\n\t}\n\treturn ret;\n}\n\nexport function getAllAssociationGroups(\n\tctx: GetValueDB & GetDeviceConfig,\n\tnode: NodeId & GetAllEndpoints<EndpointId & SupportsCC>,\n): ReadonlyMap<number, ReadonlyMap<number, AssociationGroup>> {\n\tconst ret = new Map<number, ReadonlyMap<number, AssociationGroup>>();\n\tfor (const endpoint of node.getAllEndpoints()) {\n\t\tif (endpoint.supportsCC(CommandClasses.Association)) {\n\t\t\tret.set(endpoint.index, getAssociationGroups(ctx, endpoint));\n\t\t}\n\t}\n\treturn ret;\n}\n\nexport async function addAssociations(\n\tctx: CCAPIHost<\n\t\t& CCAPINode\n\t\t& SupportsCC\n\t\t& GetEndpoint<EndpointId & SupportsCC>\n\t\t& QuerySecurityClasses\n\t>,\n\tendpoint: EndpointId & SupportsCC & ControlsCC,\n\tgroup: number,\n\tdestinations: AssociationAddress[],\n): Promise<void> {\n\tconst nodeAndEndpointString = `${endpoint.nodeId}${\n\t\tendpoint.index > 0 ? `, endpoint ${endpoint.index}` : \"\"\n\t}`;\n\n\t// Check whether we should add any associations the device does not have support for\n\tlet assocInstance: typeof AssociationCC | undefined;\n\tlet mcInstance: typeof MultiChannelAssociationCC | undefined;\n\t// Split associations into conventional and endpoint associations\n\tconst nodeAssociations = distinct(\n\t\tdestinations\n\t\t\t.filter((a) => a.endpoint == undefined)\n\t\t\t.map((a) => a.nodeId),\n\t);\n\tconst endpointAssociations = destinations.filter(\n\t\t(a) => a.endpoint != undefined,\n\t) as EndpointAddress[];\n\n\tif (endpoint.supportsCC(CommandClasses.Association)) {\n\t\tassocInstance = AssociationCC;\n\t} else if (nodeAssociations.length > 0) {\n\t\tthrow new ZWaveError(\n\t\t\t`Node ${nodeAndEndpointString} does not support associations!`,\n\t\t\tZWaveErrorCodes.CC_NotSupported,\n\t\t);\n\t}\n\tif (endpoint.supportsCC(CommandClasses[\"Multi Channel Association\"])) {\n\t\tmcInstance = MultiChannelAssociationCC;\n\t} else if (endpointAssociations.length > 0) {\n\t\tthrow new ZWaveError(\n\t\t\t`Node ${nodeAndEndpointString} does not support multi channel associations!`,\n\t\t\tZWaveErrorCodes.CC_NotSupported,\n\t\t);\n\t}\n\n\t// Disallow associating a node with itself. This is technically checked as part of\n\t// checkAssociations, but here we provide a better error message.\n\tconst selfAssociations = destinations.filter((d) =>\n\t\td.nodeId === endpoint.nodeId\n\t);\n\tif (selfAssociations.length > 0) {\n\t\tthrow new ZWaveError(\n\t\t\t`Associating a node with itself is not allowed!`,\n\t\t\tZWaveErrorCodes.AssociationCC_NotAllowed,\n\t\t\tselfAssociations.map((a) => ({\n\t\t\t\t...a,\n\t\t\t\tcheckResult: AssociationCheckResult.Forbidden_SelfAssociation,\n\t\t\t})),\n\t\t);\n\t}\n\n\tconst assocGroupCount = assocInstance?.getGroupCountCached(ctx, endpoint)\n\t\t?? 0;\n\tconst mcGroupCount = mcInstance?.getGroupCountCached(ctx, endpoint)\n\t\t?? 0;\n\tconst groupCount = Math.max(assocGroupCount, mcGroupCount);\n\tif (group > groupCount) {\n\t\tthrow new ZWaveError(\n\t\t\t`Group ${group} does not exist on node ${nodeAndEndpointString}`,\n\t\t\tZWaveErrorCodes.AssociationCC_InvalidGroup,\n\t\t);\n\t}\n\n\tconst deviceConfig = ctx.getDeviceConfig?.(endpoint.nodeId);\n\n\tconst groupIsMultiChannel = !!mcInstance\n\t\t&& group <= mcGroupCount\n\t\t&& deviceConfig?.associations?.get(group)?.multiChannel !== false;\n\n\tif (groupIsMultiChannel) {\n\t\t// Check that all associations are allowed\n\t\tconst disallowedAssociations = destinations.map(\n\t\t\t(a) => ({\n\t\t\t\t...a,\n\t\t\t\tcheckResult: checkAssociation(ctx, endpoint, group, a),\n\t\t\t}),\n\t\t).filter(({ checkResult }) =>\n\t\t\tcheckResult !== AssociationCheckResult.OK\n\t\t);\n\t\tif (disallowedAssociations.length) {\n\t\t\tlet message = `The following associations are not allowed:`;\n\t\t\tmessage += disallowedAssociations\n\t\t\t\t.map(\n\t\t\t\t\t(a) =>\n\t\t\t\t\t\t`\\n\u00B7 Node ${a.nodeId}${\n\t\t\t\t\t\t\ta.endpoint ? `, endpoint ${a.endpoint}` : \"\"\n\t\t\t\t\t\t}: ${\n\t\t\t\t\t\t\tgetEnumMemberName(\n\t\t\t\t\t\t\t\tAssociationCheckResult,\n\t\t\t\t\t\t\t\ta.checkResult,\n\t\t\t\t\t\t\t).replace(\"Forbidden_\", \"\")\n\t\t\t\t\t\t}`,\n\t\t\t\t)\n\t\t\t\t.join(\"\");\n\t\t\tthrow new ZWaveError(\n\t\t\t\tmessage,\n\t\t\t\tZWaveErrorCodes.AssociationCC_NotAllowed,\n\t\t\t\tdisallowedAssociations,\n\t\t\t);\n\t\t}\n\n\t\t// And add them\n\t\tconst api = CCAPI.create(\n\t\t\tCommandClasses[\"Multi Channel Association\"],\n\t\t\tctx,\n\t\t\tendpoint,\n\t\t);\n\t\tawait api.addDestinations({\n\t\t\tgroupId: group,\n\t\t\tnodeIds: nodeAssociations,\n\t\t\tendpoints: endpointAssociations,\n\t\t});\n\t\t// Refresh the association list\n\t\tawait api.getGroup(group);\n\t} else {\n\t\t// Although the node supports multi channel associations, this group only supports \"normal\" associations\n\t\tif (destinations.some((a) => a.endpoint != undefined)) {\n\t\t\tthrow new ZWaveError(\n\t\t\t\t`Node ${nodeAndEndpointString}, group ${group} does not support multi channel associations!`,\n\t\t\t\tZWaveErrorCodes.CC_NotSupported,\n\t\t\t);\n\t\t}\n\n\t\t// Check that all associations are allowed\n\t\tconst disallowedAssociations = destinations.map(\n\t\t\t(a) => ({\n\t\t\t\t...a,\n\t\t\t\tcheckResult: checkAssociation(ctx, endpoint, group, a),\n\t\t\t}),\n\t\t).filter(({ checkResult }) =>\n\t\t\tcheckResult !== AssociationCheckResult.OK\n\t\t);\n\t\tif (disallowedAssociations.length) {\n\t\t\tlet message =\n\t\t\t\t`The associations to the following nodes are not allowed`;\n\t\t\tmessage += disallowedAssociations\n\t\t\t\t.map(\n\t\t\t\t\t(a) =>\n\t\t\t\t\t\t`\\n\u00B7 Node ${a.nodeId}: ${\n\t\t\t\t\t\t\tgetEnumMemberName(\n\t\t\t\t\t\t\t\tAssociationCheckResult,\n\t\t\t\t\t\t\t\ta.checkResult,\n\t\t\t\t\t\t\t).replace(\"Forbidden_\", \"\")\n\t\t\t\t\t\t}`,\n\t\t\t\t)\n\t\t\t\t.join(\"\");\n\n\t\t\tthrow new ZWaveError(\n\t\t\t\tmessage,\n\t\t\t\tZWaveErrorCodes.AssociationCC_NotAllowed,\n\t\t\t\tdisallowedAssociations,\n\t\t\t);\n\t\t}\n\n\t\tconst api = CCAPI.create(\n\t\t\tCommandClasses.Association,\n\t\t\tctx,\n\t\t\tendpoint,\n\t\t);\n\t\tawait api.addNodeIds(group, ...destinations.map((a) => a.nodeId));\n\t\t// Refresh the association list\n\t\tawait api.getGroup(group);\n\t}\n}\n\nexport async function removeAssociations(\n\tctx: CCAPIHost,\n\tendpoint: EndpointId & SupportsCC & ControlsCC,\n\tgroup: number,\n\tdestinations: AssociationAddress[],\n): Promise<void> {\n\tconst nodeAndEndpointString = `${endpoint.nodeId}${\n\t\tendpoint.index > 0 ? `, endpoint ${endpoint.index}` : \"\"\n\t}`;\n\n\t// Split associations into conventional and endpoint associations\n\tconst nodeAssociations = distinct(\n\t\tdestinations\n\t\t\t.filter((a) => a.endpoint == undefined)\n\t\t\t.map((a) => a.nodeId),\n\t);\n\tconst endpointAssociations = destinations.filter(\n\t\t(a) => a.endpoint != undefined,\n\t) as EndpointAddress[];\n\n\t// Removing associations is not either/or - we could have a device with duplicated associations between\n\t// Association CC and Multi Channel Association CC\n\t// Figure out what we need to use to remove the associations\n\n\tlet groupExistsAsMultiChannel = false;\n\tlet groupExistsAsNodeAssociation = false;\n\n\tlet mcInstance: typeof MultiChannelAssociationCC | undefined;\n\tlet assocInstance: typeof AssociationCC | undefined;\n\n\t// To remove a multi channel association, we need to make sure that the group exists\n\t// and the node supports multi channel associations\n\tif (endpoint.supportsCC(CommandClasses[\"Multi Channel Association\"])) {\n\t\tmcInstance = MultiChannelAssociationCC;\n\t\tif (group <= mcInstance.getGroupCountCached(ctx, endpoint)) {\n\t\t\tgroupExistsAsMultiChannel = true;\n\t\t}\n\t} else if (endpointAssociations.length > 0) {\n\t\tthrow new ZWaveError(\n\t\t\t`Node ${nodeAndEndpointString} does not support multi channel associations!`,\n\t\t\tZWaveErrorCodes.CC_NotSupported,\n\t\t);\n\t}\n\n\t// To remove a normal association, we need to make sure that the group exists either as a normal association\n\t// or as a multi channel association\n\tif (endpoint.supportsCC(CommandClasses.Association)) {\n\t\tassocInstance = AssociationCC;\n\t\tif (group <= assocInstance.getGroupCountCached(ctx, endpoint)) {\n\t\t\tgroupExistsAsNodeAssociation = true;\n\t\t}\n\t}\n\n\tif (!mcInstance && !assocInstance) {\n\t\tthrow new ZWaveError(\n\t\t\t`Node ${nodeAndEndpointString} does not support associations!`,\n\t\t\tZWaveErrorCodes.CC_NotSupported,\n\t\t);\n\t}\n\n\t// Ensure the group exists and can be used\n\tif (!groupExistsAsMultiChannel && !groupExistsAsNodeAssociation) {\n\t\tthrow new ZWaveError(\n\t\t\t` Association group ${group} does not exist for node ${nodeAndEndpointString}`,\n\t\t\tZWaveErrorCodes.AssociationCC_InvalidGroup,\n\t\t);\n\t}\n\tif (endpointAssociations.length > 0 && !groupExistsAsMultiChannel) {\n\t\tthrow new ZWaveError(\n\t\t\t`Node ${nodeAndEndpointString}, association group ${group} does not support multi channel associations!`,\n\t\t\tZWaveErrorCodes.AssociationCC_InvalidGroup,\n\t\t);\n\t}\n\n\t// Even if we only remove node associations, we use both CCs since it has been found that some\n\t// devices do not correctly share the node list between the two commands\n\tif (\n\t\tassocInstance\n\t\t&& nodeAssociations.length > 0\n\t\t&& groupExistsAsNodeAssociation\n\t) {\n\t\tconst api = CCAPI.create(\n\t\t\tCommandClasses.Association,\n\t\t\tctx,\n\t\t\tendpoint,\n\t\t);\n\t\tawait api.removeNodeIds({\n\t\t\tgroupId: group,\n\t\t\tnodeIds: nodeAssociations,\n\t\t});\n\t\t// Refresh the association list\n\t\tawait api.getGroup(group);\n\t}\n\n\tif (mcInstance && groupExistsAsMultiChannel) {\n\t\tconst api = CCAPI.create(\n\t\t\tCommandClasses[\"Multi Channel Association\"],\n\t\t\tctx,\n\t\t\tendpoint,\n\t\t);\n\t\tawait api.removeDestinations({\n\t\t\tgroupId: group,\n\t\t\tnodeIds: nodeAssociations,\n\t\t\tendpoints: endpointAssociations,\n\t\t});\n\t\t// Refresh the multi channel association list\n\t\tawait api.getGroup(group);\n\t}\n}\n\nexport function getLifelineGroupIds(\n\tctx: GetValueDB & GetDeviceConfig,\n\tendpoint: EndpointId & SupportsCC,\n): number[] {\n\t// For now only support this for the root endpoint - i.e. node\n\tif (endpoint.index > 0) return [];\n\n\t// Some nodes define multiple lifeline groups, so we need to assign us to\n\t// all of them\n\tconst lifelineGroups: number[] = [];\n\n\t// If the target node supports Z-Wave+ info that means the lifeline MUST be group #1\n\tif (endpoint.supportsCC(CommandClasses[\"Z-Wave Plus Info\"])) {\n\t\tlifelineGroups.push(1);\n\t}\n\n\t// We have a device config file that tells us which (additional) association to assign\n\tlet associations: ReadonlyMap<number, AssociationConfig> | undefined;\n\tconst deviceConfig = ctx.getDeviceConfig?.(endpoint.nodeId);\n\tif (endpoint.index === 0) {\n\t\t// The root endpoint's associations may be configured separately or as part of \"endpoints\"\n\t\tassociations = deviceConfig?.associations\n\t\t\t?? deviceConfig?.endpoints?.get(0)?.associations;\n\t} else {\n\t\t// The other endpoints can only have a configuration as part of \"endpoints\"\n\t\tassociations = deviceConfig?.endpoints?.get(\n\t\t\tendpoint.index,\n\t\t)?.associations;\n\t}\n\n\tif (associations?.size) {\n\t\tlifelineGroups.push(\n\t\t\t...[...associations.values()]\n\t\t\t\t.filter((a) => a.isLifeline)\n\t\t\t\t.map((a) => a.groupId),\n\t\t);\n\t}\n\n\treturn distinct(lifelineGroups).sort();\n}\n\nexport async function configureLifelineAssociations(\n\tctx: CCAPIHost<\n\t\t& CCAPINode\n\t\t& SupportsCC\n\t\t& ControlsCC\n\t\t& GetAllEndpoints<EndpointId & SupportsCC & ControlsCC>\n\t>,\n\tendpoint: EndpointId & SupportsCC & ControlsCC,\n): Promise<void> {\n\t// Assign the controller to all lifeline groups\n\tconst ownNodeId = ctx.ownNodeId;\n\tconst node = ctx.getNodeOrThrow(endpoint.nodeId);\n\tconst valueDB = ctx.getValueDB(node.id);\n\tconst deviceConfig = ctx.getDeviceConfig?.(node.id);\n\n\t// We check if a node supports Multi Channel CC before creating Multi Channel Lifeline Associations (#1109)\n\tconst nodeSupportsMultiChannel = node.supportsCC(\n\t\tCommandClasses[\"Multi Channel\"],\n\t);\n\n\tlet assocInstance: typeof AssociationCC | undefined;\n\tconst assocAPI = CCAPI.create(\n\t\tCommandClasses.Association,\n\t\tctx,\n\t\tendpoint,\n\t);\n\tif (endpoint.supportsCC(CommandClasses.Association)) {\n\t\tassocInstance = AssociationCC;\n\t}\n\n\tlet mcInstance: typeof MultiChannelAssociationCC | undefined;\n\tlet mcGroupCount = 0;\n\tconst mcAPI = CCAPI.create(\n\t\tCommandClasses[\"Multi Channel Association\"],\n\t\tctx,\n\t\tendpoint,\n\t);\n\tif (endpoint.supportsCC(CommandClasses[\"Multi Channel Association\"])) {\n\t\tmcInstance = MultiChannelAssociationCC;\n\t\tmcGroupCount = mcInstance.getGroupCountCached(ctx, endpoint) ?? 0;\n\t}\n\n\tconst lifelineGroups = getLifelineGroupIds(ctx, node);\n\tif (lifelineGroups.length === 0) {\n\t\t// We can look for the General Lifeline AGI profile as a last resort\n\t\tif (\n\t\t\tendpoint.supportsCC(CommandClasses[\"Association Group Information\"])\n\t\t) {\n\t\t\tconst agiAPI = CCAPI.create(\n\t\t\t\tCommandClasses[\"Association Group Information\"],\n\t\t\t\tctx,\n\t\t\t\tendpoint,\n\t\t\t);\n\n\t\t\t// The lifeline MUST be group 1\n\t\t\tconst lifeline = await agiAPI\n\t\t\t\t.getGroupInfo(1, true)\n\t\t\t\t.catch(() => undefined);\n\t\t\tif (\n\t\t\t\tlifeline?.profile\n\t\t\t\t\t=== AssociationGroupInfoProfile[\"General: Lifeline\"]\n\t\t\t) {\n\t\t\t\tlifelineGroups.push(1);\n\t\t\t}\n\t\t}\n\t}\n\n\tif (lifelineGroups.length === 0) {\n\t\tctx.logNode(node.id, {\n\t\t\tendpoint: endpoint.index,\n\t\t\tmessage:\n\t\t\t\t\"No information about Lifeline associations, cannot assign ourselves!\",\n\t\t\tlevel: \"warn\",\n\t\t});\n\t\t// Remember that we have NO lifeline association\n\t\tvalueDB.setValue(\n\t\t\tAssociationCCValues.hasLifeline.endpoint(endpoint.index),\n\t\t\tfalse,\n\t\t);\n\t\treturn;\n\t}\n\n\tctx.logNode(node.id, {\n\t\tendpoint: endpoint.index,\n\t\tmessage: `Checking/assigning lifeline groups: ${\n\t\t\tlifelineGroups.join(\n\t\t\t\t\", \",\n\t\t\t)\n\t\t}\nsupports classic associations: ${!!assocInstance}\nsupports multi channel associations: ${!!mcInstance}`,\n\t});\n\n\tfor (const group of lifelineGroups) {\n\t\tconst groupSupportsMultiChannelAssociation = group <= mcGroupCount;\n\t\tconst assocConfig = deviceConfig?.getAssociationConfigForEndpoint(\n\t\t\tendpoint.index,\n\t\t\tgroup,\n\t\t);\n\n\t\tconst mustUseNodeAssociation = !groupSupportsMultiChannelAssociation\n\t\t\t|| !nodeSupportsMultiChannel\n\t\t\t|| assocConfig?.multiChannel === false;\n\t\tlet mustUseMultiChannelAssociation = false;\n\n\t\tif (groupSupportsMultiChannelAssociation && nodeSupportsMultiChannel) {\n\t\t\tif (assocConfig?.multiChannel === true) {\n\t\t\t\tmustUseMultiChannelAssociation = true;\n\t\t\t} else if (endpoint.index === 0) {\n\t\t\t\t// If the node has multiple endpoints but none of the extra ones support associations,\n\t\t\t\t// the root endpoints needs a Multi Channel Association\n\t\t\t\tconst allEndpoints = node.getAllEndpoints();\n\t\t\t\tif (\n\t\t\t\t\tallEndpoints.length > 1\n\t\t\t\t\t&& allEndpoints\n\t\t\t\t\t\t.filter((e) => e.index !== endpoint.index)\n\t\t\t\t\t\t.every(\n\t\t\t\t\t\t\t(e) =>\n\t\t\t\t\t\t\t\t!e.supportsCC(CommandClasses.Association)\n\t\t\t\t\t\t\t\t&& !e.supportsCC(\n\t\t\t\t\t\t\t\t\tCommandClasses[\"Multi Channel Association\"],\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\tmustUseMultiChannelAssociation = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tctx.logNode(node.id, {\n\t\t\tendpoint: endpoint.index,\n\t\t\tmessage: `Configuring lifeline group #${group}:\ngroup supports multi channel: ${groupSupportsMultiChannelAssociation}\nconfigured strategy: ${assocConfig?.multiChannel ?? \"auto\"}\nmust use node association: ${mustUseNodeAssociation}\nmust use endpoint association: ${mustUseMultiChannelAssociation}`,\n\t\t});\n\n\t\t// Figure out which associations exist and may need to be removed\n\t\tconst isAssignedAsNodeAssociation = (\n\t\t\tendpoint: EndpointId,\n\t\t): boolean => {\n\t\t\tif (groupSupportsMultiChannelAssociation && mcInstance) {\n\t\t\t\tif (\n\t\t\t\t\t// Only consider a group if it doesn't share its associations with the root endpoint\n\t\t\t\t\tmcInstance.getMaxNodesCached(ctx, endpoint, group)\n\t\t\t\t\t\t> 0\n\t\t\t\t\t&& !!mcInstance\n\t\t\t\t\t\t.getAllDestinationsCached(ctx, endpoint)\n\t\t\t\t\t\t.get(group)\n\t\t\t\t\t\t?.some(\n\t\t\t\t\t\t\t(addr) =>\n\t\t\t\t\t\t\t\taddr.nodeId === ownNodeId\n\t\t\t\t\t\t\t\t&& addr.endpoint == undefined,\n\t\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (assocInstance) {\n\t\t\t\tif (\n\t\t\t\t\t// Only consider a group if it doesn't share its associations with the root endpoint\n\t\t\t\t\tassocInstance.getMaxNodesCached(ctx, endpoint, group)\n\t\t\t\t\t\t> 0\n\t\t\t\t\t&& !!assocInstance\n\t\t\t\t\t\t.getAllDestinationsCached(ctx, endpoint)\n\t\t\t\t\t\t.get(group)\n\t\t\t\t\t\t?.some((addr) => addr.nodeId === ownNodeId)\n\t\t\t\t) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn false;\n\t\t};\n\n\t\tconst isAssignedAsEndpointAssociation = (\n\t\t\tendpoint: EndpointId,\n\t\t): boolean => {\n\t\t\tif (mcInstance) {\n\t\t\t\tif (\n\t\t\t\t\t// Only consider a group if it doesn't share its associations with the root endpoint\n\t\t\t\t\tmcInstance.getMaxNodesCached(ctx, endpoint, group)\n\t\t\t\t\t\t> 0\n\t\t\t\t\t&& mcInstance\n\t\t\t\t\t\t.getAllDestinationsCached(ctx, endpoint)\n\t\t\t\t\t\t.get(group)\n\t\t\t\t\t\t?.some(\n\t\t\t\t\t\t\t(addr) =>\n\t\t\t\t\t\t\t\taddr.nodeId === ownNodeId\n\t\t\t\t\t\t\t\t&& addr.endpoint === 0,\n\t\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn false;\n\t\t};\n\n\t\t// If the node was used with other controller software, there might be\n\t\t// invalid lifeline associations which cause reporting problems\n\t\tconst invalidEndpointAssociations: EndpointAddress[] = mcInstance\n\t\t\t?.getAllDestinationsCached(ctx, endpoint)\n\t\t\t.get(group)\n\t\t\t?.filter(\n\t\t\t\t(addr): addr is AssociationAddress & EndpointAddress =>\n\t\t\t\t\taddr.nodeId === ownNodeId\n\t\t\t\t\t&& addr.endpoint != undefined\n\t\t\t\t\t&& addr.endpoint !== 0,\n\t\t\t) ?? [];\n\n\t\t// Clean them up first\n\t\tif (\n\t\t\tinvalidEndpointAssociations.length > 0\n\t\t\t&& mcAPI.isSupported()\n\t\t\t&& groupSupportsMultiChannelAssociation\n\t\t) {\n\t\t\tctx.logNode(node.id, {\n\t\t\t\tendpoint: endpoint.index,\n\t\t\t\tmessage:\n\t\t\t\t\t`Found invalid lifeline associations in group #${group}, removing them...`,\n\t\t\t\tdirection: \"outbound\",\n\t\t\t});\n\t\t\tawait mcAPI.removeDestinations({\n\t\t\t\tgroupId: group,\n\t\t\t\tendpoints: invalidEndpointAssociations,\n\t\t\t});\n\t\t\t// refresh the associations - don't trust that it worked\n\t\t\tawait mcAPI.getGroup(group);\n\t\t}\n\n\t\t// Assigning the correct lifelines depends on the association kind, source endpoint and the desired strategy:\n\t\t//\n\t\t// When `mustUseMultiChannelAssociation` is `true` - Use a multi channel association (if possible), no fallback\n\t\t// When `mustUseNodeAssociation` is `true` - Use a node association (if possible), no fallback\n\t\t// Otherwise:\n\t\t// 1. Try a node association on the current endpoint/root\n\t\t// 2. If Association CC is not supported, try assigning a node association with the Multi Channel Association CC\n\t\t// 3. If that did not work, fall back to a multi channel association (target endpoint 0)\n\t\t// 4. If that did not work either, the endpoint index is >0 and the node is Z-Wave+:\n\t\t// Fall back to a multi channel association (target endpoint 0) on the root, if it doesn't have one yet.\n\n\t\tlet hasLifeline = false;\n\n\t\t// First try: node association\n\t\tif (!mustUseMultiChannelAssociation) {\n\t\t\tif (isAssignedAsNodeAssociation(endpoint)) {\n\t\t\t\t// We already have the correct association\n\t\t\t\thasLifeline = true;\n\t\t\t\tctx.logNode(node.id, {\n\t\t\t\t\tendpoint: endpoint.index,\n\t\t\t\t\tmessage:\n\t\t\t\t\t\t`Lifeline group #${group} is already assigned with a node association`,\n\t\t\t\t\tdirection: \"none\",\n\t\t\t\t});\n\t\t\t} else if (\n\t\t\t\tassocAPI.isSupported()\n\t\t\t\t// Some endpoint groups don't support having any destinations because they are shared with the root\n\t\t\t\t&& assocInstance!.getMaxNodesCached(ctx, endpoint, group)\n\t\t\t\t\t> 0\n\t\t\t) {\n\t\t\t\t// We can use a node association, but first remove any possible endpoint associations\n\t\t\t\tctx.logNode(node.id, {\n\t\t\t\t\tendpoint: endpoint.index,\n\t\t\t\t\tmessage:\n\t\t\t\t\t\t`Assigning lifeline group #${group} with a node association via Association CC...`,\n\t\t\t\t\tdirection: \"outbound\",\n\t\t\t\t});\n\t\t\t\tif (\n\t\t\t\t\tisAssignedAsEndpointAssociation(endpoint)\n\t\t\t\t\t&& mcAPI.isSupported()\n\t\t\t\t) {\n\t\t\t\t\tawait mcAPI.removeDestinations({\n\t\t\t\t\t\tgroupId: group,\n\t\t\t\t\t\tendpoints: [{ nodeId: ownNodeId, endpoint: 0 }],\n\t\t\t\t\t});\n\t\t\t\t\t// refresh the associations - don't trust that it worked\n\t\t\t\t\tawait mcAPI.getGroup(group);\n\t\t\t\t}\n\n\t\t\t\tawait assocAPI.addNodeIds(group, ownNodeId);\n\t\t\t\t// refresh the associations - don't trust that it worked\n\t\t\t\tconst groupReport = await assocAPI.getGroup(group);\n\t\t\t\thasLifeline = !!groupReport?.nodeIds.includes(ownNodeId);\n\n\t\t\t\tif (hasLifeline) {\n\t\t\t\t\tctx.logNode(node.id, {\n\t\t\t\t\t\tendpoint: endpoint.index,\n\t\t\t\t\t\tmessage:\n\t\t\t\t\t\t\t`Lifeline group #${group} was assigned with a node association via Association CC`,\n\t\t\t\t\t\tdirection: \"none\",\n\t\t\t\t\t});\n\t\t\t\t} else {\n\t\t\t\t\tctx.logNode(node.id, {\n\t\t\t\t\t\tendpoint: endpoint.index,\n\t\t\t\t\t\tmessage:\n\t\t\t\t\t\t\t`Assigning lifeline group #${group} with a node association via Association CC did not work`,\n\t\t\t\t\t\tdirection: \"none\",\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Second try: Node association using the Multi Channel Association CC\n\t\t\tif (\n\t\t\t\t!hasLifeline\n\t\t\t\t&& mcAPI.isSupported()\n\t\t\t\t&& mcInstance!.getMaxNodesCached(ctx, endpoint, group) > 0\n\t\t\t) {\n\t\t\t\t// We can use a node association, but first remove any possible endpoint associations\n\t\t\t\tctx.logNode(node.id, {\n\t\t\t\t\tendpoint: endpoint.index,\n\t\t\t\t\tmessage:\n\t\t\t\t\t\t`Assigning lifeline group #${group} with a node association via Multi Channel Association CC...`,\n\t\t\t\t\tdirection: \"outbound\",\n\t\t\t\t});\n\t\t\t\tif (isAssignedAsEndpointAssociation(endpoint)) {\n\t\t\t\t\tawait mcAPI.removeDestinations({\n\t\t\t\t\t\tgroupId: group,\n\t\t\t\t\t\tendpoints: [{ nodeId: ownNodeId, endpoint: 0 }],\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tawait mcAPI.addDestinations({\n\t\t\t\t\tgroupId: group,\n\t\t\t\t\tnodeIds: [ownNodeId],\n\t\t\t\t});\n\t\t\t\t// refresh the associations - don't trust that it worked\n\t\t\t\tconst groupReport = await mcAPI.getGroup(group);\n\t\t\t\thasLifeline = !!groupReport?.nodeIds.includes(ownNodeId);\n\n\t\t\t\tif (hasLifeline) {\n\t\t\t\t\tctx.logNode(node.id, {\n\t\t\t\t\t\tendpoint: endpoint.index,\n\t\t\t\t\t\tmessage:\n\t\t\t\t\t\t\t`Lifeline group #${group} was assigned with a node association via Multi Channel Association CC`,\n\t\t\t\t\t\tdirection: \"none\",\n\t\t\t\t\t});\n\t\t\t\t} else {\n\t\t\t\t\tctx.logNode(node.id, {\n\t\t\t\t\t\tendpoint: endpoint.index,\n\t\t\t\t\t\tmessage:\n\t\t\t\t\t\t\t`Assigning lifeline group #${group} with a node association via Multi Channel Association CC did not work`,\n\t\t\t\t\t\tdirection: \"none\",\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Third try: Use an endpoint association (target endpoint 0)\n\t\t// This is only supported starting in Multi Channel Association CC V3\n\t\tif (!hasLifeline && !mustUseNodeAssociation) {\n\t\t\tif (isAssignedAsEndpointAssociation(endpoint)) {\n\t\t\t\t// We already have the correct association\n\t\t\t\thasLifeline = true;\n\t\t\t\tctx.logNode(node.id, {\n\t\t\t\t\tendpoint: endpoint.index,\n\t\t\t\t\tmessage:\n\t\t\t\t\t\t`Lifeline group #${group} is already assigned with an endpoint association`,\n\t\t\t\t\tdirection: \"none\",\n\t\t\t\t});\n\t\t\t} else if (\n\t\t\t\tmcAPI.isSupported()\n\t\t\t\t&& mcAPI.version >= 3\n\t\t\t\t&& mcInstance!.getMaxNodesCached(ctx, endpoint, group) > 0\n\t\t\t) {\n\t\t\t\t// We can use a multi channel association, but first remove any possible node associations\n\t\t\t\tctx.logNode(node.id, {\n\t\t\t\t\tendpoint: endpoint.index,\n\t\t\t\t\tmessage:\n\t\t\t\t\t\t`Assigning lifeline group #${group} with a multi channel association...`,\n\t\t\t\t\tdirection: \"outbound\",\n\t\t\t\t});\n\t\t\t\tif (isAssignedAsNodeAssociation(endpoint)) {\n\t\t\t\t\t// It has been found that some devices don't correctly share the node associations between\n\t\t\t\t\t// Association CC and Multi Channel Association CC, so we remove the nodes from both lists\n\t\t\t\t\tawait mcAPI.removeDestinations({\n\t\t\t\t\t\tgroupId: group,\n\t\t\t\t\t\tnodeIds: [ownNodeId],\n\t\t\t\t\t});\n\t\t\t\t\tif (assocAPI.isSupported()) {\n\t\t\t\t\t\tawait assocAPI.removeNodeIds({\n\t\t\t\t\t\t\tgroupId: group,\n\t\t\t\t\t\t\tnodeIds: [ownNodeId],\n\t\t\t\t\t\t});\n\t\t\t\t\t\t// refresh the associations - don't trust that it worked\n\t\t\t\t\t\tawait assocAPI.getGroup(group);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tawait mcAPI.addDestinations({\n\t\t\t\t\tgroupId: group,\n\t\t\t\t\tendpoints: [{ nodeId: ownNodeId, endpoint: 0 }],\n\t\t\t\t});\n\t\t\t\t// refresh the associations - don't trust that it worked\n\t\t\t\tconst groupReport = await mcAPI.getGroup(group);\n\t\t\t\thasLifeline = !!groupReport?.endpoints.some(\n\t\t\t\t\t(a) => a.nodeId === ownNodeId && a.endpoint === 0,\n\t\t\t\t);\n\n\t\t\t\tif (hasLifeline) {\n\t\t\t\t\tctx.logNode(node.id, {\n\t\t\t\t\t\tendpoint: endpoint.index,\n\t\t\t\t\t\tmessage:\n\t\t\t\t\t\t\t`Lifeline group #${group} was assigned with a multi channel association`,\n\t\t\t\t\t\tdirection: \"none\",\n\t\t\t\t\t});\n\t\t\t\t} else {\n\t\t\t\t\tctx.logNode(node.id, {\n\t\t\t\t\t\tendpoint: endpoint.index,\n\t\t\t\t\t\tmessage:\n\t\t\t\t\t\t\t`Assigning lifeline group #${group} with a multi channel association did not work`,\n\t\t\t\t\t\tdirection: \"none\",\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Last attempt (actual Z-Wave+ Lifelines only): Try a multi channel association on the root.\n\t\t// Endpoint interviews happen AFTER the root interview, so this enables us to overwrite what\n\t\t// we previously configured on the root.\n\t\tif (\n\t\t\t!hasLifeline\n\t\t\t&& group === 1\n\t\t\t&& node.supportsCC(CommandClasses[\"Z-Wave Plus Info\"])\n\t\t\t&& endpoint.index > 0\n\t\t) {\n\t\t\t// But first check if the root may have a multi channel association\n\t\t\tconst rootAssocConfig = deviceConfig\n\t\t\t\t?.getAssociationConfigForEndpoint(0, group);\n\t\t\tconst rootMustUseNodeAssociation = !nodeSupportsMultiChannel\n\t\t\t\t|| rootAssocConfig?.multiChannel === false;\n\n\t\t\tctx.logNode(node.id, {\n\t\t\t\tendpoint: endpoint.index,\n\t\t\t\tmessage:\n\t\t\t\t\t`Checking root device for fallback assignment of lifeline group #${group}:\nroot supports multi channel: ${nodeSupportsMultiChannel}\nconfigured strategy: ${rootAssocConfig?.multiChannel ?? \"auto\"}\nmust use node association: ${rootMustUseNodeAssociation}`,\n\t\t\t});\n\n\t\t\tif (!rootMustUseNodeAssociation) {\n\t\t\t\tif (isAssignedAsEndpointAssociation(node)) {\n\t\t\t\t\t// We already have the correct association\n\t\t\t\t\thasLifeline = true;\n\t\t\t\t\tctx.logNode(node.id, {\n\t\t\t\t\t\tendpoint: endpoint.index,\n\t\t\t\t\t\tmessage:\n\t\t\t\t\t\t\t`Lifeline group #${group} is already assigned with a multi channel association on the root device`,\n\t\t\t\t\t\tdirection: \"none\",\n\t\t\t\t\t});\n\t\t\t\t} else {\n\t\t\t\t\tconst rootMCAPI = CCAPI.create(\n\t\t\t\t\t\tCommandClasses[\"Multi Channel Association\"],\n\t\t\t\t\t\tctx,\n\t\t\t\t\t\tnode,\n\t\t\t\t\t);\n\t\t\t\t\tconst rootAssocAPI = CCAPI.create(\n\t\t\t\t\t\tCommandClasses.Association,\n\t\t\t\t\t\tctx,\n\t\t\t\t\t\tnode,\n\t\t\t\t\t);\n\t\t\t\t\tif (rootMCAPI.isSupported()) {\n\t\t\t\t\t\tctx.logNode(node.id, {\n\t\t\t\t\t\t\tendpoint: endpoint.index,\n\t\t\t\t\t\t\tmessage:\n\t\t\t\t\t\t\t\t`Assigning lifeline group #${group} with a multi channel association on the root device...`,\n\t\t\t\t\t\t\tdirection: \"outbound\",\n\t\t\t\t\t\t});\n\t\t\t\t\t\t// Clean up node associations because they might prevent us from adding the endpoint association\n\t\t\t\t\t\tif (isAssignedAsNodeAssociation(node)) {\n\t\t\t\t\t\t\t// It has been found that some devices don't correctly share the node associations between\n\t\t\t\t\t\t\t// Association CC and Multi Channel Association CC, so we remove the nodes from both lists\n\t\t\t\t\t\t\tawait rootMCAPI.removeDestinations({\n\t\t\t\t\t\t\t\tgroupId: group,\n\t\t\t\t\t\t\t\tnodeIds: [ownNodeId],\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\tif (rootAssocAPI.isSupported()) {\n\t\t\t\t\t\t\t\tawait rootAssocAPI.removeNodeIds({\n\t\t\t\t\t\t\t\t\tgroupId: group,\n\t\t\t\t\t\t\t\t\tnodeIds: [ownNodeId],\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t// refresh the associations - don't trust that it worked\n\t\t\t\t\t\t\t\tawait rootAssocAPI.getGroup(group);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tawait rootMCAPI.addDestinations({\n\t\t\t\t\t\t\tgroupId: group,\n\t\t\t\t\t\t\tendpoints: [{ nodeId: ownNodeId, endpoint: 0 }],\n\t\t\t\t\t\t});\n\t\t\t\t\t\t// refresh the associations - don't trust that it worked\n\t\t\t\t\t\tconst groupReport = await rootMCAPI.getGroup(group);\n\t\t\t\t\t\thasLifeline = !!groupReport?.endpoints.some(\n\t\t\t\t\t\t\t(a) => a.nodeId === ownNodeId && a.endpoint === 0,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (!hasLifeline) {\n\t\t\tctx.logNode(node.id, {\n\t\t\t\tendpoint: endpoint.index,\n\t\t\t\tmessage:\n\t\t\t\t\t`All attempts to assign lifeline group #${group} failed, skipping...`,\n\t\t\t\tdirection: \"none\",\n\t\t\t\tlevel: \"warn\",\n\t\t\t});\n\t\t}\n\t}\n\n\t// Remember that we did the association assignment\n\tvalueDB.setValue(\n\t\tAssociationCCValues.hasLifeline.endpoint(endpoint.index),\n\t\ttrue,\n\t);\n}\n\nexport async function assignLifelineIssueingCommand(\n\tctx: CCAPIHost<\n\t\t& CCAPINode\n\t\t& SupportsCC\n\t\t& ControlsCC\n\t\t& GetEndpoint<EndpointId & SupportsCC>\n\t\t& QuerySecurityClasses\n\t>,\n\tendpoint: EndpointId,\n\tccId: CommandClasses,\n\tccCommand: number,\n): Promise<void> {\n\tconst node = ctx.getNodeOrThrow(endpoint.nodeId);\n\tif (\n\t\tnode.supportsCC(CommandClasses[\"Association Group Information\"])\n\t\t&& (node.supportsCC(CommandClasses.Association)\n\t\t\t|| node.supportsCC(CommandClasses[\"Multi Channel Association\"]))\n\t) {\n\t\tconst groupsIssueingNotifications = AssociationGroupInfoCC\n\t\t\t.findGroupsForIssuedCommand(\n\t\t\t\tctx,\n\t\t\t\tnode,\n\t\t\t\tccId,\n\t\t\t\tccCommand,\n\t\t\t);\n\t\tif (groupsIssueingNotifications.length > 0) {\n\t\t\t// We always grab the first group - usually it should be the lifeline\n\t\t\tconst groupId = groupsIssueingNotifications[0];\n\t\t\tconst existingAssociations = getAssociations(ctx, node).get(groupId)\n\t\t\t\t?? [];\n\n\t\t\tif (\n\t\t\t\t!existingAssociations.some(\n\t\t\t\t\t(a) => a.nodeId === ctx.ownNodeId,\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tctx.logNode(node.id, {\n\t\t\t\t\tendpoint: endpoint.index,\n\t\t\t\t\tmessage: `Configuring associations to receive ${\n\t\t\t\t\t\tgetCCName(\n\t\t\t\t\t\t\tccId,\n\t\t\t\t\t\t)\n\t\t\t\t\t} commands...`,\n\t\t\t\t\tdirection: \"outbound\",\n\t\t\t\t});\n\t\t\t\tawait addAssociations(ctx, node, groupId, [\n\t\t\t\t\t{ nodeId: ctx.ownNodeId },\n\t\t\t\t]);\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport function doesAnyLifelineSendActuatorOrSensorReports(\n\tctx: GetValueDB & GetDeviceConfig,\n\tnode: NodeId & SupportsCC,\n): MaybeNotKnown<boolean> {\n\t// No association support means no unsolicited reports\n\tif (\n\t\t!node.supportsCC(CommandClasses.Association)\n\t\t&& !node.supportsCC(CommandClasses[\"Multi Channel Association\"])\n\t) {\n\t\treturn false;\n\t}\n\n\t// No AGI support means we cannot know\n\tif (!node.supportsCC(CommandClasses[\"Association Group Information\"])) {\n\t\treturn NOT_KNOWN;\n\t}\n\n\t// Lifeline group IDs include the ones we added via a config file, so they may not be considered true lifelines\n\tconst lifelineGroupIds = getLifelineGroupIds(ctx, node);\n\t// If any potential lifeline group has the \"General: Lifeline\" profile, the node MUST send unsolicited reports that way\n\tif (\n\t\tlifelineGroupIds.some(\n\t\t\t(id) =>\n\t\t\t\tAssociationGroupInfoCC.getGroupProfileCached(\n\t\t\t\t\tctx,\n\t\t\t\t\tnode,\n\t\t\t\t\tid,\n\t\t\t\t) === AssociationGroupInfoProfile[\"General: Lifeline\"],\n\t\t)\n\t) {\n\t\treturn true;\n\t}\n\n\t// Otherwise check if any of the groups sends any actuator or sensor commands. We'll assume that those are reports\n\tfor (const groupId of lifelineGroupIds) {\n\t\tconst issuedCommands = AssociationGroupInfoCC.getIssuedCommandsCached(\n\t\t\tctx,\n\t\t\tnode,\n\t\t\tgroupId,\n\t\t);\n\t\tif (!issuedCommands) continue;\n\t\tconst commands = [...issuedCommands.keys()];\n\t\tif (commands.some((c) => isActuatorCC(c) || isSensorCC(c))) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\treturn false;\n}\n"],
4
+ "sourcesContent": ["import type { AssociationConfig } from \"@zwave-js/config\";\nimport {\n\tCommandClasses,\n\ttype ControlsCC,\n\ttype EndpointId,\n\ttype GetAllEndpoints,\n\ttype GetEndpoint,\n\ttype MaybeNotKnown,\n\tNOT_KNOWN,\n\ttype NodeId,\n\ttype QuerySecurityClasses,\n\tSecurityClass,\n\ttype SupportsCC,\n\tZWaveError,\n\tZWaveErrorCodes,\n\tactuatorCCs,\n\tgetCCName,\n\tisActuatorCC,\n\tisLongRangeNodeId,\n\tisSensorCC,\n} from \"@zwave-js/core/safe\";\nimport {\n\ttype GetDeviceConfig,\n\ttype GetNode,\n\ttype GetValueDB,\n\ttype HostIDs,\n} from \"@zwave-js/host\";\nimport {\n\tObjectKeyMap,\n\ttype ReadonlyObjectKeyMap,\n\tgetEnumMemberName,\n} from \"@zwave-js/shared/safe\";\nimport { distinct } from \"alcalzone-shared/arrays\";\nimport { AssociationCC, AssociationCCValues } from \"../cc/AssociationCC.js\";\nimport { AssociationGroupInfoCC } from \"../cc/AssociationGroupInfoCC.js\";\nimport { MultiChannelAssociationCC } from \"../cc/MultiChannelAssociationCC.js\";\nimport { CCAPI, type CCAPIHost, type CCAPINode } from \"./API.js\";\nimport {\n\ttype AssociationAddress,\n\tAssociationCheckResult,\n\ttype AssociationGroup,\n\tAssociationGroupInfoProfile,\n\ttype EndpointAddress,\n} from \"./_Types.js\";\n\nexport function getAssociations(\n\tctx: GetValueDB,\n\tendpoint: EndpointId & SupportsCC,\n): ReadonlyMap<number, readonly AssociationAddress[]> {\n\tconst ret = new Map<number, readonly AssociationAddress[]>();\n\n\tif (endpoint.supportsCC(CommandClasses.Association)) {\n\t\tconst destinations = AssociationCC.getAllDestinationsCached(\n\t\t\tctx,\n\t\t\tendpoint,\n\t\t);\n\t\tfor (const [groupId, assocs] of destinations) {\n\t\t\tret.set(groupId, assocs);\n\t\t}\n\t} else {\n\t\tthrow new ZWaveError(\n\t\t\t`Node ${endpoint.nodeId}${\n\t\t\t\tendpoint.index > 0 ? `, endpoint ${endpoint.index}` : \"\"\n\t\t\t} does not support associations!`,\n\t\t\tZWaveErrorCodes.CC_NotSupported,\n\t\t);\n\t}\n\n\t// Merge the \"normal\" destinations with multi channel destinations\n\tif (endpoint.supportsCC(CommandClasses[\"Multi Channel Association\"])) {\n\t\tconst destinations = MultiChannelAssociationCC.getAllDestinationsCached(\n\t\t\tctx,\n\t\t\tendpoint,\n\t\t);\n\t\tfor (const [groupId, assocs] of destinations) {\n\t\t\tif (ret.has(groupId)) {\n\t\t\t\tconst normalAssociations = ret.get(groupId)!;\n\t\t\t\tret.set(groupId, [\n\t\t\t\t\t...normalAssociations,\n\t\t\t\t\t// Eliminate potential duplicates\n\t\t\t\t\t...assocs.filter(\n\t\t\t\t\t\t(a1) =>\n\t\t\t\t\t\t\t!normalAssociations.some(\n\t\t\t\t\t\t\t\t(a2) =>\n\t\t\t\t\t\t\t\t\ta1.nodeId === a2.nodeId\n\t\t\t\t\t\t\t\t\t&& a1.endpoint === a2.endpoint,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t),\n\t\t\t\t]);\n\t\t\t} else {\n\t\t\t\tret.set(groupId, assocs);\n\t\t\t}\n\t\t}\n\t}\n\n\treturn ret;\n}\n\nexport function getAllAssociations(\n\tctx: GetValueDB,\n\tnode: NodeId & GetAllEndpoints<EndpointId & SupportsCC>,\n): ReadonlyObjectKeyMap<\n\tAssociationAddress,\n\tReadonlyMap<number, readonly AssociationAddress[]>\n> {\n\tconst ret = new ObjectKeyMap<\n\t\tAssociationAddress,\n\t\tReadonlyMap<number, readonly AssociationAddress[]>\n\t>();\n\tfor (const endpoint of node.getAllEndpoints()) {\n\t\tconst address: AssociationAddress = {\n\t\t\tnodeId: node.id,\n\t\t\tendpoint: endpoint.index,\n\t\t};\n\t\tif (endpoint.supportsCC(CommandClasses.Association)) {\n\t\t\tret.set(address, getAssociations(ctx, endpoint));\n\t\t}\n\t}\n\treturn ret;\n}\n\nexport function checkAssociation(\n\tctx:\n\t\t& HostIDs\n\t\t& GetValueDB\n\t\t& GetNode<\n\t\t\t& NodeId\n\t\t\t& SupportsCC\n\t\t\t& GetEndpoint<EndpointId & SupportsCC>\n\t\t\t& QuerySecurityClasses\n\t\t>,\n\tendpoint: EndpointId & SupportsCC & ControlsCC,\n\tgroup: number,\n\tdestination: AssociationAddress,\n): AssociationCheckResult {\n\t// Check that the target endpoint exists except when adding an association to the controller\n\tconst targetNode = ctx.getNodeOrThrow(destination.nodeId);\n\tconst targetEndpoint = destination.nodeId === ctx.ownNodeId\n\t\t? targetNode\n\t\t: targetNode.getEndpointOrThrow(destination.endpoint ?? 0);\n\n\tif (\n\t\t!endpoint.supportsCC(CommandClasses.Association)\n\t\t&& !endpoint.supportsCC(CommandClasses[\"Multi Channel Association\"])\n\t) {\n\t\tthrow new ZWaveError(\n\t\t\t`Node ${endpoint.nodeId}${\n\t\t\t\tendpoint.index > 0 ? `, endpoint ${endpoint.index}` : \"\"\n\t\t\t} does not support associations!`,\n\t\t\tZWaveErrorCodes.CC_NotSupported,\n\t\t);\n\t}\n\n\t// Associations to and from ZWLR devices are not allowed\n\tif (isLongRangeNodeId(destination.nodeId)) {\n\t\treturn AssociationCheckResult.Forbidden_DestinationIsLongRange;\n\t} else if (isLongRangeNodeId(endpoint.nodeId)) {\n\t\t// Except the lifeline back to the host\n\t\tif (group !== 1 || destination.nodeId !== ctx.ownNodeId) {\n\t\t\treturn AssociationCheckResult.Forbidden_SourceIsLongRange;\n\t\t}\n\t}\n\n\t// The following checks don't apply to Lifeline associations\n\tif (destination.nodeId === ctx.ownNodeId) {\n\t\treturn AssociationCheckResult.OK;\n\t}\n\n\t// Disallow self-associations\n\tif (destination.nodeId === endpoint.nodeId) {\n\t\treturn AssociationCheckResult.Forbidden_SelfAssociation;\n\t}\n\n\t// For Association version 1 and version 2 / MCA version 1-3:\n\t// A controlling node MUST NOT associate Node A to a Node B destination\n\t// if Node A and Node B\u2019s highest Security Class are not identical.\n\t// For Association version 3 / MCA version 4:\n\t// A controlling node MUST NOT associate Node A to a Node B destination\n\t// if Node A was not granted Node B\u2019s highest Security Class.\n\n\tconst sourceNode = ctx.getNode(endpoint.nodeId)!;\n\tlet securityClassMustMatch: boolean;\n\tif (destination.endpoint == undefined) {\n\t\t// \"normal\" association\n\t\tconst sourceNodeCCVersion = endpoint.getCCVersion(\n\t\t\tCommandClasses.Association,\n\t\t);\n\t\tsecurityClassMustMatch = sourceNodeCCVersion < 3;\n\t} else {\n\t\t// multi channel association\n\t\tconst sourceNodeCCVersion = endpoint.getCCVersion(\n\t\t\tCommandClasses[\"Multi Channel Association\"],\n\t\t);\n\t\tsecurityClassMustMatch = sourceNodeCCVersion < 4;\n\t}\n\n\tconst sourceSecurityClass = sourceNode.getHighestSecurityClass();\n\tconst targetSecurityClass = targetNode.getHighestSecurityClass();\n\n\t// If the security classes are unknown, all bets are off\n\tif (sourceSecurityClass != undefined && targetSecurityClass != undefined) {\n\t\tif (\n\t\t\tsecurityClassMustMatch\n\t\t\t&& sourceSecurityClass !== targetSecurityClass\n\t\t) {\n\t\t\treturn AssociationCheckResult.Forbidden_SecurityClassMismatch;\n\t\t} else if (\n\t\t\t// Commands to insecure nodes are allowed\n\t\t\ttargetSecurityClass !== SecurityClass.None\n\t\t\t// Otherwise, the sender must know the target's highest key\n\t\t\t&& !securityClassMustMatch\n\t\t\t&& !sourceNode.hasSecurityClass(targetSecurityClass)\n\t\t) {\n\t\t\treturn AssociationCheckResult\n\t\t\t\t.Forbidden_DestinationSecurityClassNotGranted;\n\t\t}\n\t}\n\n\t// SDS14223:\n\t// A controlling node MUST NOT associate Node A to a Node B destination that does not support\n\t// the Command Class that the Node A will be controlling\n\t//\n\t// To determine this, the node must support the AGI CC or we have no way of knowing which\n\t// CCs the node will control\n\tif (!endpoint.supportsCC(CommandClasses[\"Association Group Information\"])) {\n\t\treturn AssociationCheckResult.OK;\n\t}\n\n\tconst groupCommandList = AssociationGroupInfoCC.getIssuedCommandsCached(\n\t\tctx,\n\t\tendpoint,\n\t\tgroup,\n\t);\n\tif (!groupCommandList || !groupCommandList.size) {\n\t\t// We don't know which CCs this group controls, just allow it\n\t\treturn AssociationCheckResult.OK;\n\t}\n\tconst groupCCs = [...groupCommandList.keys()];\n\n\t// A controlling node MAY create an association to a destination supporting an\n\t// actuator Command Class if the actual association group sends Basic Control Command Class.\n\tif (\n\t\tgroupCCs.includes(CommandClasses.Basic)\n\t\t&& actuatorCCs.some((cc) => targetEndpoint?.supportsCC(cc))\n\t) {\n\t\treturn AssociationCheckResult.OK;\n\t}\n\n\t// Enforce that at least one issued CC is supported\n\tif (groupCCs.some((cc) => targetEndpoint?.supportsCC(cc))) {\n\t\treturn AssociationCheckResult.OK;\n\t} else {\n\t\treturn AssociationCheckResult.Forbidden_NoSupportedCCs;\n\t}\n}\n\nexport function getAssociationGroups(\n\tctx: GetValueDB & GetDeviceConfig,\n\tendpoint: EndpointId & SupportsCC,\n): ReadonlyMap<number, AssociationGroup> {\n\t// Check whether we have multi channel support or not\n\tlet assocInstance: typeof AssociationCC;\n\tlet mcInstance: typeof MultiChannelAssociationCC | undefined;\n\tif (endpoint.supportsCC(CommandClasses.Association)) {\n\t\tassocInstance = AssociationCC;\n\t} else {\n\t\tthrow new ZWaveError(\n\t\t\t`Node ${endpoint.nodeId}${\n\t\t\t\tendpoint.index > 0 ? `, endpoint ${endpoint.index}` : \"\"\n\t\t\t} does not support associations!`,\n\t\t\tZWaveErrorCodes.CC_NotSupported,\n\t\t);\n\t}\n\tif (endpoint.supportsCC(CommandClasses[\"Multi Channel Association\"])) {\n\t\tmcInstance = MultiChannelAssociationCC;\n\t}\n\n\tconst assocGroupCount = assocInstance.getGroupCountCached(ctx, endpoint)\n\t\t?? 0;\n\tconst mcGroupCount = mcInstance?.getGroupCountCached(ctx, endpoint)\n\t\t?? 0;\n\tconst groupCount = Math.max(assocGroupCount, mcGroupCount);\n\n\tconst deviceConfig = ctx.getDeviceConfig?.(endpoint.nodeId);\n\n\tconst ret = new Map<number, AssociationGroup>();\n\n\tif (endpoint.supportsCC(CommandClasses[\"Association Group Information\"])) {\n\t\t// We can read all information we need from the AGI CC\n\t\tconst agiInstance = AssociationGroupInfoCC;\n\t\tfor (let group = 1; group <= groupCount; group++) {\n\t\t\tconst assocConfig = deviceConfig?.getAssociationConfigForEndpoint(\n\t\t\t\tendpoint.index,\n\t\t\t\tgroup,\n\t\t\t);\n\t\t\tconst multiChannel = !!mcInstance && group <= mcGroupCount;\n\t\t\tret.set(group, {\n\t\t\t\tmaxNodes: (multiChannel\n\t\t\t\t\t? mcInstance!\n\t\t\t\t\t: assocInstance).getMaxNodesCached(\n\t\t\t\t\t\tctx,\n\t\t\t\t\t\tendpoint,\n\t\t\t\t\t\tgroup,\n\t\t\t\t\t) || 1,\n\t\t\t\t// AGI implies Z-Wave+ where group 1 is the lifeline\n\t\t\t\tisLifeline: group === 1,\n\t\t\t\tlabel:\n\t\t\t\t\t// prefer the configured label if we have one\n\t\t\t\t\tassocConfig?.label\n\t\t\t\t\t\t// the ones reported by AGI are sometimes pretty bad\n\t\t\t\t\t\t?? agiInstance.getGroupNameCached(\n\t\t\t\t\t\t\tctx,\n\t\t\t\t\t\t\tendpoint,\n\t\t\t\t\t\t\tgroup,\n\t\t\t\t\t\t)\n\t\t\t\t\t\t// but still better than \"unnamed\"\n\t\t\t\t\t\t?? `Unnamed group ${group}`,\n\t\t\t\tmultiChannel,\n\t\t\t\tprofile: agiInstance.getGroupProfileCached(\n\t\t\t\t\tctx,\n\t\t\t\t\tendpoint,\n\t\t\t\t\tgroup,\n\t\t\t\t),\n\t\t\t\tissuedCommands: agiInstance.getIssuedCommandsCached(\n\t\t\t\t\tctx,\n\t\t\t\t\tendpoint,\n\t\t\t\t\tgroup,\n\t\t\t\t),\n\t\t\t});\n\t\t}\n\t} else {\n\t\t// we need to consult the device config\n\t\tfor (let group = 1; group <= groupCount; group++) {\n\t\t\tconst assocConfig = deviceConfig?.getAssociationConfigForEndpoint(\n\t\t\t\tendpoint.index,\n\t\t\t\tgroup,\n\t\t\t);\n\t\t\tconst multiChannel = !!mcInstance && group <= mcGroupCount;\n\t\t\tret.set(group, {\n\t\t\t\tmaxNodes: (multiChannel\n\t\t\t\t\t? mcInstance!\n\t\t\t\t\t: assocInstance).getMaxNodesCached(\n\t\t\t\t\t\tctx,\n\t\t\t\t\t\tendpoint,\n\t\t\t\t\t\tgroup,\n\t\t\t\t\t)\n\t\t\t\t\t|| assocConfig?.maxNodes\n\t\t\t\t\t|| 1,\n\t\t\t\tisLifeline: assocConfig?.isLifeline ?? group === 1,\n\t\t\t\tlabel: assocConfig?.label ?? `Unnamed group ${group}`,\n\t\t\t\tmultiChannel,\n\t\t\t});\n\t\t}\n\t}\n\treturn ret;\n}\n\nexport function getAllAssociationGroups(\n\tctx: GetValueDB & GetDeviceConfig,\n\tnode: NodeId & GetAllEndpoints<EndpointId & SupportsCC>,\n): ReadonlyMap<number, ReadonlyMap<number, AssociationGroup>> {\n\tconst ret = new Map<number, ReadonlyMap<number, AssociationGroup>>();\n\tfor (const endpoint of node.getAllEndpoints()) {\n\t\tif (endpoint.supportsCC(CommandClasses.Association)) {\n\t\t\tret.set(endpoint.index, getAssociationGroups(ctx, endpoint));\n\t\t}\n\t}\n\treturn ret;\n}\n\nexport async function addAssociations(\n\tctx: CCAPIHost<\n\t\t& CCAPINode\n\t\t& SupportsCC\n\t\t& GetEndpoint<EndpointId & SupportsCC>\n\t\t& QuerySecurityClasses\n\t>,\n\tendpoint: EndpointId & SupportsCC & ControlsCC,\n\tgroup: number,\n\tdestinations: AssociationAddress[],\n): Promise<void> {\n\tconst nodeAndEndpointString = `${endpoint.nodeId}${\n\t\tendpoint.index > 0 ? `, endpoint ${endpoint.index}` : \"\"\n\t}`;\n\n\t// Check whether we should add any associations the device does not have support for\n\tlet assocInstance: typeof AssociationCC | undefined;\n\tlet mcInstance: typeof MultiChannelAssociationCC | undefined;\n\t// Split associations into conventional and endpoint associations\n\tconst nodeAssociations = distinct(\n\t\tdestinations\n\t\t\t.filter((a) => a.endpoint == undefined)\n\t\t\t.map((a) => a.nodeId),\n\t);\n\tconst endpointAssociations = destinations.filter(\n\t\t(a) => a.endpoint != undefined,\n\t) as EndpointAddress[];\n\n\tif (endpoint.supportsCC(CommandClasses.Association)) {\n\t\tassocInstance = AssociationCC;\n\t} else if (nodeAssociations.length > 0) {\n\t\tthrow new ZWaveError(\n\t\t\t`Node ${nodeAndEndpointString} does not support associations!`,\n\t\t\tZWaveErrorCodes.CC_NotSupported,\n\t\t);\n\t}\n\tif (endpoint.supportsCC(CommandClasses[\"Multi Channel Association\"])) {\n\t\tmcInstance = MultiChannelAssociationCC;\n\t} else if (endpointAssociations.length > 0) {\n\t\tthrow new ZWaveError(\n\t\t\t`Node ${nodeAndEndpointString} does not support multi channel associations!`,\n\t\t\tZWaveErrorCodes.CC_NotSupported,\n\t\t);\n\t}\n\n\t// Disallow associating a node with itself. This is technically checked as part of\n\t// checkAssociations, but here we provide a better error message.\n\tconst selfAssociations = destinations.filter((d) =>\n\t\td.nodeId === endpoint.nodeId\n\t);\n\tif (selfAssociations.length > 0) {\n\t\tthrow new ZWaveError(\n\t\t\t`Associating a node with itself is not allowed!`,\n\t\t\tZWaveErrorCodes.AssociationCC_NotAllowed,\n\t\t\tselfAssociations.map((a) => ({\n\t\t\t\t...a,\n\t\t\t\tcheckResult: AssociationCheckResult.Forbidden_SelfAssociation,\n\t\t\t})),\n\t\t);\n\t}\n\n\tconst assocGroupCount = assocInstance?.getGroupCountCached(ctx, endpoint)\n\t\t?? 0;\n\tconst mcGroupCount = mcInstance?.getGroupCountCached(ctx, endpoint)\n\t\t?? 0;\n\tconst groupCount = Math.max(assocGroupCount, mcGroupCount);\n\tif (group > groupCount) {\n\t\tthrow new ZWaveError(\n\t\t\t`Group ${group} does not exist on node ${nodeAndEndpointString}`,\n\t\t\tZWaveErrorCodes.AssociationCC_InvalidGroup,\n\t\t);\n\t}\n\n\tconst deviceConfig = ctx.getDeviceConfig?.(endpoint.nodeId);\n\n\tconst groupIsMultiChannel = !!mcInstance\n\t\t&& group <= mcGroupCount\n\t\t&& deviceConfig?.associations?.get(group)?.multiChannel !== false;\n\n\tif (groupIsMultiChannel) {\n\t\t// Check that all associations are allowed\n\t\tconst disallowedAssociations = destinations.map(\n\t\t\t(a) => ({\n\t\t\t\t...a,\n\t\t\t\tcheckResult: checkAssociation(ctx, endpoint, group, a),\n\t\t\t}),\n\t\t).filter(({ checkResult }) =>\n\t\t\tcheckResult !== AssociationCheckResult.OK\n\t\t);\n\t\tif (disallowedAssociations.length) {\n\t\t\tlet message = `The following associations are not allowed:`;\n\t\t\tmessage += disallowedAssociations\n\t\t\t\t.map(\n\t\t\t\t\t(a) =>\n\t\t\t\t\t\t`\\n\u00B7 Node ${a.nodeId}${\n\t\t\t\t\t\t\ta.endpoint ? `, endpoint ${a.endpoint}` : \"\"\n\t\t\t\t\t\t}: ${\n\t\t\t\t\t\t\tgetEnumMemberName(\n\t\t\t\t\t\t\t\tAssociationCheckResult,\n\t\t\t\t\t\t\t\ta.checkResult,\n\t\t\t\t\t\t\t).replace(\"Forbidden_\", \"\")\n\t\t\t\t\t\t}`,\n\t\t\t\t)\n\t\t\t\t.join(\"\");\n\t\t\tthrow new ZWaveError(\n\t\t\t\tmessage,\n\t\t\t\tZWaveErrorCodes.AssociationCC_NotAllowed,\n\t\t\t\tdisallowedAssociations,\n\t\t\t);\n\t\t}\n\n\t\t// And add them\n\t\tconst api = CCAPI.create(\n\t\t\tCommandClasses[\"Multi Channel Association\"],\n\t\t\tctx,\n\t\t\tendpoint,\n\t\t);\n\t\tawait api.addDestinations({\n\t\t\tgroupId: group,\n\t\t\tnodeIds: nodeAssociations,\n\t\t\tendpoints: endpointAssociations,\n\t\t});\n\t\t// Refresh the association list\n\t\tawait api.getGroup(group);\n\t} else {\n\t\t// Although the node supports multi channel associations, this group only supports \"normal\" associations\n\t\tif (destinations.some((a) => a.endpoint != undefined)) {\n\t\t\tthrow new ZWaveError(\n\t\t\t\t`Node ${nodeAndEndpointString}, group ${group} does not support multi channel associations!`,\n\t\t\t\tZWaveErrorCodes.CC_NotSupported,\n\t\t\t);\n\t\t}\n\n\t\t// Check that all associations are allowed\n\t\tconst disallowedAssociations = destinations.map(\n\t\t\t(a) => ({\n\t\t\t\t...a,\n\t\t\t\tcheckResult: checkAssociation(ctx, endpoint, group, a),\n\t\t\t}),\n\t\t).filter(({ checkResult }) =>\n\t\t\tcheckResult !== AssociationCheckResult.OK\n\t\t);\n\t\tif (disallowedAssociations.length) {\n\t\t\tlet message =\n\t\t\t\t`The associations to the following nodes are not allowed`;\n\t\t\tmessage += disallowedAssociations\n\t\t\t\t.map(\n\t\t\t\t\t(a) =>\n\t\t\t\t\t\t`\\n\u00B7 Node ${a.nodeId}: ${\n\t\t\t\t\t\t\tgetEnumMemberName(\n\t\t\t\t\t\t\t\tAssociationCheckResult,\n\t\t\t\t\t\t\t\ta.checkResult,\n\t\t\t\t\t\t\t).replace(\"Forbidden_\", \"\")\n\t\t\t\t\t\t}`,\n\t\t\t\t)\n\t\t\t\t.join(\"\");\n\n\t\t\tthrow new ZWaveError(\n\t\t\t\tmessage,\n\t\t\t\tZWaveErrorCodes.AssociationCC_NotAllowed,\n\t\t\t\tdisallowedAssociations,\n\t\t\t);\n\t\t}\n\n\t\tconst api = CCAPI.create(\n\t\t\tCommandClasses.Association,\n\t\t\tctx,\n\t\t\tendpoint,\n\t\t);\n\t\tawait api.addNodeIds(group, ...destinations.map((a) => a.nodeId));\n\t\t// Refresh the association list\n\t\tawait api.getGroup(group);\n\t}\n}\n\nexport async function removeAssociations(\n\tctx: CCAPIHost,\n\tendpoint: EndpointId & SupportsCC & ControlsCC,\n\tgroup: number,\n\tdestinations: AssociationAddress[],\n): Promise<void> {\n\tconst nodeAndEndpointString = `${endpoint.nodeId}${\n\t\tendpoint.index > 0 ? `, endpoint ${endpoint.index}` : \"\"\n\t}`;\n\n\t// Split associations into conventional and endpoint associations\n\tconst nodeAssociations = distinct(\n\t\tdestinations\n\t\t\t.filter((a) => a.endpoint == undefined)\n\t\t\t.map((a) => a.nodeId),\n\t);\n\tconst endpointAssociations = destinations.filter(\n\t\t(a) => a.endpoint != undefined,\n\t) as EndpointAddress[];\n\n\t// Removing associations is not either/or - we could have a device with duplicated associations between\n\t// Association CC and Multi Channel Association CC\n\t// Figure out what we need to use to remove the associations\n\n\tlet groupExistsAsMultiChannel = false;\n\tlet groupExistsAsNodeAssociation = false;\n\n\tlet mcInstance: typeof MultiChannelAssociationCC | undefined;\n\tlet assocInstance: typeof AssociationCC | undefined;\n\n\t// To remove a multi channel association, we need to make sure that the group exists\n\t// and the node supports multi channel associations\n\tif (endpoint.supportsCC(CommandClasses[\"Multi Channel Association\"])) {\n\t\tmcInstance = MultiChannelAssociationCC;\n\t\tif (group <= mcInstance.getGroupCountCached(ctx, endpoint)) {\n\t\t\tgroupExistsAsMultiChannel = true;\n\t\t}\n\t} else if (endpointAssociations.length > 0) {\n\t\tthrow new ZWaveError(\n\t\t\t`Node ${nodeAndEndpointString} does not support multi channel associations!`,\n\t\t\tZWaveErrorCodes.CC_NotSupported,\n\t\t);\n\t}\n\n\t// To remove a normal association, we need to make sure that the group exists either as a normal association\n\t// or as a multi channel association\n\tif (endpoint.supportsCC(CommandClasses.Association)) {\n\t\tassocInstance = AssociationCC;\n\t\tif (group <= assocInstance.getGroupCountCached(ctx, endpoint)) {\n\t\t\tgroupExistsAsNodeAssociation = true;\n\t\t}\n\t}\n\n\tif (!mcInstance && !assocInstance) {\n\t\tthrow new ZWaveError(\n\t\t\t`Node ${nodeAndEndpointString} does not support associations!`,\n\t\t\tZWaveErrorCodes.CC_NotSupported,\n\t\t);\n\t}\n\n\t// Ensure the group exists and can be used\n\tif (!groupExistsAsMultiChannel && !groupExistsAsNodeAssociation) {\n\t\tthrow new ZWaveError(\n\t\t\t` Association group ${group} does not exist for node ${nodeAndEndpointString}`,\n\t\t\tZWaveErrorCodes.AssociationCC_InvalidGroup,\n\t\t);\n\t}\n\tif (endpointAssociations.length > 0 && !groupExistsAsMultiChannel) {\n\t\tthrow new ZWaveError(\n\t\t\t`Node ${nodeAndEndpointString}, association group ${group} does not support multi channel associations!`,\n\t\t\tZWaveErrorCodes.AssociationCC_InvalidGroup,\n\t\t);\n\t}\n\n\t// Even if we only remove node associations, we use both CCs since it has been found that some\n\t// devices do not correctly share the node list between the two commands\n\tif (\n\t\tassocInstance\n\t\t&& nodeAssociations.length > 0\n\t\t&& groupExistsAsNodeAssociation\n\t) {\n\t\tconst api = CCAPI.create(\n\t\t\tCommandClasses.Association,\n\t\t\tctx,\n\t\t\tendpoint,\n\t\t);\n\t\tawait api.removeNodeIds({\n\t\t\tgroupId: group,\n\t\t\tnodeIds: nodeAssociations,\n\t\t});\n\t\t// Refresh the association list\n\t\tawait api.getGroup(group);\n\t}\n\n\tif (mcInstance && groupExistsAsMultiChannel) {\n\t\tconst api = CCAPI.create(\n\t\t\tCommandClasses[\"Multi Channel Association\"],\n\t\t\tctx,\n\t\t\tendpoint,\n\t\t);\n\t\tawait api.removeDestinations({\n\t\t\tgroupId: group,\n\t\t\tnodeIds: nodeAssociations,\n\t\t\tendpoints: endpointAssociations,\n\t\t});\n\t\t// Refresh the multi channel association list\n\t\tawait api.getGroup(group);\n\t}\n}\n\nexport function getLifelineGroupIds(\n\tctx: GetValueDB & GetDeviceConfig,\n\tendpoint: EndpointId & SupportsCC,\n): number[] {\n\t// For now only support this for the root endpoint - i.e. node\n\tif (endpoint.index > 0) return [];\n\n\t// Some nodes define multiple lifeline groups, so we need to assign us to\n\t// all of them\n\tconst lifelineGroups: number[] = [];\n\n\t// If the target node supports Z-Wave+ info that means the lifeline MUST be group #1\n\tif (endpoint.supportsCC(CommandClasses[\"Z-Wave Plus Info\"])) {\n\t\tlifelineGroups.push(1);\n\t}\n\n\t// We have a device config file that tells us which (additional) association to assign\n\tlet associations: ReadonlyMap<number, AssociationConfig> | undefined;\n\tconst deviceConfig = ctx.getDeviceConfig?.(endpoint.nodeId);\n\tif (endpoint.index === 0) {\n\t\t// The root endpoint's associations may be configured separately or as part of \"endpoints\"\n\t\tassociations = deviceConfig?.associations\n\t\t\t?? deviceConfig?.endpoints?.get(0)?.associations;\n\t} else {\n\t\t// The other endpoints can only have a configuration as part of \"endpoints\"\n\t\tassociations = deviceConfig?.endpoints?.get(\n\t\t\tendpoint.index,\n\t\t)?.associations;\n\t}\n\n\tif (associations?.size) {\n\t\tlifelineGroups.push(\n\t\t\t...[...associations.values()]\n\t\t\t\t.filter((a) => a.isLifeline)\n\t\t\t\t.map((a) => a.groupId),\n\t\t);\n\t}\n\n\treturn distinct(lifelineGroups).sort();\n}\n\nexport async function configureLifelineAssociations(\n\tctx: CCAPIHost<\n\t\t& CCAPINode\n\t\t& SupportsCC\n\t\t& ControlsCC\n\t\t& GetAllEndpoints<EndpointId & SupportsCC & ControlsCC>\n\t>,\n\tendpoint: EndpointId & SupportsCC & ControlsCC,\n): Promise<void> {\n\t// Assign the controller to all lifeline groups\n\tconst ownNodeId = ctx.ownNodeId;\n\tconst node = ctx.getNodeOrThrow(endpoint.nodeId);\n\tconst valueDB = ctx.getValueDB(node.id);\n\tconst deviceConfig = ctx.getDeviceConfig?.(node.id);\n\n\t// We check if a node supports Multi Channel CC before creating Multi Channel Lifeline Associations (#1109)\n\tconst nodeSupportsMultiChannel = node.supportsCC(\n\t\tCommandClasses[\"Multi Channel\"],\n\t);\n\n\tlet assocInstance: typeof AssociationCC | undefined;\n\tconst assocAPI = CCAPI.create(\n\t\tCommandClasses.Association,\n\t\tctx,\n\t\tendpoint,\n\t);\n\tif (endpoint.supportsCC(CommandClasses.Association)) {\n\t\tassocInstance = AssociationCC;\n\t}\n\n\tlet mcInstance: typeof MultiChannelAssociationCC | undefined;\n\tlet mcGroupCount = 0;\n\tconst mcAPI = CCAPI.create(\n\t\tCommandClasses[\"Multi Channel Association\"],\n\t\tctx,\n\t\tendpoint,\n\t);\n\tif (endpoint.supportsCC(CommandClasses[\"Multi Channel Association\"])) {\n\t\tmcInstance = MultiChannelAssociationCC;\n\t\tmcGroupCount = mcInstance.getGroupCountCached(ctx, endpoint) ?? 0;\n\t}\n\n\tconst lifelineGroups = getLifelineGroupIds(ctx, node);\n\tif (lifelineGroups.length === 0) {\n\t\t// We can look for the General Lifeline AGI profile as a last resort\n\t\tif (\n\t\t\tendpoint.supportsCC(CommandClasses[\"Association Group Information\"])\n\t\t) {\n\t\t\tconst agiAPI = CCAPI.create(\n\t\t\t\tCommandClasses[\"Association Group Information\"],\n\t\t\t\tctx,\n\t\t\t\tendpoint,\n\t\t\t);\n\n\t\t\t// The lifeline MUST be group 1\n\t\t\tconst lifeline = await agiAPI\n\t\t\t\t.getGroupInfo(1, true)\n\t\t\t\t.catch(() => undefined);\n\t\t\tif (\n\t\t\t\tlifeline?.profile\n\t\t\t\t\t=== AssociationGroupInfoProfile[\"General: Lifeline\"]\n\t\t\t) {\n\t\t\t\tlifelineGroups.push(1);\n\t\t\t}\n\t\t}\n\t}\n\n\tif (lifelineGroups.length === 0) {\n\t\tctx.logNode(node.id, {\n\t\t\tendpoint: endpoint.index,\n\t\t\tmessage:\n\t\t\t\t\"No information about Lifeline associations, cannot assign ourselves!\",\n\t\t\tlevel: \"warn\",\n\t\t});\n\t\t// Remember that we have NO lifeline association\n\t\tvalueDB.setValue(\n\t\t\tAssociationCCValues.hasLifeline.endpoint(endpoint.index),\n\t\t\tfalse,\n\t\t);\n\t\treturn;\n\t}\n\n\tctx.logNode(node.id, {\n\t\tendpoint: endpoint.index,\n\t\tmessage: `Checking/assigning lifeline groups: ${\n\t\t\tlifelineGroups.join(\n\t\t\t\t\", \",\n\t\t\t)\n\t\t}\nsupports classic associations: ${!!assocInstance}\nsupports multi channel associations: ${!!mcInstance}`,\n\t});\n\n\tfor (const group of lifelineGroups) {\n\t\tconst groupSupportsMultiChannelAssociation = group <= mcGroupCount;\n\t\tconst assocConfig = deviceConfig?.getAssociationConfigForEndpoint(\n\t\t\tendpoint.index,\n\t\t\tgroup,\n\t\t);\n\n\t\tconst mustUseNodeAssociation = !groupSupportsMultiChannelAssociation\n\t\t\t|| !nodeSupportsMultiChannel\n\t\t\t|| assocConfig?.multiChannel === false;\n\t\tlet mustUseMultiChannelAssociation = false;\n\n\t\tif (groupSupportsMultiChannelAssociation && nodeSupportsMultiChannel) {\n\t\t\tif (assocConfig?.multiChannel === true) {\n\t\t\t\tmustUseMultiChannelAssociation = true;\n\t\t\t} else if (endpoint.index === 0) {\n\t\t\t\t// If the node has multiple endpoints but none of the extra ones support associations,\n\t\t\t\t// the root endpoints needs a Multi Channel Association\n\t\t\t\tconst allEndpoints = node.getAllEndpoints();\n\t\t\t\tif (\n\t\t\t\t\tallEndpoints.length > 1\n\t\t\t\t\t&& allEndpoints\n\t\t\t\t\t\t.filter((e) => e.index !== endpoint.index)\n\t\t\t\t\t\t.every(\n\t\t\t\t\t\t\t(e) =>\n\t\t\t\t\t\t\t\t!e.supportsCC(CommandClasses.Association)\n\t\t\t\t\t\t\t\t&& !e.supportsCC(\n\t\t\t\t\t\t\t\t\tCommandClasses[\"Multi Channel Association\"],\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\tmustUseMultiChannelAssociation = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tctx.logNode(node.id, {\n\t\t\tendpoint: endpoint.index,\n\t\t\tmessage: `Configuring lifeline group #${group}:\ngroup supports multi channel: ${groupSupportsMultiChannelAssociation}\nconfigured strategy: ${assocConfig?.multiChannel ?? \"auto\"}\nmust use node association: ${mustUseNodeAssociation}\nmust use endpoint association: ${mustUseMultiChannelAssociation}`,\n\t\t});\n\n\t\t// Figure out which associations exist and may need to be removed\n\t\tconst isAssignedAsNodeAssociation = (\n\t\t\tendpoint: EndpointId,\n\t\t): boolean => {\n\t\t\tif (groupSupportsMultiChannelAssociation && mcInstance) {\n\t\t\t\tif (\n\t\t\t\t\t// Only consider a group if it doesn't share its associations with the root endpoint\n\t\t\t\t\tmcInstance.getMaxNodesCached(ctx, endpoint, group)\n\t\t\t\t\t\t> 0\n\t\t\t\t\t&& !!mcInstance\n\t\t\t\t\t\t.getAllDestinationsCached(ctx, endpoint)\n\t\t\t\t\t\t.get(group)\n\t\t\t\t\t\t?.some(\n\t\t\t\t\t\t\t(addr) =>\n\t\t\t\t\t\t\t\taddr.nodeId === ownNodeId\n\t\t\t\t\t\t\t\t&& addr.endpoint == undefined,\n\t\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (assocInstance) {\n\t\t\t\tif (\n\t\t\t\t\t// Only consider a group if it doesn't share its associations with the root endpoint\n\t\t\t\t\tassocInstance.getMaxNodesCached(ctx, endpoint, group)\n\t\t\t\t\t\t> 0\n\t\t\t\t\t&& !!assocInstance\n\t\t\t\t\t\t.getAllDestinationsCached(ctx, endpoint)\n\t\t\t\t\t\t.get(group)\n\t\t\t\t\t\t?.some((addr) => addr.nodeId === ownNodeId)\n\t\t\t\t) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn false;\n\t\t};\n\n\t\tconst isAssignedAsEndpointAssociation = (\n\t\t\tendpoint: EndpointId,\n\t\t): boolean => {\n\t\t\tif (mcInstance) {\n\t\t\t\tif (\n\t\t\t\t\t// Only consider a group if it doesn't share its associations with the root endpoint\n\t\t\t\t\tmcInstance.getMaxNodesCached(ctx, endpoint, group)\n\t\t\t\t\t\t> 0\n\t\t\t\t\t&& mcInstance\n\t\t\t\t\t\t.getAllDestinationsCached(ctx, endpoint)\n\t\t\t\t\t\t.get(group)\n\t\t\t\t\t\t?.some(\n\t\t\t\t\t\t\t(addr) =>\n\t\t\t\t\t\t\t\taddr.nodeId === ownNodeId\n\t\t\t\t\t\t\t\t&& addr.endpoint === 0,\n\t\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn false;\n\t\t};\n\n\t\t// If the node was used with other controller software, there might be\n\t\t// invalid lifeline associations which cause reporting problems\n\t\tconst invalidEndpointAssociations: EndpointAddress[] = mcInstance\n\t\t\t?.getAllDestinationsCached(ctx, endpoint)\n\t\t\t.get(group)\n\t\t\t?.filter(\n\t\t\t\t(addr): addr is AssociationAddress & EndpointAddress =>\n\t\t\t\t\taddr.nodeId === ownNodeId\n\t\t\t\t\t&& addr.endpoint != undefined\n\t\t\t\t\t&& addr.endpoint !== 0,\n\t\t\t) ?? [];\n\n\t\t// Clean them up first\n\t\tif (\n\t\t\tinvalidEndpointAssociations.length > 0\n\t\t\t&& mcAPI.isSupported()\n\t\t\t&& groupSupportsMultiChannelAssociation\n\t\t) {\n\t\t\tctx.logNode(node.id, {\n\t\t\t\tendpoint: endpoint.index,\n\t\t\t\tmessage:\n\t\t\t\t\t`Found invalid lifeline associations in group #${group}, removing them...`,\n\t\t\t\tdirection: \"outbound\",\n\t\t\t});\n\t\t\tawait mcAPI.removeDestinations({\n\t\t\t\tgroupId: group,\n\t\t\t\tendpoints: invalidEndpointAssociations,\n\t\t\t});\n\t\t\t// refresh the associations - don't trust that it worked\n\t\t\tawait mcAPI.getGroup(group);\n\t\t}\n\n\t\t// Assigning the correct lifelines depends on the association kind, source endpoint and the desired strategy:\n\t\t//\n\t\t// When `mustUseMultiChannelAssociation` is `true` - Use a multi channel association (if possible), no fallback\n\t\t// When `mustUseNodeAssociation` is `true` - Use a node association (if possible), no fallback\n\t\t// Otherwise:\n\t\t// 1. Try a node association on the current endpoint/root\n\t\t// 2. If Association CC is not supported, try assigning a node association with the Multi Channel Association CC\n\t\t// 3. If that did not work, fall back to a multi channel association (target endpoint 0)\n\t\t// 4. If that did not work either, the endpoint index is >0 and the node is Z-Wave+:\n\t\t// Fall back to a multi channel association (target endpoint 0) on the root, if it doesn't have one yet.\n\n\t\tlet hasLifeline = false;\n\n\t\t// First try: node association\n\t\tif (!mustUseMultiChannelAssociation) {\n\t\t\tif (isAssignedAsNodeAssociation(endpoint)) {\n\t\t\t\t// We already have the correct association\n\t\t\t\thasLifeline = true;\n\t\t\t\tctx.logNode(node.id, {\n\t\t\t\t\tendpoint: endpoint.index,\n\t\t\t\t\tmessage:\n\t\t\t\t\t\t`Lifeline group #${group} is already assigned with a node association`,\n\t\t\t\t\tdirection: \"none\",\n\t\t\t\t});\n\t\t\t} else if (\n\t\t\t\tassocAPI.isSupported()\n\t\t\t\t// Some endpoint groups don't support having any destinations because they are shared with the root\n\t\t\t\t&& assocInstance!.getMaxNodesCached(ctx, endpoint, group)\n\t\t\t\t\t> 0\n\t\t\t) {\n\t\t\t\t// We can use a node association, but first remove any possible endpoint associations\n\t\t\t\tctx.logNode(node.id, {\n\t\t\t\t\tendpoint: endpoint.index,\n\t\t\t\t\tmessage:\n\t\t\t\t\t\t`Assigning lifeline group #${group} with a node association via Association CC...`,\n\t\t\t\t\tdirection: \"outbound\",\n\t\t\t\t});\n\t\t\t\tif (\n\t\t\t\t\tisAssignedAsEndpointAssociation(endpoint)\n\t\t\t\t\t&& mcAPI.isSupported()\n\t\t\t\t) {\n\t\t\t\t\tawait mcAPI.removeDestinations({\n\t\t\t\t\t\tgroupId: group,\n\t\t\t\t\t\tendpoints: [{ nodeId: ownNodeId, endpoint: 0 }],\n\t\t\t\t\t});\n\t\t\t\t\t// refresh the associations - don't trust that it worked\n\t\t\t\t\tawait mcAPI.getGroup(group);\n\t\t\t\t}\n\n\t\t\t\tawait assocAPI.addNodeIds(group, ownNodeId);\n\t\t\t\t// refresh the associations - don't trust that it worked\n\t\t\t\tconst groupReport = await assocAPI.getGroup(group);\n\t\t\t\thasLifeline = !!groupReport?.nodeIds.includes(ownNodeId);\n\n\t\t\t\tif (hasLifeline) {\n\t\t\t\t\tctx.logNode(node.id, {\n\t\t\t\t\t\tendpoint: endpoint.index,\n\t\t\t\t\t\tmessage:\n\t\t\t\t\t\t\t`Lifeline group #${group} was assigned with a node association via Association CC`,\n\t\t\t\t\t\tdirection: \"none\",\n\t\t\t\t\t});\n\t\t\t\t} else {\n\t\t\t\t\tctx.logNode(node.id, {\n\t\t\t\t\t\tendpoint: endpoint.index,\n\t\t\t\t\t\tmessage:\n\t\t\t\t\t\t\t`Assigning lifeline group #${group} with a node association via Association CC did not work`,\n\t\t\t\t\t\tdirection: \"none\",\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Second try: Node association using the Multi Channel Association CC\n\t\t\tif (\n\t\t\t\t!hasLifeline\n\t\t\t\t&& mcAPI.isSupported()\n\t\t\t\t&& mcInstance!.getMaxNodesCached(ctx, endpoint, group) > 0\n\t\t\t) {\n\t\t\t\t// We can use a node association, but first remove any possible endpoint associations\n\t\t\t\tctx.logNode(node.id, {\n\t\t\t\t\tendpoint: endpoint.index,\n\t\t\t\t\tmessage:\n\t\t\t\t\t\t`Assigning lifeline group #${group} with a node association via Multi Channel Association CC...`,\n\t\t\t\t\tdirection: \"outbound\",\n\t\t\t\t});\n\t\t\t\tif (isAssignedAsEndpointAssociation(endpoint)) {\n\t\t\t\t\tawait mcAPI.removeDestinations({\n\t\t\t\t\t\tgroupId: group,\n\t\t\t\t\t\tendpoints: [{ nodeId: ownNodeId, endpoint: 0 }],\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tawait mcAPI.addDestinations({\n\t\t\t\t\tgroupId: group,\n\t\t\t\t\tnodeIds: [ownNodeId],\n\t\t\t\t});\n\t\t\t\t// refresh the associations - don't trust that it worked\n\t\t\t\tconst groupReport = await mcAPI.getGroup(group);\n\t\t\t\thasLifeline = !!groupReport?.nodeIds.includes(ownNodeId);\n\n\t\t\t\tif (hasLifeline) {\n\t\t\t\t\tctx.logNode(node.id, {\n\t\t\t\t\t\tendpoint: endpoint.index,\n\t\t\t\t\t\tmessage:\n\t\t\t\t\t\t\t`Lifeline group #${group} was assigned with a node association via Multi Channel Association CC`,\n\t\t\t\t\t\tdirection: \"none\",\n\t\t\t\t\t});\n\t\t\t\t} else {\n\t\t\t\t\tctx.logNode(node.id, {\n\t\t\t\t\t\tendpoint: endpoint.index,\n\t\t\t\t\t\tmessage:\n\t\t\t\t\t\t\t`Assigning lifeline group #${group} with a node association via Multi Channel Association CC did not work`,\n\t\t\t\t\t\tdirection: \"none\",\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Third try: Use an endpoint association (target endpoint 0)\n\t\t// This is only supported starting in Multi Channel Association CC V3\n\t\tif (!hasLifeline && !mustUseNodeAssociation) {\n\t\t\tif (isAssignedAsEndpointAssociation(endpoint)) {\n\t\t\t\t// We already have the correct association\n\t\t\t\thasLifeline = true;\n\t\t\t\tctx.logNode(node.id, {\n\t\t\t\t\tendpoint: endpoint.index,\n\t\t\t\t\tmessage:\n\t\t\t\t\t\t`Lifeline group #${group} is already assigned with an endpoint association`,\n\t\t\t\t\tdirection: \"none\",\n\t\t\t\t});\n\t\t\t} else if (\n\t\t\t\tmcAPI.isSupported()\n\t\t\t\t&& mcAPI.version >= 3\n\t\t\t\t&& mcInstance!.getMaxNodesCached(ctx, endpoint, group) > 0\n\t\t\t) {\n\t\t\t\t// We can use a multi channel association, but first remove any possible node associations\n\t\t\t\tctx.logNode(node.id, {\n\t\t\t\t\tendpoint: endpoint.index,\n\t\t\t\t\tmessage:\n\t\t\t\t\t\t`Assigning lifeline group #${group} with a multi channel association...`,\n\t\t\t\t\tdirection: \"outbound\",\n\t\t\t\t});\n\t\t\t\tif (isAssignedAsNodeAssociation(endpoint)) {\n\t\t\t\t\t// It has been found that some devices don't correctly share the node associations between\n\t\t\t\t\t// Association CC and Multi Channel Association CC, so we remove the nodes from both lists\n\t\t\t\t\tawait mcAPI.removeDestinations({\n\t\t\t\t\t\tgroupId: group,\n\t\t\t\t\t\tnodeIds: [ownNodeId],\n\t\t\t\t\t});\n\t\t\t\t\tif (assocAPI.isSupported()) {\n\t\t\t\t\t\tawait assocAPI.removeNodeIds({\n\t\t\t\t\t\t\tgroupId: group,\n\t\t\t\t\t\t\tnodeIds: [ownNodeId],\n\t\t\t\t\t\t});\n\t\t\t\t\t\t// refresh the associations - don't trust that it worked\n\t\t\t\t\t\tawait assocAPI.getGroup(group);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tawait mcAPI.addDestinations({\n\t\t\t\t\tgroupId: group,\n\t\t\t\t\tendpoints: [{ nodeId: ownNodeId, endpoint: 0 }],\n\t\t\t\t});\n\t\t\t\t// refresh the associations - don't trust that it worked\n\t\t\t\tconst groupReport = await mcAPI.getGroup(group);\n\t\t\t\thasLifeline = !!groupReport?.endpoints.some(\n\t\t\t\t\t(a) => a.nodeId === ownNodeId && a.endpoint === 0,\n\t\t\t\t);\n\n\t\t\t\tif (hasLifeline) {\n\t\t\t\t\tctx.logNode(node.id, {\n\t\t\t\t\t\tendpoint: endpoint.index,\n\t\t\t\t\t\tmessage:\n\t\t\t\t\t\t\t`Lifeline group #${group} was assigned with a multi channel association`,\n\t\t\t\t\t\tdirection: \"none\",\n\t\t\t\t\t});\n\t\t\t\t} else {\n\t\t\t\t\tctx.logNode(node.id, {\n\t\t\t\t\t\tendpoint: endpoint.index,\n\t\t\t\t\t\tmessage:\n\t\t\t\t\t\t\t`Assigning lifeline group #${group} with a multi channel association did not work`,\n\t\t\t\t\t\tdirection: \"none\",\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Last attempt (actual Z-Wave+ Lifelines only): Try a multi channel association on the root.\n\t\t// Endpoint interviews happen AFTER the root interview, so this enables us to overwrite what\n\t\t// we previously configured on the root.\n\t\tif (\n\t\t\t!hasLifeline\n\t\t\t&& group === 1\n\t\t\t&& node.supportsCC(CommandClasses[\"Z-Wave Plus Info\"])\n\t\t\t&& endpoint.index > 0\n\t\t) {\n\t\t\t// But first check if the root may have a multi channel association\n\t\t\tconst rootAssocConfig = deviceConfig\n\t\t\t\t?.getAssociationConfigForEndpoint(0, group);\n\t\t\tconst rootMustUseNodeAssociation = !nodeSupportsMultiChannel\n\t\t\t\t|| rootAssocConfig?.multiChannel === false;\n\n\t\t\tctx.logNode(node.id, {\n\t\t\t\tendpoint: endpoint.index,\n\t\t\t\tmessage:\n\t\t\t\t\t`Checking root device for fallback assignment of lifeline group #${group}:\nroot supports multi channel: ${nodeSupportsMultiChannel}\nconfigured strategy: ${rootAssocConfig?.multiChannel ?? \"auto\"}\nmust use node association: ${rootMustUseNodeAssociation}`,\n\t\t\t});\n\n\t\t\tif (!rootMustUseNodeAssociation) {\n\t\t\t\tif (isAssignedAsEndpointAssociation(node)) {\n\t\t\t\t\t// We already have the correct association\n\t\t\t\t\thasLifeline = true;\n\t\t\t\t\tctx.logNode(node.id, {\n\t\t\t\t\t\tendpoint: endpoint.index,\n\t\t\t\t\t\tmessage:\n\t\t\t\t\t\t\t`Lifeline group #${group} is already assigned with a multi channel association on the root device`,\n\t\t\t\t\t\tdirection: \"none\",\n\t\t\t\t\t});\n\t\t\t\t} else {\n\t\t\t\t\tconst rootMCAPI = CCAPI.create(\n\t\t\t\t\t\tCommandClasses[\"Multi Channel Association\"],\n\t\t\t\t\t\tctx,\n\t\t\t\t\t\tnode,\n\t\t\t\t\t);\n\t\t\t\t\tconst rootAssocAPI = CCAPI.create(\n\t\t\t\t\t\tCommandClasses.Association,\n\t\t\t\t\t\tctx,\n\t\t\t\t\t\tnode,\n\t\t\t\t\t);\n\t\t\t\t\tif (rootMCAPI.isSupported()) {\n\t\t\t\t\t\tctx.logNode(node.id, {\n\t\t\t\t\t\t\tendpoint: endpoint.index,\n\t\t\t\t\t\t\tmessage:\n\t\t\t\t\t\t\t\t`Assigning lifeline group #${group} with a multi channel association on the root device...`,\n\t\t\t\t\t\t\tdirection: \"outbound\",\n\t\t\t\t\t\t});\n\t\t\t\t\t\t// Clean up node associations because they might prevent us from adding the endpoint association\n\t\t\t\t\t\tif (isAssignedAsNodeAssociation(node)) {\n\t\t\t\t\t\t\t// It has been found that some devices don't correctly share the node associations between\n\t\t\t\t\t\t\t// Association CC and Multi Channel Association CC, so we remove the nodes from both lists\n\t\t\t\t\t\t\tawait rootMCAPI.removeDestinations({\n\t\t\t\t\t\t\t\tgroupId: group,\n\t\t\t\t\t\t\t\tnodeIds: [ownNodeId],\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\tif (rootAssocAPI.isSupported()) {\n\t\t\t\t\t\t\t\tawait rootAssocAPI.removeNodeIds({\n\t\t\t\t\t\t\t\t\tgroupId: group,\n\t\t\t\t\t\t\t\t\tnodeIds: [ownNodeId],\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t// refresh the associations - don't trust that it worked\n\t\t\t\t\t\t\t\tawait rootAssocAPI.getGroup(group);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tawait rootMCAPI.addDestinations({\n\t\t\t\t\t\t\tgroupId: group,\n\t\t\t\t\t\t\tendpoints: [{ nodeId: ownNodeId, endpoint: 0 }],\n\t\t\t\t\t\t});\n\t\t\t\t\t\t// refresh the associations - don't trust that it worked\n\t\t\t\t\t\tconst groupReport = await rootMCAPI.getGroup(group);\n\t\t\t\t\t\thasLifeline = !!groupReport?.endpoints.some(\n\t\t\t\t\t\t\t(a) => a.nodeId === ownNodeId && a.endpoint === 0,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (!hasLifeline) {\n\t\t\tctx.logNode(node.id, {\n\t\t\t\tendpoint: endpoint.index,\n\t\t\t\tmessage:\n\t\t\t\t\t`All attempts to assign lifeline group #${group} failed, skipping...`,\n\t\t\t\tdirection: \"none\",\n\t\t\t\tlevel: \"warn\",\n\t\t\t});\n\t\t}\n\t}\n\n\t// Remember that we did the association assignment\n\tvalueDB.setValue(\n\t\tAssociationCCValues.hasLifeline.endpoint(endpoint.index),\n\t\ttrue,\n\t);\n}\n\nexport async function assignLifelineIssueingCommand(\n\tctx: CCAPIHost<\n\t\t& CCAPINode\n\t\t& SupportsCC\n\t\t& ControlsCC\n\t\t& GetEndpoint<EndpointId & SupportsCC>\n\t\t& QuerySecurityClasses\n\t>,\n\tendpoint: EndpointId,\n\tccId: CommandClasses,\n\tccCommand: number,\n): Promise<void> {\n\tconst node = ctx.getNodeOrThrow(endpoint.nodeId);\n\tif (\n\t\tnode.supportsCC(CommandClasses[\"Association Group Information\"])\n\t\t&& (node.supportsCC(CommandClasses.Association)\n\t\t\t|| node.supportsCC(CommandClasses[\"Multi Channel Association\"]))\n\t) {\n\t\tconst groupsIssueingNotifications = AssociationGroupInfoCC\n\t\t\t.findGroupsForIssuedCommand(\n\t\t\t\tctx,\n\t\t\t\tnode,\n\t\t\t\tccId,\n\t\t\t\tccCommand,\n\t\t\t);\n\t\tif (groupsIssueingNotifications.length > 0) {\n\t\t\t// We always grab the first group - usually it should be the lifeline\n\t\t\tconst groupId = groupsIssueingNotifications[0];\n\t\t\tconst existingAssociations = getAssociations(ctx, node).get(groupId)\n\t\t\t\t?? [];\n\n\t\t\tif (\n\t\t\t\t!existingAssociations.some(\n\t\t\t\t\t(a) => a.nodeId === ctx.ownNodeId,\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tctx.logNode(node.id, {\n\t\t\t\t\tendpoint: endpoint.index,\n\t\t\t\t\tmessage: `Configuring associations to receive ${\n\t\t\t\t\t\tgetCCName(\n\t\t\t\t\t\t\tccId,\n\t\t\t\t\t\t)\n\t\t\t\t\t} commands...`,\n\t\t\t\t\tdirection: \"outbound\",\n\t\t\t\t});\n\t\t\t\tawait addAssociations(ctx, node, groupId, [\n\t\t\t\t\t{ nodeId: ctx.ownNodeId },\n\t\t\t\t]);\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport function doesAnyLifelineSendActuatorOrSensorReports(\n\tctx: GetValueDB & GetDeviceConfig,\n\tnode: NodeId & SupportsCC,\n): MaybeNotKnown<boolean> {\n\t// No association support means no unsolicited reports\n\tif (\n\t\t!node.supportsCC(CommandClasses.Association)\n\t\t&& !node.supportsCC(CommandClasses[\"Multi Channel Association\"])\n\t) {\n\t\treturn false;\n\t}\n\n\t// No AGI support means we cannot know\n\tif (!node.supportsCC(CommandClasses[\"Association Group Information\"])) {\n\t\treturn NOT_KNOWN;\n\t}\n\n\t// Lifeline group IDs include the ones we added via a config file, so they may not be considered true lifelines\n\tconst lifelineGroupIds = getLifelineGroupIds(ctx, node);\n\t// If any potential lifeline group has the \"General: Lifeline\" profile, the node MUST send unsolicited reports that way\n\tif (\n\t\tlifelineGroupIds.some(\n\t\t\t(id) =>\n\t\t\t\tAssociationGroupInfoCC.getGroupProfileCached(\n\t\t\t\t\tctx,\n\t\t\t\t\tnode,\n\t\t\t\t\tid,\n\t\t\t\t) === AssociationGroupInfoProfile[\"General: Lifeline\"],\n\t\t)\n\t) {\n\t\treturn true;\n\t}\n\n\t// Otherwise check if any of the groups sends any actuator or sensor commands. We'll assume that those are reports\n\tfor (const groupId of lifelineGroupIds) {\n\t\tconst issuedCommands = AssociationGroupInfoCC.getIssuedCommandsCached(\n\t\t\tctx,\n\t\t\tnode,\n\t\t\tgroupId,\n\t\t);\n\t\tif (!issuedCommands) continue;\n\t\tconst commands = [...issuedCommands.keys()];\n\t\tif (commands.some((c) => isActuatorCC(c) || isSensorCC(c))) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\treturn false;\n}\n"],
5
5
  "mappings": ";;;;;;;;;;;;;;;;;;AACA;;;;;;;;;;;;;;;AAAA,kBAmBO;AAOP,IAAAA,eAIO;AACP,oBAAyB;AACzB,2BAAmD;AACnD,oCAAuC;AACvC,uCAA0C;AAC1C,iBAAsD;AACtD,mBAMO;AAED,SAAU,gBACf,KACA,UAAiC;AAEjC,QAAM,MAAM,oBAAI,IAAG;AAEnB,MAAI,SAAS,WAAW,2BAAe,WAAW,GAAG;AACpD,UAAM,eAAe,mCAAc,yBAClC,KACA,QAAQ;AAET,eAAW,CAAC,SAAS,MAAM,KAAK,cAAc;AAC7C,UAAI,IAAI,SAAS,MAAM;IACxB;EACD,OAAO;AACN,UAAM,IAAI,uBACT,QAAQ,SAAS,MAAM,GACtB,SAAS,QAAQ,IAAI,cAAc,SAAS,KAAK,KAAK,EACvD,mCACA,4BAAgB,eAAe;EAEjC;AAGA,MAAI,SAAS,WAAW,2BAAe,2BAA2B,CAAC,GAAG;AACrE,UAAM,eAAe,2DAA0B,yBAC9C,KACA,QAAQ;AAET,eAAW,CAAC,SAAS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names": ["import_safe", "endpoint"]
7
7
  }
@@ -142,7 +142,7 @@ const __assertType__AssociationCCRemoveOptions = $o => {
142
142
  };
143
143
  import { CommandClasses, MAX_NODES, MessagePriority, ZWaveError, ZWaveErrorCodes, validatePayload, } from "@zwave-js/core/safe";
144
144
  import { Bytes } from "@zwave-js/shared/safe";
145
- import { distinct } from "alcalzone-shared/arrays/index.js";
145
+ import { distinct } from "alcalzone-shared/arrays";
146
146
  import { CCAPI, PhysicalCCAPI } from "../lib/API.js";
147
147
  import { CommandClass, } from "../lib/CommandClass.js";
148
148
  import { API, CCCommand, ccValueProperty, ccValues, commandClass, expectedCCResponse, implementedVersion, useSupervision, } from "../lib/CommandClassDecorators.js";