milesight-powermeter-api 2024.9.13-1 → 2024.9.24-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.
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  ## Description
4
4
 
5
- The Milesight Powermeter API is an internal tool exclusively accessible to our backend team. It serves as a command hub for the Milesight CT10x powermeter using lorawan downlink commands.
5
+ The Milesight Powermeter API is an internal tool exclusively accessible to our backend team. It serves as a command hub for both single-phase and three-phase Milesight powermeters using lorawan downlink commands. The API provides separate endpoints for managing single-phase CT10x powermeters and three-phase CT3xx powermeters with independent functionality.
6
6
 
7
7
  ## Requirements
8
8
  - RabbitMQ 3.9.11
@@ -64,16 +64,22 @@ $ npm run test:cov
64
64
  ```
65
65
  ## REST API
66
66
 
67
- ### Get lorawan powermeter list
67
+ ### Single-Phase Powermeter Endpoints
68
+
69
+ #### Get single-phase lorawan powermeter list
68
70
 
69
71
  ```
70
72
  GET powermeter/milesight
71
73
  ```
72
74
 
73
- `maxResult`(optional) range from 1-255 (default is 25)
74
- `nextToken`(optional) token for the succeeding page/request
75
+ **Query Parameters:**
76
+ - `maxResult` (optional) - Range from 1-255 (default is 25)
77
+ - `nextToken` (optional) - Token for the succeeding page/request
78
+
79
+ **Response:**
80
+ Returns a list of single-phase Milesight powermeters with AWS IoT Thing details.
75
81
 
76
- ### Reboot the powermeter
82
+ #### Reboot single-phase powermeter
77
83
 
78
84
  ```
79
85
  POST powermeter/milesight/reboot
@@ -83,10 +89,15 @@ Body: {
83
89
  serialNumber?: string;
84
90
  }
85
91
  ```
86
- `deviceEui`(required) device eui of the milesight powermeter<br />
87
- `serialNumber`(optional) serial number of the milesight powermeter<br />
88
92
 
89
- ### Set device interval for the powermeter
93
+ **Parameters:**
94
+ - `deviceEui` (required) - Device EUI of the single-phase Milesight powermeter
95
+ - `serialNumber` (optional) - Serial number of the single-phase Milesight powermeter
96
+
97
+ **Response:**
98
+ Returns success message and boolean result indicating if the reboot command was sent successfully.
99
+
100
+ #### Set device interval for single-phase powermeter
90
101
 
91
102
  ```
92
103
  POST powermeter/milesight/interval
@@ -97,7 +108,74 @@ Body: {
97
108
  interval: number;
98
109
  }
99
110
  ```
100
- `deviceEui`(required) device eui of the milesight powermeter<br />
101
- `serialNumber`(optional) serial number of the milesight powermeter<br />
102
- `interval`(required) interval value in minutes (1-1440)<br />
111
+
112
+ **Parameters:**
113
+ - `deviceEui` (required) - Device EUI of the single-phase Milesight powermeter
114
+ - `serialNumber` (optional) - Serial number of the single-phase Milesight powermeter
115
+ - `interval` (required) - Interval value in minutes (1-1440)
116
+
117
+ **Response:**
118
+ Returns success message and boolean result indicating if the interval configuration was sent successfully.
119
+
120
+ ### Three-Phase Powermeter Endpoints
121
+
122
+ #### Get three-phase lorawan powermeter list
123
+
124
+ ```
125
+ GET powermeter/three-phase/milesight
126
+ ```
127
+
128
+ **Query Parameters:**
129
+ - `maxResult` (optional) - Range from 1-255 (default is 25)
130
+ - `nextToken` (optional) - Token for the succeeding page/request
131
+
132
+ **Response:**
133
+ Returns a list of three-phase Milesight powermeters with AWS IoT Thing details. Uses `thingType: 'three-phase-powermeter-milesight'` to filter devices.
134
+
135
+ #### Reboot three-phase powermeter WIP
136
+
137
+ ```
138
+ POST powermeter/three-phase/milesight/reboot
139
+
140
+ Body: {
141
+ deviceEui: string;
142
+ serialNumber?: string;
143
+ }
144
+ ```
145
+
146
+ **Parameters:**
147
+ - `deviceEui` (required) - Device EUI of the three-phase Milesight powermeter
148
+ - `serialNumber` (optional) - Serial number of the three-phase Milesight powermeter
149
+
150
+ **Response:**
151
+ Returns success message and boolean result indicating if the reboot command was sent successfully to the three-phase device.
152
+
153
+ #### Set device interval for three-phase powermeter WIP
154
+
155
+ ```
156
+ POST powermeter/three-phase/milesight/interval
157
+
158
+ Body: {
159
+ deviceEui: string;
160
+ serialNumber?: string;
161
+ interval: number;
162
+ }
163
+ ```
164
+
165
+ **Parameters:**
166
+ - `deviceEui` (required) - Device EUI of the three-phase Milesight powermeter
167
+ - `serialNumber` (optional) - Serial number of the three-phase Milesight powermeter
168
+ - `interval` (required) - Interval value in minutes (1-1440)
169
+
170
+ **Response:**
171
+ Returns success message and boolean result indicating if the interval configuration was sent successfully to the three-phase device.
172
+
173
+ ## API Architecture
174
+
175
+ The API is structured with separate controllers and services for single-phase and three-phase powermeters:
176
+
177
+ - **Single-Phase**: Uses `MilesightController` and `MilesightService` with `thingType: 'powermeter-milesight'`
178
+ - **Three-Phase**: Uses `ThreePhaseMilesightController` and `ThreePhaseMilesightService` with `thingType: 'three-phase-powermeter-milesight'`
179
+
180
+ This separation ensures clean isolation of functionality and allows for independent management of different powermeter types.
103
181
 
package/jest.config.js ADDED
@@ -0,0 +1,19 @@
1
+ module.exports = {
2
+ moduleFileExtensions: ['js', 'json', 'ts'],
3
+ rootDir: 'src',
4
+ testRegex: '.*\\.spec\\.ts$',
5
+ transform: {
6
+ '^.+\\.(t|j)s$': 'ts-jest',
7
+ },
8
+ collectCoverageFrom: ['**/*.(t|j)s'],
9
+ coverageDirectory: '../coverage',
10
+ testEnvironment: 'node',
11
+ setupFilesAfterEnv: ['<rootDir>/../jest.setup.ts'],
12
+ testTimeout: 30000,
13
+ detectOpenHandles: true,
14
+ forceExit: true,
15
+ maxWorkers: 1,
16
+ logHeapUsage: false,
17
+ silent: true,
18
+ verbose: false,
19
+ };
package/jest.setup.ts ADDED
@@ -0,0 +1,104 @@
1
+ // jest.setup.ts
2
+ jest.setTimeout(30000);
3
+
4
+ const isCI = process.env.CI || process.env.BITBUCKET_BUILD_NUMBER;
5
+
6
+ if (isCI) {
7
+ console.log = () => {};
8
+ console.warn = () => {};
9
+ console.error = () => {};
10
+ console.info = () => {};
11
+ console.debug = () => {};
12
+ } else {
13
+ const originalConsoleWarn = console.warn;
14
+ const originalConsoleError = console.error;
15
+ const originalConsoleLog = console.log;
16
+
17
+ console.warn = (...args: any[]) => {
18
+ const message = args.join(' ');
19
+ if (
20
+ message.includes('Unhandled rejection') ||
21
+ message.includes('ECONNREFUSED') ||
22
+ message.includes('AggregateError') ||
23
+ message.includes('internalConnectMultiple') ||
24
+ message.includes('afterConnectMultiple') ||
25
+ message.includes('TCPConnectWrap.callbackTrampoline') ||
26
+ message.includes('Cannot log after tests are done') ||
27
+ message.includes('bluebird') ||
28
+ message.includes('winston')
29
+ ) {
30
+ return;
31
+ }
32
+ originalConsoleWarn.apply(console, args);
33
+ };
34
+
35
+ console.error = (...args: any[]) => {
36
+ const message = args.join(' ');
37
+ if (
38
+ message.includes('ECONNREFUSED') ||
39
+ message.includes('AggregateError') ||
40
+ message.includes('internalConnectMultiple') ||
41
+ message.includes('bluebird') ||
42
+ message.includes('winston')
43
+ ) {
44
+ return;
45
+ }
46
+ originalConsoleError.apply(console, args);
47
+ };
48
+
49
+ console.log = (...args: any[]) => {
50
+ const message = args.join(' ');
51
+ if (
52
+ message.includes('instantiating amqp connection') ||
53
+ message.includes('Failed to establish connection') ||
54
+ message.includes('AmqpService') ||
55
+ message.includes('bluebird') ||
56
+ message.includes('winston')
57
+ ) {
58
+ return;
59
+ }
60
+ originalConsoleLog.apply(console, args);
61
+ };
62
+ }
63
+
64
+
65
+ process.removeAllListeners('unhandledRejection');
66
+ process.removeAllListeners('uncaughtException');
67
+ process.removeAllListeners('warning');
68
+
69
+
70
+ process.on('unhandledRejection', () => {
71
+
72
+ if (!isCI) {
73
+ }
74
+ });
75
+
76
+
77
+ process.on('uncaughtException', () => {
78
+
79
+ if (!isCI) {
80
+ }
81
+ });
82
+
83
+
84
+ process.on('warning', () => {
85
+
86
+ });
87
+
88
+
89
+ process.setMaxListeners(0);
90
+
91
+
92
+ afterAll(async () => {
93
+
94
+ process.removeAllListeners('unhandledRejection');
95
+ process.removeAllListeners('uncaughtException');
96
+ process.removeAllListeners('warning');
97
+
98
+
99
+ if (global.gc) {
100
+ global.gc();
101
+ }
102
+
103
+ await new Promise(resolve => setTimeout(resolve, 2000));
104
+ });