@mp-consulting/homebridge-lg-thinq 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (241) hide show
  1. package/.claude/settings.local.json +15 -0
  2. package/CHANGELOG.md +98 -0
  3. package/LICENSE +176 -0
  4. package/README.md +114 -0
  5. package/config.schema.json +399 -0
  6. package/dist/__tests__/baseDevice.spec.d.ts +1 -0
  7. package/dist/__tests__/baseDevice.spec.js +96 -0
  8. package/dist/__tests__/baseDevice.spec.js.map +1 -0
  9. package/dist/__tests__/deviceControl.coercion.spec.d.ts +1 -0
  10. package/dist/__tests__/deviceControl.coercion.spec.js +53 -0
  11. package/dist/__tests__/deviceControl.coercion.spec.js.map +1 -0
  12. package/dist/__tests__/helper.spec.d.ts +1 -0
  13. package/dist/__tests__/helper.spec.js +74 -0
  14. package/dist/__tests__/helper.spec.js.map +1 -0
  15. package/dist/baseDevice.d.ts +40 -0
  16. package/dist/baseDevice.js +85 -0
  17. package/dist/baseDevice.js.map +1 -0
  18. package/dist/baseDevice.spec.d.ts +1 -0
  19. package/dist/baseDevice.spec.js +107 -0
  20. package/dist/baseDevice.spec.js.map +1 -0
  21. package/dist/characteristics/TotalConsumption.d.ts +2 -0
  22. package/dist/characteristics/TotalConsumption.js +17 -0
  23. package/dist/characteristics/TotalConsumption.js.map +1 -0
  24. package/dist/characteristics/index.d.ts +2 -0
  25. package/dist/characteristics/index.js +7 -0
  26. package/dist/characteristics/index.js.map +1 -0
  27. package/dist/cli.d.ts +2 -0
  28. package/dist/cli.js +89 -0
  29. package/dist/cli.js.map +1 -0
  30. package/dist/devices/AeroTower.d.ts +24 -0
  31. package/dist/devices/AeroTower.js +113 -0
  32. package/dist/devices/AeroTower.js.map +1 -0
  33. package/dist/devices/AirConditioner.d.ts +425 -0
  34. package/dist/devices/AirConditioner.js +1253 -0
  35. package/dist/devices/AirConditioner.js.map +1 -0
  36. package/dist/devices/AirPurifier.d.ts +50 -0
  37. package/dist/devices/AirPurifier.js +281 -0
  38. package/dist/devices/AirPurifier.js.map +1 -0
  39. package/dist/devices/Dehumidifier.d.ts +28 -0
  40. package/dist/devices/Dehumidifier.js +175 -0
  41. package/dist/devices/Dehumidifier.js.map +1 -0
  42. package/dist/devices/Dishwasher.d.ts +64 -0
  43. package/dist/devices/Dishwasher.js +740 -0
  44. package/dist/devices/Dishwasher.js.map +1 -0
  45. package/dist/devices/Microwave.d.ts +128 -0
  46. package/dist/devices/Microwave.js +1939 -0
  47. package/dist/devices/Microwave.js.map +1 -0
  48. package/dist/devices/Oven.d.ts +148 -0
  49. package/dist/devices/Oven.js +1850 -0
  50. package/dist/devices/Oven.js.map +1 -0
  51. package/dist/devices/RangeHood.d.ts +16 -0
  52. package/dist/devices/RangeHood.js +99 -0
  53. package/dist/devices/RangeHood.js.map +1 -0
  54. package/dist/devices/Refrigerator.d.ts +50 -0
  55. package/dist/devices/Refrigerator.js +325 -0
  56. package/dist/devices/Refrigerator.js.map +1 -0
  57. package/dist/devices/Styler.d.ts +27 -0
  58. package/dist/devices/Styler.js +76 -0
  59. package/dist/devices/Styler.js.map +1 -0
  60. package/dist/devices/WasherDryer.d.ts +39 -0
  61. package/dist/devices/WasherDryer.js +170 -0
  62. package/dist/devices/WasherDryer.js.map +1 -0
  63. package/dist/devices/WasherDryer2.d.ts +9 -0
  64. package/dist/devices/WasherDryer2.js +16 -0
  65. package/dist/devices/WasherDryer2.js.map +1 -0
  66. package/dist/errors/AuthenticationError.d.ts +2 -0
  67. package/dist/errors/AuthenticationError.js +3 -0
  68. package/dist/errors/AuthenticationError.js.map +1 -0
  69. package/dist/errors/ManualProcessNeeded.d.ts +3 -0
  70. package/dist/errors/ManualProcessNeeded.js +4 -0
  71. package/dist/errors/ManualProcessNeeded.js.map +1 -0
  72. package/dist/errors/MonitorError.d.ts +2 -0
  73. package/dist/errors/MonitorError.js +3 -0
  74. package/dist/errors/MonitorError.js.map +1 -0
  75. package/dist/errors/NotConnectedError.d.ts +3 -0
  76. package/dist/errors/NotConnectedError.js +4 -0
  77. package/dist/errors/NotConnectedError.js.map +1 -0
  78. package/dist/errors/TokenError.d.ts +2 -0
  79. package/dist/errors/TokenError.js +3 -0
  80. package/dist/errors/TokenError.js.map +1 -0
  81. package/dist/errors/TokenExpiredError.d.ts +3 -0
  82. package/dist/errors/TokenExpiredError.js +4 -0
  83. package/dist/errors/TokenExpiredError.js.map +1 -0
  84. package/dist/errors/index.d.ts +6 -0
  85. package/dist/errors/index.js +7 -0
  86. package/dist/errors/index.js.map +1 -0
  87. package/dist/helper.d.ts +24 -0
  88. package/dist/helper.js +66 -0
  89. package/dist/helper.js.map +1 -0
  90. package/dist/helper.spec.d.ts +1 -0
  91. package/dist/helper.spec.js +74 -0
  92. package/dist/helper.spec.js.map +1 -0
  93. package/dist/index.d.ts +6 -0
  94. package/dist/index.js +9 -0
  95. package/dist/index.js.map +1 -0
  96. package/dist/lib/API.d.ts +141 -0
  97. package/dist/lib/API.js +362 -0
  98. package/dist/lib/API.js.map +1 -0
  99. package/dist/lib/API.spec.d.ts +1 -0
  100. package/dist/lib/API.spec.js +55 -0
  101. package/dist/lib/API.spec.js.map +1 -0
  102. package/dist/lib/Auth.d.ts +99 -0
  103. package/dist/lib/Auth.js +348 -0
  104. package/dist/lib/Auth.js.map +1 -0
  105. package/dist/lib/Auth.spec.d.ts +1 -0
  106. package/dist/lib/Auth.spec.js +111 -0
  107. package/dist/lib/Auth.spec.js.map +1 -0
  108. package/dist/lib/Device.d.ts +88 -0
  109. package/dist/lib/Device.js +95 -0
  110. package/dist/lib/Device.js.map +1 -0
  111. package/dist/lib/Device.spec.d.ts +1 -0
  112. package/dist/lib/Device.spec.js +53 -0
  113. package/dist/lib/Device.spec.js.map +1 -0
  114. package/dist/lib/DeviceModel.d.ts +164 -0
  115. package/dist/lib/DeviceModel.js +321 -0
  116. package/dist/lib/DeviceModel.js.map +1 -0
  117. package/dist/lib/DeviceModel.spec.d.ts +1 -0
  118. package/dist/lib/DeviceModel.spec.js +90 -0
  119. package/dist/lib/DeviceModel.spec.js.map +1 -0
  120. package/dist/lib/Gateway.d.ts +18 -0
  121. package/dist/lib/Gateway.js +25 -0
  122. package/dist/lib/Gateway.js.map +1 -0
  123. package/dist/lib/Gateway.spec.d.ts +1 -0
  124. package/dist/lib/Gateway.spec.js +35 -0
  125. package/dist/lib/Gateway.spec.js.map +1 -0
  126. package/dist/lib/Persist.d.ts +101 -0
  127. package/dist/lib/Persist.js +245 -0
  128. package/dist/lib/Persist.js.map +1 -0
  129. package/dist/lib/Persist.spec.d.ts +1 -0
  130. package/dist/lib/Persist.spec.js +90 -0
  131. package/dist/lib/Persist.spec.js.map +1 -0
  132. package/dist/lib/Session.d.ts +80 -0
  133. package/dist/lib/Session.js +100 -0
  134. package/dist/lib/Session.js.map +1 -0
  135. package/dist/lib/Session.spec.d.ts +1 -0
  136. package/dist/lib/Session.spec.js +43 -0
  137. package/dist/lib/Session.spec.js.map +1 -0
  138. package/dist/lib/ThinQ.d.ts +28 -0
  139. package/dist/lib/ThinQ.js +373 -0
  140. package/dist/lib/ThinQ.js.map +1 -0
  141. package/dist/lib/__tests__/API.spec.d.ts +1 -0
  142. package/dist/lib/__tests__/API.spec.js +55 -0
  143. package/dist/lib/__tests__/API.spec.js.map +1 -0
  144. package/dist/lib/__tests__/Auth.spec.d.ts +1 -0
  145. package/dist/lib/__tests__/Auth.spec.js +110 -0
  146. package/dist/lib/__tests__/Auth.spec.js.map +1 -0
  147. package/dist/lib/__tests__/Device.spec.d.ts +1 -0
  148. package/dist/lib/__tests__/Device.spec.js +53 -0
  149. package/dist/lib/__tests__/Device.spec.js.map +1 -0
  150. package/dist/lib/__tests__/DeviceModel.spec.d.ts +1 -0
  151. package/dist/lib/__tests__/DeviceModel.spec.js +90 -0
  152. package/dist/lib/__tests__/DeviceModel.spec.js.map +1 -0
  153. package/dist/lib/__tests__/Gateway.spec.d.ts +1 -0
  154. package/dist/lib/__tests__/Gateway.spec.js +35 -0
  155. package/dist/lib/__tests__/Gateway.spec.js.map +1 -0
  156. package/dist/lib/__tests__/Persist.spec.d.ts +1 -0
  157. package/dist/lib/__tests__/Persist.spec.js +90 -0
  158. package/dist/lib/__tests__/Persist.spec.js.map +1 -0
  159. package/dist/lib/__tests__/Session.spec.d.ts +1 -0
  160. package/dist/lib/__tests__/Session.spec.js +43 -0
  161. package/dist/lib/__tests__/Session.spec.js.map +1 -0
  162. package/dist/lib/constants.d.ts +95 -0
  163. package/dist/lib/constants.js +106 -0
  164. package/dist/lib/constants.js.map +1 -0
  165. package/dist/lib/request.d.ts +2 -0
  166. package/dist/lib/request.js +66 -0
  167. package/dist/lib/request.js.map +1 -0
  168. package/dist/platform.d.ts +41 -0
  169. package/dist/platform.js +229 -0
  170. package/dist/platform.js.map +1 -0
  171. package/dist/settings.d.ts +8 -0
  172. package/dist/settings.js +9 -0
  173. package/dist/settings.js.map +1 -0
  174. package/dist/status/BaseStatus.d.ts +48 -0
  175. package/dist/status/BaseStatus.js +59 -0
  176. package/dist/status/BaseStatus.js.map +1 -0
  177. package/dist/types/snapshots.d.ts +142 -0
  178. package/dist/types/snapshots.js +6 -0
  179. package/dist/types/snapshots.js.map +1 -0
  180. package/dist/utils/__tests__/normalize.spec.d.ts +1 -0
  181. package/dist/utils/__tests__/normalize.spec.js +95 -0
  182. package/dist/utils/__tests__/normalize.spec.js.map +1 -0
  183. package/dist/utils/normalize.d.ts +22 -0
  184. package/dist/utils/normalize.js +51 -0
  185. package/dist/utils/normalize.js.map +1 -0
  186. package/dist/v1/__tests__/prepareControlData.spec.d.ts +1 -0
  187. package/dist/v1/__tests__/prepareControlData.spec.js +48 -0
  188. package/dist/v1/__tests__/prepareControlData.spec.js.map +1 -0
  189. package/dist/v1/devices/AC.d.ts +13 -0
  190. package/dist/v1/devices/AC.js +112 -0
  191. package/dist/v1/devices/AC.js.map +1 -0
  192. package/dist/v1/devices/AirPurifier.d.ts +15 -0
  193. package/dist/v1/devices/AirPurifier.js +57 -0
  194. package/dist/v1/devices/AirPurifier.js.map +1 -0
  195. package/dist/v1/devices/RangeHood.d.ts +6 -0
  196. package/dist/v1/devices/RangeHood.js +12 -0
  197. package/dist/v1/devices/RangeHood.js.map +1 -0
  198. package/dist/v1/devices/Refrigerator.d.ts +17 -0
  199. package/dist/v1/devices/Refrigerator.js +69 -0
  200. package/dist/v1/devices/Refrigerator.js.map +1 -0
  201. package/dist/v1/devices/Washer.d.ts +10 -0
  202. package/dist/v1/devices/Washer.js +23 -0
  203. package/dist/v1/devices/Washer.js.map +1 -0
  204. package/dist/v1/devices/index.d.ts +6 -0
  205. package/dist/v1/devices/index.js +7 -0
  206. package/dist/v1/devices/index.js.map +1 -0
  207. package/dist/v1/helper.d.ts +14 -0
  208. package/dist/v1/helper.js +111 -0
  209. package/dist/v1/helper.js.map +1 -0
  210. package/dist/v1/transforms/AirPurifierState.d.ts +2 -0
  211. package/dist/v1/transforms/AirPurifierState.js +9 -0
  212. package/dist/v1/transforms/AirPurifierState.js.map +1 -0
  213. package/dist/v1/transforms/AirState.d.ts +9 -0
  214. package/dist/v1/transforms/AirState.js +55 -0
  215. package/dist/v1/transforms/AirState.js.map +1 -0
  216. package/dist/v1/transforms/HoodState.d.ts +17 -0
  217. package/dist/v1/transforms/HoodState.js +20 -0
  218. package/dist/v1/transforms/HoodState.js.map +1 -0
  219. package/dist/v1/transforms/RefState.d.ts +6 -0
  220. package/dist/v1/transforms/RefState.js +29 -0
  221. package/dist/v1/transforms/RefState.js.map +1 -0
  222. package/dist/v1/transforms/WasherDryer.d.ts +49 -0
  223. package/dist/v1/transforms/WasherDryer.js +56 -0
  224. package/dist/v1/transforms/WasherDryer.js.map +1 -0
  225. package/docs/authorization.md +40 -0
  226. package/docs/device-configuration.md +68 -0
  227. package/homebridge-ui/public/index.html +120 -0
  228. package/homebridge-ui/public/js/app.js +300 -0
  229. package/homebridge-ui/public/js/countries.js +233 -0
  230. package/homebridge-ui/public/styles.css +185 -0
  231. package/homebridge-ui/server.js +103 -0
  232. package/jest.config.ts +39 -0
  233. package/package.json +83 -0
  234. package/sample/README.md +10 -0
  235. package/sample/airconditioner-model.json +3080 -0
  236. package/sample/airconditioner-snapshot.json +49 -0
  237. package/sample/airconditioner.json +157 -0
  238. package/sample/dishwasher-model.json +869 -0
  239. package/sample/dishwasher.json +125 -0
  240. package/sample/washer_dryer-model.json +1294 -0
  241. package/sample/washer_dryer.json +126 -0
@@ -0,0 +1,88 @@
1
+ import { DeviceModel } from './DeviceModel.js';
2
+ export interface DeviceData {
3
+ deviceId: string;
4
+ alias: string;
5
+ modelJsonUri: string;
6
+ deviceType: number;
7
+ modelName?: string;
8
+ manufacture?: {
9
+ macAddress?: string;
10
+ salesModel?: string;
11
+ serialNo?: string;
12
+ manufactureModel?: string;
13
+ };
14
+ modemInfo?: {
15
+ appVersion?: string;
16
+ modelName?: string;
17
+ };
18
+ snapshot: {
19
+ online?: boolean;
20
+ } & Record<string, any>;
21
+ platformType?: string;
22
+ online?: boolean;
23
+ }
24
+ /**
25
+ * Represents a device connected to the LG ThinQ platform.
26
+ * This class provides methods to interact with and retrieve information about the device.
27
+ */
28
+ export declare class Device {
29
+ data: DeviceData;
30
+ deviceModel: DeviceModel;
31
+ constructor(data: DeviceData);
32
+ /**
33
+ * Gets the unique identifier for the device.
34
+ */
35
+ get id(): string;
36
+ /**
37
+ * Gets the name of the device.
38
+ */
39
+ get name(): string;
40
+ /**
41
+ * Gets the type of the device.
42
+ */
43
+ get type(): string;
44
+ /**
45
+ * Gets the model information for the device.
46
+ */
47
+ get model(): string;
48
+ /**
49
+ * Gets the MAC address of the device.
50
+ */
51
+ get macAddress(): string | undefined;
52
+ /**
53
+ * Gets the sales model of the device.
54
+ */
55
+ get salesModel(): string | undefined;
56
+ /**
57
+ * Gets the serial number of the device.
58
+ */
59
+ get serialNumber(): string | undefined;
60
+ /**
61
+ * Gets the firmware version of the device.
62
+ */
63
+ get firmwareVersion(): string | undefined;
64
+ /**
65
+ * Gets the current state snapshot of the device.
66
+ */
67
+ get snapshot(): {
68
+ online?: boolean;
69
+ } & Record<string, any>;
70
+ /**
71
+ * Sets the current state snapshot of the device.
72
+ */
73
+ set snapshot(value: {
74
+ online?: boolean;
75
+ } & Record<string, any>);
76
+ /**
77
+ * Gets the platform type of the device.
78
+ */
79
+ get platform(): string | undefined;
80
+ /**
81
+ * Gets the online status of the device.
82
+ */
83
+ get online(): boolean | undefined;
84
+ /**
85
+ * Returns a string representation of the device.
86
+ */
87
+ toString(): string;
88
+ }
@@ -0,0 +1,95 @@
1
+ import { DeviceType } from './constants.js';
2
+ /**
3
+ * Represents a device connected to the LG ThinQ platform.
4
+ * This class provides methods to interact with and retrieve information about the device.
5
+ */
6
+ export class Device {
7
+ data;
8
+ deviceModel;
9
+ constructor(data) {
10
+ this.data = data;
11
+ }
12
+ /**
13
+ * Gets the unique identifier for the device.
14
+ */
15
+ get id() {
16
+ return this.data.deviceId;
17
+ }
18
+ /**
19
+ * Gets the name of the device.
20
+ */
21
+ get name() {
22
+ return this.data.alias;
23
+ }
24
+ /**
25
+ * Gets the type of the device.
26
+ */
27
+ get type() {
28
+ return DeviceType[this.data.deviceType];
29
+ }
30
+ /**
31
+ * Gets the model information for the device.
32
+ */
33
+ get model() {
34
+ const modelName = this.data.modelName || this.data.modemInfo?.modelName || this.data.manufacture?.manufactureModel || '';
35
+ if (/^([A-Z]+)_(\d+)_([A-Z]{2})$/.test(modelName)) {
36
+ return modelName.slice(0, -3);
37
+ }
38
+ return modelName;
39
+ }
40
+ /**
41
+ * Gets the MAC address of the device.
42
+ */
43
+ get macAddress() {
44
+ return this.data.manufacture?.macAddress;
45
+ }
46
+ /**
47
+ * Gets the sales model of the device.
48
+ */
49
+ get salesModel() {
50
+ return this.data.manufacture?.salesModel;
51
+ }
52
+ /**
53
+ * Gets the serial number of the device.
54
+ */
55
+ get serialNumber() {
56
+ return this.data.manufacture?.serialNo;
57
+ }
58
+ /**
59
+ * Gets the firmware version of the device.
60
+ */
61
+ get firmwareVersion() {
62
+ return this.data.modemInfo?.appVersion;
63
+ }
64
+ /**
65
+ * Gets the current state snapshot of the device.
66
+ */
67
+ get snapshot() {
68
+ return this.data.snapshot || null;
69
+ }
70
+ /**
71
+ * Sets the current state snapshot of the device.
72
+ */
73
+ set snapshot(value) {
74
+ this.data.snapshot = value;
75
+ }
76
+ /**
77
+ * Gets the platform type of the device.
78
+ */
79
+ get platform() {
80
+ return this.data.platformType;
81
+ }
82
+ /**
83
+ * Gets the online status of the device.
84
+ */
85
+ get online() {
86
+ return this.data.online !== undefined ? this.data.online : this.data.snapshot.online;
87
+ }
88
+ /**
89
+ * Returns a string representation of the device.
90
+ */
91
+ toString() {
92
+ return `${this.id}: ${this.name} (${this.type} ${this.model})`;
93
+ }
94
+ }
95
+ //# sourceMappingURL=Device.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Device.js","sourceRoot":"","sources":["../../src/lib/Device.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AA0B5C;;;GAGG;AACH,MAAM,OAAO,MAAM;IAGE;IAFZ,WAAW,CAAe;IAEjC,YAAmB,IAAgB;QAAhB,SAAI,GAAJ,IAAI,CAAY;IAAG,CAAC;IAEvC;;OAEG;IACH,IAAW,EAAE;QACX,OAAO,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC;IAC5B,CAAC;IAED;;OAEG;IACH,IAAW,IAAI;QACb,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,IAAW,IAAI;QACb,OAAO,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAC1C,CAAC;IAED;;OAEG;IACH,IAAW,KAAK;QACd,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,SAAS,IAAI,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,g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AI,IAAI,IAAI,CAAC,KAAK,GAAG,CAAC;IACjE,CAAC;CACF"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,53 @@
1
+ import { Device } from './Device.js';
2
+ import { describe, test, beforeEach, expect } from '@jest/globals';
3
+ import Fs from 'fs';
4
+ import Path from 'path';
5
+ const mockDeviceData = JSON.parse(Fs.readFileSync(Path.resolve(process.cwd(), 'sample/airconditioner.json'), 'utf8'));
6
+ describe('Device', () => {
7
+ let device;
8
+ beforeEach(() => {
9
+ device = new Device(mockDeviceData);
10
+ });
11
+ test('should retrieve device ID', () => {
12
+ expect(device.id).toBe(mockDeviceData.deviceId);
13
+ });
14
+ test('should retrieve device name', () => {
15
+ expect(device.name).toBe(mockDeviceData.alias);
16
+ });
17
+ test('should retrieve device type', () => {
18
+ expect(device.type).toBe('AC');
19
+ });
20
+ test('should retrieve device model from modelName', () => {
21
+ expect(device.model).toBe(mockDeviceData.modelName.slice(0, -3));
22
+ });
23
+ test('should retrieve MAC address', () => {
24
+ expect(device.macAddress).toBe(mockDeviceData.manufacture.macAddress);
25
+ });
26
+ test('should retrieve sales model', () => {
27
+ expect(device.salesModel).toBe(mockDeviceData.manufacture.salesModel);
28
+ });
29
+ test('should retrieve serial number', () => {
30
+ expect(device.serialNumber).toBe(mockDeviceData.manufacture.serialNo);
31
+ });
32
+ test('should retrieve firmware version', () => {
33
+ expect(device.firmwareVersion).toBe(mockDeviceData.modemInfo.appVersion);
34
+ });
35
+ test('should retrieve snapshot when available', () => {
36
+ expect(device.snapshot).toEqual(mockDeviceData.snapshot);
37
+ });
38
+ test('should set snapshot', () => {
39
+ const newSnapshot = { online: false };
40
+ device.snapshot = newSnapshot;
41
+ expect(device.snapshot).toEqual(newSnapshot);
42
+ });
43
+ test('should retrieve platform type', () => {
44
+ expect(device.platform).toBe(mockDeviceData.platformType);
45
+ });
46
+ test('should retrieve online status from data.online', () => {
47
+ expect(device.online).toBe(mockDeviceData.online);
48
+ });
49
+ test('should return string representation of the device', () => {
50
+ expect(device.toString()).toBe(`${mockDeviceData.deviceId}: ${mockDeviceData.alias} (AC ${mockDeviceData.modelName.slice(0, -3)})`);
51
+ });
52
+ });
53
+ //# sourceMappingURL=Device.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Device.spec.js","sourceRoot":"","sources":["../../src/lib/Device.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAc,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACnE,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,MAAM,cAAc,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,4BAA4B,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;AAEtH,QAAQ,CAAC,QAAQ,EAAE,GAAG,EAAE;IACtB,IAAI,MAAc,CAAC;IAEnB,UAAU,CAAC,GAAG,EAAE;QACd,MAAM,GAAG,IAAI,MAAM,CAAC,cAAuC,CAAC,CAAC;IAC/D,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,2BAA2B,EAAE,GAAG,EAAE;QACrC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;IAClD,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,6BAA6B,EAAE,GAAG,EAAE;QACvC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;IACjD,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,6BAA6B,EAAE,GAAG,EAAE;QACvC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAA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QAC9B,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IAC/C,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,+BAA+B,EAAE,GAAG,EAAE;QACzC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,YAAY,CAAC,CAAC;IAC5D,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,gDAAgD,EAAE,GAAG,EAAE;QAC1D,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;IACpD,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,mDAAmD,EAAE,GAAG,EAAE;QAC7D,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,cAAc,CAAC,QAAQ,KAAK,cAAc,CAAC,KAAK,QAAQ,cAAc,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IACtI,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,164 @@
1
+ export declare enum ValueType {
2
+ Bit = "Bit",
3
+ Enum = "Enum",
4
+ Range = "Range",
5
+ Reference = "Reference",
6
+ StringComment = "StringComment"
7
+ }
8
+ export interface ModelDataValue {
9
+ type: string;
10
+ [key: string]: any;
11
+ }
12
+ export interface MonitoringValue {
13
+ dataType: string;
14
+ valueMapping: {
15
+ [key: string]: {
16
+ index: string;
17
+ label: string;
18
+ };
19
+ };
20
+ }
21
+ export interface ModelData {
22
+ Info: {
23
+ productType: string;
24
+ productCode: string;
25
+ country: string;
26
+ modelType: string;
27
+ model: string;
28
+ modelName: string;
29
+ networkType: string;
30
+ version: string;
31
+ };
32
+ Value: {
33
+ [key: string]: ModelDataValue;
34
+ };
35
+ MonitoringValue?: {
36
+ [key: string]: MonitoringValue;
37
+ };
38
+ [key: string]: any;
39
+ }
40
+ export interface BitValue {
41
+ type: ValueType.Bit;
42
+ options: any;
43
+ }
44
+ export interface EnumValue {
45
+ type: ValueType.Enum;
46
+ options: Record<string, string | number>;
47
+ }
48
+ export interface RangeValue {
49
+ type: ValueType.Range;
50
+ min: number;
51
+ max: number;
52
+ step: number;
53
+ }
54
+ export interface ReferenceValue {
55
+ type: ValueType.Reference;
56
+ reference: any;
57
+ }
58
+ export interface StringCommentValue {
59
+ type: ValueType.StringComment;
60
+ comment: string;
61
+ }
62
+ /**
63
+ * Represents the model of a device, including its metadata, values, and monitoring data.
64
+ * This class provides methods to retrieve and decode device-specific information.
65
+ */
66
+ export declare class DeviceModel {
67
+ data: ModelData;
68
+ /**
69
+ * Creates a new `DeviceModel` instance.
70
+ *
71
+ * @param data - The raw model data for the device.
72
+ */
73
+ constructor(data: ModelData);
74
+ /**
75
+ * Retrieves the monitoring values defined in the device model.
76
+ */
77
+ get monitoringValue(): {
78
+ [key: string]: MonitoringValue;
79
+ } | undefined;
80
+ /**
81
+ * Retrieves the value definition for a given key in the device model.
82
+ * Supports ThinQ2 protocol mappings for monitoring values.
83
+ *
84
+ * @param name - The key to retrieve the value definition for.
85
+ * @returns The value definition or `null` if not found.
86
+ */
87
+ value(name: string): BitValue | EnumValue | RangeValue | ReferenceValue | StringCommentValue | null;
88
+ /**
89
+ * Retrieves the default value for a given key in the device model.
90
+ *
91
+ * @param name - The key to retrieve the default value for.
92
+ * @returns The default value or `undefined` if not found.
93
+ */
94
+ default(name: string): any;
95
+ /**
96
+ * Retrieves the enum value for a given key and name.
97
+ *
98
+ * @param key - The key to retrieve the enum value for.
99
+ * @param name - The name of the enum **value**.
100
+ * @returns The enum value or `undefined` if not found.
101
+ */
102
+ enumValue(key: string, name: string): string | null;
103
+ /**
104
+ * Retrieves the enum name for a given key and value.
105
+ *
106
+ * @param key - The key to retrieve the enum name for.
107
+ * @param value - The value of the enum.
108
+ * @returns The enum name or `null` if not found.
109
+ */
110
+ enumName(key: string, value: string): string | number | null;
111
+ /**
112
+ * Retrieves the monitoring value mapping for a given key.
113
+ *
114
+ * @param key - The key to retrieve the monitoring value mapping for.
115
+ * @returns The monitoring value mapping or `null` if not found.
116
+ */
117
+ monitoringValueMapping(key: string): {
118
+ [key: string]: {
119
+ index: string;
120
+ label: string;
121
+ };
122
+ } | null;
123
+ /**
124
+ * Looks up a monitor value based on a given key and name, with an optional default value.
125
+ *
126
+ * @param key - The key used to identify the monitoring value mapping.
127
+ * @param name - The name of the specific value to look up within the mapping.
128
+ * @param default_value - An optional default value to return if the lookup fails. Defaults to `null`.
129
+ * @returns The label of the monitoring value if found, or the `default_value` if not found.
130
+ */
131
+ lookupMonitorValue(key: string, name: string): string | number | null;
132
+ /**
133
+ * Looks up a monitor value based on a given key and name, with an optional default value.
134
+ *
135
+ * @param key - The key used to identify the monitoring value mapping.
136
+ * @param name - The name of the specific value to look up within the mapping.
137
+ * @param default_value - An optional default value to return if the lookup fails. Defaults to `null`.
138
+ * @returns The label of the monitoring value if found, or the `default_value` if not found.
139
+ */
140
+ lookupMonitorValue2(key: string, name: string, default_value: string): string | number;
141
+ /**
142
+ * Looks up a monitor name based on a given key and label.
143
+ *
144
+ * @param key - The key used to identify the monitoring value mapping.
145
+ * @param label - The label of the specific value to look up within the mapping.
146
+ * @returns The name of the monitoring value if found, or `null` if not found.
147
+ */
148
+ lookupMonitorName(key: string, label: string): string | null;
149
+ /**
150
+ * Decodes the monitoring data for the device.
151
+ *
152
+ * @param data - The raw monitoring data to decode.
153
+ * @returns The decoded monitoring data.
154
+ */
155
+ decodeMonitor(data: any): any;
156
+ /**
157
+ * Decodes binary monitoring data for the device.
158
+ *
159
+ * @param data - The raw binary monitoring data to decode.
160
+ * @param length - The length of each binary segment (default: 8).
161
+ * @returns The decoded monitoring data.
162
+ */
163
+ private decodeMonitorBinary;
164
+ }