@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.
Files changed (65) hide show
  1. package/package.json +1 -1
  2. package/src/api/native.d.ts +13 -0
  3. package/src/api/native.ts +197 -179
  4. package/src/api/nativeEventEmitter.ts +54 -54
  5. package/src/components/Card.tsx +25 -25
  6. package/src/components/Cell.tsx +32 -32
  7. package/src/components/ColorAdjustView.tsx +44 -44
  8. package/src/components/ColorTempAdjustView.tsx +37 -37
  9. package/src/components/ColorsLine.d.ts +7 -0
  10. package/src/components/ColorsLine.tsx +34 -34
  11. package/src/components/DeleteButton.d.ts +1 -1
  12. package/src/components/DeleteButton.tsx +27 -27
  13. package/src/components/Dialog.tsx +28 -28
  14. package/src/components/FanAdjustView.tsx +115 -105
  15. package/src/components/InfoText.tsx +29 -29
  16. package/src/components/LampAdjustView.tsx +52 -52
  17. package/src/components/LinearGradientLine.tsx +53 -53
  18. package/src/components/MoodColorsLine.d.ts +9 -0
  19. package/src/components/MoodColorsLine.tsx +23 -23
  20. package/src/components/Page.tsx +34 -34
  21. package/src/components/Popup.tsx +17 -17
  22. package/src/components/Segmented.d.ts +2 -2
  23. package/src/components/Segmented.tsx +66 -65
  24. package/src/components/Spacer.tsx +5 -5
  25. package/src/components/Tag.tsx +42 -42
  26. package/src/components/TextButton.d.ts +1 -1
  27. package/src/components/TextButton.tsx +23 -23
  28. package/src/components/TextField.tsx +58 -58
  29. package/src/components/connect.tsx +10 -10
  30. package/src/components/ldvColorBrightness.tsx +12 -12
  31. package/src/components/ldvColorSlider.tsx +109 -109
  32. package/src/components/ldvPickerView.tsx +70 -70
  33. package/src/components/ldvPresetView.tsx +68 -68
  34. package/src/components/ldvSaturation.tsx +14 -14
  35. package/src/components/ldvSlider.d.ts +3 -3
  36. package/src/components/ldvSlider.tsx +93 -93
  37. package/src/components/ldvSwitch.tsx +35 -35
  38. package/src/components/ldvTemperatureSlider.tsx +120 -120
  39. package/src/components/ldvTopBar.tsx +50 -50
  40. package/src/components/ldvTopName.tsx +44 -44
  41. package/src/components/segmentControl.tsx +59 -59
  42. package/src/components/weekSelect.tsx +76 -76
  43. package/src/composeLayout.tsx +165 -165
  44. package/src/i18n/index.ts +12 -12
  45. package/src/i18n/strings.ts +11004 -11004
  46. package/src/main.tsx +4 -4
  47. package/src/models/GlobalParams.ts +7 -7
  48. package/src/models/TuyaApi.d.ts +3 -3
  49. package/src/models/TuyaApi.ts +61 -61
  50. package/src/models/combine.ts +7 -7
  51. package/src/models/configureStore.ts +14 -14
  52. package/src/models/index.ts +4 -4
  53. package/src/models/modules/NativePropsSlice.d.ts +5 -2
  54. package/src/models/modules/NativePropsSlice.tsx +170 -169
  55. package/src/models/modules/Result.ts +8 -8
  56. package/src/models/modules/common.ts +90 -90
  57. package/src/res/index.ts +35 -35
  58. package/src/utils/ColorParser.ts +150 -150
  59. package/src/utils/ColorUtils.tsx +414 -414
  60. package/src/utils/Support.d.ts +9 -0
  61. package/src/utils/Support.ts +73 -73
  62. package/src/utils/cctUtils.d.ts +1 -0
  63. package/src/utils/cctUtils.ts +106 -106
  64. package/src/utils/common.ts +186 -174
  65. package/src/utils/index.ts +123 -123
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "name": "@ledvance/base",
5
5
  "pid": [],
6
6
  "uiid": "",
7
- "version": "1.1.14",
7
+ "version": "1.1.16",
8
8
  "scripts": {},
9
9
  "dependencies": {
10
10
  "@reduxjs/toolkit": "^1.8.6",
@@ -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
- 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
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
- devicePanel.back()
36
+ devicePanel.back()
28
37
  }
29
38
 
30
39
  const log = (str: string) => {
31
- logManager.log(str)
40
+ logManager.log(str)
32
41
  }
33
42
 
34
43
  const showObj = (objc) => {
35
- if (!!objc) {
36
- logManager.objc(objc)
37
- }
44
+ if (!!objc) {
45
+ logManager.objc(objc)
46
+ }
38
47
  }
39
48
 
40
49
 
41
50
  const control = (devId, dps, callback) => {
42
- devicePanel.control({ devId, dps: JSON.stringify(dps) }, res => {
43
- callback && callback(res)
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
- return new Promise((resolve, _reject) => {
52
- const params = { devId, task: TASK, action: 'list', bizType: 0 }
53
- devicePanel.setTimer(params, res => {
54
- resolve(res)
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
- const params = { devId, task: TASK, action: 'add', value, bizType: 0 }
61
- devicePanel.setTimer(params, res => {
62
- callback && callback(res)
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
- const params = { devId, task: TASK, action: 'update', value, bizType: 0 }
68
- devicePanel.setTimer(params, res => {
69
- callback && callback(res)
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
- const params = { devId, task: TASK, action: 'delete', value, bizType: 0 }
75
- devicePanel.setTimer(params, res => {
76
- callback && callback(res)
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
- devicePanel.getAllTaskTimer(devId, type, callback)
96
+ devicePanel.getAllTaskTimer(devId, type, callback)
88
97
  }
89
98
 
90
99
  const setDp = <T>(deviceId: string, key: string, value: any) => {
91
- return new Promise<NativeResult<T>>((resolve, _reject) => {
92
- control(deviceId, { [key]: value }, res => {
93
- resolve(res)
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
- return new Promise<NativeResult<T>>((resolve, _reject) => {
100
- control(deviceId, dps, res => {
101
- resolve(res)
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
- deviceId: string,
109
- featureId: string,
110
- value: any,
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
- 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)
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
- deviceId: string,
127
- featureId: string,
128
- value: any,
135
+ deviceId: string,
136
+ featureId: string,
137
+ value: any,
129
138
  ) => {
130
- return new Promise((resolve, _reject) => {
131
- devicePanel.putFeature(deviceId, featureId, JSON.stringify({ value }), res => {
132
- resolve(res)
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
- return new Promise((resolve, _reject) => {
141
- devicePanel.deleteDevice(deviceId, isReset, res => {
142
- resolve(res)
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
- return new Promise((resolve, _reject) => {
151
- devicePanel.rename(deviceId, name, res => {
152
- resolve(res)
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
- devicePanel.toDeviceSettingsPage(tuyaDeviceId)
167
+ devicePanel.toDeviceSettingsPage(tuyaDeviceId)
159
168
  }
160
169
 
161
170
  export class NativeApi {
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,
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
- 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,
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
- 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,
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
- 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
- }
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
- return new Promise((_reject) => {
263
- devicePanel.openDownloadFile(filePath)
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
- return new Promise((resolve, _reject) => {
269
- devicePanel.getInitiativeQueryDpsInfoWithDpsArray(dpIds, deviceId, res => {
270
- resolve(res)
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
- const res = devicePanel.formatNumber(num, fixed)
277
- log(`formatNumber: num=${num}, fixed=${fixed}, res=${res}`)
278
- return res
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
- return Platform.OS === 'android' ? devicePanel.getTimeZone() || '' : Intl.DateTimeFormat().resolvedOptions().timeZone
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
- DeviceInfo,
4
- NativeProps,
5
- setGroupNativeProps,
6
- setNativeProps,
7
- UAGroupInfo,
3
+ DeviceInfo,
4
+ NativeProps,
5
+ setGroupNativeProps,
6
+ setNativeProps,
7
+ UAGroupInfo,
8
8
  } from '../models/modules/NativePropsSlice'
9
- import { actions } from '@models'
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
- tyGroupId: number
19
- config: string
18
+ tyGroupId: number
19
+ config: string
20
20
  }
21
21
 
22
22
  interface DeviceEvent {
23
- devId: string
24
- dps: any
25
- name: string
26
- pId: string
23
+ devId: string
24
+ dps: any
25
+ name: string
26
+ pId: string
27
27
  }
28
28
 
29
29
  export const addListener = (store) => {
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
- })
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
- 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
- })
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
- deviceDPListener && deviceDPListener.remove()
71
- deviceDPListener = null
70
+ deviceDPListener && deviceDPListener.remove()
71
+ deviceDPListener = null
72
72
 
73
- groupFeatureListener && groupFeatureListener.remove()
74
- groupFeatureListener = null
73
+ groupFeatureListener && groupFeatureListener.remove()
74
+ groupFeatureListener = null
75
75
  }