@zwave-js/cc 9.3.1-0-pr-4662-79458fb

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 (297) hide show
  1. package/build/cc/AlarmSensorCC.d.ts +54 -0
  2. package/build/cc/AlarmSensorCC.d.ts.map +1 -0
  3. package/build/cc/AlarmSensorCC.js +378 -0
  4. package/build/cc/AlarmSensorCC.js.map +1 -0
  5. package/build/cc/AssociationCC.d.ts +123 -0
  6. package/build/cc/AssociationCC.d.ts.map +1 -0
  7. package/build/cc/AssociationCC.js +615 -0
  8. package/build/cc/AssociationCC.js.map +1 -0
  9. package/build/cc/AssociationGroupInfoCC.d.ts +97 -0
  10. package/build/cc/AssociationGroupInfoCC.d.ts.map +1 -0
  11. package/build/cc/AssociationGroupInfoCC.js +530 -0
  12. package/build/cc/AssociationGroupInfoCC.js.map +1 -0
  13. package/build/cc/BarrierOperatorCC.d.ts +75 -0
  14. package/build/cc/BarrierOperatorCC.d.ts.map +1 -0
  15. package/build/cc/BarrierOperatorCC.js +492 -0
  16. package/build/cc/BarrierOperatorCC.js.map +1 -0
  17. package/build/cc/BasicCC.d.ts +51 -0
  18. package/build/cc/BasicCC.d.ts.map +1 -0
  19. package/build/cc/BasicCC.js +344 -0
  20. package/build/cc/BasicCC.js.map +1 -0
  21. package/build/cc/BatteryCC.d.ts +56 -0
  22. package/build/cc/BatteryCC.d.ts.map +1 -0
  23. package/build/cc/BatteryCC.js +417 -0
  24. package/build/cc/BatteryCC.js.map +1 -0
  25. package/build/cc/BinarySensorCC.d.ts +52 -0
  26. package/build/cc/BinarySensorCC.d.ts.map +1 -0
  27. package/build/cc/BinarySensorCC.js +321 -0
  28. package/build/cc/BinarySensorCC.js.map +1 -0
  29. package/build/cc/BinarySwitchCC.d.ts +55 -0
  30. package/build/cc/BinarySwitchCC.d.ts.map +1 -0
  31. package/build/cc/BinarySwitchCC.js +327 -0
  32. package/build/cc/BinarySwitchCC.js.map +1 -0
  33. package/build/cc/CRC16CC.d.ts +28 -0
  34. package/build/cc/CRC16CC.d.ts.map +1 -0
  35. package/build/cc/CRC16CC.js +109 -0
  36. package/build/cc/CRC16CC.js.map +1 -0
  37. package/build/cc/CentralSceneCC.d.ts +69 -0
  38. package/build/cc/CentralSceneCC.d.ts.map +1 -0
  39. package/build/cc/CentralSceneCC.js +443 -0
  40. package/build/cc/CentralSceneCC.js.map +1 -0
  41. package/build/cc/ClimateControlScheduleCC.d.ts +78 -0
  42. package/build/cc/ClimateControlScheduleCC.d.ts.map +1 -0
  43. package/build/cc/ClimateControlScheduleCC.js +417 -0
  44. package/build/cc/ClimateControlScheduleCC.js.map +1 -0
  45. package/build/cc/ClockCC.d.ts +40 -0
  46. package/build/cc/ClockCC.d.ts.map +1 -0
  47. package/build/cc/ClockCC.js +185 -0
  48. package/build/cc/ClockCC.js.map +1 -0
  49. package/build/cc/ColorSwitchCC.d.ts +98 -0
  50. package/build/cc/ColorSwitchCC.d.ts.map +1 -0
  51. package/build/cc/ColorSwitchCC.js +1045 -0
  52. package/build/cc/ColorSwitchCC.js.map +1 -0
  53. package/build/cc/ConfigurationCC.d.ts +315 -0
  54. package/build/cc/ConfigurationCC.d.ts.map +1 -0
  55. package/build/cc/ConfigurationCC.js +2257 -0
  56. package/build/cc/ConfigurationCC.js.map +1 -0
  57. package/build/cc/DeviceResetLocallyCC.d.ts +9 -0
  58. package/build/cc/DeviceResetLocallyCC.d.ts.map +1 -0
  59. package/build/cc/DeviceResetLocallyCC.js +28 -0
  60. package/build/cc/DeviceResetLocallyCC.js.map +1 -0
  61. package/build/cc/DoorLockCC.d.ts +116 -0
  62. package/build/cc/DoorLockCC.d.ts.map +1 -0
  63. package/build/cc/DoorLockCC.js +1112 -0
  64. package/build/cc/DoorLockCC.js.map +1 -0
  65. package/build/cc/DoorLockLoggingCC.d.ts +41 -0
  66. package/build/cc/DoorLockLoggingCC.d.ts.map +1 -0
  67. package/build/cc/DoorLockLoggingCC.js +288 -0
  68. package/build/cc/DoorLockLoggingCC.js.map +1 -0
  69. package/build/cc/EntryControlCC.d.ts +71 -0
  70. package/build/cc/EntryControlCC.d.ts.map +1 -0
  71. package/build/cc/EntryControlCC.js +492 -0
  72. package/build/cc/EntryControlCC.js.map +1 -0
  73. package/build/cc/FirmwareUpdateMetaDataCC.d.ts +148 -0
  74. package/build/cc/FirmwareUpdateMetaDataCC.d.ts.map +1 -0
  75. package/build/cc/FirmwareUpdateMetaDataCC.js +727 -0
  76. package/build/cc/FirmwareUpdateMetaDataCC.js.map +1 -0
  77. package/build/cc/HailCC.d.ts +6 -0
  78. package/build/cc/HailCC.d.ts.map +1 -0
  79. package/build/cc/HailCC.js +23 -0
  80. package/build/cc/HailCC.js.map +1 -0
  81. package/build/cc/HumidityControlModeCC.d.ts +47 -0
  82. package/build/cc/HumidityControlModeCC.d.ts.map +1 -0
  83. package/build/cc/HumidityControlModeCC.js +288 -0
  84. package/build/cc/HumidityControlModeCC.js.map +1 -0
  85. package/build/cc/HumidityControlOperatingStateCC.d.ts +24 -0
  86. package/build/cc/HumidityControlOperatingStateCC.d.ts.map +1 -0
  87. package/build/cc/HumidityControlOperatingStateCC.js +129 -0
  88. package/build/cc/HumidityControlOperatingStateCC.js.map +1 -0
  89. package/build/cc/HumidityControlSetpointCC.d.ts +103 -0
  90. package/build/cc/HumidityControlSetpointCC.d.ts.map +1 -0
  91. package/build/cc/HumidityControlSetpointCC.js +626 -0
  92. package/build/cc/HumidityControlSetpointCC.js.map +1 -0
  93. package/build/cc/IndicatorCC.d.ts +88 -0
  94. package/build/cc/IndicatorCC.d.ts.map +1 -0
  95. package/build/cc/IndicatorCC.js +758 -0
  96. package/build/cc/IndicatorCC.js.map +1 -0
  97. package/build/cc/IrrigationCC.d.ts +278 -0
  98. package/build/cc/IrrigationCC.d.ts.map +1 -0
  99. package/build/cc/IrrigationCC.js +2062 -0
  100. package/build/cc/IrrigationCC.js.map +1 -0
  101. package/build/cc/LanguageCC.d.ts +41 -0
  102. package/build/cc/LanguageCC.d.ts.map +1 -0
  103. package/build/cc/LanguageCC.js +220 -0
  104. package/build/cc/LanguageCC.js.map +1 -0
  105. package/build/cc/LockCC.d.ts +41 -0
  106. package/build/cc/LockCC.d.ts.map +1 -0
  107. package/build/cc/LockCC.js +185 -0
  108. package/build/cc/LockCC.js.map +1 -0
  109. package/build/cc/ManufacturerProprietaryCC.d.ts +31 -0
  110. package/build/cc/ManufacturerProprietaryCC.d.ts.map +1 -0
  111. package/build/cc/ManufacturerProprietaryCC.js +275 -0
  112. package/build/cc/ManufacturerProprietaryCC.js.map +1 -0
  113. package/build/cc/ManufacturerSpecificCC.d.ts +59 -0
  114. package/build/cc/ManufacturerSpecificCC.d.ts.map +1 -0
  115. package/build/cc/ManufacturerSpecificCC.js +285 -0
  116. package/build/cc/ManufacturerSpecificCC.js.map +1 -0
  117. package/build/cc/MeterCC.d.ts +100 -0
  118. package/build/cc/MeterCC.d.ts.map +1 -0
  119. package/build/cc/MeterCC.js +820 -0
  120. package/build/cc/MeterCC.js.map +1 -0
  121. package/build/cc/MultiChannelAssociationCC.d.ts +127 -0
  122. package/build/cc/MultiChannelAssociationCC.d.ts.map +1 -0
  123. package/build/cc/MultiChannelAssociationCC.js +883 -0
  124. package/build/cc/MultiChannelAssociationCC.js.map +1 -0
  125. package/build/cc/MultiChannelCC.d.ts +164 -0
  126. package/build/cc/MultiChannelCC.d.ts.map +1 -0
  127. package/build/cc/MultiChannelCC.js +1004 -0
  128. package/build/cc/MultiChannelCC.js.map +1 -0
  129. package/build/cc/MultiCommandCC.d.ts +28 -0
  130. package/build/cc/MultiCommandCC.d.ts.map +1 -0
  131. package/build/cc/MultiCommandCC.js +137 -0
  132. package/build/cc/MultiCommandCC.js.map +1 -0
  133. package/build/cc/MultilevelSensorCC.d.ts +83 -0
  134. package/build/cc/MultilevelSensorCC.d.ts.map +1 -0
  135. package/build/cc/MultilevelSensorCC.js +633 -0
  136. package/build/cc/MultilevelSensorCC.js.map +1 -0
  137. package/build/cc/MultilevelSwitchCC.d.ts +86 -0
  138. package/build/cc/MultilevelSwitchCC.d.ts.map +1 -0
  139. package/build/cc/MultilevelSwitchCC.js +774 -0
  140. package/build/cc/MultilevelSwitchCC.js.map +1 -0
  141. package/build/cc/NoOperationCC.d.ts +17 -0
  142. package/build/cc/NoOperationCC.d.ts.map +1 -0
  143. package/build/cc/NoOperationCC.js +50 -0
  144. package/build/cc/NoOperationCC.js.map +1 -0
  145. package/build/cc/NodeNamingCC.d.ts +57 -0
  146. package/build/cc/NodeNamingCC.d.ts.map +1 -0
  147. package/build/cc/NodeNamingCC.js +313 -0
  148. package/build/cc/NodeNamingCC.js.map +1 -0
  149. package/build/cc/NotificationCC.d.ts +127 -0
  150. package/build/cc/NotificationCC.d.ts.map +1 -0
  151. package/build/cc/NotificationCC.js +1193 -0
  152. package/build/cc/NotificationCC.js.map +1 -0
  153. package/build/cc/PowerlevelCC.d.ts +63 -0
  154. package/build/cc/PowerlevelCC.d.ts.map +1 -0
  155. package/build/cc/PowerlevelCC.js +262 -0
  156. package/build/cc/PowerlevelCC.js.map +1 -0
  157. package/build/cc/ProtectionCC.d.ts +94 -0
  158. package/build/cc/ProtectionCC.d.ts.map +1 -0
  159. package/build/cc/ProtectionCC.js +630 -0
  160. package/build/cc/ProtectionCC.js.map +1 -0
  161. package/build/cc/SceneActivationCC.d.ts +34 -0
  162. package/build/cc/SceneActivationCC.d.ts.map +1 -0
  163. package/build/cc/SceneActivationCC.js +170 -0
  164. package/build/cc/SceneActivationCC.js.map +1 -0
  165. package/build/cc/SceneActuatorConfigurationCC.d.ts +52 -0
  166. package/build/cc/SceneActuatorConfigurationCC.d.ts.map +1 -0
  167. package/build/cc/SceneActuatorConfigurationCC.js +368 -0
  168. package/build/cc/SceneActuatorConfigurationCC.js.map +1 -0
  169. package/build/cc/SceneControllerConfigurationCC.d.ts +61 -0
  170. package/build/cc/SceneControllerConfigurationCC.d.ts.map +1 -0
  171. package/build/cc/SceneControllerConfigurationCC.js +444 -0
  172. package/build/cc/SceneControllerConfigurationCC.js.map +1 -0
  173. package/build/cc/Security2CC.d.ts +213 -0
  174. package/build/cc/Security2CC.d.ts.map +1 -0
  175. package/build/cc/Security2CC.js +1124 -0
  176. package/build/cc/Security2CC.js.map +1 -0
  177. package/build/cc/SecurityCC.d.ts +109 -0
  178. package/build/cc/SecurityCC.d.ts.map +1 -0
  179. package/build/cc/SecurityCC.js +609 -0
  180. package/build/cc/SecurityCC.js.map +1 -0
  181. package/build/cc/SoundSwitchCC.d.ts +87 -0
  182. package/build/cc/SoundSwitchCC.d.ts.map +1 -0
  183. package/build/cc/SoundSwitchCC.js +548 -0
  184. package/build/cc/SoundSwitchCC.js.map +1 -0
  185. package/build/cc/SupervisionCC.d.ts +63 -0
  186. package/build/cc/SupervisionCC.d.ts.map +1 -0
  187. package/build/cc/SupervisionCC.js +239 -0
  188. package/build/cc/SupervisionCC.js.map +1 -0
  189. package/build/cc/ThermostatFanModeCC.d.ts +53 -0
  190. package/build/cc/ThermostatFanModeCC.d.ts.map +1 -0
  191. package/build/cc/ThermostatFanModeCC.js +359 -0
  192. package/build/cc/ThermostatFanModeCC.js.map +1 -0
  193. package/build/cc/ThermostatFanStateCC.d.ts +24 -0
  194. package/build/cc/ThermostatFanStateCC.d.ts.map +1 -0
  195. package/build/cc/ThermostatFanStateCC.js +131 -0
  196. package/build/cc/ThermostatFanStateCC.js.map +1 -0
  197. package/build/cc/ThermostatModeCC.d.ts +58 -0
  198. package/build/cc/ThermostatModeCC.d.ts.map +1 -0
  199. package/build/cc/ThermostatModeCC.js +370 -0
  200. package/build/cc/ThermostatModeCC.js.map +1 -0
  201. package/build/cc/ThermostatOperatingStateCC.d.ts +24 -0
  202. package/build/cc/ThermostatOperatingStateCC.d.ts.map +1 -0
  203. package/build/cc/ThermostatOperatingStateCC.js +127 -0
  204. package/build/cc/ThermostatOperatingStateCC.js.map +1 -0
  205. package/build/cc/ThermostatSetbackCC.d.ts +42 -0
  206. package/build/cc/ThermostatSetbackCC.d.ts.map +1 -0
  207. package/build/cc/ThermostatSetbackCC.js +237 -0
  208. package/build/cc/ThermostatSetbackCC.js.map +1 -0
  209. package/build/cc/ThermostatSetpointCC.d.ts +98 -0
  210. package/build/cc/ThermostatSetpointCC.d.ts.map +1 -0
  211. package/build/cc/ThermostatSetpointCC.js +707 -0
  212. package/build/cc/ThermostatSetpointCC.js.map +1 -0
  213. package/build/cc/TimeCC.d.ts +78 -0
  214. package/build/cc/TimeCC.d.ts.map +1 -0
  215. package/build/cc/TimeCC.js +373 -0
  216. package/build/cc/TimeCC.js.map +1 -0
  217. package/build/cc/TimeParametersCC.d.ts +40 -0
  218. package/build/cc/TimeParametersCC.d.ts.map +1 -0
  219. package/build/cc/TimeParametersCC.js +275 -0
  220. package/build/cc/TimeParametersCC.js.map +1 -0
  221. package/build/cc/TransportServiceCC.d.ts +101 -0
  222. package/build/cc/TransportServiceCC.d.ts.map +1 -0
  223. package/build/cc/TransportServiceCC.js +404 -0
  224. package/build/cc/TransportServiceCC.js.map +1 -0
  225. package/build/cc/UserCodeCC.d.ts +219 -0
  226. package/build/cc/UserCodeCC.d.ts.map +1 -0
  227. package/build/cc/UserCodeCC.js +1526 -0
  228. package/build/cc/UserCodeCC.js.map +1 -0
  229. package/build/cc/VersionCC.d.ts +91 -0
  230. package/build/cc/VersionCC.d.ts.map +1 -0
  231. package/build/cc/VersionCC.js +654 -0
  232. package/build/cc/VersionCC.js.map +1 -0
  233. package/build/cc/WakeUpCC.d.ts +67 -0
  234. package/build/cc/WakeUpCC.d.ts.map +1 -0
  235. package/build/cc/WakeUpCC.js +425 -0
  236. package/build/cc/WakeUpCC.js.map +1 -0
  237. package/build/cc/ZWavePlusCC.d.ts +40 -0
  238. package/build/cc/ZWavePlusCC.d.ts.map +1 -0
  239. package/build/cc/ZWavePlusCC.js +269 -0
  240. package/build/cc/ZWavePlusCC.js.map +1 -0
  241. package/build/cc/index.d.ts +64 -0
  242. package/build/cc/index.d.ts.map +1 -0
  243. package/build/cc/index.js +496 -0
  244. package/build/cc/index.js.map +1 -0
  245. package/build/cc/manufacturerProprietary/FibaroCC.d.ts +62 -0
  246. package/build/cc/manufacturerProprietary/FibaroCC.d.ts.map +1 -0
  247. package/build/cc/manufacturerProprietary/FibaroCC.js +247 -0
  248. package/build/cc/manufacturerProprietary/FibaroCC.js.map +1 -0
  249. package/build/index.d.ts +11 -0
  250. package/build/index.d.ts.map +1 -0
  251. package/build/index.js +48 -0
  252. package/build/index.js.map +1 -0
  253. package/build/index_safe.d.ts +4 -0
  254. package/build/index_safe.d.ts.map +1 -0
  255. package/build/index_safe.js +30 -0
  256. package/build/index_safe.js.map +1 -0
  257. package/build/lib/API.d.ts +176 -0
  258. package/build/lib/API.d.ts.map +1 -0
  259. package/build/lib/API.js +325 -0
  260. package/build/lib/API.js.map +1 -0
  261. package/build/lib/CommandClass.d.ts +341 -0
  262. package/build/lib/CommandClass.d.ts.map +1 -0
  263. package/build/lib/CommandClass.js +1088 -0
  264. package/build/lib/CommandClass.js.map +1 -0
  265. package/build/lib/EncapsulatingCommandClass.d.ts +35 -0
  266. package/build/lib/EncapsulatingCommandClass.d.ts.map +1 -0
  267. package/build/lib/EncapsulatingCommandClass.js +53 -0
  268. package/build/lib/EncapsulatingCommandClass.js.map +1 -0
  269. package/build/lib/ICommandClassContainer.d.ts +9 -0
  270. package/build/lib/ICommandClassContainer.d.ts.map +1 -0
  271. package/build/lib/ICommandClassContainer.js +12 -0
  272. package/build/lib/ICommandClassContainer.js.map +1 -0
  273. package/build/lib/NotificationEventPayload.d.ts +11 -0
  274. package/build/lib/NotificationEventPayload.d.ts.map +1 -0
  275. package/build/lib/NotificationEventPayload.js +11 -0
  276. package/build/lib/NotificationEventPayload.js.map +1 -0
  277. package/build/lib/Security2/Extension.d.ts +87 -0
  278. package/build/lib/Security2/Extension.d.ts.map +1 -0
  279. package/build/lib/Security2/Extension.js +235 -0
  280. package/build/lib/Security2/Extension.js.map +1 -0
  281. package/build/lib/Security2/shared.d.ts +31 -0
  282. package/build/lib/Security2/shared.d.ts.map +1 -0
  283. package/build/lib/Security2/shared.js +37 -0
  284. package/build/lib/Security2/shared.js.map +1 -0
  285. package/build/lib/_Types.d.ts +1446 -0
  286. package/build/lib/_Types.d.ts.map +1 -0
  287. package/build/lib/_Types.js +1334 -0
  288. package/build/lib/_Types.js.map +1 -0
  289. package/build/lib/serializers.d.ts +24 -0
  290. package/build/lib/serializers.d.ts.map +1 -0
  291. package/build/lib/serializers.js +66 -0
  292. package/build/lib/serializers.js.map +1 -0
  293. package/build/lib/utils.d.ts +13 -0
  294. package/build/lib/utils.d.ts.map +1 -0
  295. package/build/lib/utils.js +675 -0
  296. package/build/lib/utils.js.map +1 -0
  297. package/package.json +77 -0
@@ -0,0 +1,1088 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getAPI = exports.API = exports.getCCValueMetadata = exports.ccValueMetadata = exports.ccKeyValuePair = exports.ccValue = exports.getCCResponsePredicate = exports.getExpectedCCResponse = exports.expectedCCResponse = exports.getCCCommandConstructor = exports.getCCCommand = exports.CCCommand = exports.getImplementedVersionStatic = exports.getImplementedVersion = exports.implementedVersion = exports.getCCConstructor = exports.getCommandClassStatic = exports.getCommandClass = exports.commandClass = exports.assertValidCCs = exports.InvalidCC = exports.CommandClass = exports.gotDeserializationOptions = void 0;
4
+ const core_1 = require("@zwave-js/core");
5
+ const shared_1 = require("@zwave-js/shared");
6
+ const typeguards_1 = require("alcalzone-shared/typeguards");
7
+ const API_1 = require("./API");
8
+ const EncapsulatingCommandClass_1 = require("./EncapsulatingCommandClass");
9
+ const ICommandClassContainer_1 = require("./ICommandClassContainer");
10
+ function gotDeserializationOptions(options) {
11
+ return "data" in options && Buffer.isBuffer(options.data);
12
+ }
13
+ exports.gotDeserializationOptions = gotDeserializationOptions;
14
+ function gotCCCommandOptions(options) {
15
+ return typeof options.nodeId === "number" || (0, typeguards_1.isArray)(options.nodeId);
16
+ }
17
+ // @publicAPI
18
+ class CommandClass {
19
+ // empty constructor to parse messages
20
+ constructor(host, options) {
21
+ var _a, _b, _c;
22
+ /**
23
+ * Whether the command should be sent encrypted
24
+ * This only has an effect if the target node supports Security.
25
+ */
26
+ this.secure = false;
27
+ /** Which variables should be persisted when requested */
28
+ this._registeredCCValues = new Map();
29
+ this.host = host;
30
+ // Extract the cc from declared metadata if not provided by the CC constructor
31
+ this.ccId =
32
+ ("ccId" in options && options.ccId) || getCommandClass(this);
33
+ // Default to the root endpoint - Inherited classes may override this behavior
34
+ this.endpointIndex =
35
+ (_a = ("endpoint" in options ? options.endpoint : undefined)) !== null && _a !== void 0 ? _a : 0;
36
+ // Default to non-supervised commands
37
+ this.supervised =
38
+ (_b = ("supervised" in options ? options.supervised : undefined)) !== null && _b !== void 0 ? _b : false;
39
+ // We cannot use @ccValue for non-derived classes, so register interviewComplete as an internal value here
40
+ this.registerValue("interviewComplete", { internal: true });
41
+ if (gotDeserializationOptions(options)) {
42
+ // For deserialized commands, try to invoke the correct subclass constructor
43
+ const CCConstructor = (_c = getCCConstructor(CommandClass.getCommandClass(options.data))) !== null && _c !== void 0 ? _c : CommandClass;
44
+ const ccCommand = CCConstructor.getCCCommand(options.data);
45
+ if (ccCommand != undefined) {
46
+ const CommandConstructor = getCCCommandConstructor(this.ccId, ccCommand);
47
+ if (CommandConstructor &&
48
+ new.target !== CommandConstructor) {
49
+ return new CommandConstructor(host, options);
50
+ }
51
+ }
52
+ // If the constructor is correct or none was found, fall back to normal deserialization
53
+ if (options.fromEncapsulation) {
54
+ // Propagate the node ID and endpoint index from the encapsulating CC
55
+ this.nodeId = options.encapCC.nodeId;
56
+ if (!this.endpointIndex && options.encapCC.endpointIndex) {
57
+ this.endpointIndex = options.encapCC.endpointIndex;
58
+ }
59
+ // And remember which CC encapsulates this CC
60
+ this.encapsulatingCC = options.encapCC;
61
+ }
62
+ else {
63
+ this.nodeId = options.nodeId;
64
+ }
65
+ ({
66
+ ccId: this.ccId,
67
+ ccCommand: this.ccCommand,
68
+ payload: this.payload,
69
+ } = this.deserialize(options.data));
70
+ }
71
+ else if (gotCCCommandOptions(options)) {
72
+ const { nodeId, ccCommand = getCCCommand(this), payload = Buffer.allocUnsafe(0), } = options;
73
+ this.nodeId = nodeId;
74
+ this.ccCommand = ccCommand;
75
+ this.payload = payload;
76
+ }
77
+ if (this instanceof InvalidCC)
78
+ return;
79
+ if (this.isSinglecast() && this.nodeId !== core_1.NODE_ID_BROADCAST) {
80
+ // For singlecast CCs, set the CC version as high as possible
81
+ this.version = this.host.getSafeCCVersionForNode(this.ccId, this.nodeId, this.endpointIndex);
82
+ // Send secure commands if necessary
83
+ this.secure = this.host.isCCSecure(this.ccId, this.nodeId, this.endpointIndex);
84
+ }
85
+ else {
86
+ // For multicast and broadcast CCs, we just use the highest implemented version to serialize
87
+ // Older nodes will ignore the additional fields
88
+ this.version = getImplementedVersion(this.ccId);
89
+ }
90
+ }
91
+ get ccName() {
92
+ return (0, core_1.getCCName)(this.ccId);
93
+ }
94
+ /** Returns true if this CC is an extended CC (0xF100..0xFFFF) */
95
+ isExtended() {
96
+ return this.ccId >= 0xf100;
97
+ }
98
+ /** Whether the interview for this CC was previously completed */
99
+ isInterviewComplete(applHost) {
100
+ return !!this.getValueDB(applHost).getValue({
101
+ commandClass: this.ccId,
102
+ endpoint: this.endpointIndex,
103
+ property: "interviewComplete",
104
+ });
105
+ }
106
+ /** Marks the interview for this CC as complete or not */
107
+ setInterviewComplete(applHost, complete) {
108
+ this.getValueDB(applHost).setValue({
109
+ commandClass: this.ccId,
110
+ endpoint: this.endpointIndex,
111
+ property: "interviewComplete",
112
+ }, complete);
113
+ }
114
+ /**
115
+ * Deserializes a CC from a buffer that contains a serialized CC
116
+ */
117
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
118
+ deserialize(data) {
119
+ const ccId = CommandClass.getCommandClass(data);
120
+ const ccIdLength = this.isExtended() ? 2 : 1;
121
+ if (data.length > ccIdLength) {
122
+ // This is not a NoOp CC (contains command and payload)
123
+ const ccCommand = data[ccIdLength];
124
+ const payload = data.slice(ccIdLength + 1);
125
+ return {
126
+ ccId,
127
+ ccCommand,
128
+ payload,
129
+ };
130
+ }
131
+ else {
132
+ // NoOp CC (no command, no payload)
133
+ const payload = Buffer.allocUnsafe(0);
134
+ return { ccId, payload };
135
+ }
136
+ }
137
+ /**
138
+ * Serializes this CommandClass to be embedded in a message payload or another CC
139
+ */
140
+ serialize() {
141
+ // NoOp CCs have no command and no payload
142
+ if (this.ccId === core_1.CommandClasses["No Operation"])
143
+ return Buffer.from([this.ccId]);
144
+ else if (this.ccCommand == undefined) {
145
+ throw new core_1.ZWaveError("Cannot serialize a Command Class without a command", core_1.ZWaveErrorCodes.CC_Invalid);
146
+ }
147
+ const payloadLength = this.payload.length;
148
+ const ccIdLength = this.isExtended() ? 2 : 1;
149
+ const data = Buffer.allocUnsafe(ccIdLength + 1 + payloadLength);
150
+ data.writeUIntBE(this.ccId, 0, ccIdLength);
151
+ data[ccIdLength] = this.ccCommand;
152
+ if (payloadLength > 0 /* implies payload != undefined */) {
153
+ this.payload.copy(data, 1 + ccIdLength);
154
+ }
155
+ return data;
156
+ }
157
+ /** Extracts the CC id from a buffer that contains a serialized CC */
158
+ static getCommandClass(data) {
159
+ return (0, core_1.parseCCId)(data).ccId;
160
+ }
161
+ /** Extracts the CC command from a buffer that contains a serialized CC */
162
+ static getCCCommand(data) {
163
+ if (data[0] === 0)
164
+ return undefined; // NoOp
165
+ const isExtendedCC = data[0] >= 0xf1;
166
+ return isExtendedCC ? data[2] : data[1];
167
+ }
168
+ /**
169
+ * Retrieves the correct constructor for the CommandClass in the given Buffer.
170
+ * It is assumed that the buffer only contains the serialized CC. This throws if the CC is not implemented.
171
+ */
172
+ static getConstructor(ccData) {
173
+ // Encapsulated CCs don't have the two header bytes
174
+ const cc = CommandClass.getCommandClass(ccData);
175
+ const ret = getCCConstructor(cc);
176
+ if (!ret) {
177
+ const ccName = (0, core_1.getCCName)(cc);
178
+ throw new core_1.ZWaveError(`The command class ${ccName} is not implemented`, core_1.ZWaveErrorCodes.CC_NotImplemented);
179
+ }
180
+ return ret;
181
+ }
182
+ /**
183
+ * Creates an instance of the CC that is serialized in the given buffer
184
+ */
185
+ static from(host, options) {
186
+ var _a;
187
+ // Fall back to unspecified command class in case we receive one that is not implemented
188
+ const Constructor = CommandClass.getConstructor(options.data);
189
+ try {
190
+ const ret = new Constructor(host, options);
191
+ return ret;
192
+ }
193
+ catch (e) {
194
+ // Indicate invalid payloads with a special CC type
195
+ if ((0, core_1.isZWaveError)(e) &&
196
+ e.code === core_1.ZWaveErrorCodes.PacketFormat_InvalidPayload) {
197
+ const nodeId = options.fromEncapsulation
198
+ ? options.encapCC.nodeId
199
+ : options.nodeId;
200
+ let ccName;
201
+ const ccId = CommandClass.getCommandClass(options.data);
202
+ const ccCommand = CommandClass.getCCCommand(options.data);
203
+ if (ccCommand != undefined) {
204
+ ccName = (_a = getCCCommandConstructor(ccId, ccCommand)) === null || _a === void 0 ? void 0 : _a.name;
205
+ }
206
+ // Fall back to the unspecified CC if the command cannot be determined
207
+ if (!ccName) {
208
+ ccName = `${(0, core_1.getCCName)(ccId)} CC`;
209
+ }
210
+ // Preserve why the command was invalid
211
+ let reason;
212
+ if (typeof e.context === "string" ||
213
+ (typeof e.context === "number" &&
214
+ core_1.ZWaveErrorCodes[e.context] != undefined)) {
215
+ reason = e.context;
216
+ }
217
+ const ret = new InvalidCC(host, {
218
+ nodeId,
219
+ ccId,
220
+ ccName,
221
+ reason,
222
+ });
223
+ if (options.fromEncapsulation) {
224
+ ret.encapsulatingCC = options.encapCC;
225
+ }
226
+ return ret;
227
+ }
228
+ throw e;
229
+ }
230
+ }
231
+ /**
232
+ * Create an instance of the given CC without checking whether it is supported.
233
+ * If the CC is implemented, this returns an instance of the given CC which is linked to the given endpoint.
234
+ *
235
+ * **INTERNAL:** Applications should not use this directly.
236
+ */
237
+ static createInstanceUnchecked(host, endpoint, cc) {
238
+ const Constructor = typeof cc === "number" ? getCCConstructor(cc) : cc;
239
+ if (Constructor) {
240
+ return new Constructor(host, {
241
+ nodeId: endpoint.nodeId,
242
+ endpoint: endpoint.index,
243
+ });
244
+ }
245
+ }
246
+ /** Generates a representation of this CC for the log */
247
+ toLogEntry(_applHost) {
248
+ let tag = this.constructor.name;
249
+ const message = {};
250
+ if (this.constructor === CommandClass) {
251
+ tag = `${(0, shared_1.getEnumMemberName)(core_1.CommandClasses, this.ccId)} CC (not implemented)`;
252
+ if (this.ccCommand != undefined) {
253
+ message.command = (0, shared_1.num2hex)(this.ccCommand);
254
+ }
255
+ }
256
+ if (this.payload.length > 0) {
257
+ message.payload = (0, shared_1.buffer2hex)(this.payload);
258
+ }
259
+ return {
260
+ tags: [tag],
261
+ message,
262
+ };
263
+ }
264
+ /** Generates the JSON representation of this CC */
265
+ toJSON() {
266
+ return this.toJSONInternal();
267
+ }
268
+ toJSONInternal() {
269
+ const ret = {
270
+ nodeId: this.nodeId,
271
+ ccId: core_1.CommandClasses[this.ccId] || (0, shared_1.num2hex)(this.ccId),
272
+ };
273
+ if (this.ccCommand != undefined) {
274
+ ret.ccCommand = (0, shared_1.num2hex)(this.ccCommand);
275
+ }
276
+ if (this.payload.length > 0) {
277
+ ret.payload = "0x" + this.payload.toString("hex");
278
+ }
279
+ return ret;
280
+ }
281
+ throwMissingCriticalInterviewResponse() {
282
+ throw new core_1.ZWaveError(`The node did not respond to a critical interview query in time.`, core_1.ZWaveErrorCodes.Controller_NodeTimeout);
283
+ }
284
+ /**
285
+ * Performs the interview procedure for this CC according to SDS14223
286
+ */
287
+ async interview(_applHost) {
288
+ // This needs to be overwritten per command class. In the default implementation, don't do anything
289
+ }
290
+ /**
291
+ * Refreshes all dynamic values of this CC
292
+ */
293
+ async refreshValues(_applHost) {
294
+ // This needs to be overwritten per command class. In the default implementation, don't do anything
295
+ }
296
+ /** Determines which CC interviews must be performed before this CC can be interviewed */
297
+ determineRequiredCCInterviews() {
298
+ // By default, all CCs require the VersionCC interview
299
+ // There are two exceptions to this rule:
300
+ // * ManufacturerSpecific must be interviewed first
301
+ // * VersionCC itself must be done after that
302
+ // These exceptions are defined in the overrides of this method of each corresponding CC
303
+ return [core_1.CommandClasses.Version];
304
+ }
305
+ /**
306
+ * Whether the endpoint interview may be skipped by a CC. Can be overwritten by a subclass.
307
+ */
308
+ skipEndpointInterview() {
309
+ // By default no interview may be skipped
310
+ return false;
311
+ }
312
+ /**
313
+ * Maps a BasicCC value to a more specific CC implementation. Returns true if the value was mapped, false otherwise.
314
+ * @param _value The value of the received BasicCC
315
+ */
316
+ setMappedBasicValue(_applHost, _value) {
317
+ // By default, don't map
318
+ return false;
319
+ }
320
+ isSinglecast() {
321
+ return typeof this.nodeId === "number";
322
+ }
323
+ isMulticast() {
324
+ return (0, typeguards_1.isArray)(this.nodeId);
325
+ }
326
+ /**
327
+ * Returns the node this CC is linked to. Throws if the controller is not yet ready.
328
+ */
329
+ getNode(applHost) {
330
+ if (this.isSinglecast()) {
331
+ return applHost.nodes.get(this.nodeId);
332
+ }
333
+ }
334
+ /**
335
+ * @internal
336
+ * Returns the node this CC is linked to (or undefined if the node doesn't exist)
337
+ */
338
+ getNodeUnsafe(applHost) {
339
+ try {
340
+ return this.getNode(applHost);
341
+ }
342
+ catch (e) {
343
+ // This was expected
344
+ if ((0, core_1.isZWaveError)(e) && e.code === core_1.ZWaveErrorCodes.Driver_NotReady) {
345
+ return undefined;
346
+ }
347
+ // Something else happened
348
+ throw e;
349
+ }
350
+ }
351
+ getEndpoint(applHost) {
352
+ var _a;
353
+ return (_a = this.getNode(applHost)) === null || _a === void 0 ? void 0 : _a.getEndpoint(this.endpointIndex);
354
+ }
355
+ /** Returns the value DB for this CC's node */
356
+ getValueDB(applHost) {
357
+ if (this.isSinglecast()) {
358
+ try {
359
+ return applHost.getValueDB(this.nodeId);
360
+ }
361
+ catch {
362
+ throw new core_1.ZWaveError("The node for this CC does not exist or the driver is not ready yet", core_1.ZWaveErrorCodes.Driver_NotReady);
363
+ }
364
+ }
365
+ throw new core_1.ZWaveError("Cannot retrieve the value DB for non-singlecast CCs", core_1.ZWaveErrorCodes.CC_NoNodeID);
366
+ }
367
+ /**
368
+ * Creates a value that will be stored in the valueDB alongside with the ones marked with `@ccValue()`
369
+ * @param property The property the value belongs to
370
+ * @param internal Whether the value should be exposed to library users
371
+ */
372
+ registerValue(property, options = {}) {
373
+ var _a, _b;
374
+ (_a = options.internal) !== null && _a !== void 0 ? _a : (options.internal = false);
375
+ (_b = options.secret) !== null && _b !== void 0 ? _b : (options.secret = false);
376
+ this._registeredCCValues.set(property, options);
377
+ }
378
+ /** Returns a list of all value names that are defined for this CommandClass */
379
+ getDefinedValueIDs(applHost) {
380
+ // In order to compare value ids, we need them to be strings
381
+ const ret = new Map();
382
+ const addValueId = (property, propertyKey) => {
383
+ const valueId = {
384
+ commandClass: this.ccId,
385
+ endpoint: this.endpointIndex,
386
+ property,
387
+ propertyKey,
388
+ };
389
+ const dbKey = (0, core_1.valueIdToString)(valueId);
390
+ if (!ret.has(dbKey))
391
+ ret.set(dbKey, valueId);
392
+ };
393
+ // Return all manually registered CC values that are not internal
394
+ const registeredCCValueNames = [...this._registeredCCValues]
395
+ .filter(([, isInternal]) => !isInternal)
396
+ .map(([key]) => key);
397
+ registeredCCValueNames.forEach((property) => addValueId(property));
398
+ // Return all defined non-internal CC values that are available in the current version of this CC
399
+ const valueDefinitions = getCCValueDefinitions(this);
400
+ const definedCCValueNames = [...valueDefinitions]
401
+ .filter(([, options]) => options.internal !== true &&
402
+ (options.minVersion == undefined ||
403
+ options.minVersion <= this.version))
404
+ .map(([key]) => key);
405
+ definedCCValueNames.forEach((property) => addValueId(property));
406
+ const kvpDefinitions = getCCKeyValuePairDefinitions(this);
407
+ // Also return all existing value ids that are not internal (values AND metadata without values!)
408
+ const valueDB = this.getValueDB(applHost);
409
+ const existingValueIds = [
410
+ ...valueDB.getValues(this.ccId),
411
+ ...valueDB.getAllMetadata(this.ccId),
412
+ ]
413
+ .filter((valueId) => valueId.endpoint === this.endpointIndex)
414
+ // allow the value id if it is NOT registered or it is registered as non-internal
415
+ .filter((valueId) => {
416
+ var _a;
417
+ return ((_a = this._registeredCCValues.get(valueId.property)) === null || _a === void 0 ? void 0 : _a.internal) !==
418
+ true;
419
+ })
420
+ // allow the value ID if it is NOT defined or it is defined as non-internal
421
+ .filter((valueId) => { var _a; return ((_a = valueDefinitions.get(valueId.property)) === null || _a === void 0 ? void 0 : _a.internal) !== true; })
422
+ .filter((valueId) => { var _a; return ((_a = kvpDefinitions.get(valueId.property)) === null || _a === void 0 ? void 0 : _a.internal) !== true; });
423
+ existingValueIds.forEach(({ property, propertyKey }) => addValueId(property, propertyKey));
424
+ return [...ret.values()];
425
+ }
426
+ /** Determines if the given value is an internal value */
427
+ isInternalValue(property) {
428
+ var _a;
429
+ // A value is internal if any of the possible definitions say so (true)
430
+ if ((_a = this._registeredCCValues.get(property)) === null || _a === void 0 ? void 0 : _a.internal) {
431
+ return true;
432
+ }
433
+ const ccValueDefinition = getCCValueDefinitions(this).get(property);
434
+ if ((ccValueDefinition === null || ccValueDefinition === void 0 ? void 0 : ccValueDefinition.internal) === true)
435
+ return true;
436
+ const ccKeyValuePairDefinition = getCCKeyValuePairDefinitions(this).get(property);
437
+ if ((ccKeyValuePairDefinition === null || ccKeyValuePairDefinition === void 0 ? void 0 : ccKeyValuePairDefinition.internal) === true)
438
+ return true;
439
+ return false;
440
+ }
441
+ /** Determines if the given value is an secret value */
442
+ isSecretValue(property) {
443
+ var _a;
444
+ // A value is secret if any of the possible definitions say so (true)
445
+ if ((_a = this._registeredCCValues.get(property)) === null || _a === void 0 ? void 0 : _a.secret) {
446
+ return true;
447
+ }
448
+ const ccValueDefinition = getCCValueDefinitions(this).get(property);
449
+ if ((ccValueDefinition === null || ccValueDefinition === void 0 ? void 0 : ccValueDefinition.secret) === true)
450
+ return true;
451
+ const ccKeyValuePairDefinition = getCCKeyValuePairDefinitions(this).get(property);
452
+ if ((ccKeyValuePairDefinition === null || ccKeyValuePairDefinition === void 0 ? void 0 : ccKeyValuePairDefinition.secret) === true)
453
+ return true;
454
+ return false;
455
+ }
456
+ /** Determines if the given value should always be persisted */
457
+ shouldValueAlwaysBeCreated(property) {
458
+ const ccValueDefinition = getCCValueDefinitions(this).get(property);
459
+ if ((ccValueDefinition === null || ccValueDefinition === void 0 ? void 0 : ccValueDefinition.forceCreation) === true)
460
+ return true;
461
+ const ccKeyValuePairDefinition = getCCKeyValuePairDefinitions(this).get(property);
462
+ if ((ccKeyValuePairDefinition === null || ccKeyValuePairDefinition === void 0 ? void 0 : ccKeyValuePairDefinition.forceCreation) === true)
463
+ return true;
464
+ return false;
465
+ }
466
+ /** Determines if the given value should be persisted or represents an event */
467
+ isStatefulValue(property) {
468
+ const ccValueDefinition = getCCValueDefinitions(this).get(property);
469
+ if ((ccValueDefinition === null || ccValueDefinition === void 0 ? void 0 : ccValueDefinition.stateful) === false)
470
+ return false;
471
+ const ccKeyValuePairDefinition = getCCKeyValuePairDefinitions(this).get(property);
472
+ if ((ccKeyValuePairDefinition === null || ccKeyValuePairDefinition === void 0 ? void 0 : ccKeyValuePairDefinition.stateful) === false)
473
+ return false;
474
+ return true;
475
+ }
476
+ /** Persists all values on the given node into the value. Returns true if the process succeeded, false otherwise */
477
+ persistValues(applHost, valueNames) {
478
+ // In order to avoid cluttering applications with heaps of unsupported properties,
479
+ // we filter out those that are only available in future versions of this CC
480
+ // or have no version constraint
481
+ const keyValuePairDefinitions = getCCKeyValuePairDefinitions(this);
482
+ const keyValuePairs = [...keyValuePairDefinitions].filter(([, options]) => options.minVersion == undefined ||
483
+ options.minVersion <= this.version);
484
+ const ccValueDefinitions = [...getCCValueDefinitions(this)].filter(([, options]) => options.minVersion == undefined ||
485
+ options.minVersion <= this.version);
486
+ // If not specified otherwise, persist all registered values in the value db
487
+ // But filter out those that don't match the minimum version
488
+ if (!valueNames) {
489
+ valueNames = [
490
+ ...this._registeredCCValues.keys(),
491
+ ...ccValueDefinitions.map(([key]) => key),
492
+ ...keyValuePairs.map(([key]) => key),
493
+ ];
494
+ }
495
+ let db;
496
+ try {
497
+ db = this.getValueDB(applHost);
498
+ }
499
+ catch {
500
+ return false;
501
+ }
502
+ const cc = getCommandClass(this);
503
+ for (const variable of valueNames) {
504
+ // interviewComplete automatically updates the value DB, so no need to persist again
505
+ if (variable === "interviewComplete")
506
+ continue;
507
+ // Only persist non-undefined values and things that are not functions
508
+ const sourceValue = this[variable];
509
+ if (typeof sourceValue === "function")
510
+ continue;
511
+ if (sourceValue == undefined &&
512
+ !this.shouldValueAlwaysBeCreated(variable)) {
513
+ continue;
514
+ }
515
+ if (keyValuePairDefinitions.has(variable)) {
516
+ // This value is one or more key value pair(s) to be stored in a map
517
+ if (sourceValue instanceof Map) {
518
+ // Just copy the entries
519
+ for (const [propertyKey, value] of sourceValue.entries()) {
520
+ db.setValue({
521
+ commandClass: cc,
522
+ endpoint: this.endpointIndex,
523
+ property: variable,
524
+ propertyKey,
525
+ }, value);
526
+ }
527
+ }
528
+ else if ((0, typeguards_1.isArray)(sourceValue)) {
529
+ const [propertyKey, value] = sourceValue;
530
+ db.setValue({
531
+ commandClass: cc,
532
+ endpoint: this.endpointIndex,
533
+ property: variable,
534
+ propertyKey,
535
+ }, value);
536
+ }
537
+ else {
538
+ throw new core_1.ZWaveError(`ccKeyValuePairs can only be Maps or [key, value]-tuples`, core_1.ZWaveErrorCodes.Argument_Invalid);
539
+ }
540
+ }
541
+ else {
542
+ // This value belongs to a simple property
543
+ const valueId = {
544
+ commandClass: cc,
545
+ endpoint: this.endpointIndex,
546
+ property: variable,
547
+ };
548
+ // Avoid overwriting existing values with undefined if forceCreation is true
549
+ if (sourceValue != undefined || !db.hasValue(valueId)) {
550
+ // Tell the value DB if this is a stateful value
551
+ const stateful = this.isStatefulValue(variable);
552
+ db.setValue(valueId, sourceValue, { stateful });
553
+ }
554
+ }
555
+ }
556
+ return true;
557
+ }
558
+ /**
559
+ * When a CC supports to be split into multiple partial CCs, this can be used to identify the
560
+ * session the partial CCs belong to.
561
+ * If a CC expects `mergePartialCCs` to be always called, you should return an empty object here.
562
+ */
563
+ getPartialCCSessionId() {
564
+ return undefined; // Only select CCs support to be split
565
+ }
566
+ /**
567
+ * When a CC supports to be split into multiple partial CCs, this indicates that the last report hasn't been received yet.
568
+ * @param _session The previously received set of messages received in this partial CC session
569
+ */
570
+ expectMoreMessages(_session) {
571
+ return false; // By default, all CCs are monolithic
572
+ }
573
+ /** Include previously received partial responses into a final CC */
574
+ /* istanbul ignore next */
575
+ mergePartialCCs(_applHost, _partials) {
576
+ // This is highly CC dependent
577
+ // Overwrite this in derived classes, by default do nothing
578
+ }
579
+ /** Tests whether this CC expects at least one command in return */
580
+ expectsCCResponse() {
581
+ let expected = getExpectedCCResponse(this);
582
+ // Evaluate dynamic CC responses
583
+ if (typeof expected === "function" &&
584
+ !(0, shared_1.staticExtends)(expected, CommandClass)) {
585
+ expected = expected(this);
586
+ }
587
+ if (expected === undefined)
588
+ return false;
589
+ if ((0, typeguards_1.isArray)(expected)) {
590
+ return expected.every((cc) => (0, shared_1.staticExtends)(cc, CommandClass));
591
+ }
592
+ else {
593
+ return (0, shared_1.staticExtends)(expected, CommandClass);
594
+ }
595
+ }
596
+ isExpectedCCResponse(received) {
597
+ var _a;
598
+ if (received.nodeId !== this.nodeId)
599
+ return false;
600
+ let expected = getExpectedCCResponse(this);
601
+ // Evaluate dynamic CC responses
602
+ if (typeof expected === "function" &&
603
+ !(0, shared_1.staticExtends)(expected, CommandClass)) {
604
+ expected = expected(this);
605
+ }
606
+ if (expected == undefined) {
607
+ // Fallback, should not happen if the expected response is defined correctly
608
+ return false;
609
+ }
610
+ else if ((0, typeguards_1.isArray)(expected) &&
611
+ expected.every((cc) => (0, shared_1.staticExtends)(cc, CommandClass))) {
612
+ // The CC always expects a response from the given list, check if the received
613
+ // message is in that list
614
+ if (expected.every((base) => !(received instanceof base))) {
615
+ return false;
616
+ }
617
+ }
618
+ else if ((0, shared_1.staticExtends)(expected, CommandClass)) {
619
+ // The CC always expects the same single response, check if this is the one
620
+ if (!(received instanceof expected))
621
+ return false;
622
+ }
623
+ // If the CC wants to test the response, let it
624
+ const predicate = getCCResponsePredicate(this);
625
+ const ret = (_a = predicate === null || predicate === void 0 ? void 0 : predicate(this, received)) !== null && _a !== void 0 ? _a : true;
626
+ if (ret === "checkEncapsulated") {
627
+ if ((0, EncapsulatingCommandClass_1.isEncapsulatingCommandClass)(this) &&
628
+ (0, EncapsulatingCommandClass_1.isEncapsulatingCommandClass)(received)) {
629
+ return this.encapsulated.isExpectedCCResponse(received.encapsulated);
630
+ }
631
+ else {
632
+ // Fallback, should not happen if the expected response is defined correctly
633
+ return false;
634
+ }
635
+ }
636
+ return ret;
637
+ }
638
+ /**
639
+ * Translates a property identifier into a speaking name for use in an external API
640
+ * @param property The property identifier that should be translated
641
+ * @param _propertyKey The (optional) property key the translated name may depend on
642
+ */
643
+ translateProperty(_applHost, property, _propertyKey) {
644
+ // Overwrite this in derived classes, by default just return the property key
645
+ return property.toString();
646
+ }
647
+ /**
648
+ * Translates a property key into a speaking name for use in an external API
649
+ * @param _property The property the key in question belongs to
650
+ * @param propertyKey The property key for which the speaking name should be retrieved
651
+ */
652
+ translatePropertyKey(_applHost, _property, propertyKey) {
653
+ // Overwrite this in derived classes, by default just return the property key
654
+ return propertyKey.toString();
655
+ }
656
+ /** Returns the number of bytes that are added to the payload by this CC */
657
+ computeEncapsulationOverhead() {
658
+ // Default is ccId (+ ccCommand):
659
+ return (this.isExtended() ? 2 : 1) + 1;
660
+ }
661
+ /** Computes the maximum net payload size that can be transmitted inside this CC */
662
+ getMaxPayloadLength(baseLength) {
663
+ let ret = baseLength;
664
+ let cur = this;
665
+ while (cur) {
666
+ ret -= cur.computeEncapsulationOverhead();
667
+ cur = (0, EncapsulatingCommandClass_1.isEncapsulatingCommandClass)(cur)
668
+ ? cur.encapsulated
669
+ : undefined;
670
+ }
671
+ return ret;
672
+ }
673
+ /** Checks whether this CC is encapsulated with one that has the given CC id and (optionally) CC Command */
674
+ isEncapsulatedWith(ccId, ccCommand) {
675
+ let cc = this;
676
+ // Check whether there was a S0 encapsulation
677
+ while (cc.encapsulatingCC) {
678
+ cc = cc.encapsulatingCC;
679
+ if (cc.ccId === ccId &&
680
+ (ccCommand === undefined || cc.ccCommand === ccCommand)) {
681
+ return true;
682
+ }
683
+ }
684
+ return false;
685
+ }
686
+ /** Traverses the encapsulation stack of this CC and returns the one that has the given CC id and (optionally) CC Command if that exists. */
687
+ getEncapsulatingCC(ccId, ccCommand) {
688
+ let cc = this;
689
+ while (cc.encapsulatingCC) {
690
+ cc = cc.encapsulatingCC;
691
+ if (cc.ccId === ccId &&
692
+ (ccCommand === undefined || cc.ccCommand === ccCommand)) {
693
+ return cc;
694
+ }
695
+ }
696
+ }
697
+ }
698
+ exports.CommandClass = CommandClass;
699
+ class InvalidCC extends CommandClass {
700
+ constructor(host, options) {
701
+ super(host, options);
702
+ this._ccName = options.ccName;
703
+ // Numeric reasons are used internally to communicate problems with a CC
704
+ // without ignoring them entirely
705
+ this.reason = options.reason;
706
+ }
707
+ get ccName() {
708
+ return this._ccName;
709
+ }
710
+ toLogEntry() {
711
+ return {
712
+ tags: [this.ccName, "INVALID"],
713
+ message: this.reason != undefined
714
+ ? {
715
+ error: typeof this.reason === "string"
716
+ ? this.reason
717
+ : (0, shared_1.getEnumMemberName)(core_1.ZWaveErrorCodes, this.reason),
718
+ }
719
+ : undefined,
720
+ };
721
+ }
722
+ }
723
+ exports.InvalidCC = InvalidCC;
724
+ /** @publicAPI */
725
+ function assertValidCCs(container) {
726
+ if (container.command instanceof InvalidCC) {
727
+ if (typeof container.command.reason === "number") {
728
+ throw new core_1.ZWaveError("The message payload failed validation!", container.command.reason);
729
+ }
730
+ else {
731
+ throw new core_1.ZWaveError("The message payload is invalid!", core_1.ZWaveErrorCodes.PacketFormat_InvalidPayload, container.command.reason);
732
+ }
733
+ }
734
+ else if ((0, ICommandClassContainer_1.isCommandClassContainer)(container.command)) {
735
+ assertValidCCs(container.command);
736
+ }
737
+ }
738
+ exports.assertValidCCs = assertValidCCs;
739
+ // =======================
740
+ // use decorators to link command class values to actual command classes
741
+ const METADATA_commandClass = Symbol("commandClass");
742
+ const METADATA_commandClassMap = Symbol("commandClassMap");
743
+ const METADATA_ccResponse = Symbol("ccResponse");
744
+ const METADATA_ccCommand = Symbol("ccCommand");
745
+ const METADATA_ccCommandMap = Symbol("ccCommandMap");
746
+ const METADATA_ccValues = Symbol("ccValues");
747
+ const METADATA_ccKeyValuePairs = Symbol("ccKeyValuePairs");
748
+ const METADATA_ccValueMeta = Symbol("ccValueMeta");
749
+ const METADATA_version = Symbol("version");
750
+ const METADATA_API = Symbol("API");
751
+ const METADATA_APIMap = Symbol("APIMap");
752
+ function getCCCommandMapKey(ccId, ccCommand) {
753
+ return JSON.stringify({ ccId, ccCommand });
754
+ }
755
+ /**
756
+ * @publicAPI
757
+ * Defines the command class associated with a Z-Wave message
758
+ */
759
+ function commandClass(cc) {
760
+ return (messageClass) => {
761
+ Reflect.defineMetadata(METADATA_commandClass, cc, messageClass);
762
+ // also store a map in the CommandClass metadata for lookup.
763
+ const map = Reflect.getMetadata(METADATA_commandClassMap, CommandClass) ||
764
+ new Map();
765
+ map.set(cc, messageClass);
766
+ Reflect.defineMetadata(METADATA_commandClassMap, map, CommandClass);
767
+ };
768
+ }
769
+ exports.commandClass = commandClass;
770
+ /**
771
+ * @publicAPI
772
+ * Retrieves the command class defined for a Z-Wave message class
773
+ */
774
+ function getCommandClass(cc) {
775
+ // get the class constructor
776
+ const constr = cc.constructor;
777
+ // retrieve the current metadata
778
+ const ret = cc instanceof CommandClass
779
+ ? Reflect.getMetadata(METADATA_commandClass, constr)
780
+ : cc instanceof API_1.CCAPI
781
+ ? Reflect.getMetadata(METADATA_API, constr)
782
+ : undefined;
783
+ if (ret == undefined) {
784
+ throw new core_1.ZWaveError(`No command class defined for ${constr.name}!`, core_1.ZWaveErrorCodes.CC_Invalid);
785
+ }
786
+ return ret;
787
+ }
788
+ exports.getCommandClass = getCommandClass;
789
+ /**
790
+ * @publicAPI
791
+ * Retrieves the function type defined for a Z-Wave message class
792
+ */
793
+ function getCommandClassStatic(classConstructor) {
794
+ // retrieve the current metadata
795
+ const ret = Reflect.getMetadata(METADATA_commandClass, classConstructor);
796
+ if (ret == undefined) {
797
+ throw new core_1.ZWaveError(`No command class defined for ${classConstructor.name}!`, core_1.ZWaveErrorCodes.CC_Invalid);
798
+ }
799
+ return ret;
800
+ }
801
+ exports.getCommandClassStatic = getCommandClassStatic;
802
+ /**
803
+ * @publicAPI
804
+ * Looks up the command class constructor for a given command class type and function type
805
+ */
806
+ function getCCConstructor(cc) {
807
+ // Retrieve the constructor map from the CommandClass class
808
+ const map = Reflect.getMetadata(METADATA_commandClassMap, CommandClass);
809
+ if (map != undefined)
810
+ return map.get(cc);
811
+ }
812
+ exports.getCCConstructor = getCCConstructor;
813
+ /**
814
+ * @publicAPI
815
+ * Defines the implemented version of a Z-Wave command class
816
+ */
817
+ function implementedVersion(version) {
818
+ return (ccClass) => {
819
+ Reflect.defineMetadata(METADATA_version, version, ccClass);
820
+ };
821
+ }
822
+ exports.implementedVersion = implementedVersion;
823
+ /**
824
+ * @publicAPI
825
+ * Retrieves the implemented version defined for a Z-Wave command class
826
+ */
827
+ function getImplementedVersion(cc) {
828
+ // get the class constructor
829
+ let constr;
830
+ if (typeof cc === "number") {
831
+ constr = getCCConstructor(cc);
832
+ }
833
+ else {
834
+ constr = cc.constructor;
835
+ }
836
+ // retrieve the current metadata
837
+ let ret;
838
+ if (constr != undefined)
839
+ ret = Reflect.getMetadata(METADATA_version, constr);
840
+ if (ret == undefined)
841
+ ret = 0;
842
+ return ret;
843
+ }
844
+ exports.getImplementedVersion = getImplementedVersion;
845
+ /**
846
+ * @publicAPI
847
+ * Retrieves the implemented version defined for a Z-Wave command class
848
+ */
849
+ function getImplementedVersionStatic(classConstructor) {
850
+ // retrieve the current metadata
851
+ const ret = Reflect.getMetadata(METADATA_version, classConstructor) || 0;
852
+ return ret;
853
+ }
854
+ exports.getImplementedVersionStatic = getImplementedVersionStatic;
855
+ /**
856
+ * @publicAPI
857
+ * Defines the CC command a subclass of a CC implements
858
+ */
859
+ function CCCommand(command) {
860
+ return (ccClass) => {
861
+ Reflect.defineMetadata(METADATA_ccCommand, command, ccClass);
862
+ // also store a map in the Message metadata for lookup.
863
+ const ccId = getCommandClassStatic(ccClass);
864
+ const map = Reflect.getMetadata(METADATA_ccCommandMap, CommandClass) ||
865
+ new Map();
866
+ map.set(getCCCommandMapKey(ccId, command), ccClass);
867
+ Reflect.defineMetadata(METADATA_ccCommandMap, map, CommandClass);
868
+ };
869
+ }
870
+ exports.CCCommand = CCCommand;
871
+ /**
872
+ * @publicAPI
873
+ * Retrieves the CC command a subclass of a CC implements
874
+ */
875
+ function getCCCommand(cc) {
876
+ // get the class constructor
877
+ const constr = cc.constructor;
878
+ // retrieve the current metadata
879
+ const ret = Reflect.getMetadata(METADATA_ccCommand, constr);
880
+ return ret;
881
+ }
882
+ exports.getCCCommand = getCCCommand;
883
+ /**
884
+ * @publicAPI
885
+ * Looks up the command class constructor for a given command class type and function type
886
+ */
887
+ function getCCCommandConstructor(ccId, ccCommand) {
888
+ // Retrieve the constructor map from the CommandClass class
889
+ const map = Reflect.getMetadata(METADATA_ccCommandMap, CommandClass);
890
+ if (map != undefined)
891
+ return map.get(getCCCommandMapKey(ccId, ccCommand));
892
+ }
893
+ exports.getCCCommandConstructor = getCCCommandConstructor;
894
+ /**
895
+ * @publicAPI
896
+ * Defines the expected response associated with a Z-Wave message
897
+ */
898
+ function expectedCCResponse(cc, predicate) {
899
+ return (ccClass) => {
900
+ Reflect.defineMetadata(METADATA_ccResponse, { cc, predicate }, ccClass);
901
+ };
902
+ }
903
+ exports.expectedCCResponse = expectedCCResponse;
904
+ /**
905
+ * @publicAPI
906
+ * Retrieves the expected response (static or dynamic) defined for a Z-Wave message class
907
+ */
908
+ function getExpectedCCResponse(ccClass) {
909
+ // get the class constructor
910
+ const constr = ccClass.constructor;
911
+ // retrieve the current metadata
912
+ const ret = Reflect.getMetadata(METADATA_ccResponse, constr);
913
+ return ret === null || ret === void 0 ? void 0 : ret.cc;
914
+ }
915
+ exports.getExpectedCCResponse = getExpectedCCResponse;
916
+ /**
917
+ * @publicAPI
918
+ * Retrieves the CC response predicate defined for a Z-Wave message class
919
+ */
920
+ function getCCResponsePredicate(ccClass) {
921
+ // get the class constructor
922
+ const constr = ccClass.constructor;
923
+ // retrieve the current metadata
924
+ const ret = Reflect.getMetadata(METADATA_ccResponse, constr);
925
+ return ret === null || ret === void 0 ? void 0 : ret.predicate;
926
+ }
927
+ exports.getCCResponsePredicate = getCCResponsePredicate;
928
+ /**
929
+ * @publicAPI
930
+ * Marks the decorated property as a value of the Command Class. This allows saving it on the node with persistValues()
931
+ * @param internal Whether the value should be exposed to library users
932
+ */
933
+ function ccValue(options) {
934
+ return (target, property) => {
935
+ var _a;
936
+ if (!target || !(target instanceof CommandClass))
937
+ return;
938
+ // Set default arguments
939
+ if (!options)
940
+ options = {};
941
+ if (options.internal == undefined)
942
+ options.internal = false;
943
+ if (options.minVersion == undefined)
944
+ options.minVersion = 1;
945
+ if (options.forceCreation == undefined)
946
+ options.forceCreation = false;
947
+ // get the class constructor
948
+ const constr = target.constructor;
949
+ const cc = getCommandClassStatic(constr);
950
+ // retrieve the current metadata
951
+ const metadata = (_a = Reflect.getMetadata(METADATA_ccValues, CommandClass)) !== null && _a !== void 0 ? _a : {};
952
+ if (!(cc in metadata))
953
+ metadata[cc] = new Map();
954
+ // And add the variable
955
+ const variables = metadata[cc];
956
+ variables.set(property, options);
957
+ // store back to the object
958
+ Reflect.defineMetadata(METADATA_ccValues, metadata, CommandClass);
959
+ };
960
+ }
961
+ exports.ccValue = ccValue;
962
+ /**
963
+ * Returns all CC values and their definitions that have been defined with @ccValue()
964
+ */
965
+ function getCCValueDefinitions(commandClass) {
966
+ var _a;
967
+ // get the class constructor
968
+ const constr = commandClass.constructor;
969
+ const cc = getCommandClassStatic(constr);
970
+ // retrieve the current metadata
971
+ const metadata = (_a = Reflect.getMetadata(METADATA_ccValues, CommandClass)) !== null && _a !== void 0 ? _a : {};
972
+ if (!(cc in metadata))
973
+ return new Map();
974
+ return metadata[cc];
975
+ }
976
+ /**
977
+ * @publicAPI
978
+ * Marks the decorated property as the key of a Command Class's key value pair,
979
+ * which can later be saved with persistValues()
980
+ * @param internal Whether the key value pair should be exposed to library users
981
+ */
982
+ function ccKeyValuePair(options) {
983
+ return (target, property) => {
984
+ if (!target || !(target instanceof CommandClass))
985
+ return;
986
+ // Set default arguments
987
+ if (!options)
988
+ options = {};
989
+ if (options.internal == undefined)
990
+ options.internal = false;
991
+ if (options.minVersion == undefined)
992
+ options.minVersion = 1;
993
+ if (options.forceCreation == undefined)
994
+ options.forceCreation = false;
995
+ // get the class constructor
996
+ const constr = target.constructor;
997
+ const cc = getCommandClassStatic(constr);
998
+ // retrieve the current metadata
999
+ const metadata = Reflect.getMetadata(METADATA_ccKeyValuePairs, CommandClass) || {};
1000
+ if (!(cc in metadata))
1001
+ metadata[cc] = new Map();
1002
+ // And add the variable
1003
+ const variables = metadata[cc];
1004
+ variables.set(property, options);
1005
+ // store back to the object
1006
+ Reflect.defineMetadata(METADATA_ccKeyValuePairs, metadata, CommandClass);
1007
+ };
1008
+ }
1009
+ exports.ccKeyValuePair = ccKeyValuePair;
1010
+ /**
1011
+ * Returns all CC key value pairs and their definitions that have been defined with @ccKeyValuePair()
1012
+ */
1013
+ function getCCKeyValuePairDefinitions(commandClass) {
1014
+ // get the class constructor
1015
+ const constr = commandClass.constructor;
1016
+ const cc = getCommandClassStatic(constr);
1017
+ // retrieve the current metadata
1018
+ const metadata = Reflect.getMetadata(METADATA_ccKeyValuePairs, CommandClass) || {};
1019
+ if (!(cc in metadata))
1020
+ return new Map();
1021
+ return metadata[cc];
1022
+ }
1023
+ /**
1024
+ * @publicAPI
1025
+ * Defines additional metadata for the given CC value
1026
+ */
1027
+ function ccValueMetadata(meta) {
1028
+ return (target, property) => {
1029
+ if (!target || !(target instanceof CommandClass))
1030
+ return;
1031
+ // get the class constructor
1032
+ const constr = target.constructor;
1033
+ const cc = getCommandClassStatic(constr);
1034
+ // retrieve the current metadata
1035
+ const metadata = Reflect.getMetadata(METADATA_ccValueMeta, CommandClass) || {};
1036
+ if (!(cc in metadata))
1037
+ metadata[cc] = new Map();
1038
+ // And add the variable
1039
+ const variables = metadata[cc];
1040
+ variables.set(property, meta);
1041
+ // store back to the object
1042
+ Reflect.defineMetadata(METADATA_ccValueMeta, metadata, CommandClass);
1043
+ };
1044
+ }
1045
+ exports.ccValueMetadata = ccValueMetadata;
1046
+ /**
1047
+ * @publicAPI
1048
+ * Retrieves defined metadata for the given CC value. If none is found, the default settings are returned.
1049
+ */
1050
+ function getCCValueMetadata(cc, property) {
1051
+ // retrieve the current metadata
1052
+ const metadata = Reflect.getMetadata(METADATA_ccValueMeta, CommandClass) || {};
1053
+ if (!(cc in metadata))
1054
+ return core_1.ValueMetadata.Any;
1055
+ const map = metadata[cc];
1056
+ if (map.has(property))
1057
+ return map.get(property);
1058
+ return core_1.ValueMetadata.Any;
1059
+ }
1060
+ exports.getCCValueMetadata = getCCValueMetadata;
1061
+ /**
1062
+ * @publicAPI
1063
+ * Defines the simplified API associated with a Z-Wave command class
1064
+ */
1065
+ function API(cc) {
1066
+ return (apiClass) => {
1067
+ // and store the metadata
1068
+ Reflect.defineMetadata(METADATA_API, cc, apiClass);
1069
+ // also store a map in the CCAPI metadata for lookup.
1070
+ const map = (Reflect.getMetadata(METADATA_APIMap, API_1.CCAPI) ||
1071
+ new Map());
1072
+ map.set(cc, apiClass);
1073
+ Reflect.defineMetadata(METADATA_APIMap, map, API_1.CCAPI);
1074
+ };
1075
+ }
1076
+ exports.API = API;
1077
+ /**
1078
+ * @publicAPI
1079
+ * Retrieves the CC API constructor that is defined for a Z-Wave command class
1080
+ */
1081
+ function getAPI(cc) {
1082
+ // Retrieve the constructor map from the CCAPI class
1083
+ const map = Reflect.getMetadata(METADATA_APIMap, API_1.CCAPI);
1084
+ const ret = map === null || map === void 0 ? void 0 : map.get(cc);
1085
+ return ret;
1086
+ }
1087
+ exports.getAPI = getAPI;
1088
+ //# sourceMappingURL=CommandClass.js.map