isy-nodejs 1.0.1-alpha.26 → 1.0.1-alpha.28

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 (218) hide show
  1. package/dist/cjs/CodeGeneration/EnumFactory.js +6 -6
  2. package/dist/cjs/CodeGeneration/EnumFactory.js.map +1 -1
  3. package/dist/cjs/CodeGeneration/NodeClassFactory.js +7 -7
  4. package/dist/cjs/CodeGeneration/NodeClassFactory.js.map +1 -1
  5. package/dist/cjs/Converters.js +10 -13
  6. package/dist/cjs/Converters.js.map +1 -1
  7. package/dist/cjs/Definitions/Global/Commands.js.map +1 -1
  8. package/dist/cjs/Devices/ISYDeviceNode.js.map +1 -1
  9. package/dist/cjs/Devices/Insteon/DimmerLampSwitch.js +2 -2
  10. package/dist/cjs/Devices/Insteon/DimmerLampSwitch.js.map +1 -1
  11. package/dist/cjs/Devices/Insteon/InsteonDevice.js.map +1 -1
  12. package/dist/cjs/Devices/Insteon/InsteonDeviceFactory.js +12 -8
  13. package/dist/cjs/Devices/Insteon/InsteonDeviceFactory.js.map +1 -1
  14. package/dist/cjs/Devices/Insteon/InsteonKeypadDevice.js +2 -2
  15. package/dist/cjs/Devices/Insteon/InsteonKeypadDevice.js.map +1 -1
  16. package/dist/cjs/Devices/Insteon/KeypadButton.js +52 -0
  17. package/dist/cjs/Devices/Insteon/KeypadButton.js.map +1 -0
  18. package/dist/cjs/Devices/Insteon/RelayLampSwitch.js +5 -5
  19. package/dist/cjs/Devices/Insteon/RelayLampSwitch.js.map +1 -1
  20. package/dist/cjs/Devices/NodeFactory.js +5 -4
  21. package/dist/cjs/Devices/NodeFactory.js.map +1 -1
  22. package/dist/cjs/Devices/index.js.map +1 -1
  23. package/dist/cjs/ISY.js +220 -213
  24. package/dist/cjs/ISY.js.map +1 -1
  25. package/dist/cjs/ISYNode.js +3 -3
  26. package/dist/cjs/ISYNode.js.map +1 -1
  27. package/dist/cjs/ISYScene.js +1 -1
  28. package/dist/cjs/ISYScene.js.map +1 -1
  29. package/dist/cjs/Matter/Behaviors/ISYBridgedDeviceBehavior.js.map +1 -1
  30. package/dist/cjs/Matter/Behaviors/ISYClusterBehavior.js +7 -5
  31. package/dist/cjs/Matter/Behaviors/ISYClusterBehavior.js.map +1 -1
  32. package/dist/cjs/Matter/Behaviors/ISYOnOffBehavior.js +1 -1
  33. package/dist/cjs/Matter/Behaviors/ISYOnOffBehavior.js.map +1 -1
  34. package/dist/cjs/Matter/Behaviors/Insteon/ISYOnOffBehavior.js +47 -0
  35. package/dist/cjs/Matter/Behaviors/Insteon/ISYOnOffBehavior.js.map +1 -0
  36. package/dist/cjs/Matter/Bridge/Server.js +5 -5
  37. package/dist/cjs/Matter/Bridge/Server.js.map +1 -1
  38. package/dist/cjs/Matter/Mappings/Insteon.js +3 -4
  39. package/dist/cjs/Matter/Mappings/Insteon.js.map +1 -1
  40. package/dist/cjs/Model/ClusterMap.js +2 -2
  41. package/dist/cjs/Model/ClusterMap.js.map +1 -1
  42. package/dist/cjs/Model/NodeInfo.js +3 -3
  43. package/dist/cjs/Model/NodeInfo.js.map +1 -1
  44. package/dist/cjs/Utils.js.map +1 -1
  45. package/dist/cjs/types/CodeGeneration/EnumFactory.d.ts +1 -1
  46. package/dist/cjs/types/CodeGeneration/EnumFactory.d.ts.map +1 -1
  47. package/dist/cjs/types/CodeGeneration/NodeClassFactory.d.ts +1 -1
  48. package/dist/cjs/types/CodeGeneration/NodeClassFactory.d.ts.map +1 -1
  49. package/dist/cjs/types/Converters.d.ts +15 -2
  50. package/dist/cjs/types/Converters.d.ts.map +1 -1
  51. package/dist/cjs/types/Definitions/Global/Commands.d.ts +1 -1
  52. package/dist/cjs/types/Definitions/Global/Commands.d.ts.map +1 -1
  53. package/dist/cjs/types/Devices/EndpointFor.d.ts +1 -1
  54. package/dist/cjs/types/Devices/ISYDeviceNode.d.ts +2 -1
  55. package/dist/cjs/types/Devices/ISYDeviceNode.d.ts.map +1 -1
  56. package/dist/cjs/types/Devices/Insteon/DimmerLampSwitch.d.ts +1 -1
  57. package/dist/cjs/types/Devices/Insteon/DimmerLampSwitch.d.ts.map +1 -1
  58. package/dist/cjs/types/Devices/Insteon/InsteonDevice.d.ts +8 -7
  59. package/dist/cjs/types/Devices/Insteon/InsteonDevice.d.ts.map +1 -1
  60. package/dist/cjs/types/Devices/Insteon/InsteonDeviceFactory.d.ts +2 -1
  61. package/dist/cjs/types/Devices/Insteon/InsteonDeviceFactory.d.ts.map +1 -1
  62. package/dist/cjs/types/Devices/Insteon/InsteonFanDevice.d.ts.map +1 -1
  63. package/dist/cjs/types/Devices/Insteon/InsteonKeypadDevice.d.ts +4 -4
  64. package/dist/cjs/types/Devices/Insteon/InsteonKeypadDevice.d.ts.map +1 -1
  65. package/dist/cjs/types/Devices/Insteon/InsteonRelayDevice.d.ts.map +1 -1
  66. package/dist/cjs/types/Devices/Insteon/KeypadButton.d.ts +63 -0
  67. package/dist/cjs/types/Devices/Insteon/KeypadButton.d.ts.map +1 -0
  68. package/dist/cjs/types/Devices/Insteon/RelayLampSwitch.d.ts +32 -32
  69. package/dist/cjs/types/Devices/Insteon/RelayLampSwitch.d.ts.map +1 -1
  70. package/dist/cjs/types/Devices/NodeFactory.d.ts +2 -1
  71. package/dist/cjs/types/Devices/NodeFactory.d.ts.map +1 -1
  72. package/dist/cjs/types/Devices/index.d.ts +1 -1
  73. package/dist/cjs/types/Devices/index.d.ts.map +1 -1
  74. package/dist/cjs/types/ISY.d.ts +13 -28
  75. package/dist/cjs/types/ISY.d.ts.map +1 -1
  76. package/dist/cjs/types/ISYDevice.d.ts +1 -1
  77. package/dist/cjs/types/ISYDevice.d.ts.map +1 -1
  78. package/dist/cjs/types/ISYNode.d.ts +4 -2
  79. package/dist/cjs/types/ISYNode.d.ts.map +1 -1
  80. package/dist/cjs/types/Matter/Behaviors/ISYBridgedDeviceBehavior.d.ts +1 -1
  81. package/dist/cjs/types/Matter/Behaviors/ISYBridgedDeviceBehavior.d.ts.map +1 -1
  82. package/dist/cjs/types/Matter/Behaviors/ISYClusterBehavior.d.ts.map +1 -1
  83. package/dist/cjs/types/Matter/Behaviors/Insteon/ISYOnOffBehavior.d.ts +54 -0
  84. package/dist/cjs/types/Matter/Behaviors/Insteon/ISYOnOffBehavior.d.ts.map +1 -0
  85. package/dist/cjs/types/Matter/Bridge/Server.d.ts.map +1 -1
  86. package/dist/cjs/types/Model/ClusterMap.d.ts +1 -1
  87. package/dist/cjs/types/Model/ClusterMap.d.ts.map +1 -1
  88. package/dist/cjs/types/Model/EnumDefinition.d.ts +1 -1
  89. package/dist/cjs/types/Model/NodeInfo.d.ts +2 -2
  90. package/dist/cjs/types/Model/NodeInfo.d.ts.map +1 -1
  91. package/dist/cjs/types/Utils.d.ts +8 -1
  92. package/dist/cjs/types/Utils.d.ts.map +1 -1
  93. package/dist/esm/CodeGeneration/EnumFactory.js +1 -1
  94. package/dist/esm/CodeGeneration/EnumFactory.js.map +1 -1
  95. package/dist/esm/CodeGeneration/NodeClassFactory.js +1 -1
  96. package/dist/esm/CodeGeneration/NodeClassFactory.js.map +1 -1
  97. package/dist/esm/Converters.js +10 -13
  98. package/dist/esm/Converters.js.map +1 -1
  99. package/dist/esm/Definitions/Global/Commands.js.map +1 -1
  100. package/dist/esm/Devices/ISYDeviceNode.js.map +1 -1
  101. package/dist/esm/Devices/Insteon/DimmerLampSwitch.js +2 -2
  102. package/dist/esm/Devices/Insteon/DimmerLampSwitch.js.map +1 -1
  103. package/dist/esm/Devices/Insteon/InsteonDevice.js.map +1 -1
  104. package/dist/esm/Devices/Insteon/InsteonDeviceFactory.js +5 -1
  105. package/dist/esm/Devices/Insteon/InsteonDeviceFactory.js.map +1 -1
  106. package/dist/esm/Devices/Insteon/InsteonKeypadDevice.js +2 -2
  107. package/dist/esm/Devices/Insteon/InsteonKeypadDevice.js.map +1 -1
  108. package/dist/esm/Devices/Insteon/KeypadButton.js +48 -0
  109. package/dist/esm/Devices/Insteon/KeypadButton.js.map +1 -0
  110. package/dist/esm/Devices/Insteon/RelayLampSwitch.js +7 -7
  111. package/dist/esm/Devices/Insteon/RelayLampSwitch.js.map +1 -1
  112. package/dist/esm/Devices/NodeFactory.js +2 -1
  113. package/dist/esm/Devices/NodeFactory.js.map +1 -1
  114. package/dist/esm/Devices/index.js.map +1 -1
  115. package/dist/esm/ISY.js +220 -183
  116. package/dist/esm/ISY.js.map +1 -1
  117. package/dist/esm/ISYNode.js +2 -2
  118. package/dist/esm/ISYNode.js.map +1 -1
  119. package/dist/esm/ISYScene.js +1 -1
  120. package/dist/esm/ISYScene.js.map +1 -1
  121. package/dist/esm/Matter/Behaviors/ISYBridgedDeviceBehavior.js.map +1 -1
  122. package/dist/esm/Matter/Behaviors/ISYClusterBehavior.js +7 -5
  123. package/dist/esm/Matter/Behaviors/ISYClusterBehavior.js.map +1 -1
  124. package/dist/esm/Matter/Behaviors/ISYOnOffBehavior.js +1 -1
  125. package/dist/esm/Matter/Behaviors/ISYOnOffBehavior.js.map +1 -1
  126. package/dist/esm/Matter/Behaviors/Insteon/ISYOnOffBehavior.js +42 -0
  127. package/dist/esm/Matter/Behaviors/Insteon/ISYOnOffBehavior.js.map +1 -0
  128. package/dist/esm/Matter/Bridge/Server.js +6 -6
  129. package/dist/esm/Matter/Bridge/Server.js.map +1 -1
  130. package/dist/esm/Matter/Mappings/Insteon.js +3 -4
  131. package/dist/esm/Matter/Mappings/Insteon.js.map +1 -1
  132. package/dist/esm/Model/ClusterMap.js +2 -2
  133. package/dist/esm/Model/ClusterMap.js.map +1 -1
  134. package/dist/esm/Model/NodeInfo.js +1 -1
  135. package/dist/esm/Model/NodeInfo.js.map +1 -1
  136. package/dist/esm/Utils.js.map +1 -1
  137. package/dist/esm/types/CodeGeneration/EnumFactory.d.ts +1 -1
  138. package/dist/esm/types/CodeGeneration/EnumFactory.d.ts.map +1 -1
  139. package/dist/esm/types/CodeGeneration/NodeClassFactory.d.ts +1 -1
  140. package/dist/esm/types/CodeGeneration/NodeClassFactory.d.ts.map +1 -1
  141. package/dist/esm/types/Converters.d.ts +15 -2
  142. package/dist/esm/types/Converters.d.ts.map +1 -1
  143. package/dist/esm/types/Definitions/Global/Commands.d.ts +1 -1
  144. package/dist/esm/types/Definitions/Global/Commands.d.ts.map +1 -1
  145. package/dist/esm/types/Devices/EndpointFor.d.ts +1 -1
  146. package/dist/esm/types/Devices/ISYDeviceNode.d.ts +2 -1
  147. package/dist/esm/types/Devices/ISYDeviceNode.d.ts.map +1 -1
  148. package/dist/esm/types/Devices/Insteon/DimmerLampSwitch.d.ts +1 -1
  149. package/dist/esm/types/Devices/Insteon/DimmerLampSwitch.d.ts.map +1 -1
  150. package/dist/esm/types/Devices/Insteon/InsteonDevice.d.ts +8 -7
  151. package/dist/esm/types/Devices/Insteon/InsteonDevice.d.ts.map +1 -1
  152. package/dist/esm/types/Devices/Insteon/InsteonDeviceFactory.d.ts +2 -1
  153. package/dist/esm/types/Devices/Insteon/InsteonDeviceFactory.d.ts.map +1 -1
  154. package/dist/esm/types/Devices/Insteon/InsteonFanDevice.d.ts.map +1 -1
  155. package/dist/esm/types/Devices/Insteon/InsteonKeypadDevice.d.ts +4 -4
  156. package/dist/esm/types/Devices/Insteon/InsteonKeypadDevice.d.ts.map +1 -1
  157. package/dist/esm/types/Devices/Insteon/InsteonRelayDevice.d.ts.map +1 -1
  158. package/dist/esm/types/Devices/Insteon/KeypadButton.d.ts +63 -0
  159. package/dist/esm/types/Devices/Insteon/KeypadButton.d.ts.map +1 -0
  160. package/dist/esm/types/Devices/Insteon/RelayLampSwitch.d.ts +32 -32
  161. package/dist/esm/types/Devices/Insteon/RelayLampSwitch.d.ts.map +1 -1
  162. package/dist/esm/types/Devices/NodeFactory.d.ts +2 -1
  163. package/dist/esm/types/Devices/NodeFactory.d.ts.map +1 -1
  164. package/dist/esm/types/Devices/index.d.ts +1 -1
  165. package/dist/esm/types/Devices/index.d.ts.map +1 -1
  166. package/dist/esm/types/ISY.d.ts +13 -28
  167. package/dist/esm/types/ISY.d.ts.map +1 -1
  168. package/dist/esm/types/ISYDevice.d.ts +1 -1
  169. package/dist/esm/types/ISYDevice.d.ts.map +1 -1
  170. package/dist/esm/types/ISYNode.d.ts +4 -2
  171. package/dist/esm/types/ISYNode.d.ts.map +1 -1
  172. package/dist/esm/types/Matter/Behaviors/ISYBridgedDeviceBehavior.d.ts +1 -1
  173. package/dist/esm/types/Matter/Behaviors/ISYBridgedDeviceBehavior.d.ts.map +1 -1
  174. package/dist/esm/types/Matter/Behaviors/ISYClusterBehavior.d.ts.map +1 -1
  175. package/dist/esm/types/Matter/Behaviors/Insteon/ISYOnOffBehavior.d.ts +54 -0
  176. package/dist/esm/types/Matter/Behaviors/Insteon/ISYOnOffBehavior.d.ts.map +1 -0
  177. package/dist/esm/types/Matter/Bridge/Server.d.ts.map +1 -1
  178. package/dist/esm/types/Model/ClusterMap.d.ts +1 -1
  179. package/dist/esm/types/Model/ClusterMap.d.ts.map +1 -1
  180. package/dist/esm/types/Model/EnumDefinition.d.ts +1 -1
  181. package/dist/esm/types/Model/NodeInfo.d.ts +2 -2
  182. package/dist/esm/types/Model/NodeInfo.d.ts.map +1 -1
  183. package/dist/esm/types/Utils.d.ts +8 -1
  184. package/dist/esm/types/Utils.d.ts.map +1 -1
  185. package/dist/tsconfig.cjs.tsbuildinfo +1 -1
  186. package/dist/tsconfig.esm.tsbuildinfo +1 -1
  187. package/package.json +2 -2
  188. package/src/CodeGeneration/EnumFactory.ts +2 -1
  189. package/src/CodeGeneration/NodeClassFactory.ts +2 -1
  190. package/src/Converters.ts +18 -24
  191. package/src/Definitions/Global/Commands.ts +13 -1
  192. package/src/Definitions/Global/Events.ts +2 -2
  193. package/src/Devices/ISYDeviceNode.ts +2 -1
  194. package/src/Devices/ISYMultiNodeDevice.ts +1 -1
  195. package/src/Devices/Insteon/DimmerLampSwitch.ts +3 -3
  196. package/src/Devices/Insteon/Generated/DimmerLampSwitch.ts +8 -7
  197. package/src/Devices/Insteon/InsteonDevice.ts +3 -2
  198. package/src/Devices/Insteon/InsteonDeviceFactory.ts +7 -2
  199. package/src/Devices/Insteon/InsteonFanDevice.ts +1 -1
  200. package/src/Devices/Insteon/InsteonKeypadDevice.ts +5 -5
  201. package/src/Devices/Insteon/InsteonRelayDevice.ts +1 -1
  202. package/src/Devices/Insteon/{Generated/KeypadButton.ts → KeypadButton.ts} +20 -20
  203. package/src/Devices/Insteon/RelayLampSwitch.ts +39 -39
  204. package/src/Devices/NodeFactory.ts +3 -2
  205. package/src/Devices/ZWave/ZWaveDimmerSwitchDevice.ts +1 -1
  206. package/src/Devices/index.ts +2 -2
  207. package/src/ISY.ts +249 -228
  208. package/src/ISYDevice.ts +3 -2
  209. package/src/ISYNode.ts +7 -5
  210. package/src/ISYScene.ts +2 -2
  211. package/src/Matter/Behaviors/ISYBridgedDeviceBehavior.ts +12 -2
  212. package/src/Matter/Behaviors/ISYClusterBehavior.ts +11 -14
  213. package/src/Matter/Behaviors/{ISYOnOffBehavior.ts → Insteon/ISYOnOffBehavior.ts} +9 -14
  214. package/src/Matter/Bridge/Server.ts +9 -7
  215. package/src/Matter/Mappings/Insteon.ts +3 -3
  216. package/src/Model/ClusterMap.ts +4 -3
  217. package/src/Model/NodeInfo.ts +4 -3
  218. package/src/Utils.ts +13 -6
package/dist/esm/ISY.js CHANGED
@@ -5,32 +5,11 @@ import { parseBooleans, parseNumbers } from 'xml2js/lib/processors.js';
5
5
  import axios from 'axios';
6
6
  import { EventEmitter } from 'events';
7
7
  import { format, Logger, loggers } from 'winston';
8
- import { Category } from './Definitions/Global/Categories.js';
9
- import { Family } from './Definitions/Global/Families.js';
10
8
  import { DeviceFactory } from './Devices/DeviceFactory.js';
11
9
  import { ELKAlarmPanelDevice } from './Devices/Elk/ElkAlarmPanelDevice.js';
12
- import { ElkAlarmSensorDevice } from './Devices/Elk/ElkAlarmSensorDevice.js';
13
- import { InsteonBaseDevice } from './Devices/Insteon/InsteonBaseDevice.js';
14
- import { InsteonOutletDevice } from './Devices/Insteon/InsteonDevice.js';
15
- import { InsteonDimmableDevice } from './Devices/Insteon/InsteonDimmableDevice.js';
16
- import { InsteonDimmerOutletDevice } from './Devices/Insteon/InsteonDimmerOutletDevice.js';
17
- import { InsteonDimmerSwitchDevice } from './Devices/Insteon/InsteonDimmerSwitchDevice.js';
18
- import { InsteonDoorWindowSensorDevice } from './Devices/Insteon/InsteonDoorWindowSensorDevice.js';
19
- import { InsteonFanDevice, InsteonFanMotorDevice } from './Devices/Insteon/InsteonFanDevice.js';
20
- import { InsteonKeypadButtonDevice } from './Devices/Insteon/InsteonKeypadDevice.js';
21
- import { InsteonKeypadDimmerDevice } from './Devices/Insteon/InsteonKeypadDimmerDevice.js';
22
- import { InsteonKeypadRelayDevice } from './Devices/Insteon/InsteonKeypadRelayDevice.js';
23
- import { InsteonLeakSensorDevice } from './Devices/Insteon/InsteonLeakSensorDevice.js';
24
- import { InsteonLockDevice } from './Devices/Insteon/InsteonLockDevice.js';
25
- import { InsteonMotionSensorDevice } from './Devices/Insteon/InsteonMotionSensorDevice.js';
26
- import { InsteonOnOffOutletDevice } from './Devices/Insteon/InsteonOnOffOutletDevice.js';
27
- import { InsteonRelayDevice } from './Devices/Insteon/InsteonRelayDevice.js';
28
- import { InsteonSmokeSensorDevice } from './Devices/Insteon/InsteonSmokeSensorDevice.js';
29
- import { InsteonThermostatDevice } from './Devices/Insteon/InsteonThermostatDevice.js';
30
10
  import { ISYDeviceNode } from './Devices/ISYDeviceNode.js';
31
11
  import { EventType } from './Events/EventType.js';
32
- import { NodeType, Props, States, VariableType } from './ISYConstants.js';
33
- import { ISYNode } from './ISYNode.js';
12
+ import { VariableType } from './ISYConstants.js';
34
13
  import { ISYScene } from './ISYScene.js';
35
14
  import { ISYVariable } from './ISYVariable.js';
36
15
  import * as Utils from './Utils.js';
@@ -38,7 +17,36 @@ import { XMLParser } from 'fast-xml-parser';
38
17
  import path from 'path';
39
18
  import { NodeFactory } from './Devices/NodeFactory.js';
40
19
  import { findPackageJson } from './Utils.js';
41
- export { Category as Categories, ELKAlarmPanelDevice, ElkAlarmSensorDevice, Family, InsteonBaseDevice, InsteonDimmableDevice, InsteonDimmerOutletDevice, InsteonDimmerSwitchDevice, InsteonDoorWindowSensorDevice, InsteonFanDevice, InsteonFanMotorDevice, InsteonKeypadButtonDevice, InsteonKeypadDimmerDevice, InsteonKeypadRelayDevice, InsteonLeakSensorDevice, InsteonLockDevice, InsteonMotionSensorDevice, InsteonOnOffOutletDevice, InsteonOutletDevice, InsteonRelayDevice, InsteonSmokeSensorDevice, InsteonThermostatDevice, ISYDeviceNode as ISYDevice, ISYNode, ISYScene, ISYVariable, NodeType, Props, States, Utils, VariableType };
20
+ class ISYError extends Error {
21
+ constructor(messageOrError) {
22
+ if (messageOrError instanceof Error) {
23
+ super(messageOrError.message);
24
+ this.stack = messageOrError.stack;
25
+ this.cause = messageOrError;
26
+ this.name = 'ISYError';
27
+ }
28
+ else if (typeof messageOrError === 'string') {
29
+ super(messageOrError);
30
+ this.name = 'ISYError';
31
+ }
32
+ }
33
+ }
34
+ class ISYNodeError extends ISYError {
35
+ constructor(messageOrError, node) {
36
+ super(messageOrError);
37
+ this.name = 'ISYNodeError';
38
+ this.node = node;
39
+ }
40
+ node;
41
+ }
42
+ class ISYInitializationError extends ISYError {
43
+ step;
44
+ constructor(messageOrError, step) {
45
+ super(messageOrError);
46
+ this.name = 'ISYInitializationError';
47
+ this.step = step;
48
+ }
49
+ }
42
50
  const defaultParserOptions = {
43
51
  explicitArray: false,
44
52
  mergeAttrs: true,
@@ -108,6 +116,18 @@ export class ISY extends EventEmitter {
108
116
  vendorName = 'Universal Devices, Inc.';
109
117
  webSocket;
110
118
  apiVersion;
119
+ socketPath;
120
+ get axiosOptions() {
121
+ return {
122
+ baseURL: `${this.protocol}://${this.host}:${this.port}`,
123
+ auth: {
124
+ username: this.credentials.username,
125
+ password: this.credentials.password
126
+ },
127
+ socketPath: this.socketPath,
128
+ validateStatus: (status) => status >= 200 && status < 300,
129
+ };
130
+ }
111
131
  // #endregion Properties (30)
112
132
  // #region Constructors (1)
113
133
  constructor(config, logger = new Logger(), storagePath) {
@@ -279,64 +299,79 @@ export class ISY extends EventEmitter {
279
299
  const that = this;
280
300
  try {
281
301
  this.apiVersion = (await findPackageJson()).version;
302
+ }
303
+ catch (e) {
304
+ this.logger.error(`Unable to read package.json: ${e.message}`);
305
+ }
306
+ try {
282
307
  await this.loadConfig();
283
308
  await this.loadNodes();
284
309
  await this.loadVariables(VariableType.Integer);
285
310
  await this.loadVariables(VariableType.State);
286
311
  await this.refreshStatuses();
287
312
  await this.#finishInitialize(true);
313
+ return true;
288
314
  }
289
315
  catch (e) {
290
- this.handleInitializeError('initialize', e);
316
+ if (e instanceof ISYInitializationError) {
317
+ this.logger.error(`Error initializing ISY during (${e.step}): ${e.message}`);
318
+ }
319
+ else {
320
+ this.logger.error(`Error initializing ISY: ${e.message}`);
321
+ }
322
+ throw e;
291
323
  }
292
324
  finally {
293
325
  if (this.nodesLoaded !== true) {
294
326
  that.#finishInitialize(false);
295
327
  }
296
328
  }
297
- return Promise.resolve(true);
298
329
  }
299
- initializeWebSocket() {
300
- const that = this;
301
- const auth = `Basic ${Buffer.from(`${this.credentials.username}:${this.credentials.password}`).toString('base64')}`;
302
- this.logger.info(`Opening webSocket: ${this.wsprotocol}://${this.address}/rest/subscribe`);
303
- if (this.webSocket) {
304
- try {
305
- this.webSocket.close();
306
- }
307
- catch (e) {
308
- this.logger.warn(`Error closing existing websocket: ${e.message}`);
330
+ async initializeWebSocket() {
331
+ try {
332
+ const that = this;
333
+ const auth = `Basic ${Buffer.from(`${this.credentials.username}:${this.credentials.password}`).toString('base64')}`;
334
+ this.logger.info(`Opening webSocket: ${this.wsprotocol}://${this.address}/rest/subscribe`);
335
+ if (this.webSocket) {
336
+ try {
337
+ this.webSocket.close();
338
+ }
339
+ catch (e) {
340
+ this.logger.warn(`Error closing existing websocket: ${e.message}`);
341
+ }
309
342
  }
343
+ this.webSocket = new WebSocket.Client(`${this.wsprotocol}://${this.address}/rest/subscribe`, ['ISYSUB'], {
344
+ headers: {
345
+ Origin: 'com.universal-devices.websockets.isy',
346
+ Authorization: auth
347
+ },
348
+ ping: 10
349
+ });
350
+ this.lastActivity = new Date();
351
+ this.webSocket
352
+ .on('message', (event) => {
353
+ that.logger.silly(`Received message: ${Utils.logStringify(event.data, 1)}`);
354
+ that.handleWebSocketMessage(event);
355
+ })
356
+ .on('error', (err, response) => {
357
+ that.logger.warn(`Websocket subscription error: ${Utils.logStringify(err, 1)}`);
358
+ })
359
+ .on('fail', (data, response) => {
360
+ that.logger.warn(`Websocket subscription failure: ${data}`);
361
+ throw new Error('Websocket subscription failure');
362
+ })
363
+ .on('abort', () => {
364
+ that.logger.warn('Websocket subscription aborted.');
365
+ throw new Error('Websocket subscription aborted.');
366
+ })
367
+ .on('timeout', (ms) => {
368
+ that.logger.warn(`Websocket subscription timed out after ${ms} milliseconds.`);
369
+ throw new Error('Timeout contacting ISY');
370
+ });
371
+ }
372
+ catch (e) {
373
+ throw new ISYInitializationError(e, 'websocket');
310
374
  }
311
- this.webSocket = new WebSocket.Client(`${this.wsprotocol}://${this.address}/rest/subscribe`, ['ISYSUB'], {
312
- headers: {
313
- Origin: 'com.universal-devices.websockets.isy',
314
- Authorization: auth
315
- },
316
- ping: 10
317
- });
318
- this.lastActivity = new Date();
319
- this.webSocket
320
- .on('message', (event) => {
321
- that.logger.silly(`Received message: ${JSON.stringify(event.data, null, 2)}`);
322
- that.handleWebSocketMessage(event);
323
- })
324
- .on('error', (err, response) => {
325
- that.logger.warn(`Websocket subscription error: ${JSON.stringify(err.message)}`);
326
- /// throw new Error('Error calling ISY' + err);
327
- })
328
- .on('fail', (data, response) => {
329
- that.logger.warn(`Websocket subscription failure: ${data}`);
330
- throw new Error('Failed calling ISY');
331
- })
332
- .on('abort', () => {
333
- that.logger.warn('Websocket subscription aborted.');
334
- throw new Error('Call to ISY was aborted');
335
- })
336
- .on('timeout', (ms) => {
337
- that.logger.warn(`Websocket subscription timed out after ${ms} milliseconds.`);
338
- throw new Error('Timeout contacting ISY');
339
- });
340
375
  }
341
376
  async loadConfig() {
342
377
  try {
@@ -364,26 +399,32 @@ export class ISY extends EventEmitter {
364
399
  return configuration;
365
400
  }
366
401
  catch (e) {
367
- this.handleInitializeError('config', e);
368
- throw Error(`Error Loading Config: ${e.message}`);
402
+ throw new ISYInitializationError(e, 'config');
369
403
  }
370
404
  }
371
405
  async loadNodes() {
372
406
  try {
407
+ this.logger.info('Loading ISY Nodes');
373
408
  const result = await this.sendRequest('nodes');
374
409
  if (this.isDebugEnabled)
375
410
  writeFile(this.storagePath + '/ISYNodesDump.json', JSON.stringify(result), this.logger.error);
376
- await this.#readFolderNodes(result).catch((p) => this.logger.error('Error Loading Folders', p));
377
- await this.#readDeviceNodes(result).catch((p) => this.logger.error('Error Loading Devices', p));
378
- await this.#readSceneNodes(result).catch((p) => this.logger.error('Error Loading Scenes', p));
411
+ await this.#readFolderNodes(result);
412
+ await this.#readDeviceNodes(result);
413
+ await this.#readSceneNodes(result);
379
414
  return result;
380
415
  }
381
416
  catch (e) {
382
- throw new Error(`Error loading nodes: ${e.message}`);
417
+ if (e instanceof ISYInitializationError) {
418
+ throw e;
419
+ }
420
+ else {
421
+ throw new ISYInitializationError(e, 'loadNodes');
422
+ }
383
423
  }
384
424
  }
385
425
  async loadVariables(type) {
386
426
  const that = this;
427
+ this.logger.info(`Loading ISY Variables of type: ${type}`);
387
428
  return this.sendRequest(`vars/definitions/${type}`)
388
429
  .then((result) => that.#createVariables(type, result))
389
430
  .then(() => that.sendRequest(`vars/get/${type}`))
@@ -408,39 +449,11 @@ export class ISY extends EventEmitter {
408
449
  if (that.isDebugEnabled) {
409
450
  writeFile(that.storagePath + '/ISYStatusDump.json', JSON.stringify(result), this.logger.error);
410
451
  }
411
- this.logger.debug(result);
452
+ //this.logger.debug(result);
412
453
  for (const node of result.nodes.node) {
413
- this.logger.debug(node);
414
- let device = that.getDevice(node.id);
454
+ let device = that.getNode(node.id);
415
455
  if (device !== null && device !== undefined) {
416
- // let child = device.children.find((p) => p.address === node.id);
417
- // if (child) {
418
- // //Case FanLinc where we treat the light as a child of the fan.
419
- // device = child;
420
- // }
421
456
  device.parseResult(node.property);
422
- // if (Array.isArray(node.property)) {
423
- // for (let prop of node.property) {
424
- // device.applyStatus(prop)
425
- // // device.local[prop.id] = device.convertFrom(prop.value, prop.uom);
426
- // // device.formatted[prop.id] = prop.formatted;
427
- // // device.uom[prop.id] = prop.uom;
428
- // // device.logger(
429
- // // `Property ${Controls[prop.id].label} (${prop.id}) initialized to: ${device.local[prop.id]} (${
430
- // // device.formatted[prop.id]
431
- // // })`
432
- // // );
433
- // }
434
- // } else if (node.property) {
435
- // device.local[node.property.id] = device.convertFrom(node.property.value, node.property.uom);
436
- // device.formatted[node.property.id] = node.property.formatted;
437
- // device.uom[node.property.id] = node.property.uom;
438
- // device.logger(
439
- // `Property ${Controls[node.property.id].label} (${node.property.id}) initialized to: ${
440
- // device.local[node.property.id]
441
- // } (${device.formatted[node.property.id]})`
442
- // );
443
- // }
444
457
  }
445
458
  }
446
459
  }
@@ -449,8 +462,7 @@ export class ISY extends EventEmitter {
449
462
  }
450
463
  }
451
464
  async sendGetVariable(id, type, handleResult) {
452
- const uriToUse = `${this.protocol}://${this.address}/rest/vars/get/${type}/${id}`;
453
- this.logger.info(`Sending ISY command...${uriToUse}`);
465
+ const uriToUse = `vars/get/${type}/${id}`;
454
466
  return this.sendRequest(uriToUse).then((p) => handleResult(p.val, p.init));
455
467
  }
456
468
  async sendISYCommand(path) {
@@ -485,10 +497,14 @@ export class ISY extends EventEmitter {
485
497
  const responseLogLevel = options.responseLogLevel ?? 'silly';
486
498
  url = `${this.protocol}://${this.address}/rest/${url}${options.trailingSlash ? '/' : ''}`;
487
499
  this.logger.log(requestLogLevel, `Sending request: ${url}`);
500
+ const reqOps = { ...this.axiosOptions, ...options, url: path.join('/rest', url) };
501
+ /*{
502
+ auth: { username: this.credentials.username, password: this.credentials.password },
503
+ baseURL: `${this.protocol}://${this.address}`,
504
+
505
+ }*/
488
506
  try {
489
- const response = await axios.get(url, {
490
- auth: { username: this.credentials.username, password: this.credentials.password }
491
- });
507
+ const response = await axios.get(url, reqOps);
492
508
  if (response.data) {
493
509
  if (response.headers['content-type'].toString().includes('xml')) {
494
510
  let curParser = parser;
@@ -500,21 +516,26 @@ export class ISY extends EventEmitter {
500
516
  return s;
501
517
  }
502
518
  else if (response.headers['content-type'].toString().includes('json')) {
503
- this.logger.log(responseLogLevel ?? 'debug', `Response: ${JSON.stringify(response.data)}`);
519
+ this.logger.log(responseLogLevel, `Response: ${JSON.stringify(response.data)}`);
504
520
  return JSON.parse(response.data);
505
521
  }
506
522
  else {
507
- this.logger.log(responseLogLevel ?? 'debug', `Response Header: ${JSON.stringify(response.headers)} Response: ${JSON.stringify(response.data)}`);
523
+ this.logger.log(responseLogLevel, `Response Header: ${JSON.stringify(response.headers)} Response: ${JSON.stringify(response.data)}`);
508
524
  return response.data;
509
525
  }
510
526
  }
511
527
  }
512
528
  catch (error) {
513
- if (options.errorLogLevel) {
514
- this.logger.log(options.errorLogLevel, `Error sending request to ISY: ${error?.message}`);
529
+ if (options.throwOnError) {
530
+ throw error;
515
531
  }
516
532
  else {
517
- this.logger.error(`Error sending request to ISY: ${error?.message}`);
533
+ if (options.errorLogLevel) {
534
+ this.logger.log(options.errorLogLevel, `Error sending request to ISY: ${error?.message}`);
535
+ }
536
+ else {
537
+ this.logger.error(`Error sending request to ISY: ${error?.message}`);
538
+ }
518
539
  }
519
540
  }
520
541
  }
@@ -610,97 +631,113 @@ export class ISY extends EventEmitter {
610
631
  }
611
632
  } */
612
633
  async #readDeviceNodes(obj) {
613
- this.logger.info('Loading Device Nodes');
614
- for (const nodeInfo of obj.nodes.node) {
615
- try {
616
- this.logger.debug(`Loading Device Node: ${JSON.stringify(nodeInfo)}`);
617
- if (!this.deviceMap.has(nodeInfo.pnode)) {
618
- const address = nodeInfo.address;
619
- this.deviceMap[nodeInfo.pnode] = {
620
- address
621
- };
622
- }
623
- else {
624
- this.deviceMap[nodeInfo.pnode].push(nodeInfo.address);
625
- }
626
- let newDevice = null;
627
- // let deviceTypeInfo = this.isyTypeToTypeName(device.type, device.address);
628
- // this.logger.info(JSON.stringify(deviceTypeInfo));
629
- const enabled = nodeInfo.enabled ?? true;
630
- const d = await NodeFactory.get(nodeInfo);
631
- const m = DeviceFactory.getDeviceDetails(nodeInfo);
632
- const cls = m?.class ?? d;
633
- nodeInfo.property = Array.isArray(nodeInfo.property) ? nodeInfo.property : [nodeInfo.property];
634
- nodeInfo.state = nodeInfo.property.reduce((acc, p) => {
635
- if (p && p?.id) {
636
- p.name = p.name == '' ? undefined : p.name;
637
- acc[p.id] = p;
634
+ try {
635
+ this.logger.info('Loading Device Nodes');
636
+ for (const nodeInfo of obj.nodes.node) {
637
+ try {
638
+ this.logger.debug(`Loading Device Node: ${JSON.stringify(nodeInfo)}`);
639
+ if (!this.deviceMap.has(nodeInfo.pnode)) {
640
+ const address = nodeInfo.address;
641
+ this.deviceMap[nodeInfo.pnode] = {
642
+ address
643
+ };
638
644
  }
639
- return acc;
640
- }, {});
641
- newDevice = new cls(this, nodeInfo);
642
- if (m) {
643
- newDevice.productName = m.name;
644
- newDevice.model = `(${m.modelNumber}) ${m.name} v.${m.version}`;
645
- newDevice.modelNumber = m.modelNumber;
646
- newDevice.version = m.version;
647
- }
648
- if (enabled) {
649
- if (newDevice === null) {
650
- this.logger.warn(`Device type resolution failed for ${nodeInfo.name} with type: ${nodeInfo.type} and nodedef: ${nodeInfo.nodeDefId}`);
651
- newDevice = new ISYDeviceNode(this, nodeInfo);
645
+ else {
646
+ this.deviceMap[nodeInfo.pnode].push(nodeInfo.address);
647
+ }
648
+ let newDevice = null;
649
+ // let deviceTypeInfo = this.isyTypeToTypeName(device.type, device.address);
650
+ // this.logger.info(JSON.stringify(deviceTypeInfo));
651
+ const enabled = nodeInfo.enabled ?? true;
652
+ const d = await NodeFactory.get(nodeInfo);
653
+ const m = DeviceFactory.getDeviceDetails(nodeInfo);
654
+ const cls = m?.class ?? d;
655
+ nodeInfo.property = Array.isArray(nodeInfo.property) ? nodeInfo.property : [nodeInfo.property];
656
+ nodeInfo.state = nodeInfo.property.reduce((acc, p) => {
657
+ if (p && p?.id) {
658
+ p.name = p.name == '' ? undefined : p.name;
659
+ acc[p.id] = p;
660
+ }
661
+ return acc;
662
+ }, {});
663
+ newDevice = new cls(this, nodeInfo);
664
+ if (m) {
665
+ newDevice.productName = m.name;
666
+ newDevice.model = `(${m.modelNumber}) ${m.name} v.${m.version}`;
667
+ newDevice.modelNumber = m.modelNumber;
668
+ newDevice.version = m.version;
652
669
  }
653
- else if (newDevice !== null) {
654
- if (m.unsupported) {
655
- this.logger.warn('Device not currently supported: ' + JSON.stringify(nodeInfo) + ' /n It has been mapped to: ' + d.name);
670
+ if (enabled) {
671
+ if (newDevice === null) {
672
+ this.logger.warn(`Device type resolution failed for ${nodeInfo.name} with type: ${nodeInfo.type} and nodedef: ${nodeInfo.nodeDefId}`);
673
+ newDevice = new ISYDeviceNode(this, nodeInfo);
656
674
  }
657
- try {
658
- await newDevice.refreshNotes();
675
+ else if (newDevice !== null) {
676
+ if (m.unsupported) {
677
+ this.logger.warn('Device not currently supported: ' + JSON.stringify(nodeInfo) + ' /n It has been mapped to: ' + d.name);
678
+ }
679
+ try {
680
+ await newDevice.refreshNotes();
681
+ }
682
+ catch (e) {
683
+ this.logger.debug('No notes found.');
684
+ }
685
+ // if (!newDevice.hidden) {
686
+ // }
687
+ // this.deviceList.push(newDevice);
659
688
  }
660
- catch (e) {
661
- this.logger.debug('No notes found.');
689
+ else {
662
690
  }
663
- // if (!newDevice.hidden) {
664
- // }
665
- // this.deviceList.push(newDevice);
691
+ this.nodeMap.set(newDevice.address, newDevice);
666
692
  }
667
693
  else {
694
+ this.logger.info(`Ignoring disabled device: ${nodeInfo.name}`);
668
695
  }
669
- this.nodeMap.set(newDevice.address, newDevice);
670
696
  }
671
- else {
672
- this.logger.info(`Ignoring disabled device: ${nodeInfo.name}`);
697
+ catch (e) {
698
+ this.logger.error(`Error loading device node: ${e.message}`);
673
699
  }
674
700
  }
675
- catch (e) {
676
- this.logger.error(`Error loading device node: ${e.message}`);
677
- }
701
+ this.logger.info(`${this.nodeMap.size} devices added.`);
702
+ }
703
+ catch (e) {
704
+ throw new ISYInitializationError(e, 'readDevices');
678
705
  }
679
- this.logger.info(`${this.nodeMap.size} devices added.`);
680
706
  }
681
707
  async #readFolderNodes(result) {
682
- this.logger.info('Loading Folder Nodes');
683
- if (result?.nodes?.folder) {
684
- for (const folder of result.nodes.folder) {
685
- this.logger.debug(`Loading Folder Node: ${JSON.stringify(folder)}`);
686
- this.folderMap.set(folder.address, folder.name);
708
+ try {
709
+ this.logger.info('Loading Folder Nodes');
710
+ if (result?.nodes?.folder) {
711
+ for (const folder of result.nodes.folder) {
712
+ this.logger.debug(`Loading Folder Node: ${JSON.stringify(folder)}`);
713
+ this.folderMap.set(folder.address, folder.name);
714
+ }
687
715
  }
688
716
  }
717
+ catch (e) {
718
+ throw new ISYInitializationError(e, 'readFolders');
719
+ }
689
720
  }
690
721
  async #readSceneNodes(result) {
691
- this.logger.info('Loading Scene Nodes');
692
- for (const scene of result.nodes?.group) {
693
- if (scene.name === 'ISY' || scene.name === 'IoX' || scene.name === 'Auto DR') {
694
- continue;
695
- } // Skip ISY & Auto DR Scenes
696
- const newScene = new ISYScene(this, scene);
697
- try {
698
- await newScene.refreshNotes();
699
- }
700
- catch (e) {
701
- this.logger.debug('No notes found.');
702
- }
703
- this.sceneList.set(newScene.address, newScene);
722
+ try {
723
+ this.logger.info('Loading Scene Nodes');
724
+ for (const scene of result.nodes?.group) {
725
+ if (scene.name === 'ISY' || scene.name === 'IoX' || scene.name === 'Auto DR') {
726
+ continue;
727
+ } // Skip ISY & Auto DR Scenes
728
+ const newScene = new ISYScene(this, scene);
729
+ try {
730
+ await newScene.refreshNotes();
731
+ }
732
+ catch (e) {
733
+ this.logger.debug('No notes found.');
734
+ }
735
+ this.sceneList.set(newScene.address, newScene);
736
+ }
737
+ this.logger.info(`${this.sceneList.size} scenes added.`);
738
+ }
739
+ catch (e) {
740
+ throw new ISYInitializationError(e, 'readScenes');
704
741
  }
705
742
  }
706
743
  #setVariableValues(result) {