milesight-powermeter-api 2024.9.13-0 → 2024.9.23
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 +15 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/src/controller/milesight.controller.spec.ts +30 -0
- package/src/controller/milesight.controller.ts +28 -1
- package/src/dto/milesight.dto.ts +9 -0
- package/src/service/milesight.service.spec.ts +29 -0
- package/src/service/milesight.service.ts +31 -0
- package/timestamp.sh +1 -1
- package/src/app.controller.spec.ts +0 -22
- package/src/app.controller.ts +0 -12
- package/src/app.module.ts +0 -10
- package/src/app.service.ts +0 -8
- package/test/app.e2e-spec.ts +0 -24
package/README.md
CHANGED
@@ -86,3 +86,18 @@ Body: {
|
|
86
86
|
`deviceEui`(required) device eui of the milesight powermeter<br />
|
87
87
|
`serialNumber`(optional) serial number of the milesight powermeter<br />
|
88
88
|
|
89
|
+
### Set device interval for the powermeter
|
90
|
+
|
91
|
+
```
|
92
|
+
POST powermeter/milesight/interval
|
93
|
+
|
94
|
+
Body: {
|
95
|
+
deviceEui: string;
|
96
|
+
serialNumber?: string;
|
97
|
+
interval: number;
|
98
|
+
}
|
99
|
+
```
|
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 />
|
103
|
+
|
package/npm-shrinkwrap.json
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
{
|
2
2
|
"name": "milesight-powermeter-api",
|
3
|
-
"version": "2024.9.
|
3
|
+
"version": "2024.9.23",
|
4
4
|
"lockfileVersion": 3,
|
5
5
|
"requires": true,
|
6
6
|
"packages": {
|
7
7
|
"": {
|
8
8
|
"name": "milesight-powermeter-api",
|
9
|
-
"version": "2024.9.
|
9
|
+
"version": "2024.9.23",
|
10
10
|
"license": "UNLICENSED",
|
11
11
|
"dependencies": {
|
12
12
|
"@coinspect/therma-action-rule-decoder": "2024.9.12",
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "milesight-powermeter-api",
|
3
|
-
"version": "2024.9.
|
3
|
+
"version": "2024.9.23",
|
4
4
|
"description": "Milesight Powermeter API is an internal tool accessible on backend. The API allows detail retrieval and command sending to its powermeters.",
|
5
5
|
"author": "Lester Vitor",
|
6
6
|
"license": "UNLICENSED",
|
@@ -98,4 +98,34 @@ describe('MilesightController', () => {
|
|
98
98
|
expect(errorResult).toBeInstanceOf(HttpException);
|
99
99
|
});
|
100
100
|
});
|
101
|
+
describe('setDeviceInterval', () => {
|
102
|
+
const data = {
|
103
|
+
deviceEui: 'sampleDeviceEui',
|
104
|
+
serialNumber: 'sampleDeviceName',
|
105
|
+
interval: 1440,
|
106
|
+
};
|
107
|
+
it('should return result', async () => {
|
108
|
+
const controllerResult = {
|
109
|
+
message: `Successfully sent set device command for sampleDeviceEui.`,
|
110
|
+
result: true,
|
111
|
+
};
|
112
|
+
jest.spyOn(milesightService, 'setDeviceInterval').mockResolvedValue(
|
113
|
+
true,
|
114
|
+
);
|
115
|
+
const result = await milesightController.setDeviceInterval(data);
|
116
|
+
expect(result).toEqual(controllerResult);
|
117
|
+
});
|
118
|
+
it('should handle error properly', async () => {
|
119
|
+
jest.spyOn(milesightService, 'setDeviceInterval').mockResolvedValue(
|
120
|
+
null,
|
121
|
+
);
|
122
|
+
let errorResult = null;
|
123
|
+
try {
|
124
|
+
await milesightController.setDeviceInterval(data);
|
125
|
+
} catch (error) {
|
126
|
+
errorResult = error;
|
127
|
+
}
|
128
|
+
expect(errorResult).toBeInstanceOf(HttpException);
|
129
|
+
});
|
130
|
+
});
|
101
131
|
});
|
@@ -9,7 +9,11 @@ import {
|
|
9
9
|
UsePipes,
|
10
10
|
ValidationPipe,
|
11
11
|
} from '@nestjs/common';
|
12
|
-
import {
|
12
|
+
import {
|
13
|
+
DeviceListParamsDto,
|
14
|
+
MilesightBaseDto,
|
15
|
+
MilesightSetIntervalDto,
|
16
|
+
} from '../dto/milesight.dto';
|
13
17
|
import { MilesightService } from '../service/milesight.service';
|
14
18
|
import { AWSListThings } from '@coinspect/therma-action-rule-decoder';
|
15
19
|
|
@@ -58,4 +62,27 @@ export class MilesightController {
|
|
58
62
|
result,
|
59
63
|
};
|
60
64
|
}
|
65
|
+
|
66
|
+
@Post('interval')
|
67
|
+
@UsePipes(new ValidationPipe())
|
68
|
+
async setDeviceInterval(
|
69
|
+
@Body() body: MilesightSetIntervalDto,
|
70
|
+
): Promise<{ message: string; result: boolean }> {
|
71
|
+
const { deviceEui, serialNumber, interval } = body;
|
72
|
+
const result = await this.milesightService.setDeviceInterval(
|
73
|
+
deviceEui,
|
74
|
+
serialNumber ? serialNumber : deviceEui,
|
75
|
+
interval,
|
76
|
+
);
|
77
|
+
if (!result) {
|
78
|
+
throw new HttpException(
|
79
|
+
`Error occured rebooting device: ${deviceEui}`,
|
80
|
+
HttpStatus.INTERNAL_SERVER_ERROR,
|
81
|
+
);
|
82
|
+
}
|
83
|
+
return {
|
84
|
+
message: `Successfully sent set device command for ${deviceEui}.`,
|
85
|
+
result,
|
86
|
+
};
|
87
|
+
}
|
61
88
|
}
|
package/src/dto/milesight.dto.ts
CHANGED
@@ -110,4 +110,33 @@ describe('MilesightService', () => {
|
|
110
110
|
sendDownlinkSpy.mockClear();
|
111
111
|
});
|
112
112
|
});
|
113
|
+
|
114
|
+
describe('setDeviceInterval', () => {
|
115
|
+
const data = {
|
116
|
+
deviceEui: 'sampleDeviceEui',
|
117
|
+
serialNumber: 'sampleDeviceName',
|
118
|
+
interval: 1440,
|
119
|
+
};
|
120
|
+
|
121
|
+
it('should return true when downlink is successful', async () => {
|
122
|
+
const expectedDownlinkCommand = 'ff8e0005a0';
|
123
|
+
const sendDownlinkSpy = jest
|
124
|
+
.spyOn(downlinkService, 'sendDownlink')
|
125
|
+
.mockResolvedValue(true);
|
126
|
+
await milesightService.setDeviceInterval(
|
127
|
+
data.deviceEui,
|
128
|
+
data.serialNumber,
|
129
|
+
data.interval,
|
130
|
+
);
|
131
|
+
expect(sendDownlinkSpy).toHaveBeenCalledWith(
|
132
|
+
data.deviceEui,
|
133
|
+
data.serialNumber,
|
134
|
+
expectedDownlinkCommand,
|
135
|
+
'milesightPowermeterSetDeviceInterval',
|
136
|
+
85,
|
137
|
+
true,
|
138
|
+
);
|
139
|
+
sendDownlinkSpy.mockClear();
|
140
|
+
});
|
141
|
+
});
|
113
142
|
});
|
@@ -61,4 +61,35 @@ export class MilesightService {
|
|
61
61
|
return null;
|
62
62
|
}
|
63
63
|
}
|
64
|
+
|
65
|
+
async setDeviceInterval(
|
66
|
+
deviceEui: string,
|
67
|
+
serialNumber: string,
|
68
|
+
interval: number,
|
69
|
+
): Promise<boolean | null> {
|
70
|
+
try {
|
71
|
+
this.logger.log(
|
72
|
+
`Setting ${interval} minutes interval for device: ${deviceEui}`,
|
73
|
+
);
|
74
|
+
const hexString = interval.toString(16).padStart(4, '0');
|
75
|
+
const downlinkCommand = 'ff8e00' + hexString;
|
76
|
+
const response = await this.downlinkService.sendDownlink(
|
77
|
+
deviceEui,
|
78
|
+
serialNumber,
|
79
|
+
downlinkCommand,
|
80
|
+
'milesightPowermeterSetDeviceInterval',
|
81
|
+
fPort,
|
82
|
+
true,
|
83
|
+
);
|
84
|
+
this.logger.log(
|
85
|
+
`Successfully set device interval for ${deviceEui}`,
|
86
|
+
);
|
87
|
+
return response;
|
88
|
+
} catch (error) {
|
89
|
+
this.logger.error(
|
90
|
+
`Error setting device interval ${deviceEui}: ${error}`,
|
91
|
+
);
|
92
|
+
return null;
|
93
|
+
}
|
94
|
+
}
|
64
95
|
}
|
package/timestamp.sh
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export DT=
|
1
|
+
export DT=20240926085218
|
@@ -1,22 +0,0 @@
|
|
1
|
-
import { Test, TestingModule } from '@nestjs/testing';
|
2
|
-
import { AppController } from './app.controller';
|
3
|
-
import { AppService } from './app.service';
|
4
|
-
|
5
|
-
describe('AppController', () => {
|
6
|
-
let appController: AppController;
|
7
|
-
|
8
|
-
beforeEach(async () => {
|
9
|
-
const app: TestingModule = await Test.createTestingModule({
|
10
|
-
controllers: [AppController],
|
11
|
-
providers: [AppService],
|
12
|
-
}).compile();
|
13
|
-
|
14
|
-
appController = app.get<AppController>(AppController);
|
15
|
-
});
|
16
|
-
|
17
|
-
describe('root', () => {
|
18
|
-
it('should return "Hello World!"', () => {
|
19
|
-
expect(appController.getHello()).toBe('Hello World!');
|
20
|
-
});
|
21
|
-
});
|
22
|
-
});
|
package/src/app.controller.ts
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
import { Controller, Get } from '@nestjs/common';
|
2
|
-
import { AppService } from './app.service';
|
3
|
-
|
4
|
-
@Controller()
|
5
|
-
export class AppController {
|
6
|
-
constructor(private readonly appService: AppService) {}
|
7
|
-
|
8
|
-
@Get()
|
9
|
-
getHello(): string {
|
10
|
-
return this.appService.getHello();
|
11
|
-
}
|
12
|
-
}
|
package/src/app.module.ts
DELETED
package/src/app.service.ts
DELETED
package/test/app.e2e-spec.ts
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
import { Test, TestingModule } from '@nestjs/testing';
|
2
|
-
import { INestApplication } from '@nestjs/common';
|
3
|
-
import * as request from 'supertest';
|
4
|
-
import { AppModule } from './../src/app.module';
|
5
|
-
|
6
|
-
describe('AppController (e2e)', () => {
|
7
|
-
let app: INestApplication;
|
8
|
-
|
9
|
-
beforeEach(async () => {
|
10
|
-
const moduleFixture: TestingModule = await Test.createTestingModule({
|
11
|
-
imports: [AppModule],
|
12
|
-
}).compile();
|
13
|
-
|
14
|
-
app = moduleFixture.createNestApplication();
|
15
|
-
await app.init();
|
16
|
-
});
|
17
|
-
|
18
|
-
it('/ (GET)', () => {
|
19
|
-
return request(app.getHttpServer())
|
20
|
-
.get('/')
|
21
|
-
.expect(200)
|
22
|
-
.expect('Hello World!');
|
23
|
-
});
|
24
|
-
});
|