-
Notifications
You must be signed in to change notification settings - Fork 5
/
particle.common.ts
65 lines (57 loc) · 1.32 KB
/
particle.common.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
export type TNSParticleDeviceType =
"Unknown"
| "Core"
| "Photon"
| "P1"
| "Electron"
| "RaspberryPi"
| "DigistumpOak"
| "RedBearDuo"
| "Bluz";
export type VariableType = "INT" | "DOUBLE" | "STRING";
export function getDeviceType(id: number): TNSParticleDeviceType {
switch (id) {
case 0:
return "Core";
case 6:
return "Photon";
case 8:
return "P1";
case 10:
return "Electron";
case 31:
return "RaspberryPi";
case 82:
return "DigistumpOak";
case 88:
return "RedBearDuo";
case 103:
return "Bluz";
default:
console.log(`Unknown device type (id: ${id})`);
return "Unknown";
}
}
export interface TNSParticleDeviceVariable {
name: string;
type: VariableType;
}
export interface TNSParticleDevice {
id: string;
name: string;
status: string;
type: TNSParticleDeviceType;
functions: Array<string>;
variables: Array<TNSParticleDeviceVariable>;
getVariable: (name: string) => Promise<any>;
callFunction: (name: string, ...args) => Promise<number>;
}
export interface TNSParticleLoginOptions {
username: string;
password: string;
}
export interface TNSParticleAPI {
login(options: TNSParticleLoginOptions): Promise<void>;
logout(): void;
listDevices(): Promise<Array<TNSParticleDevice>>;
}