@ledvance/base 1.2.83 → 1.2.85

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 (165) hide show
  1. package/.babelrc +31 -31
  2. package/.eslintignore +5 -5
  3. package/.eslintrc.js +27 -27
  4. package/.prettierrc.js +1 -1
  5. package/.versionrc +5 -5
  6. package/localazy.json +851 -848
  7. package/localazy.keys.json +4 -4
  8. package/package.json +74 -74
  9. package/rn-cli.config.js +8 -8
  10. package/src/api/native.d.ts +71 -71
  11. package/src/api/native.ts +423 -423
  12. package/src/api/nativeEventEmitter.d.ts +3 -3
  13. package/src/api/nativeEventEmitter.ts +125 -125
  14. package/src/components/AdvanceCard.d.ts +25 -25
  15. package/src/components/AdvanceCard.tsx +117 -117
  16. package/src/components/AdvanceList.d.ts +9 -9
  17. package/src/components/AdvanceList.tsx +69 -69
  18. package/src/components/ApplyForDeviceItem.d.ts +6 -6
  19. package/src/components/ApplyForDeviceItem.tsx +83 -83
  20. package/src/components/ApplyForDeviceList.d.ts +7 -7
  21. package/src/components/ApplyForDeviceList.tsx +61 -61
  22. package/src/components/ApplyForText.d.ts +6 -6
  23. package/src/components/ApplyForText.tsx +52 -52
  24. package/src/components/Card.d.ts +10 -10
  25. package/src/components/Card.tsx +40 -40
  26. package/src/components/Cell.d.ts +21 -21
  27. package/src/components/Cell.tsx +69 -69
  28. package/src/components/CircularProgress.d.ts +8 -8
  29. package/src/components/CircularProgress.tsx +42 -42
  30. package/src/components/ColorAdjustView.d.ts +12 -12
  31. package/src/components/ColorAdjustView.tsx +64 -64
  32. package/src/components/ColorExtractor.d.ts +73 -73
  33. package/src/components/ColorExtractor.tsx +374 -374
  34. package/src/components/ColorTempAdjustView.d.ts +13 -13
  35. package/src/components/ColorTempAdjustView.tsx +57 -57
  36. package/src/components/ColorsLine.d.ts +7 -7
  37. package/src/components/ColorsLine.tsx +47 -47
  38. package/src/components/CustomListDialog.d.ts +15 -15
  39. package/src/components/CustomListDialog.tsx +66 -66
  40. package/src/components/DeleteButton.d.ts +10 -10
  41. package/src/components/DeleteButton.tsx +40 -40
  42. package/src/components/Dialog.d.ts +10 -10
  43. package/src/components/Dialog.tsx +38 -38
  44. package/src/components/DrawToolView.d.ts +46 -46
  45. package/src/components/DrawToolView.tsx +262 -262
  46. package/src/components/FanAdjustView.d.ts +23 -23
  47. package/src/components/FanAdjustView.tsx +141 -141
  48. package/src/components/InfoText.d.ts +11 -11
  49. package/src/components/InfoText.tsx +45 -45
  50. package/src/components/LampAdjustView.d.ts +10 -10
  51. package/src/components/LampAdjustView.tsx +75 -75
  52. package/src/components/LampAdjustView2.d.ts +24 -24
  53. package/src/components/LampAdjustView2.tsx +104 -104
  54. package/src/components/LinearGradientLine.d.ts +9 -9
  55. package/src/components/LinearGradientLine.tsx +63 -63
  56. package/src/components/LoadingView.tsx +39 -39
  57. package/src/components/MoodColorsLine.d.ts +9 -9
  58. package/src/components/MoodColorsLine.tsx +38 -38
  59. package/src/components/Page.d.ts +21 -21
  60. package/src/components/Page.tsx +104 -104
  61. package/src/components/Popup.d.ts +7 -7
  62. package/src/components/Popup.tsx +71 -71
  63. package/src/components/Segmented.d.ts +14 -14
  64. package/src/components/Segmented.tsx +76 -76
  65. package/src/components/ShowSelect.d.ts +1 -1
  66. package/src/components/ShowSelect.tsx +158 -158
  67. package/src/components/SocketItem.d.ts +13 -13
  68. package/src/components/SocketItem.tsx +87 -87
  69. package/src/components/Spacer.d.ts +7 -7
  70. package/src/components/Spacer.tsx +13 -13
  71. package/src/components/Stepper.d.ts +19 -19
  72. package/src/components/Stepper.tsx +130 -130
  73. package/src/components/StripAdjustView.d.ts +16 -16
  74. package/src/components/StripAdjustView.tsx +129 -129
  75. package/src/components/StripLightView.d.ts +14 -14
  76. package/src/components/StripLightView.tsx +24 -24
  77. package/src/components/Summary.tsx +116 -116
  78. package/src/components/Tag.d.ts +8 -8
  79. package/src/components/Tag.tsx +56 -56
  80. package/src/components/TextButton.d.ts +9 -9
  81. package/src/components/TextButton.tsx +31 -31
  82. package/src/components/TextField.d.ts +9 -9
  83. package/src/components/TextField.tsx +92 -92
  84. package/src/components/TextFieldStyleButton.d.ts +8 -8
  85. package/src/components/TextFieldStyleButton.tsx +85 -85
  86. package/src/components/UATabTitle.d.ts +6 -6
  87. package/src/components/UATabTitle.tsx +31 -31
  88. package/src/components/UATabs.d.ts +12 -12
  89. package/src/components/UATabs.tsx +77 -77
  90. package/src/components/connect.d.ts +10 -10
  91. package/src/components/connect.tsx +20 -20
  92. package/src/components/ldvColorBrightness.d.ts +1 -1
  93. package/src/components/ldvColorBrightness.tsx +18 -18
  94. package/src/components/ldvColorSlider.d.ts +14 -14
  95. package/src/components/ldvColorSlider.tsx +131 -131
  96. package/src/components/ldvItemView.d.ts +12 -12
  97. package/src/components/ldvItemView.tsx +43 -43
  98. package/src/components/ldvPickerView.d.ts +13 -13
  99. package/src/components/ldvPickerView.tsx +97 -97
  100. package/src/components/ldvPresetView.d.ts +2 -2
  101. package/src/components/ldvPresetView.tsx +86 -86
  102. package/src/components/ldvSaturation.d.ts +2 -2
  103. package/src/components/ldvSaturation.tsx +22 -22
  104. package/src/components/ldvSlider.d.ts +15 -15
  105. package/src/components/ldvSlider.tsx +103 -103
  106. package/src/components/ldvSwitch.d.ts +10 -10
  107. package/src/components/ldvSwitch.tsx +52 -52
  108. package/src/components/ldvTemperatureSlider.d.ts +13 -13
  109. package/src/components/ldvTemperatureSlider.tsx +139 -139
  110. package/src/components/ldvTopBar.d.ts +10 -10
  111. package/src/components/ldvTopBar.tsx +76 -76
  112. package/src/components/ldvTopName.d.ts +9 -9
  113. package/src/components/ldvTopName.tsx +63 -63
  114. package/src/components/segmentControl.d.ts +1 -1
  115. package/src/components/segmentControl.tsx +65 -65
  116. package/src/components/weekSelect.d.ts +7 -7
  117. package/src/components/weekSelect.tsx +98 -98
  118. package/src/composeLayout.d.ts +30 -30
  119. package/src/composeLayout.tsx +261 -261
  120. package/src/config/dark-theme.ts +61 -61
  121. package/src/config/light-theme.ts +61 -61
  122. package/src/hooks/Hooks.d.ts +2 -2
  123. package/src/hooks/Hooks.ts +8 -8
  124. package/src/i18n/index.d.ts +16 -16
  125. package/src/i18n/index.ts +37 -37
  126. package/src/i18n/strings.d.ts +15953 -15953
  127. package/src/i18n/strings.ts +23781 -23723
  128. package/src/main.tsx +9 -9
  129. package/src/models/GlobalParams.d.ts +14 -14
  130. package/src/models/GlobalParams.ts +14 -14
  131. package/src/models/TuyaApi.d.ts +29 -29
  132. package/src/models/TuyaApi.ts +92 -92
  133. package/src/models/combine.d.ts +26 -26
  134. package/src/models/combine.ts +17 -17
  135. package/src/models/configureStore.d.ts +9 -9
  136. package/src/models/configureStore.ts +33 -33
  137. package/src/models/index.d.ts +31 -31
  138. package/src/models/index.ts +22 -22
  139. package/src/models/modules/NativePropsSlice.d.ts +61 -61
  140. package/src/models/modules/NativePropsSlice.tsx +467 -467
  141. package/src/models/modules/Result.d.ts +14 -14
  142. package/src/models/modules/Result.ts +15 -15
  143. package/src/models/modules/common.d.ts +44 -44
  144. package/src/models/modules/common.ts +161 -161
  145. package/src/res/index.d.ts +70 -70
  146. package/src/res/index.ts +73 -73
  147. package/src/utils/ColorParser.d.ts +66 -66
  148. package/src/utils/ColorParser.ts +189 -189
  149. package/src/utils/ColorUtils.d.ts +71 -71
  150. package/src/utils/ColorUtils.tsx +448 -448
  151. package/src/utils/Support.d.ts +13 -13
  152. package/src/utils/Support.ts +108 -108
  153. package/src/utils/TypeUtils.d.ts +3 -3
  154. package/src/utils/cctUtils.d.ts +1 -1
  155. package/src/utils/cctUtils.ts +110 -110
  156. package/src/utils/common.d.ts +35 -35
  157. package/src/utils/common.ts +379 -379
  158. package/src/utils/index.d.ts +26 -26
  159. package/src/utils/index.ts +191 -191
  160. package/src/utils/interface.d.ts +6 -6
  161. package/src/utils/interface.ts +50 -50
  162. package/src/utils/loopsCompare.d.ts +1 -1
  163. package/src/utils/loopsCompare.ts +62 -62
  164. package/tsconfig.json +50 -50
  165. package/update-localazy.py +52 -52
package/src/api/native.ts CHANGED
@@ -1,423 +1,423 @@
1
- import {NativeModules, Platform} from 'react-native'
2
- import {NativeResult, Result} from '../models/modules/Result'
3
- import { TYSdk } from 'tuya-panel-kit'
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, isGroup: boolean) => void
12
- toRoutinesPage: (params: {backTitle:string, deviceId:string}) => void
13
- putJson: (deviceId: string, featureType: string, json: string, callback: (res: NativeResult<any>) => void) => void
14
- getJson: (deviceId: string, featureType: string, callback: (res: NativeResult<string>) => void) => void
15
- getInitiativeQueryDpsInfoWithDpsArray: (dpIds: string, deviceId: string, callback: (res: NativeResult<string>) => void) => void
16
- openDownloadFile: (filePath: string) => void
17
- formatNumber: (num: number, fixed: number, isCN: boolean) => string
18
- getTimeZone: () => string
19
- groupControl: (tyGroupId: number, dps: string, config: string) => Promise<NativeResult<any>>
20
- groupControlToTuya: (tyGroupId: number, dps: string) => Promise<NativeResult<any>>
21
- groupControlToEzviz: (tyGroupId: number, config: string) => Promise<NativeResult<any>>
22
- getFeature: (deviceId: string, featureId: string, callback: (res: NativeResult<string>) => void) => void
23
- putFeature: (deviceId: string, featureId: string, value: any, callback: (res: NativeResult<string>) => void) => void
24
- getGroupDevices: (tyGroupId: number) => Promise<NativeResult<string>>
25
- getSystemTimeFormat: () => Promise<number>
26
- getMicrophoneAccess: (res:any) => Promise<Result<any>>
27
- }
28
-
29
- export enum UADeviceCategory {
30
- ThirdParty = 'ThirdParty',
31
- General = 'General',
32
- LightSource = 'LightSource',
33
- CeilingLight = 'CeilingLight',
34
- CeilingFan = 'CeilingFan',
35
- SterilizedCeilingFan = 'SterilizedCeilingFan',
36
- PIRLight = 'PIRLight',
37
- SolarLight = 'SolarLight',
38
- StringLights = 'StringLights',
39
- StripLights = 'StripLights',
40
- PowerStrip = 'PowerStrip',
41
- NightlightPlug = 'NightlightPlug',
42
- WifiPlug = 'WifiPlug',
43
- ChildLockPlug = 'ChildLockPlug',
44
- RepeaterSocket = 'RepeaterSocket',
45
- ContactSensor = 'ContactSensor',
46
- MotionDetector = 'MotionDetector',
47
- PIRCamera = 'PIRCamera',
48
- LinkageCamera = 'LinkageCamera',
49
- SmartCamera = 'SmartCamera',
50
- MatterLight = 'MatterLight',
51
- MeshLight = 'MeshLight',
52
- MeshSwitch = 'MeshSwitch',
53
- }
54
-
55
- export interface DeviceInfo {
56
- deviceId: string
57
- deviceName: string
58
- deviceIcon: string
59
- tyPid: string
60
- deviceCategory: UADeviceCategory
61
- roomName: string
62
- status: number
63
- }
64
-
65
- const devicePanel: LDVDevicePanelManager = NativeModules.LDVDevicePanelManager
66
- const logManager = NativeModules.RNLogManager
67
-
68
- const back = () => {
69
- devicePanel.back()
70
- }
71
-
72
- const log = (str: string) => {
73
- logManager.log(str)
74
- }
75
-
76
- const showObj = (objc) => {
77
- if (!!objc) {
78
- logManager.objc(objc)
79
- }
80
- }
81
-
82
-
83
- const control = (devId, dps, callback) => {
84
- devicePanel.control({devId, dps: JSON.stringify(dps)}, res => {
85
- callback && callback(res)
86
- })
87
- }
88
-
89
- // timer
90
- const TASK = 'LDV_TY'
91
-
92
- const timerList = devId => {
93
- return new Promise((resolve, _reject) => {
94
- const params = {devId, task: TASK, action: 'list', bizType: 0}
95
- devicePanel.setTimer(params, res => {
96
- resolve(res)
97
- })
98
- })
99
- }
100
-
101
- const addTimer = (devId, value, callback: any = undefined) => {
102
- const params = {devId, task: TASK, action: 'add', value, bizType: 0}
103
- devicePanel.setTimer(params, res => {
104
- callback && callback(res)
105
- })
106
- }
107
-
108
- const editTimer = (devId, value, callback: any = undefined) => {
109
- const params = {devId, task: TASK, action: 'update', value, bizType: 0}
110
- devicePanel.setTimer(params, res => {
111
- callback && callback(res)
112
- })
113
- }
114
-
115
- const deleteTimer = (devId, value, callback: any = undefined) => {
116
- const params = {devId, task: TASK, action: 'delete', value, bizType: 0}
117
- devicePanel.setTimer(params, res => {
118
- callback && callback(res)
119
- })
120
- }
121
-
122
- /**
123
- * 获取所有Timer,不区分TASK
124
- * @param devId 涂鸦 设备 ID 或群组 ID
125
- * @param type 0:设备,1:群组
126
- * @param callback
127
- */
128
- function getAllTaskTimer(devId: string, type: number = 0, callback: ((res: NativeResult<string>) => void)) {
129
- devicePanel.getAllTaskTimer(devId, type, callback)
130
- }
131
-
132
- const setDp = <T>(deviceId: string, key: string, value: any) => {
133
- return new Promise<NativeResult<T>>((resolve, _reject) => {
134
- control(deviceId, {[key]: value}, res => {
135
- resolve(res)
136
- })
137
- })
138
- }
139
-
140
- const setDps = <T>(deviceId: string, dps: any) => {
141
- return new Promise<NativeResult<T>>((resolve, _reject) => {
142
- control(deviceId, dps, res => {
143
- resolve(res)
144
- })
145
- })
146
- }
147
-
148
- type GetFeatureResultType = (deviceId: string, featureId: string) => Promise<NativeResult<any>>;
149
- type SetFeatureResultType = (
150
- deviceId: string,
151
- featureId: string,
152
- value: any,
153
- ) => Promise<NativeResult<any>>;
154
-
155
- export const getFeature: GetFeatureResultType = (deviceId: string, featureId: string) => {
156
- return new Promise((resolve, _reject) => {
157
- devicePanel.getFeature(deviceId, featureId, res => {
158
- const result: NativeResult<any> = {
159
- ...res,
160
- data: !!res.data ? JSON.parse(res.data).value : null,
161
- }
162
- resolve(result)
163
- })
164
- })
165
- }
166
-
167
- export const putFeature: SetFeatureResultType = (
168
- deviceId: string,
169
- featureId: string,
170
- value: any,
171
- ) => {
172
- return new Promise((resolve, _reject) => {
173
- devicePanel.putFeature(deviceId, featureId, JSON.stringify({value}), res => {
174
- resolve(res)
175
- })
176
- })
177
- }
178
-
179
- type DeleteDeviceResultType = (deviceId: string, isReset: boolean) => Promise<NativeResult<any>>
180
-
181
- const deleteDevice: DeleteDeviceResultType = (deviceId: string, isReset: boolean) => {
182
- return new Promise((resolve, _reject) => {
183
- devicePanel.deleteDevice(deviceId, isReset, res => {
184
- resolve(res)
185
- })
186
- })
187
- }
188
-
189
- type RenameResultType = (deviceId: string, name: string) => Promise<NativeResult<any>>
190
-
191
- const rename: RenameResultType = (deviceId: string, name: string) => {
192
- return new Promise((resolve, _reject) => {
193
- devicePanel.rename(deviceId, name, res => {
194
- resolve(res)
195
- })
196
- })
197
- }
198
-
199
- function toDeviceSettingsPage(tuyaDeviceId: string, isGroup: boolean = false) {
200
- devicePanel.toDeviceSettingsPage(tuyaDeviceId, isGroup)
201
- }
202
-
203
- function toRoutinesPage(params: {backTitle:string, deviceId:string}) {
204
- devicePanel.toRoutinesPage(params)
205
- }
206
-
207
- export class NativeApi {
208
- static back(): void {
209
- back()
210
- }
211
-
212
- static log(msg: string): void {
213
- log(msg)
214
- }
215
-
216
- static logObj(msg: any): void {
217
- this.log(JSON.stringify(msg))
218
- }
219
-
220
- static showObj(obj: any): void {
221
- showObj(obj)
222
- }
223
-
224
- static getAllTaskTimer(devId: string, type: number = 0): Promise<Result<any>> {
225
- return new Promise<Result<any>>((resolve, _reject) => {
226
- getAllTaskTimer(devId, type, res => {
227
- const allList = JSON.parse(res.data || '[]')
228
- .map(item => item.mTimerList)
229
- .flat();
230
- resolve({
231
- success: res.result,
232
- data: res.result ? allList : undefined,
233
- msg: res.msg,
234
- })
235
- })
236
- })
237
- }
238
-
239
- static timerList(deviceId: string): Promise<any> {
240
- return timerList(deviceId)
241
- }
242
-
243
- static addTimer(deviceId: string, value: any, callback?: (res: any) => void): void {
244
- addTimer(deviceId, value, callback)
245
- }
246
-
247
- static editTimer(deviceId: string, value: any, callback?: (res: any) => void): void {
248
- editTimer(deviceId, value, callback)
249
- }
250
-
251
- static deleteTimer(deviceId: string, value: any, callback?: (res: any) => void): void {
252
- deleteTimer(deviceId, value, callback)
253
- }
254
-
255
- static manageTimer(devId: string, timer: any, mode: 'add' | 'delete' | 'update'){
256
- return new Promise<Result<any>>((resolve) =>{
257
- const params = {devId, task: TASK, action: mode, value: timer, bizType: 0}
258
- devicePanel.setTimer(params, res => {
259
- resolve({
260
- success: res.result,
261
- data: res.data,
262
- msg: res.msg
263
- })
264
- })
265
- })
266
- }
267
-
268
- static setDp<T>(deviceId: string, key: string, value: any): Promise<NativeResult<T>> {
269
- return setDp<T>(deviceId, key, value)
270
- }
271
-
272
- static setDps<T>(deviceId: string, dps: any): Promise<NativeResult<T>> {
273
- return setDps<T>(deviceId, dps)
274
- }
275
-
276
- static deleteDevice(deviceId: string, isReset: boolean): Promise<NativeResult<any>> {
277
- return deleteDevice(deviceId, isReset)
278
- }
279
-
280
- static renameDevice(deviceId: string, name: string): Promise<NativeResult<any>> {
281
- return rename(deviceId, name)
282
- }
283
-
284
- static toDeviceSettingsPage(deviceId: string, isGroup: boolean = false): void {
285
- toDeviceSettingsPage(deviceId, isGroup)
286
- }
287
-
288
- static toRoutinesPage(params: {backTitle:string, deviceId:string}): void{
289
- toRoutinesPage(params)
290
- }
291
-
292
- static putJson(deviceId: string, featureType: string, json: string): Promise<Result<any>> {
293
- return new Promise<Result<any>>(resolve => {
294
- devicePanel.putJson(deviceId, featureType, json, nativeRes => {
295
- resolve({
296
- success: nativeRes.result,
297
- data: nativeRes.data,
298
- msg: nativeRes.msg,
299
- })
300
- })
301
- })
302
- }
303
-
304
- static getJson(deviceId: string, featureType: string): Promise<Result<any>> {
305
- return new Promise<Result<any>>(resolve => {
306
- devicePanel.getJson(deviceId, featureType, nativeRes => {
307
- resolve({
308
- success: nativeRes.result,
309
- data: nativeRes.data,
310
- msg: nativeRes.msg,
311
- })
312
- })
313
- })
314
- }
315
-
316
- static async groupControl(tyGroupId: number, dps: string, config: string): Promise<Result<any>> {
317
- const nativeResult = await devicePanel.groupControl(tyGroupId, dps, config)
318
- return {
319
- success: nativeResult.result,
320
- msg: nativeResult.msg,
321
- data: nativeResult.data,
322
- }
323
- }
324
-
325
- static async getGroupDevices(tyGroupId: number): Promise<Result<DeviceInfo[]>> {
326
- const nativeResult = await devicePanel.getGroupDevices(tyGroupId)
327
- return {
328
- success: nativeResult.result,
329
- msg: nativeResult.msg,
330
- data: nativeResult.data && JSON.parse(nativeResult.data),
331
- }
332
- }
333
-
334
- static async putGroupTYDps(tyGroupId: number, dps: string){
335
- const nativeResult = await devicePanel.groupControlToTuya(tyGroupId, dps)
336
- return {
337
- success: nativeResult.result,
338
- msg: nativeResult.msg,
339
- data: nativeResult.data,
340
- }
341
- }
342
-
343
- static async putGroupEzvizConfig(tyGroupId: number, config: string){
344
- const nativeResult = await devicePanel.groupControlToEzviz(tyGroupId, config)
345
- return {
346
- success: nativeResult.result,
347
- msg: nativeResult.msg,
348
- data: nativeResult.data,
349
- }
350
- }
351
-
352
- }
353
-
354
- // 打开下载文件
355
- export const openDownloadFile = (filePath: string) => {
356
- return new Promise((_reject) => {
357
- devicePanel.openDownloadFile(filePath)
358
- })
359
- }
360
-
361
- export const queryDpIds = (dpIds: string, deviceId: string) => {
362
- return new Promise((resolve, _reject) => {
363
- devicePanel.getInitiativeQueryDpsInfoWithDpsArray(dpIds, deviceId, res => {
364
- resolve(res)
365
- })
366
- })
367
- }
368
-
369
- export const formatNumber: (num: number, fixed: number, shoGroup?: boolean) => string = (num, fixed, shoGroup: boolean = true) => {
370
- const res = devicePanel.formatNumber(num, fixed, shoGroup)
371
- log(`formatNumber: num=${num}, fixed=${fixed}, res=${res}`)
372
- return res
373
- }
374
-
375
- export const getTimeZone = async (): Promise<string> => {
376
- return new Promise((resolve) => {
377
- const timeZone = Platform.OS === 'android' ? devicePanel.getTimeZone() || 'Europe/Berlin' : Intl.DateTimeFormat().resolvedOptions().timeZone
378
- resolve(timeZone)
379
- })
380
- }
381
-
382
- // 获取手机系统设置的12小时制还是24小时制
383
- export const getSystemTimeFormat = async (): Promise<number> => {
384
- try {
385
- return await devicePanel.getSystemTimeFormat()
386
- } catch (_) {
387
- return 24
388
- }
389
- }
390
-
391
- export const getMicrophoneAccess: () => Promise<boolean> = () => {
392
- return new Promise((resolve, _reject) => {
393
- devicePanel.getMicrophoneAccess(res => {
394
- const haveAuthority = (typeof res?.data === 'string') ? !!res?.data && JSON.parse(res?.data)?.haveAuthority : res?.data?.haveAuthority
395
- if(!res.result || (res.result && haveAuthority !== 'granted')){
396
- resolve(false)
397
- }
398
- resolve(true)
399
- })
400
- })
401
- }
402
-
403
- export const getTuyaCloudData = (devId: string): Promise<Record<string, any>> => {
404
- return new Promise((resolve, reject) => {
405
- TYSdk.native.apiRNRequest(
406
- {
407
- a: 's.m.dev.property.get',
408
- postData: {
409
- devId: devId,
410
- bizType: 0,
411
- },
412
- v: '2.0'
413
- },
414
- (d: string) => {
415
- const data = typeof d === 'string' ? JSON.parse(d) : d;
416
- resolve(data);
417
- },
418
- (err: string) => {
419
- reject(err);
420
- }
421
- )
422
- })
423
- }
1
+ import {NativeModules, Platform} from 'react-native'
2
+ import {NativeResult, Result} from '../models/modules/Result'
3
+ import { TYSdk } from 'tuya-panel-kit'
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, isGroup: boolean) => void
12
+ toRoutinesPage: (params: {backTitle:string, deviceId:string}) => void
13
+ putJson: (deviceId: string, featureType: string, json: string, callback: (res: NativeResult<any>) => void) => void
14
+ getJson: (deviceId: string, featureType: string, callback: (res: NativeResult<string>) => void) => void
15
+ getInitiativeQueryDpsInfoWithDpsArray: (dpIds: string, deviceId: string, callback: (res: NativeResult<string>) => void) => void
16
+ openDownloadFile: (filePath: string) => void
17
+ formatNumber: (num: number, fixed: number, isCN: boolean) => string
18
+ getTimeZone: () => string
19
+ groupControl: (tyGroupId: number, dps: string, config: string) => Promise<NativeResult<any>>
20
+ groupControlToTuya: (tyGroupId: number, dps: string) => Promise<NativeResult<any>>
21
+ groupControlToEzviz: (tyGroupId: number, config: string) => Promise<NativeResult<any>>
22
+ getFeature: (deviceId: string, featureId: string, callback: (res: NativeResult<string>) => void) => void
23
+ putFeature: (deviceId: string, featureId: string, value: any, callback: (res: NativeResult<string>) => void) => void
24
+ getGroupDevices: (tyGroupId: number) => Promise<NativeResult<string>>
25
+ getSystemTimeFormat: () => Promise<number>
26
+ getMicrophoneAccess: (res:any) => Promise<Result<any>>
27
+ }
28
+
29
+ export enum UADeviceCategory {
30
+ ThirdParty = 'ThirdParty',
31
+ General = 'General',
32
+ LightSource = 'LightSource',
33
+ CeilingLight = 'CeilingLight',
34
+ CeilingFan = 'CeilingFan',
35
+ SterilizedCeilingFan = 'SterilizedCeilingFan',
36
+ PIRLight = 'PIRLight',
37
+ SolarLight = 'SolarLight',
38
+ StringLights = 'StringLights',
39
+ StripLights = 'StripLights',
40
+ PowerStrip = 'PowerStrip',
41
+ NightlightPlug = 'NightlightPlug',
42
+ WifiPlug = 'WifiPlug',
43
+ ChildLockPlug = 'ChildLockPlug',
44
+ RepeaterSocket = 'RepeaterSocket',
45
+ ContactSensor = 'ContactSensor',
46
+ MotionDetector = 'MotionDetector',
47
+ PIRCamera = 'PIRCamera',
48
+ LinkageCamera = 'LinkageCamera',
49
+ SmartCamera = 'SmartCamera',
50
+ MatterLight = 'MatterLight',
51
+ MeshLight = 'MeshLight',
52
+ MeshSwitch = 'MeshSwitch',
53
+ }
54
+
55
+ export interface DeviceInfo {
56
+ deviceId: string
57
+ deviceName: string
58
+ deviceIcon: string
59
+ tyPid: string
60
+ deviceCategory: UADeviceCategory
61
+ roomName: string
62
+ status: number
63
+ }
64
+
65
+ const devicePanel: LDVDevicePanelManager = NativeModules.LDVDevicePanelManager
66
+ const logManager = NativeModules.RNLogManager
67
+
68
+ const back = () => {
69
+ devicePanel.back()
70
+ }
71
+
72
+ const log = (str: string) => {
73
+ logManager.log(str)
74
+ }
75
+
76
+ const showObj = (objc) => {
77
+ if (!!objc) {
78
+ logManager.objc(objc)
79
+ }
80
+ }
81
+
82
+
83
+ const control = (devId, dps, callback) => {
84
+ devicePanel.control({devId, dps: JSON.stringify(dps)}, res => {
85
+ callback && callback(res)
86
+ })
87
+ }
88
+
89
+ // timer
90
+ const TASK = 'LDV_TY'
91
+
92
+ const timerList = devId => {
93
+ return new Promise((resolve, _reject) => {
94
+ const params = {devId, task: TASK, action: 'list', bizType: 0}
95
+ devicePanel.setTimer(params, res => {
96
+ resolve(res)
97
+ })
98
+ })
99
+ }
100
+
101
+ const addTimer = (devId, value, callback: any = undefined) => {
102
+ const params = {devId, task: TASK, action: 'add', value, bizType: 0}
103
+ devicePanel.setTimer(params, res => {
104
+ callback && callback(res)
105
+ })
106
+ }
107
+
108
+ const editTimer = (devId, value, callback: any = undefined) => {
109
+ const params = {devId, task: TASK, action: 'update', value, bizType: 0}
110
+ devicePanel.setTimer(params, res => {
111
+ callback && callback(res)
112
+ })
113
+ }
114
+
115
+ const deleteTimer = (devId, value, callback: any = undefined) => {
116
+ const params = {devId, task: TASK, action: 'delete', value, bizType: 0}
117
+ devicePanel.setTimer(params, res => {
118
+ callback && callback(res)
119
+ })
120
+ }
121
+
122
+ /**
123
+ * 获取所有Timer,不区分TASK
124
+ * @param devId 涂鸦 设备 ID 或群组 ID
125
+ * @param type 0:设备,1:群组
126
+ * @param callback
127
+ */
128
+ function getAllTaskTimer(devId: string, type: number = 0, callback: ((res: NativeResult<string>) => void)) {
129
+ devicePanel.getAllTaskTimer(devId, type, callback)
130
+ }
131
+
132
+ const setDp = <T>(deviceId: string, key: string, value: any) => {
133
+ return new Promise<NativeResult<T>>((resolve, _reject) => {
134
+ control(deviceId, {[key]: value}, res => {
135
+ resolve(res)
136
+ })
137
+ })
138
+ }
139
+
140
+ const setDps = <T>(deviceId: string, dps: any) => {
141
+ return new Promise<NativeResult<T>>((resolve, _reject) => {
142
+ control(deviceId, dps, res => {
143
+ resolve(res)
144
+ })
145
+ })
146
+ }
147
+
148
+ type GetFeatureResultType = (deviceId: string, featureId: string) => Promise<NativeResult<any>>;
149
+ type SetFeatureResultType = (
150
+ deviceId: string,
151
+ featureId: string,
152
+ value: any,
153
+ ) => Promise<NativeResult<any>>;
154
+
155
+ export const getFeature: GetFeatureResultType = (deviceId: string, featureId: string) => {
156
+ return new Promise((resolve, _reject) => {
157
+ devicePanel.getFeature(deviceId, featureId, res => {
158
+ const result: NativeResult<any> = {
159
+ ...res,
160
+ data: !!res.data ? JSON.parse(res.data).value : null,
161
+ }
162
+ resolve(result)
163
+ })
164
+ })
165
+ }
166
+
167
+ export const putFeature: SetFeatureResultType = (
168
+ deviceId: string,
169
+ featureId: string,
170
+ value: any,
171
+ ) => {
172
+ return new Promise((resolve, _reject) => {
173
+ devicePanel.putFeature(deviceId, featureId, JSON.stringify({value}), res => {
174
+ resolve(res)
175
+ })
176
+ })
177
+ }
178
+
179
+ type DeleteDeviceResultType = (deviceId: string, isReset: boolean) => Promise<NativeResult<any>>
180
+
181
+ const deleteDevice: DeleteDeviceResultType = (deviceId: string, isReset: boolean) => {
182
+ return new Promise((resolve, _reject) => {
183
+ devicePanel.deleteDevice(deviceId, isReset, res => {
184
+ resolve(res)
185
+ })
186
+ })
187
+ }
188
+
189
+ type RenameResultType = (deviceId: string, name: string) => Promise<NativeResult<any>>
190
+
191
+ const rename: RenameResultType = (deviceId: string, name: string) => {
192
+ return new Promise((resolve, _reject) => {
193
+ devicePanel.rename(deviceId, name, res => {
194
+ resolve(res)
195
+ })
196
+ })
197
+ }
198
+
199
+ function toDeviceSettingsPage(tuyaDeviceId: string, isGroup: boolean = false) {
200
+ devicePanel.toDeviceSettingsPage(tuyaDeviceId, isGroup)
201
+ }
202
+
203
+ function toRoutinesPage(params: {backTitle:string, deviceId:string}) {
204
+ devicePanel.toRoutinesPage(params)
205
+ }
206
+
207
+ export class NativeApi {
208
+ static back(): void {
209
+ back()
210
+ }
211
+
212
+ static log(msg: string): void {
213
+ log(msg)
214
+ }
215
+
216
+ static logObj(msg: any): void {
217
+ this.log(JSON.stringify(msg))
218
+ }
219
+
220
+ static showObj(obj: any): void {
221
+ showObj(obj)
222
+ }
223
+
224
+ static getAllTaskTimer(devId: string, type: number = 0): Promise<Result<any>> {
225
+ return new Promise<Result<any>>((resolve, _reject) => {
226
+ getAllTaskTimer(devId, type, res => {
227
+ const allList = JSON.parse(res.data || '[]')
228
+ .map(item => item.mTimerList)
229
+ .flat();
230
+ resolve({
231
+ success: res.result,
232
+ data: res.result ? allList : undefined,
233
+ msg: res.msg,
234
+ })
235
+ })
236
+ })
237
+ }
238
+
239
+ static timerList(deviceId: string): Promise<any> {
240
+ return timerList(deviceId)
241
+ }
242
+
243
+ static addTimer(deviceId: string, value: any, callback?: (res: any) => void): void {
244
+ addTimer(deviceId, value, callback)
245
+ }
246
+
247
+ static editTimer(deviceId: string, value: any, callback?: (res: any) => void): void {
248
+ editTimer(deviceId, value, callback)
249
+ }
250
+
251
+ static deleteTimer(deviceId: string, value: any, callback?: (res: any) => void): void {
252
+ deleteTimer(deviceId, value, callback)
253
+ }
254
+
255
+ static manageTimer(devId: string, timer: any, mode: 'add' | 'delete' | 'update'){
256
+ return new Promise<Result<any>>((resolve) =>{
257
+ const params = {devId, task: TASK, action: mode, value: timer, bizType: 0}
258
+ devicePanel.setTimer(params, res => {
259
+ resolve({
260
+ success: res.result,
261
+ data: res.data,
262
+ msg: res.msg
263
+ })
264
+ })
265
+ })
266
+ }
267
+
268
+ static setDp<T>(deviceId: string, key: string, value: any): Promise<NativeResult<T>> {
269
+ return setDp<T>(deviceId, key, value)
270
+ }
271
+
272
+ static setDps<T>(deviceId: string, dps: any): Promise<NativeResult<T>> {
273
+ return setDps<T>(deviceId, dps)
274
+ }
275
+
276
+ static deleteDevice(deviceId: string, isReset: boolean): Promise<NativeResult<any>> {
277
+ return deleteDevice(deviceId, isReset)
278
+ }
279
+
280
+ static renameDevice(deviceId: string, name: string): Promise<NativeResult<any>> {
281
+ return rename(deviceId, name)
282
+ }
283
+
284
+ static toDeviceSettingsPage(deviceId: string, isGroup: boolean = false): void {
285
+ toDeviceSettingsPage(deviceId, isGroup)
286
+ }
287
+
288
+ static toRoutinesPage(params: {backTitle:string, deviceId:string}): void{
289
+ toRoutinesPage(params)
290
+ }
291
+
292
+ static putJson(deviceId: string, featureType: string, json: string): Promise<Result<any>> {
293
+ return new Promise<Result<any>>(resolve => {
294
+ devicePanel.putJson(deviceId, featureType, json, nativeRes => {
295
+ resolve({
296
+ success: nativeRes.result,
297
+ data: nativeRes.data,
298
+ msg: nativeRes.msg,
299
+ })
300
+ })
301
+ })
302
+ }
303
+
304
+ static getJson(deviceId: string, featureType: string): Promise<Result<any>> {
305
+ return new Promise<Result<any>>(resolve => {
306
+ devicePanel.getJson(deviceId, featureType, nativeRes => {
307
+ resolve({
308
+ success: nativeRes.result,
309
+ data: nativeRes.data,
310
+ msg: nativeRes.msg,
311
+ })
312
+ })
313
+ })
314
+ }
315
+
316
+ static async groupControl(tyGroupId: number, dps: string, config: string): Promise<Result<any>> {
317
+ const nativeResult = await devicePanel.groupControl(tyGroupId, dps, config)
318
+ return {
319
+ success: nativeResult.result,
320
+ msg: nativeResult.msg,
321
+ data: nativeResult.data,
322
+ }
323
+ }
324
+
325
+ static async getGroupDevices(tyGroupId: number): Promise<Result<DeviceInfo[]>> {
326
+ const nativeResult = await devicePanel.getGroupDevices(tyGroupId)
327
+ return {
328
+ success: nativeResult.result,
329
+ msg: nativeResult.msg,
330
+ data: nativeResult.data && JSON.parse(nativeResult.data),
331
+ }
332
+ }
333
+
334
+ static async putGroupTYDps(tyGroupId: number, dps: string){
335
+ const nativeResult = await devicePanel.groupControlToTuya(tyGroupId, dps)
336
+ return {
337
+ success: nativeResult.result,
338
+ msg: nativeResult.msg,
339
+ data: nativeResult.data,
340
+ }
341
+ }
342
+
343
+ static async putGroupEzvizConfig(tyGroupId: number, config: string){
344
+ const nativeResult = await devicePanel.groupControlToEzviz(tyGroupId, config)
345
+ return {
346
+ success: nativeResult.result,
347
+ msg: nativeResult.msg,
348
+ data: nativeResult.data,
349
+ }
350
+ }
351
+
352
+ }
353
+
354
+ // 打开下载文件
355
+ export const openDownloadFile = (filePath: string) => {
356
+ return new Promise((_reject) => {
357
+ devicePanel.openDownloadFile(filePath)
358
+ })
359
+ }
360
+
361
+ export const queryDpIds = (dpIds: string, deviceId: string) => {
362
+ return new Promise((resolve, _reject) => {
363
+ devicePanel.getInitiativeQueryDpsInfoWithDpsArray(dpIds, deviceId, res => {
364
+ resolve(res)
365
+ })
366
+ })
367
+ }
368
+
369
+ export const formatNumber: (num: number, fixed: number, shoGroup?: boolean) => string = (num, fixed, shoGroup: boolean = true) => {
370
+ const res = devicePanel.formatNumber(num, fixed, shoGroup)
371
+ log(`formatNumber: num=${num}, fixed=${fixed}, res=${res}`)
372
+ return res
373
+ }
374
+
375
+ export const getTimeZone = async (): Promise<string> => {
376
+ return new Promise((resolve) => {
377
+ const timeZone = Platform.OS === 'android' ? devicePanel.getTimeZone() || 'Europe/Berlin' : Intl.DateTimeFormat().resolvedOptions().timeZone
378
+ resolve(timeZone)
379
+ })
380
+ }
381
+
382
+ // 获取手机系统设置的12小时制还是24小时制
383
+ export const getSystemTimeFormat = async (): Promise<number> => {
384
+ try {
385
+ return await devicePanel.getSystemTimeFormat()
386
+ } catch (_) {
387
+ return 24
388
+ }
389
+ }
390
+
391
+ export const getMicrophoneAccess: () => Promise<boolean> = () => {
392
+ return new Promise((resolve, _reject) => {
393
+ devicePanel.getMicrophoneAccess(res => {
394
+ const haveAuthority = (typeof res?.data === 'string') ? !!res?.data && JSON.parse(res?.data)?.haveAuthority : res?.data?.haveAuthority
395
+ if(!res.result || (res.result && haveAuthority !== 'granted')){
396
+ resolve(false)
397
+ }
398
+ resolve(true)
399
+ })
400
+ })
401
+ }
402
+
403
+ export const getTuyaCloudData = (devId: string): Promise<Record<string, any>> => {
404
+ return new Promise((resolve, reject) => {
405
+ TYSdk.native.apiRNRequest(
406
+ {
407
+ a: 's.m.dev.property.get',
408
+ postData: {
409
+ devId: devId,
410
+ bizType: 0,
411
+ },
412
+ v: '2.0'
413
+ },
414
+ (d: string) => {
415
+ const data = typeof d === 'string' ? JSON.parse(d) : d;
416
+ resolve(data);
417
+ },
418
+ (err: string) => {
419
+ reject(err);
420
+ }
421
+ )
422
+ })
423
+ }