@ledvance/base 1.1.14 → 1.1.15
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 +5 -0
- package/src/api/native.ts +180 -180
- 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.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,8 @@
|
|
|
1
1
|
import { NativeResult, Result } from '../models/modules/Result';
|
|
2
|
+
declare type GetFeatureResultType = (deviceId: string, featureId: string) => Promise<NativeResult<any>>;
|
|
3
|
+
declare type SetFeatureResultType = (deviceId: string, featureId: string, value: any) => Promise<NativeResult<any>>;
|
|
4
|
+
export declare const getFeature: GetFeatureResultType;
|
|
5
|
+
export declare const putFeature: SetFeatureResultType;
|
|
2
6
|
export declare class NativeApi {
|
|
3
7
|
static back(): void;
|
|
4
8
|
static log(msg: string): void;
|
|
@@ -22,3 +26,4 @@ export declare const openDownloadFile: (filePath: string) => Promise<unknown>;
|
|
|
22
26
|
export declare const queryDpIds: (dpIds: string, deviceId: string) => Promise<unknown>;
|
|
23
27
|
export declare const formatNumber: (num: number, fixed: number) => string;
|
|
24
28
|
export declare const getTimeZone: () => string;
|
|
29
|
+
export {};
|
package/src/api/native.ts
CHANGED
|
@@ -2,79 +2,79 @@ 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
21
|
}
|
|
22
22
|
|
|
23
23
|
const devicePanel: LDVDevicePanelManager = NativeModules.LDVDevicePanelManager
|
|
24
24
|
const logManager = NativeModules.RNLogManager
|
|
25
25
|
|
|
26
26
|
const back = () => {
|
|
27
|
-
|
|
27
|
+
devicePanel.back()
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
const log = (str: string) => {
|
|
31
|
-
|
|
31
|
+
logManager.log(str)
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
const showObj = (objc) => {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
if (!!objc) {
|
|
36
|
+
logManager.objc(objc)
|
|
37
|
+
}
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
|
|
41
41
|
const control = (devId, dps, callback) => {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
devicePanel.control({devId, dps: JSON.stringify(dps)}, res => {
|
|
43
|
+
callback && callback(res)
|
|
44
|
+
})
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
// timer
|
|
48
48
|
const TASK = 'LDV_TY'
|
|
49
49
|
|
|
50
50
|
const timerList = devId => {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
})
|
|
51
|
+
return new Promise((resolve, _reject) => {
|
|
52
|
+
const params = {devId, task: TASK, action: 'list', bizType: 0}
|
|
53
|
+
devicePanel.setTimer(params, res => {
|
|
54
|
+
resolve(res)
|
|
56
55
|
})
|
|
56
|
+
})
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
const addTimer = (devId, value, callback: any = undefined) => {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
60
|
+
const params = {devId, task: TASK, action: 'add', value, bizType: 0}
|
|
61
|
+
devicePanel.setTimer(params, res => {
|
|
62
|
+
callback && callback(res)
|
|
63
|
+
})
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
const editTimer = (devId, value, callback: any = undefined) => {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
67
|
+
const params = {devId, task: TASK, action: 'update', value, bizType: 0}
|
|
68
|
+
devicePanel.setTimer(params, res => {
|
|
69
|
+
callback && callback(res)
|
|
70
|
+
})
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
const deleteTimer = (devId, value, callback: any = undefined) => {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
74
|
+
const params = {devId, task: TASK, action: 'delete', value, bizType: 0}
|
|
75
|
+
devicePanel.setTimer(params, res => {
|
|
76
|
+
callback && callback(res)
|
|
77
|
+
})
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
/**
|
|
@@ -84,200 +84,200 @@ const deleteTimer = (devId, value, callback: any = undefined) => {
|
|
|
84
84
|
* @param callback
|
|
85
85
|
*/
|
|
86
86
|
function getAllTaskTimer(devId: string, type: number = 0, callback: ((res: NativeResult<string>) => void)) {
|
|
87
|
-
|
|
87
|
+
devicePanel.getAllTaskTimer(devId, type, callback)
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
const setDp = <T>(deviceId: string, key: string, value: any) => {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
})
|
|
91
|
+
return new Promise<NativeResult<T>>((resolve, _reject) => {
|
|
92
|
+
control(deviceId, {[key]: value}, res => {
|
|
93
|
+
resolve(res)
|
|
95
94
|
})
|
|
95
|
+
})
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
const setDps = <T>(deviceId: string, dps: any) => {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
})
|
|
99
|
+
return new Promise<NativeResult<T>>((resolve, _reject) => {
|
|
100
|
+
control(deviceId, dps, res => {
|
|
101
|
+
resolve(res)
|
|
103
102
|
})
|
|
103
|
+
})
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
type GetFeatureResultType = (deviceId: string, featureId: string) => Promise<NativeResult<any>>;
|
|
107
107
|
type SetFeatureResultType = (
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
108
|
+
deviceId: string,
|
|
109
|
+
featureId: string,
|
|
110
|
+
value: any,
|
|
111
111
|
) => Promise<NativeResult<any>>;
|
|
112
112
|
|
|
113
113
|
export const getFeature: GetFeatureResultType = (deviceId: string, featureId: string) => {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
})
|
|
114
|
+
return new Promise((resolve, _reject) => {
|
|
115
|
+
devicePanel.getFeature(deviceId, featureId, res => {
|
|
116
|
+
const result: NativeResult<any> = {
|
|
117
|
+
...res,
|
|
118
|
+
data: !!res.data ? JSON.parse(res.data).value : null,
|
|
119
|
+
}
|
|
120
|
+
resolve(result)
|
|
122
121
|
})
|
|
122
|
+
})
|
|
123
123
|
}
|
|
124
124
|
|
|
125
125
|
export const putFeature: SetFeatureResultType = (
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
126
|
+
deviceId: string,
|
|
127
|
+
featureId: string,
|
|
128
|
+
value: any,
|
|
129
129
|
) => {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
})
|
|
130
|
+
return new Promise((resolve, _reject) => {
|
|
131
|
+
devicePanel.putFeature(deviceId, featureId, JSON.stringify({value}), res => {
|
|
132
|
+
resolve(res)
|
|
134
133
|
})
|
|
134
|
+
})
|
|
135
135
|
}
|
|
136
136
|
|
|
137
137
|
type DeleteDeviceResultType = (deviceId: string, isReset: boolean) => Promise<NativeResult<any>>
|
|
138
138
|
|
|
139
139
|
const deleteDevice: DeleteDeviceResultType = (deviceId: string, isReset: boolean) => {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
})
|
|
140
|
+
return new Promise((resolve, _reject) => {
|
|
141
|
+
devicePanel.deleteDevice(deviceId, isReset, res => {
|
|
142
|
+
resolve(res)
|
|
144
143
|
})
|
|
144
|
+
})
|
|
145
145
|
}
|
|
146
146
|
|
|
147
147
|
type RenameResultType = (deviceId: string, name: string) => Promise<NativeResult<any>>
|
|
148
148
|
|
|
149
149
|
const rename: RenameResultType = (deviceId: string, name: string) => {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
})
|
|
150
|
+
return new Promise((resolve, _reject) => {
|
|
151
|
+
devicePanel.rename(deviceId, name, res => {
|
|
152
|
+
resolve(res)
|
|
154
153
|
})
|
|
154
|
+
})
|
|
155
155
|
}
|
|
156
156
|
|
|
157
157
|
function toDeviceSettingsPage(tuyaDeviceId: string) {
|
|
158
|
-
|
|
158
|
+
devicePanel.toDeviceSettingsPage(tuyaDeviceId)
|
|
159
159
|
}
|
|
160
160
|
|
|
161
161
|
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
|
-
})
|
|
162
|
+
static back(): void {
|
|
163
|
+
back()
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
static log(msg: string): void {
|
|
167
|
+
log(msg)
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
static logObj(msg: any): void {
|
|
171
|
+
this.log(JSON.stringify(msg))
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
static showObj(obj: any): void {
|
|
175
|
+
showObj(obj)
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
static getAllTaskTimer(devId: string, type: number = 0): Promise<Result<any>> {
|
|
179
|
+
return new Promise<Result<any>>((resolve, _reject) => {
|
|
180
|
+
getAllTaskTimer(devId, type, res => {
|
|
181
|
+
resolve({
|
|
182
|
+
success: res.result,
|
|
183
|
+
data: res.result ? JSON.parse(res.data || '[]') : undefined,
|
|
184
|
+
msg: res.msg,
|
|
187
185
|
})
|
|
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
|
-
|
|
186
|
+
})
|
|
187
|
+
})
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
static timerList(deviceId: string): Promise<any> {
|
|
191
|
+
return timerList(deviceId)
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
static addTimer(deviceId: string, value: any, callback?: (res: any) => void): void {
|
|
195
|
+
addTimer(deviceId, value, callback)
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
static editTimer(deviceId: string, value: any, callback?: (res: any) => void): void {
|
|
199
|
+
editTimer(deviceId, value, callback)
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
static deleteTimer(deviceId: string, value: any, callback?: (res: any) => void): void {
|
|
203
|
+
deleteTimer(deviceId, value, callback)
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
static setDp<T>(deviceId: string, key: string, value: any): Promise<NativeResult<T>> {
|
|
207
|
+
return setDp<T>(deviceId, key, value)
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
static setDps<T>(deviceId: string, dps: any): Promise<NativeResult<T>> {
|
|
211
|
+
return setDps<T>(deviceId, dps)
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
static deleteDevice(deviceId: string, isReset: boolean): Promise<NativeResult<any>> {
|
|
215
|
+
return deleteDevice(deviceId, isReset)
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
static renameDevice(deviceId: string, name: string): Promise<NativeResult<any>> {
|
|
219
|
+
return rename(deviceId, name)
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
static toDeviceSettingsPage(deviceId: string): void {
|
|
223
|
+
toDeviceSettingsPage(deviceId)
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
static putJson(deviceId: string, featureType: string, json: string): Promise<Result<any>> {
|
|
227
|
+
return new Promise<Result<any>>(resolve => {
|
|
228
|
+
devicePanel.putJson(deviceId, featureType, json, nativeRes => {
|
|
229
|
+
resolve({
|
|
230
|
+
success: nativeRes.result,
|
|
231
|
+
data: nativeRes.data,
|
|
232
|
+
msg: nativeRes.msg,
|
|
235
233
|
})
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
234
|
+
})
|
|
235
|
+
})
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
static getJson(deviceId: string, featureType: string): Promise<Result<any>> {
|
|
239
|
+
return new Promise<Result<any>>(resolve => {
|
|
240
|
+
devicePanel.getJson(deviceId, featureType, nativeRes => {
|
|
241
|
+
resolve({
|
|
242
|
+
success: nativeRes.result,
|
|
243
|
+
data: nativeRes.data,
|
|
244
|
+
msg: nativeRes.msg,
|
|
247
245
|
})
|
|
246
|
+
})
|
|
247
|
+
})
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
static async groupControl(tyGroupId: number, dps: string, config: string): Promise<Result<any>> {
|
|
251
|
+
const nativeResult = await devicePanel.groupControl(tyGroupId, dps, config)
|
|
252
|
+
return {
|
|
253
|
+
success: nativeResult.result,
|
|
254
|
+
msg: nativeResult.msg,
|
|
255
|
+
data: nativeResult.data,
|
|
248
256
|
}
|
|
249
|
-
|
|
250
|
-
static async groupControl(tyGroupId: number, dps: string, config: string): Promise<Result<any>> {
|
|
251
|
-
const nativeResult = await devicePanel.groupControl(tyGroupId, dps, config)
|
|
252
|
-
return {
|
|
253
|
-
success: nativeResult.result,
|
|
254
|
-
msg: nativeResult.msg,
|
|
255
|
-
data: nativeResult.data
|
|
256
|
-
}
|
|
257
|
-
}
|
|
257
|
+
}
|
|
258
258
|
}
|
|
259
259
|
|
|
260
260
|
// 打开下载文件
|
|
261
261
|
export const openDownloadFile = (filePath: string) => {
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
262
|
+
return new Promise((_reject) => {
|
|
263
|
+
devicePanel.openDownloadFile(filePath)
|
|
264
|
+
})
|
|
265
265
|
}
|
|
266
266
|
|
|
267
267
|
export const queryDpIds = (dpIds: string, deviceId: string) => {
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
})
|
|
268
|
+
return new Promise((resolve, _reject) => {
|
|
269
|
+
devicePanel.getInitiativeQueryDpsInfoWithDpsArray(dpIds, deviceId, res => {
|
|
270
|
+
resolve(res)
|
|
272
271
|
})
|
|
272
|
+
})
|
|
273
273
|
}
|
|
274
274
|
|
|
275
275
|
export const formatNumber: (num: number, fixed: number) => string = (num, fixed) => {
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
276
|
+
const res = devicePanel.formatNumber(num, fixed)
|
|
277
|
+
log(`formatNumber: num=${num}, fixed=${fixed}, res=${res}`)
|
|
278
|
+
return res
|
|
279
279
|
}
|
|
280
280
|
|
|
281
281
|
export const getTimeZone: () => string = () => {
|
|
282
|
-
|
|
282
|
+
return Platform.OS === 'android' ? devicePanel.getTimeZone() || '' : Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
283
283
|
}
|
|
@@ -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
|
}
|