forked from tuya/tuya-homebridge
-
-
Notifications
You must be signed in to change notification settings - Fork 72
/
TuyaDevice.ts
141 lines (115 loc) · 2.67 KB
/
TuyaDevice.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
export enum TuyaDeviceSchemaMode {
UNKNOWN = '',
READ_WRITE = 'rw',
READ_ONLY = 'ro',
WRITE_ONLY = 'wo',
}
export enum TuyaDeviceSchemaType {
Boolean = 'Boolean',
Integer = 'Integer',
Enum = 'Enum',
String = 'String',
Json = 'Json',
Raw = 'Raw',
}
export type TuyaDeviceSchemaIntegerProperty = {
min: number;
max: number;
scale: number;
step: number;
unit: string;
};
export type TuyaDeviceSchemaEnumProperty = {
range: string[];
};
export type TuyaDeviceSchemaStringProperty = string;
export type TuyaDeviceSchemaJSONProperty = object;
export type TuyaDeviceSchemaProperty = TuyaDeviceSchemaIntegerProperty
| TuyaDeviceSchemaEnumProperty
| TuyaDeviceSchemaStringProperty
| TuyaDeviceSchemaJSONProperty;
export type TuyaDeviceSchema = {
code: string;
// name: string;
mode: TuyaDeviceSchemaMode;
type: TuyaDeviceSchemaType;
property: TuyaDeviceSchemaProperty;
};
export type TuyaDeviceStatus = {
code: string;
value: string | number | boolean;
};
export type TuyaIRRemoteKeyListItem = {
key: string;
key_id: number;
key_name: string;
standard_key: boolean;
learning_code?: string; // IR DIY device learning code.
};
export type TuyaIRRemoteTempListItem = {
temp: number;
temp_name: string;
fan_list: TuyaIRRemoteFanListItem[];
};
export type TuyaIRRemoteKeyRangeItem = {
mode: number;
mode_name: string;
temp_list: TuyaIRRemoteTempListItem[];
};
export type TuyaIRRemoteFanListItem = {
fan: number;
fan_name: string;
};
export type TuyaIRRemoteKeys = {
category_id: number;
brand_id: number;
remote_index: number;
single_air: boolean;
duplicate_power: boolean;
key_list: TuyaIRRemoteKeyListItem[];
key_range: TuyaIRRemoteKeyRangeItem[];
};
export default class TuyaDevice {
// device
id!: string;
uuid!: string;
name!: string;
online!: boolean;
owner_id!: string; // homeID or assetID
// product
product_id!: string;
product_name!: string;
icon!: string;
category!: string;
unbridged?: boolean;
schema!: TuyaDeviceSchema[];
// status
status!: TuyaDeviceStatus[];
// location
ip!: string;
lat!: string;
lon!: string;
time_zone!: string;
// time
create_time!: number;
active_time!: number;
update_time!: number;
// ...
sub!: boolean;
parent_id?: string;
remote_keys?: TuyaIRRemoteKeys;
constructor(obj: Partial<TuyaDevice>) {
Object.assign(this, obj);
this.status.sort((a, b) => a.code > b.code ? 1 : -1);
}
isVirtualDevice() {
return this.id.startsWith('vdevo');
}
isIRControlHub() {
return ['wnykq', 'hwktwkq', 'wsdykq']
.includes(this.category);
}
isIRRemoteControl() {
return this.remote_keys !== undefined;
}
}