@ledvance/base 1.1.14 → 1.1.16
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/package.json +1 -1
- package/src/api/native.d.ts +13 -0
- package/src/api/native.ts +197 -179
- package/src/api/nativeEventEmitter.ts +54 -54
- package/src/components/Card.tsx +25 -25
- package/src/components/Cell.tsx +32 -32
- package/src/components/ColorAdjustView.tsx +44 -44
- package/src/components/ColorTempAdjustView.tsx +37 -37
- package/src/components/ColorsLine.d.ts +7 -0
- package/src/components/ColorsLine.tsx +34 -34
- package/src/components/DeleteButton.d.ts +1 -1
- package/src/components/DeleteButton.tsx +27 -27
- package/src/components/Dialog.tsx +28 -28
- package/src/components/FanAdjustView.tsx +115 -105
- package/src/components/InfoText.tsx +29 -29
- package/src/components/LampAdjustView.tsx +52 -52
- package/src/components/LinearGradientLine.tsx +53 -53
- package/src/components/MoodColorsLine.d.ts +9 -0
- package/src/components/MoodColorsLine.tsx +23 -23
- package/src/components/Page.tsx +34 -34
- package/src/components/Popup.tsx +17 -17
- package/src/components/Segmented.d.ts +2 -2
- package/src/components/Segmented.tsx +66 -65
- package/src/components/Spacer.tsx +5 -5
- package/src/components/Tag.tsx +42 -42
- package/src/components/TextButton.d.ts +1 -1
- package/src/components/TextButton.tsx +23 -23
- package/src/components/TextField.tsx +58 -58
- package/src/components/connect.tsx +10 -10
- package/src/components/ldvColorBrightness.tsx +12 -12
- package/src/components/ldvColorSlider.tsx +109 -109
- package/src/components/ldvPickerView.tsx +70 -70
- package/src/components/ldvPresetView.tsx +68 -68
- package/src/components/ldvSaturation.tsx +14 -14
- package/src/components/ldvSlider.d.ts +3 -3
- package/src/components/ldvSlider.tsx +93 -93
- package/src/components/ldvSwitch.tsx +35 -35
- package/src/components/ldvTemperatureSlider.tsx +120 -120
- package/src/components/ldvTopBar.tsx +50 -50
- package/src/components/ldvTopName.tsx +44 -44
- package/src/components/segmentControl.tsx +59 -59
- package/src/components/weekSelect.tsx +76 -76
- package/src/composeLayout.tsx +165 -165
- package/src/i18n/index.ts +12 -12
- package/src/i18n/strings.ts +11004 -11004
- package/src/main.tsx +4 -4
- package/src/models/GlobalParams.ts +7 -7
- package/src/models/TuyaApi.d.ts +3 -3
- package/src/models/TuyaApi.ts +61 -61
- package/src/models/combine.ts +7 -7
- package/src/models/configureStore.ts +14 -14
- package/src/models/index.ts +4 -4
- package/src/models/modules/NativePropsSlice.d.ts +5 -2
- package/src/models/modules/NativePropsSlice.tsx +170 -169
- package/src/models/modules/Result.ts +8 -8
- package/src/models/modules/common.ts +90 -90
- package/src/res/index.ts +35 -35
- package/src/utils/ColorParser.ts +150 -150
- package/src/utils/ColorUtils.tsx +414 -414
- package/src/utils/Support.d.ts +9 -0
- package/src/utils/Support.ts +73 -73
- package/src/utils/cctUtils.d.ts +1 -0
- package/src/utils/cctUtils.ts +106 -106
- package/src/utils/common.ts +186 -174
- package/src/utils/index.ts +123 -123
package/package.json
CHANGED
package/src/api/native.d.ts
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
import { NativeResult, Result } from '../models/modules/Result';
|
|
2
|
+
export interface DeviceInfo {
|
|
3
|
+
deviceId: string;
|
|
4
|
+
deviceName: string;
|
|
5
|
+
deviceIcon: string;
|
|
6
|
+
roomName: string;
|
|
7
|
+
status: number;
|
|
8
|
+
}
|
|
9
|
+
declare type GetFeatureResultType = (deviceId: string, featureId: string) => Promise<NativeResult<any>>;
|
|
10
|
+
declare type SetFeatureResultType = (deviceId: string, featureId: string, value: any) => Promise<NativeResult<any>>;
|
|
11
|
+
export declare const getFeature: GetFeatureResultType;
|
|
12
|
+
export declare const putFeature: SetFeatureResultType;
|
|
2
13
|
export declare class NativeApi {
|
|
3
14
|
static back(): void;
|
|
4
15
|
static log(msg: string): void;
|
|
@@ -17,8 +28,10 @@ export declare class NativeApi {
|
|
|
17
28
|
static putJson(deviceId: string, featureType: string, json: string): Promise<Result<any>>;
|
|
18
29
|
static getJson(deviceId: string, featureType: string): Promise<Result<any>>;
|
|
19
30
|
static groupControl(tyGroupId: number, dps: string, config: string): Promise<Result<any>>;
|
|
31
|
+
static getGroupDevices(tyGroupId: number): Promise<Result<DeviceInfo[]>>;
|
|
20
32
|
}
|
|
21
33
|
export declare const openDownloadFile: (filePath: string) => Promise<unknown>;
|
|
22
34
|
export declare const queryDpIds: (dpIds: string, deviceId: string) => Promise<unknown>;
|
|
23
35
|
export declare const formatNumber: (num: number, fixed: number) => string;
|
|
24
36
|
export declare const getTimeZone: () => string;
|
|
37
|
+
export {};
|
package/src/api/native.ts
CHANGED
|
@@ -2,79 +2,88 @@ import {NativeModules, Platform} from 'react-native'
|
|
|
2
2
|
import {NativeResult, Result} from '../models/modules/Result'
|
|
3
3
|
|
|
4
4
|
interface LDVDevicePanelManager {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
5
|
+
back: () => void
|
|
6
|
+
control: (params: any, callback: (result: any) => void) => void
|
|
7
|
+
setTimer: (params: any, callback: (result: any) => void) => void
|
|
8
|
+
getAllTaskTimer: (deviceId: string, type: number, callback: (res: NativeResult<string>) => void) => void
|
|
9
|
+
deleteDevice: (deviceId: string, isReset: boolean, callback: (result: any) => void) => void
|
|
10
|
+
rename: (deviceId: string, name: string, callback: (result: any) => void) => void
|
|
11
|
+
toDeviceSettingsPage: (deviceId: string) => void
|
|
12
|
+
putJson: (deviceId: string, featureType: string, json: string, callback: (res: NativeResult<any>) => void) => void
|
|
13
|
+
getJson: (deviceId: string, featureType: string, callback: (res: NativeResult<string>) => void) => void
|
|
14
|
+
getInitiativeQueryDpsInfoWithDpsArray: (dpIds: string, deviceId: string, callback: (res: NativeResult<string>) => void) => void
|
|
15
|
+
openDownloadFile: (filePath: string) => void
|
|
16
|
+
formatNumber: (num: number, fixed: number) => string
|
|
17
|
+
getTimeZone: () => string
|
|
18
|
+
groupControl: (tyGroupId: number, dps: string, config: string) => Promise<NativeResult<any>>
|
|
19
|
+
getFeature: (deviceId: string, featureId: string, callback: (res: NativeResult<string>) => void) => void
|
|
20
|
+
putFeature: (deviceId: string, featureId: string, value: any, callback: (res: NativeResult<string>) => void) => void
|
|
21
|
+
getGroupDevices: (tyGroupId: number) => Promise<NativeResult<string>>
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface DeviceInfo {
|
|
25
|
+
deviceId: string
|
|
26
|
+
deviceName: string
|
|
27
|
+
deviceIcon: string
|
|
28
|
+
roomName: string
|
|
29
|
+
status: number
|
|
21
30
|
}
|
|
22
31
|
|
|
23
32
|
const devicePanel: LDVDevicePanelManager = NativeModules.LDVDevicePanelManager
|
|
24
33
|
const logManager = NativeModules.RNLogManager
|
|
25
34
|
|
|
26
35
|
const back = () => {
|
|
27
|
-
|
|
36
|
+
devicePanel.back()
|
|
28
37
|
}
|
|
29
38
|
|
|
30
39
|
const log = (str: string) => {
|
|
31
|
-
|
|
40
|
+
logManager.log(str)
|
|
32
41
|
}
|
|
33
42
|
|
|
34
43
|
const showObj = (objc) => {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
44
|
+
if (!!objc) {
|
|
45
|
+
logManager.objc(objc)
|
|
46
|
+
}
|
|
38
47
|
}
|
|
39
48
|
|
|
40
49
|
|
|
41
50
|
const control = (devId, dps, callback) => {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
51
|
+
devicePanel.control({devId, dps: JSON.stringify(dps)}, res => {
|
|
52
|
+
callback && callback(res)
|
|
53
|
+
})
|
|
45
54
|
}
|
|
46
55
|
|
|
47
56
|
// timer
|
|
48
57
|
const TASK = 'LDV_TY'
|
|
49
58
|
|
|
50
59
|
const timerList = devId => {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
})
|
|
60
|
+
return new Promise((resolve, _reject) => {
|
|
61
|
+
const params = {devId, task: TASK, action: 'list', bizType: 0}
|
|
62
|
+
devicePanel.setTimer(params, res => {
|
|
63
|
+
resolve(res)
|
|
56
64
|
})
|
|
65
|
+
})
|
|
57
66
|
}
|
|
58
67
|
|
|
59
68
|
const addTimer = (devId, value, callback: any = undefined) => {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
69
|
+
const params = {devId, task: TASK, action: 'add', value, bizType: 0}
|
|
70
|
+
devicePanel.setTimer(params, res => {
|
|
71
|
+
callback && callback(res)
|
|
72
|
+
})
|
|
64
73
|
}
|
|
65
74
|
|
|
66
75
|
const editTimer = (devId, value, callback: any = undefined) => {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
76
|
+
const params = {devId, task: TASK, action: 'update', value, bizType: 0}
|
|
77
|
+
devicePanel.setTimer(params, res => {
|
|
78
|
+
callback && callback(res)
|
|
79
|
+
})
|
|
71
80
|
}
|
|
72
81
|
|
|
73
82
|
const deleteTimer = (devId, value, callback: any = undefined) => {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
83
|
+
const params = {devId, task: TASK, action: 'delete', value, bizType: 0}
|
|
84
|
+
devicePanel.setTimer(params, res => {
|
|
85
|
+
callback && callback(res)
|
|
86
|
+
})
|
|
78
87
|
}
|
|
79
88
|
|
|
80
89
|
/**
|
|
@@ -84,200 +93,209 @@ const deleteTimer = (devId, value, callback: any = undefined) => {
|
|
|
84
93
|
* @param callback
|
|
85
94
|
*/
|
|
86
95
|
function getAllTaskTimer(devId: string, type: number = 0, callback: ((res: NativeResult<string>) => void)) {
|
|
87
|
-
|
|
96
|
+
devicePanel.getAllTaskTimer(devId, type, callback)
|
|
88
97
|
}
|
|
89
98
|
|
|
90
99
|
const setDp = <T>(deviceId: string, key: string, value: any) => {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
})
|
|
100
|
+
return new Promise<NativeResult<T>>((resolve, _reject) => {
|
|
101
|
+
control(deviceId, {[key]: value}, res => {
|
|
102
|
+
resolve(res)
|
|
95
103
|
})
|
|
104
|
+
})
|
|
96
105
|
}
|
|
97
106
|
|
|
98
107
|
const setDps = <T>(deviceId: string, dps: any) => {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
})
|
|
108
|
+
return new Promise<NativeResult<T>>((resolve, _reject) => {
|
|
109
|
+
control(deviceId, dps, res => {
|
|
110
|
+
resolve(res)
|
|
103
111
|
})
|
|
112
|
+
})
|
|
104
113
|
}
|
|
105
114
|
|
|
106
115
|
type GetFeatureResultType = (deviceId: string, featureId: string) => Promise<NativeResult<any>>;
|
|
107
116
|
type SetFeatureResultType = (
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
117
|
+
deviceId: string,
|
|
118
|
+
featureId: string,
|
|
119
|
+
value: any,
|
|
111
120
|
) => Promise<NativeResult<any>>;
|
|
112
121
|
|
|
113
122
|
export const getFeature: GetFeatureResultType = (deviceId: string, featureId: string) => {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
})
|
|
123
|
+
return new Promise((resolve, _reject) => {
|
|
124
|
+
devicePanel.getFeature(deviceId, featureId, res => {
|
|
125
|
+
const result: NativeResult<any> = {
|
|
126
|
+
...res,
|
|
127
|
+
data: !!res.data ? JSON.parse(res.data).value : null,
|
|
128
|
+
}
|
|
129
|
+
resolve(result)
|
|
122
130
|
})
|
|
131
|
+
})
|
|
123
132
|
}
|
|
124
133
|
|
|
125
134
|
export const putFeature: SetFeatureResultType = (
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
135
|
+
deviceId: string,
|
|
136
|
+
featureId: string,
|
|
137
|
+
value: any,
|
|
129
138
|
) => {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
})
|
|
139
|
+
return new Promise((resolve, _reject) => {
|
|
140
|
+
devicePanel.putFeature(deviceId, featureId, JSON.stringify({value}), res => {
|
|
141
|
+
resolve(res)
|
|
134
142
|
})
|
|
143
|
+
})
|
|
135
144
|
}
|
|
136
145
|
|
|
137
146
|
type DeleteDeviceResultType = (deviceId: string, isReset: boolean) => Promise<NativeResult<any>>
|
|
138
147
|
|
|
139
148
|
const deleteDevice: DeleteDeviceResultType = (deviceId: string, isReset: boolean) => {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
})
|
|
149
|
+
return new Promise((resolve, _reject) => {
|
|
150
|
+
devicePanel.deleteDevice(deviceId, isReset, res => {
|
|
151
|
+
resolve(res)
|
|
144
152
|
})
|
|
153
|
+
})
|
|
145
154
|
}
|
|
146
155
|
|
|
147
156
|
type RenameResultType = (deviceId: string, name: string) => Promise<NativeResult<any>>
|
|
148
157
|
|
|
149
158
|
const rename: RenameResultType = (deviceId: string, name: string) => {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
})
|
|
159
|
+
return new Promise((resolve, _reject) => {
|
|
160
|
+
devicePanel.rename(deviceId, name, res => {
|
|
161
|
+
resolve(res)
|
|
154
162
|
})
|
|
163
|
+
})
|
|
155
164
|
}
|
|
156
165
|
|
|
157
166
|
function toDeviceSettingsPage(tuyaDeviceId: string) {
|
|
158
|
-
|
|
167
|
+
devicePanel.toDeviceSettingsPage(tuyaDeviceId)
|
|
159
168
|
}
|
|
160
169
|
|
|
161
170
|
export class NativeApi {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
})
|
|
186
|
-
})
|
|
171
|
+
static back(): void {
|
|
172
|
+
back()
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
static log(msg: string): void {
|
|
176
|
+
log(msg)
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
static logObj(msg: any): void {
|
|
180
|
+
this.log(JSON.stringify(msg))
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
static showObj(obj: any): void {
|
|
184
|
+
showObj(obj)
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
static getAllTaskTimer(devId: string, type: number = 0): Promise<Result<any>> {
|
|
188
|
+
return new Promise<Result<any>>((resolve, _reject) => {
|
|
189
|
+
getAllTaskTimer(devId, type, res => {
|
|
190
|
+
resolve({
|
|
191
|
+
success: res.result,
|
|
192
|
+
data: res.result ? JSON.parse(res.data || '[]') : undefined,
|
|
193
|
+
msg: res.msg,
|
|
187
194
|
})
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
195
|
+
})
|
|
196
|
+
})
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
static timerList(deviceId: string): Promise<any> {
|
|
200
|
+
return timerList(deviceId)
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
static addTimer(deviceId: string, value: any, callback?: (res: any) => void): void {
|
|
204
|
+
addTimer(deviceId, value, callback)
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
static editTimer(deviceId: string, value: any, callback?: (res: any) => void): void {
|
|
208
|
+
editTimer(deviceId, value, callback)
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
static deleteTimer(deviceId: string, value: any, callback?: (res: any) => void): void {
|
|
212
|
+
deleteTimer(deviceId, value, callback)
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
static setDp<T>(deviceId: string, key: string, value: any): Promise<NativeResult<T>> {
|
|
216
|
+
return setDp<T>(deviceId, key, value)
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
static setDps<T>(deviceId: string, dps: any): Promise<NativeResult<T>> {
|
|
220
|
+
return setDps<T>(deviceId, dps)
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
static deleteDevice(deviceId: string, isReset: boolean): Promise<NativeResult<any>> {
|
|
224
|
+
return deleteDevice(deviceId, isReset)
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
static renameDevice(deviceId: string, name: string): Promise<NativeResult<any>> {
|
|
228
|
+
return rename(deviceId, name)
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
static toDeviceSettingsPage(deviceId: string): void {
|
|
232
|
+
toDeviceSettingsPage(deviceId)
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
static putJson(deviceId: string, featureType: string, json: string): Promise<Result<any>> {
|
|
236
|
+
return new Promise<Result<any>>(resolve => {
|
|
237
|
+
devicePanel.putJson(deviceId, featureType, json, nativeRes => {
|
|
238
|
+
resolve({
|
|
239
|
+
success: nativeRes.result,
|
|
240
|
+
data: nativeRes.data,
|
|
241
|
+
msg: nativeRes.msg,
|
|
235
242
|
})
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
243
|
+
})
|
|
244
|
+
})
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
static getJson(deviceId: string, featureType: string): Promise<Result<any>> {
|
|
248
|
+
return new Promise<Result<any>>(resolve => {
|
|
249
|
+
devicePanel.getJson(deviceId, featureType, nativeRes => {
|
|
250
|
+
resolve({
|
|
251
|
+
success: nativeRes.result,
|
|
252
|
+
data: nativeRes.data,
|
|
253
|
+
msg: nativeRes.msg,
|
|
247
254
|
})
|
|
255
|
+
})
|
|
256
|
+
})
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
static async groupControl(tyGroupId: number, dps: string, config: string): Promise<Result<any>> {
|
|
260
|
+
const nativeResult = await devicePanel.groupControl(tyGroupId, dps, config)
|
|
261
|
+
return {
|
|
262
|
+
success: nativeResult.result,
|
|
263
|
+
msg: nativeResult.msg,
|
|
264
|
+
data: nativeResult.data,
|
|
248
265
|
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
static async getGroupDevices(tyGroupId: number): Promise<Result<DeviceInfo[]>> {
|
|
269
|
+
const nativeResult = await devicePanel.getGroupDevices(tyGroupId)
|
|
270
|
+
return {
|
|
271
|
+
success: nativeResult.result,
|
|
272
|
+
msg: nativeResult.msg,
|
|
273
|
+
data: nativeResult.data && JSON.parse(nativeResult.data),
|
|
257
274
|
}
|
|
275
|
+
}
|
|
258
276
|
}
|
|
259
277
|
|
|
260
278
|
// 打开下载文件
|
|
261
279
|
export const openDownloadFile = (filePath: string) => {
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
280
|
+
return new Promise((_reject) => {
|
|
281
|
+
devicePanel.openDownloadFile(filePath)
|
|
282
|
+
})
|
|
265
283
|
}
|
|
266
284
|
|
|
267
285
|
export const queryDpIds = (dpIds: string, deviceId: string) => {
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
})
|
|
286
|
+
return new Promise((resolve, _reject) => {
|
|
287
|
+
devicePanel.getInitiativeQueryDpsInfoWithDpsArray(dpIds, deviceId, res => {
|
|
288
|
+
resolve(res)
|
|
272
289
|
})
|
|
290
|
+
})
|
|
273
291
|
}
|
|
274
292
|
|
|
275
293
|
export const formatNumber: (num: number, fixed: number) => string = (num, fixed) => {
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
294
|
+
const res = devicePanel.formatNumber(num, fixed)
|
|
295
|
+
log(`formatNumber: num=${num}, fixed=${fixed}, res=${res}`)
|
|
296
|
+
return res
|
|
279
297
|
}
|
|
280
298
|
|
|
281
299
|
export const getTimeZone: () => string = () => {
|
|
282
|
-
|
|
300
|
+
return Platform.OS === 'android' ? devicePanel.getTimeZone() || '' : Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
283
301
|
}
|
|
@@ -1,75 +1,75 @@
|
|
|
1
1
|
import {EmitterSubscription, NativeEventEmitter, NativeModules} from 'react-native'
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
DeviceInfo,
|
|
4
|
+
NativeProps,
|
|
5
|
+
setGroupNativeProps,
|
|
6
|
+
setNativeProps,
|
|
7
|
+
UAGroupInfo,
|
|
8
8
|
} from '../models/modules/NativePropsSlice'
|
|
9
|
-
import {
|
|
9
|
+
import {actions} from '@models'
|
|
10
10
|
|
|
11
11
|
const nativeModule = NativeModules.LDVDeviceEventEmitter
|
|
12
12
|
const nativeEventEmitter = new NativeEventEmitter(nativeModule)
|
|
13
13
|
|
|
14
|
-
let deviceDPListener: EmitterSubscription|null
|
|
15
|
-
let groupFeatureListener: EmitterSubscription|null
|
|
14
|
+
let deviceDPListener: EmitterSubscription | null
|
|
15
|
+
let groupFeatureListener: EmitterSubscription | null
|
|
16
16
|
|
|
17
17
|
interface GroupFeatureEvent {
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
tyGroupId: number
|
|
19
|
+
config: string
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
interface DeviceEvent {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
devId: string
|
|
24
|
+
dps: any
|
|
25
|
+
name: string
|
|
26
|
+
pId: string
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
export const addListener = (store) => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
30
|
+
deviceDPListener = nativeEventEmitter.addListener('TYDataUpdate', (event: DeviceEvent) => {
|
|
31
|
+
// device info
|
|
32
|
+
if (event.dps && event.devId && event.devId === store.getState().ldvModules.deviceInfo.devId) {
|
|
33
|
+
console.log('长链接刷新DP数据', event.devId, event.dps)
|
|
34
|
+
const nativeProps: NativeProps = {
|
|
35
|
+
familyName: '',
|
|
36
|
+
deviceInfo: {
|
|
37
|
+
devId: event.devId,
|
|
38
|
+
pId: event.pId,
|
|
39
|
+
dps: JSON.parse(event.dps),
|
|
40
|
+
},
|
|
41
|
+
uaGroupInfo: {} as UAGroupInfo,
|
|
42
|
+
}
|
|
43
|
+
store.dispatch(setNativeProps(nativeProps))
|
|
44
|
+
}
|
|
45
|
+
// 兼容ios修改设备名称
|
|
46
|
+
if (!!event.name && event.devId && event.devId === store.getState().ldvModules.deviceInfo.devId) {
|
|
47
|
+
store.dispatch(actions.common.devInfoChange({...store.getState().devInfo, name: event.name}))
|
|
48
|
+
}
|
|
49
|
+
})
|
|
50
50
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
51
|
+
groupFeatureListener = nativeEventEmitter.addListener('UAGroupFeatureUpdate', (event: GroupFeatureEvent) => {
|
|
52
|
+
if (event.tyGroupId === store.getState().ldvModules.uaGroupInfo.tyGroupId) {
|
|
53
|
+
console.log('长链接刷新Group数据', event)
|
|
54
|
+
const nativeProps: NativeProps = {
|
|
55
|
+
familyName: '',
|
|
56
|
+
deviceInfo: {} as DeviceInfo,
|
|
57
|
+
uaGroupInfo: {
|
|
58
|
+
tyGroupId: event.tyGroupId,
|
|
59
|
+
pId: '',
|
|
60
|
+
config: JSON.parse(event.config),
|
|
61
|
+
dps: {},
|
|
62
|
+
},
|
|
63
|
+
}
|
|
64
|
+
store.dispatch(setGroupNativeProps(nativeProps))
|
|
65
|
+
}
|
|
66
|
+
})
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
export const removeListener = () => {
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
deviceDPListener && deviceDPListener.remove()
|
|
71
|
+
deviceDPListener = null
|
|
72
72
|
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
groupFeatureListener && groupFeatureListener.remove()
|
|
74
|
+
groupFeatureListener = null
|
|
75
75
|
}
|