@cpzxrobot/sdk 1.0.4 → 1.0.5
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/assistant_gateway.ts +4 -2
- package/camera_gateway.ts +19 -15
- package/device_filter.ts +6 -4
- package/device_gateway.ts +12 -12
- package/device_type_gateway.ts +4 -2
- package/device_types/electricmeter.ts +2 -2
- package/device_types/feedtower.ts +5 -5
- package/device_types/normal_type.ts +3 -2
- package/dist/camera_gateway.js +2 -2
- package/dist/device_filter.js +3 -3
- package/dist/device_types/electricmeter.js +1 -1
- package/dist/device_types/feedtower.js +1 -1
- package/dist/device_types/normal_type.js +1 -1
- package/dist/energy_types/electric_meter_gateway.js +1 -5
- package/dist/index.js +187 -222
- package/dist/transport_gateway.js +22 -7
- package/energy_gateway.ts +3 -2
- package/energy_types/electric_meter_gateway.ts +4 -4
- package/factory_gateway.ts +4 -2
- package/index.ts +6 -29
- package/package.json +4 -2
- package/pigfarm_gateway.ts +4 -2
- package/transport_gateway.ts +52 -35
- package/types.d.ts +164 -84
- package/user_gateway.ts +5 -3
package/assistant_gateway.ts
CHANGED
package/camera_gateway.ts
CHANGED
|
@@ -1,28 +1,32 @@
|
|
|
1
|
+
import { Cpzxrobot, Unit, Camera } from ".";
|
|
2
|
+
|
|
1
3
|
export class CameraGateway extends Object {
|
|
2
|
-
context:
|
|
3
|
-
constructor(context:
|
|
4
|
-
super()
|
|
5
|
-
this.context = context
|
|
4
|
+
context: Cpzxrobot;
|
|
5
|
+
constructor(context: Cpzxrobot) {
|
|
6
|
+
super();
|
|
7
|
+
this.context = context;
|
|
6
8
|
}
|
|
7
9
|
//搜索摄像头
|
|
8
10
|
async search(data: Unit): Promise<any> {
|
|
9
|
-
await this.context.ready
|
|
10
|
-
const response = await this.context.axios.post(
|
|
11
|
-
unit_id: data.id
|
|
12
|
-
})
|
|
13
|
-
return response.data
|
|
11
|
+
await this.context.ready;
|
|
12
|
+
const response = await this.context.axios.post("/api/v1/camera/search", {
|
|
13
|
+
unit_id: data.id,
|
|
14
|
+
});
|
|
15
|
+
return response.data;
|
|
14
16
|
}
|
|
15
17
|
|
|
16
18
|
//获得摄像头的播放地址
|
|
17
19
|
async getUrl(data: Camera): Promise<any> {
|
|
18
|
-
await this.context.ready
|
|
19
|
-
const response = await this.context.axios.get(
|
|
20
|
-
|
|
20
|
+
await this.context.ready;
|
|
21
|
+
const response = await this.context.axios.get(
|
|
22
|
+
`/api/v1/camera/${data.id}/url/wss`
|
|
23
|
+
);
|
|
24
|
+
return response.data;
|
|
21
25
|
}
|
|
22
26
|
//获取工厂天气
|
|
23
27
|
async weather(id: number): Promise<any> {
|
|
24
|
-
await this.context.ready
|
|
25
|
-
const response = await this.context.axios.get(`/api/v1/weather?code=${id}`)
|
|
26
|
-
return response.data
|
|
28
|
+
await this.context.ready;
|
|
29
|
+
const response = await this.context.axios.get(`/api/v1/weather?code=${id}`);
|
|
30
|
+
return response.data;
|
|
27
31
|
}
|
|
28
32
|
}
|
package/device_filter.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Cpzxrobot } from ".";
|
|
1
2
|
import type { AxiosResponse } from "axios";
|
|
2
3
|
|
|
3
4
|
export interface DataQueryArgs {
|
|
@@ -14,8 +15,8 @@ export interface DataQueryArgs {
|
|
|
14
15
|
[key: string]: any;
|
|
15
16
|
}
|
|
16
17
|
|
|
17
|
-
export abstract class
|
|
18
|
-
context:
|
|
18
|
+
export abstract class DeviceFilter<T extends { id: number }> {
|
|
19
|
+
context: Cpzxrobot;
|
|
19
20
|
protected devices: T[] = [];
|
|
20
21
|
|
|
21
22
|
// private getDetail!: (info: T, id: number, context: Shzx) => Promise<any> | null
|
|
@@ -23,7 +24,7 @@ export abstract class deviceFilter<T extends { id: number }> {
|
|
|
23
24
|
// user: UserGateway;
|
|
24
25
|
// ready: Promise<boolean>;
|
|
25
26
|
|
|
26
|
-
constructor(context:
|
|
27
|
+
constructor(context: Cpzxrobot) {
|
|
27
28
|
this.context = context;
|
|
28
29
|
}
|
|
29
30
|
|
|
@@ -62,7 +63,7 @@ export abstract class deviceFilter<T extends { id: number }> {
|
|
|
62
63
|
|
|
63
64
|
//获得单个设备的详细信息和状态,包括设备的基本信息和跟业务类型相关的附加状态信息
|
|
64
65
|
//不应单独使用getInfo和getDetail,应使用getStatus
|
|
65
|
-
getStatus(id: number) {
|
|
66
|
+
getStatus(id: number): Promise<any> {
|
|
66
67
|
return this.context.ready
|
|
67
68
|
.then(() => this.getInfo(id))
|
|
68
69
|
.then((info) => {
|
|
@@ -275,6 +276,7 @@ export abstract class deviceFilter<T extends { id: number }> {
|
|
|
275
276
|
| null; //如果data为null,则不获取数据,只获取设备列表,否则获取设备列表和数据
|
|
276
277
|
status?: string;
|
|
277
278
|
unit?: Number;
|
|
279
|
+
detail?: boolean;
|
|
278
280
|
} = undefined
|
|
279
281
|
): Promise<T[]> {
|
|
280
282
|
// if (this.devices.length > 0) {
|
package/device_gateway.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DeviceTypeGateway } from "./device_type_gateway";
|
|
2
|
-
import {
|
|
3
|
-
import type {
|
|
2
|
+
import { DeviceFilter } from "./device_filter";
|
|
3
|
+
import type { ElectricMeter, Cpzxrobot } from ".";
|
|
4
4
|
import { FeedTowerGateway } from "./device_types/feedtower";
|
|
5
5
|
import { ElectricMeterGateway } from "./device_types/electricmeter";
|
|
6
6
|
import { NormalGateway } from "./device_types/normal_type";
|
|
@@ -12,11 +12,11 @@ import { NormalGateway } from "./device_types/normal_type";
|
|
|
12
12
|
export class DeviceGateway extends Object {
|
|
13
13
|
// private devices: Device[]
|
|
14
14
|
public type: DeviceTypeGateway;
|
|
15
|
-
filters: Map<string,
|
|
16
|
-
normalFilter: NormalGateway;
|
|
17
|
-
context:
|
|
15
|
+
filters: Map<string, DeviceFilter<any>>;
|
|
16
|
+
public normalFilter: NormalGateway;
|
|
17
|
+
context: Cpzxrobot;
|
|
18
18
|
|
|
19
|
-
constructor(context:
|
|
19
|
+
constructor(context: Cpzxrobot) {
|
|
20
20
|
super();
|
|
21
21
|
this.context = context;
|
|
22
22
|
// this.devices = []
|
|
@@ -26,21 +26,21 @@ export class DeviceGateway extends Object {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
//料塔设备的数据获取网关
|
|
29
|
-
get feedTower():
|
|
30
|
-
return this.getFilter("FeedTower", FeedTowerGateway);
|
|
29
|
+
public get feedTower(): FeedTowerGateway {
|
|
30
|
+
return this.getFilter("FeedTower", FeedTowerGateway) as FeedTowerGateway;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
//电表设备的数据获取网关
|
|
34
|
-
get electricMeter():
|
|
34
|
+
get electricMeter(): DeviceFilter<ElectricMeter> {
|
|
35
35
|
return this.getFilter("ElectricMeter", ElectricMeterGateway);
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
private getFilter<T extends { id: number }>(
|
|
39
39
|
type: string,
|
|
40
|
-
cls: new (context:
|
|
41
|
-
):
|
|
40
|
+
cls: new (context: Cpzxrobot) => DeviceFilter<T>
|
|
41
|
+
): DeviceFilter<T> {
|
|
42
42
|
if (this.filters.has(type)) {
|
|
43
|
-
return this.filters.get(type) as
|
|
43
|
+
return this.filters.get(type) as DeviceFilter<T>;
|
|
44
44
|
}
|
|
45
45
|
const filter = new cls(this.context);
|
|
46
46
|
this.filters.set(type, filter);
|
package/device_type_gateway.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import { Cpzxrobot, Unit } from "."
|
|
2
|
+
|
|
1
3
|
//缓存设备类型数据
|
|
2
4
|
export class DeviceTypeGateway {
|
|
3
5
|
deviceTypes: any
|
|
4
6
|
// axios: MyAxiosInstance;
|
|
5
|
-
context:
|
|
7
|
+
context: Cpzxrobot
|
|
6
8
|
|
|
7
|
-
constructor(context:
|
|
9
|
+
constructor(context: Cpzxrobot) {
|
|
8
10
|
this.context = context
|
|
9
11
|
}
|
|
10
12
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type ElectricMeter } from "..";
|
|
2
|
-
import {
|
|
2
|
+
import { DeviceFilter } from "../device_filter";
|
|
3
3
|
|
|
4
|
-
export class ElectricMeterGateway extends
|
|
4
|
+
export class ElectricMeterGateway extends DeviceFilter<ElectricMeter> {
|
|
5
5
|
// Add properties and methods specific to the FeedTower type here
|
|
6
6
|
|
|
7
7
|
get deviceType() {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { type FeedTower } from '..'
|
|
2
|
-
import {
|
|
1
|
+
import { type FodderOrderList, type FeedTower,type FeedTowerExtraInfo } from '..'
|
|
2
|
+
import { DeviceFilter, type DataQueryArgs } from '../device_filter'
|
|
3
3
|
|
|
4
|
-
export class FeedTowerGateway extends
|
|
4
|
+
export class FeedTowerGateway extends DeviceFilter<FeedTower> {
|
|
5
5
|
// Add properties and methods specific to the FeedTower type here
|
|
6
6
|
|
|
7
7
|
get deviceType() {
|
|
@@ -50,7 +50,7 @@ export class FeedTowerGateway extends deviceFilter<FeedTower> {
|
|
|
50
50
|
//TODO 其他设备的详情需要支持,目前只有喂料塔
|
|
51
51
|
return this.context.axios
|
|
52
52
|
.post('/api/v1/pigfarm/device/status/list', ids)
|
|
53
|
-
.then((res) => {
|
|
53
|
+
.then((res:any) => {
|
|
54
54
|
if (res.data.code != 200) {
|
|
55
55
|
throw res.data.message
|
|
56
56
|
} else {
|
|
@@ -66,7 +66,7 @@ export class FeedTowerGateway extends deviceFilter<FeedTower> {
|
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
|
|
69
|
-
async enter(data:
|
|
69
|
+
async enter(data: FodderOrderList): Promise<any> {
|
|
70
70
|
const res = await this.context.axios.post('/api/v1/pigfarm/device/fodder/import', data)
|
|
71
71
|
return res
|
|
72
72
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Device } from "..";
|
|
2
|
+
import { DeviceFilter } from "../device_filter";
|
|
2
3
|
|
|
3
4
|
//适配常见设备类型
|
|
4
|
-
export class NormalGateway extends
|
|
5
|
+
export class NormalGateway extends DeviceFilter<Device> {
|
|
5
6
|
get deviceType() {
|
|
6
7
|
return null;
|
|
7
8
|
}
|
package/dist/camera_gateway.js
CHANGED
|
@@ -9,8 +9,8 @@ class CameraGateway extends Object {
|
|
|
9
9
|
//搜索摄像头
|
|
10
10
|
async search(data) {
|
|
11
11
|
await this.context.ready;
|
|
12
|
-
const response = await this.context.axios.post(
|
|
13
|
-
unit_id: data.id
|
|
12
|
+
const response = await this.context.axios.post("/api/v1/camera/search", {
|
|
13
|
+
unit_id: data.id,
|
|
14
14
|
});
|
|
15
15
|
return response.data;
|
|
16
16
|
}
|
package/dist/device_filter.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
class
|
|
3
|
+
exports.DeviceFilter = void 0;
|
|
4
|
+
class DeviceFilter {
|
|
5
5
|
// private getDetail!: (info: T, id: number, context: Shzx) => Promise<any> | null
|
|
6
6
|
// axios: MyAxiosInstance;
|
|
7
7
|
// user: UserGateway;
|
|
@@ -250,4 +250,4 @@ class deviceFilter {
|
|
|
250
250
|
});
|
|
251
251
|
}
|
|
252
252
|
}
|
|
253
|
-
exports.
|
|
253
|
+
exports.DeviceFilter = DeviceFilter;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ElectricMeterGateway = void 0;
|
|
4
4
|
const device_filter_1 = require("../device_filter");
|
|
5
|
-
class ElectricMeterGateway extends device_filter_1.
|
|
5
|
+
class ElectricMeterGateway extends device_filter_1.DeviceFilter {
|
|
6
6
|
// Add properties and methods specific to the FeedTower type here
|
|
7
7
|
get deviceType() {
|
|
8
8
|
return "Electric";
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.FeedTowerGateway = void 0;
|
|
4
4
|
const device_filter_1 = require("../device_filter");
|
|
5
|
-
class FeedTowerGateway extends device_filter_1.
|
|
5
|
+
class FeedTowerGateway extends device_filter_1.DeviceFilter {
|
|
6
6
|
// Add properties and methods specific to the FeedTower type here
|
|
7
7
|
get deviceType() {
|
|
8
8
|
return 'FeedTower';
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.NormalGateway = void 0;
|
|
4
4
|
const device_filter_1 = require("../device_filter");
|
|
5
5
|
//适配常见设备类型
|
|
6
|
-
class NormalGateway extends device_filter_1.
|
|
6
|
+
class NormalGateway extends device_filter_1.DeviceFilter {
|
|
7
7
|
get deviceType() {
|
|
8
8
|
return null;
|
|
9
9
|
}
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.ElectricMeterGateway = void 0;
|
|
7
|
-
const __1 = __importDefault(require(".."));
|
|
8
4
|
//消息助手网关,获取消息助手的信息
|
|
9
5
|
class ElectricMeterGateway extends Object {
|
|
10
6
|
constructor(context) {
|
|
@@ -13,7 +9,7 @@ class ElectricMeterGateway extends Object {
|
|
|
13
9
|
}
|
|
14
10
|
//返回峰谷平电表的阶梯区间
|
|
15
11
|
getRates() {
|
|
16
|
-
return
|
|
12
|
+
return this.context.ready.then((axios) => {
|
|
17
13
|
return axios.get('/api/v1/energy/electricRange').then((res) => {
|
|
18
14
|
if (res.data.code !== 200) {
|
|
19
15
|
throw res.data.message;
|