@ledvance/base 1.1.13 → 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/.prettierrc.js +0 -0
- package/package.json +1 -1
- package/src/api/native.d.ts +5 -0
- package/src/api/native.ts +193 -160
- 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 +48 -0
- 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 +38 -0
- 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 +85 -0
- package/src/utils/cctUtils.d.ts +1 -0
- package/src/utils/cctUtils.ts +111 -0
- package/src/utils/common.ts +186 -174
- package/src/utils/index.ts +123 -123
package/.prettierrc.js
CHANGED
|
File without changes
|
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,77 +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
|
-
|
|
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
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
const devicePanel: LDVDevicePanelManager = NativeModules.LDVDevicePanelManager
|
|
22
24
|
const logManager = NativeModules.RNLogManager
|
|
23
25
|
|
|
24
26
|
const back = () => {
|
|
25
|
-
|
|
27
|
+
devicePanel.back()
|
|
26
28
|
}
|
|
27
29
|
|
|
28
30
|
const log = (str: string) => {
|
|
29
|
-
|
|
31
|
+
logManager.log(str)
|
|
30
32
|
}
|
|
31
33
|
|
|
32
34
|
const showObj = (objc) => {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
35
|
+
if (!!objc) {
|
|
36
|
+
logManager.objc(objc)
|
|
37
|
+
}
|
|
36
38
|
}
|
|
37
39
|
|
|
38
40
|
|
|
39
41
|
const control = (devId, dps, callback) => {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
42
|
+
devicePanel.control({devId, dps: JSON.stringify(dps)}, res => {
|
|
43
|
+
callback && callback(res)
|
|
44
|
+
})
|
|
43
45
|
}
|
|
44
46
|
|
|
45
47
|
// timer
|
|
46
48
|
const TASK = 'LDV_TY'
|
|
47
49
|
|
|
48
50
|
const timerList = devId => {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
})
|
|
51
|
+
return new Promise((resolve, _reject) => {
|
|
52
|
+
const params = {devId, task: TASK, action: 'list', bizType: 0}
|
|
53
|
+
devicePanel.setTimer(params, res => {
|
|
54
|
+
resolve(res)
|
|
54
55
|
})
|
|
56
|
+
})
|
|
55
57
|
}
|
|
56
58
|
|
|
57
59
|
const addTimer = (devId, value, callback: any = undefined) => {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
const params = {devId, task: TASK, action: 'add', value, bizType: 0}
|
|
61
|
+
devicePanel.setTimer(params, res => {
|
|
62
|
+
callback && callback(res)
|
|
63
|
+
})
|
|
62
64
|
}
|
|
63
65
|
|
|
64
66
|
const editTimer = (devId, value, callback: any = undefined) => {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
const params = {devId, task: TASK, action: 'update', value, bizType: 0}
|
|
68
|
+
devicePanel.setTimer(params, res => {
|
|
69
|
+
callback && callback(res)
|
|
70
|
+
})
|
|
69
71
|
}
|
|
70
72
|
|
|
71
73
|
const deleteTimer = (devId, value, callback: any = undefined) => {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
74
|
+
const params = {devId, task: TASK, action: 'delete', value, bizType: 0}
|
|
75
|
+
devicePanel.setTimer(params, res => {
|
|
76
|
+
callback && callback(res)
|
|
77
|
+
})
|
|
76
78
|
}
|
|
77
79
|
|
|
78
80
|
/**
|
|
@@ -82,169 +84,200 @@ const deleteTimer = (devId, value, callback: any = undefined) => {
|
|
|
82
84
|
* @param callback
|
|
83
85
|
*/
|
|
84
86
|
function getAllTaskTimer(devId: string, type: number = 0, callback: ((res: NativeResult<string>) => void)) {
|
|
85
|
-
|
|
87
|
+
devicePanel.getAllTaskTimer(devId, type, callback)
|
|
86
88
|
}
|
|
87
89
|
|
|
88
90
|
const setDp = <T>(deviceId: string, key: string, value: any) => {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
})
|
|
91
|
+
return new Promise<NativeResult<T>>((resolve, _reject) => {
|
|
92
|
+
control(deviceId, {[key]: value}, res => {
|
|
93
|
+
resolve(res)
|
|
93
94
|
})
|
|
95
|
+
})
|
|
94
96
|
}
|
|
95
97
|
|
|
96
98
|
const setDps = <T>(deviceId: string, dps: any) => {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
99
|
+
return new Promise<NativeResult<T>>((resolve, _reject) => {
|
|
100
|
+
control(deviceId, dps, res => {
|
|
101
|
+
resolve(res)
|
|
102
|
+
})
|
|
103
|
+
})
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
type GetFeatureResultType = (deviceId: string, featureId: string) => Promise<NativeResult<any>>;
|
|
107
|
+
type SetFeatureResultType = (
|
|
108
|
+
deviceId: string,
|
|
109
|
+
featureId: string,
|
|
110
|
+
value: any,
|
|
111
|
+
) => Promise<NativeResult<any>>;
|
|
112
|
+
|
|
113
|
+
export const getFeature: GetFeatureResultType = (deviceId: string, featureId: string) => {
|
|
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)
|
|
101
121
|
})
|
|
122
|
+
})
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export const putFeature: SetFeatureResultType = (
|
|
126
|
+
deviceId: string,
|
|
127
|
+
featureId: string,
|
|
128
|
+
value: any,
|
|
129
|
+
) => {
|
|
130
|
+
return new Promise((resolve, _reject) => {
|
|
131
|
+
devicePanel.putFeature(deviceId, featureId, JSON.stringify({value}), res => {
|
|
132
|
+
resolve(res)
|
|
133
|
+
})
|
|
134
|
+
})
|
|
102
135
|
}
|
|
103
136
|
|
|
104
137
|
type DeleteDeviceResultType = (deviceId: string, isReset: boolean) => Promise<NativeResult<any>>
|
|
105
138
|
|
|
106
139
|
const deleteDevice: DeleteDeviceResultType = (deviceId: string, isReset: boolean) => {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
})
|
|
140
|
+
return new Promise((resolve, _reject) => {
|
|
141
|
+
devicePanel.deleteDevice(deviceId, isReset, res => {
|
|
142
|
+
resolve(res)
|
|
111
143
|
})
|
|
144
|
+
})
|
|
112
145
|
}
|
|
113
146
|
|
|
114
147
|
type RenameResultType = (deviceId: string, name: string) => Promise<NativeResult<any>>
|
|
115
148
|
|
|
116
149
|
const rename: RenameResultType = (deviceId: string, name: string) => {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
})
|
|
150
|
+
return new Promise((resolve, _reject) => {
|
|
151
|
+
devicePanel.rename(deviceId, name, res => {
|
|
152
|
+
resolve(res)
|
|
121
153
|
})
|
|
154
|
+
})
|
|
122
155
|
}
|
|
123
156
|
|
|
124
157
|
function toDeviceSettingsPage(tuyaDeviceId: string) {
|
|
125
|
-
|
|
158
|
+
devicePanel.toDeviceSettingsPage(tuyaDeviceId)
|
|
126
159
|
}
|
|
127
160
|
|
|
128
161
|
export class NativeApi {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
})
|
|
153
|
-
})
|
|
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,
|
|
154
185
|
})
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
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
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
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,
|
|
202
233
|
})
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
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,
|
|
214
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,
|
|
215
256
|
}
|
|
216
|
-
|
|
217
|
-
static async groupControl(tyGroupId: number, dps: string, config: string): Promise<Result<any>> {
|
|
218
|
-
const nativeResult = await devicePanel.groupControl(tyGroupId, dps, config)
|
|
219
|
-
return {
|
|
220
|
-
success: nativeResult.result,
|
|
221
|
-
msg: nativeResult.msg,
|
|
222
|
-
data: nativeResult.data
|
|
223
|
-
}
|
|
224
|
-
}
|
|
257
|
+
}
|
|
225
258
|
}
|
|
226
259
|
|
|
227
260
|
// 打开下载文件
|
|
228
261
|
export const openDownloadFile = (filePath: string) => {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
262
|
+
return new Promise((_reject) => {
|
|
263
|
+
devicePanel.openDownloadFile(filePath)
|
|
264
|
+
})
|
|
232
265
|
}
|
|
233
266
|
|
|
234
267
|
export const queryDpIds = (dpIds: string, deviceId: string) => {
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
})
|
|
268
|
+
return new Promise((resolve, _reject) => {
|
|
269
|
+
devicePanel.getInitiativeQueryDpsInfoWithDpsArray(dpIds, deviceId, res => {
|
|
270
|
+
resolve(res)
|
|
239
271
|
})
|
|
272
|
+
})
|
|
240
273
|
}
|
|
241
274
|
|
|
242
275
|
export const formatNumber: (num: number, fixed: number) => string = (num, fixed) => {
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
276
|
+
const res = devicePanel.formatNumber(num, fixed)
|
|
277
|
+
log(`formatNumber: num=${num}, fixed=${fixed}, res=${res}`)
|
|
278
|
+
return res
|
|
246
279
|
}
|
|
247
280
|
|
|
248
281
|
export const getTimeZone: () => string = () => {
|
|
249
|
-
|
|
282
|
+
return Platform.OS === 'android' ? devicePanel.getTimeZone() || '' : Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
250
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
|
}
|
package/src/components/Card.tsx
CHANGED
|
@@ -5,32 +5,32 @@ import {Utils} from 'tuya-panel-kit'
|
|
|
5
5
|
const cx = Utils.RatioUtils.convertX
|
|
6
6
|
|
|
7
7
|
interface CardProps extends PropsWithChildren<ViewProps> {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
shadowHeight?: number | undefined
|
|
9
|
+
onPress?: () => void
|
|
10
|
+
onLongPress?: () => void
|
|
11
|
+
containerStyle?: StyleProp<ViewStyle>
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export default function Card(props: CardProps) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
15
|
+
const shadowHeight = props.shadowHeight || cx(7)
|
|
16
|
+
return (
|
|
17
|
+
<View
|
|
18
|
+
style={[{
|
|
19
|
+
overflow: Platform.OS === 'ios' ? undefined : 'hidden',
|
|
20
|
+
backgroundColor: 'white',
|
|
21
|
+
elevation: shadowHeight,
|
|
22
|
+
shadowColor: '#000000',
|
|
23
|
+
shadowOpacity: 0.2,
|
|
24
|
+
shadowRadius: shadowHeight,
|
|
25
|
+
shadowOffset: {
|
|
26
|
+
width: 0,
|
|
27
|
+
height: shadowHeight,
|
|
28
|
+
},
|
|
29
|
+
borderRadius: cx(10),
|
|
30
|
+
}, props.style]}>
|
|
31
|
+
<TouchableOpacity disabled={!(!!props.onPress)} onPress={props.onPress} onLongPress={props.onLongPress}>
|
|
32
|
+
<View style={props.containerStyle}>{props.children}</View>
|
|
33
|
+
</TouchableOpacity>
|
|
34
|
+
</View>
|
|
35
|
+
)
|
|
36
36
|
}
|