-
-
Notifications
You must be signed in to change notification settings - Fork 343
/
index.d.ts
87 lines (72 loc) · 2.19 KB
/
index.d.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
declare module 'tuyapi' {
import { EventEmitter } from 'events';
interface TuyaDeviceOptions {
ip?: string;
port?: number;
id: string;
gwID?: string;
key: string;
productKey?: string;
version?: number|string;
nullPayloadOnJSONError?: boolean;
issueGetOnConnect?: boolean;
issueRefreshOnConnect?: boolean;
issueRefreshOnPing?: boolean;
}
type UnionTypes = Object|number|string|boolean;
interface Object {
[key: string]: Object|number|string|boolean|Array<UnionTypes>;
}
interface DPSObject {
dps: Object;
}
interface GetOptions {
schema?: boolean;
dps?: number;
cid?: string;
}
interface RefreshOptions extends GetOptions {
requestedDPS?: Array<number>;
}
interface SingleSetOptions {
dps: number;
set: string|number|boolean;
cid?: string;
multiple?: boolean;
shouldWaitForResponse?: boolean;
}
interface MultipleSetOptions {
multiple: boolean;
data: Object;
shouldWaitForResponse?: boolean;
}
interface FindOptions {
timeout?: number;
all?: boolean;
}
type EventDataFn = (
data: DPSObject,
commandByte: number,
sequenceN: number
) => void;
interface Events {
"connected": () => void;
"heartbeat": () => void;
"disconnected": () => void;
"error": (error: Error) => void;
"dp-refresh": EventDataFn;
"data": EventDataFn;
}
export default class TuyaDevice extends EventEmitter {
constructor(options: TuyaDeviceOptions);
connect(): Promise<boolean>;
disconnect(): void;
isConnected(): boolean;
get(options: GetOptions): Promise<DPSObject|number|boolean|string>;
refresh(options: RefreshOptions): Promise<DPSObject>;
set(options: SingleSetOptions|MultipleSetOptions): Promise<DPSObject>;
toggle(property: number): Promise<boolean>;
find(options?: FindOptions): Promise<boolean|Array<DPSObject>>;
on<K extends keyof Events>(event: K, listener: Events[K]): this;
}
}