@ledvance/base 1.1.6 → 1.1.8
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
CHANGED
package/src/api/native.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ export declare class NativeApi {
|
|
|
16
16
|
static toDeviceSettingsPage(deviceId: string): void;
|
|
17
17
|
static putJson(deviceId: string, featureType: string, json: string): Promise<Result<any>>;
|
|
18
18
|
static getJson(deviceId: string, featureType: string): Promise<Result<string>>;
|
|
19
|
+
static groupControl(dps: string, config: string): Promise<Result<any>>;
|
|
19
20
|
}
|
|
20
21
|
export declare const openDownloadFile: (filePath: string) => Promise<unknown>;
|
|
21
22
|
export declare const queryDpIds: (dpIds: string, deviceId: string) => Promise<unknown>;
|
package/src/api/native.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import {NativeModules, Platform} from 'react-native'
|
|
2
|
+
import {NativeResult, Result} from '../models/modules/Result'
|
|
3
3
|
|
|
4
4
|
interface LDVDevicePanelManager {
|
|
5
5
|
back: () => void
|
|
@@ -15,7 +15,7 @@ interface LDVDevicePanelManager {
|
|
|
15
15
|
openDownloadFile: (filePath: string) => void
|
|
16
16
|
formatNumber: (num: number, fixed: number) => string
|
|
17
17
|
getTimeZone: () => string
|
|
18
|
-
|
|
18
|
+
groupControl: (dps: string, config: string) => Promise<NativeResult<any>>
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
const devicePanel: LDVDevicePanelManager = NativeModules.LDVDevicePanelManager
|
|
@@ -213,8 +213,16 @@ export class NativeApi {
|
|
|
213
213
|
})
|
|
214
214
|
})
|
|
215
215
|
}
|
|
216
|
-
}
|
|
217
216
|
|
|
217
|
+
static async groupControl(dps: string, config: string): Promise<Result<any>> {
|
|
218
|
+
const nativeResult = await devicePanel.groupControl(dps, config)
|
|
219
|
+
return {
|
|
220
|
+
success: nativeResult.result,
|
|
221
|
+
msg: nativeResult.msg,
|
|
222
|
+
data: nativeResult.data
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
218
226
|
|
|
219
227
|
// 打开下载文件
|
|
220
228
|
export const openDownloadFile = (filePath: string) => {
|
|
@@ -1,29 +1,75 @@
|
|
|
1
|
-
import { NativeEventEmitter, NativeModules
|
|
2
|
-
import {
|
|
1
|
+
import {EmitterSubscription, NativeEventEmitter, NativeModules} from 'react-native'
|
|
2
|
+
import {
|
|
3
|
+
DeviceInfo,
|
|
4
|
+
NativeProps,
|
|
5
|
+
setGroupNativeProps,
|
|
6
|
+
setNativeProps,
|
|
7
|
+
UAGroupInfo,
|
|
8
|
+
} from '../models/modules/NativePropsSlice'
|
|
3
9
|
import { actions } from '@models'
|
|
4
10
|
|
|
5
11
|
const nativeModule = NativeModules.LDVDeviceEventEmitter
|
|
6
12
|
const nativeEventEmitter = new NativeEventEmitter(nativeModule)
|
|
7
13
|
|
|
8
|
-
let
|
|
14
|
+
let deviceDPListener: EmitterSubscription|null
|
|
15
|
+
let groupFeatureListener: EmitterSubscription|null
|
|
16
|
+
|
|
17
|
+
interface GroupFeatureEvent {
|
|
18
|
+
tyGroupId: number
|
|
19
|
+
config: any
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
interface DeviceEvent {
|
|
23
|
+
devId: string
|
|
24
|
+
dps: any
|
|
25
|
+
name: string
|
|
26
|
+
pId: string
|
|
27
|
+
}
|
|
9
28
|
|
|
10
29
|
export const addListener = (store) => {
|
|
11
|
-
|
|
30
|
+
deviceDPListener = nativeEventEmitter.addListener('TYDataUpdate', (event: DeviceEvent) => {
|
|
12
31
|
// device info
|
|
13
|
-
if (
|
|
14
|
-
console.log('长链接刷新DP数据',
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
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))
|
|
18
44
|
}
|
|
19
45
|
// 兼容ios修改设备名称
|
|
20
|
-
if (!!
|
|
21
|
-
store.dispatch(actions.common.devInfoChange({ ...store.getState().devInfo, name:
|
|
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
|
+
|
|
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: event.config,
|
|
61
|
+
dps: {}
|
|
62
|
+
},
|
|
63
|
+
}
|
|
64
|
+
store.dispatch(setGroupNativeProps(nativeProps))
|
|
22
65
|
}
|
|
23
66
|
})
|
|
24
67
|
}
|
|
25
68
|
|
|
26
69
|
export const removeListener = () => {
|
|
27
|
-
|
|
28
|
-
|
|
70
|
+
deviceDPListener && deviceDPListener.remove()
|
|
71
|
+
deviceDPListener = null
|
|
72
|
+
|
|
73
|
+
groupFeatureListener && groupFeatureListener.remove()
|
|
74
|
+
groupFeatureListener = null
|
|
29
75
|
}
|
package/src/composeLayout.tsx
CHANGED
|
@@ -3,7 +3,7 @@ import React, {Component} from 'react'
|
|
|
3
3
|
import {Provider} from 'react-redux'
|
|
4
4
|
import {DevInfo, DpValue, Theme, TYSdk} from 'tuya-panel-kit'
|
|
5
5
|
import {actions, store} from './models'
|
|
6
|
-
import {addListener} from 'api/nativeEventEmitter'
|
|
6
|
+
import {addListener, removeListener} from 'api/nativeEventEmitter'
|
|
7
7
|
import {NativeApi} from 'api/native'
|
|
8
8
|
import {
|
|
9
9
|
DeviceInfo,
|
|
@@ -129,6 +129,7 @@ const composeLayout = (component: React.ComponentType) => {
|
|
|
129
129
|
tyGroupId: -1,
|
|
130
130
|
dps: {},
|
|
131
131
|
pId: '',
|
|
132
|
+
config: {},
|
|
132
133
|
},
|
|
133
134
|
familyName: ldvDevInfo.familyName,
|
|
134
135
|
}
|
|
@@ -152,6 +153,7 @@ const composeLayout = (component: React.ComponentType) => {
|
|
|
152
153
|
tyGroupId: uaGroupInfo.tyGroupId,
|
|
153
154
|
dps: {...dps, ...JSON.parse(uaGroupInfo.dps)},
|
|
154
155
|
pId: uaGroupInfo.pId,
|
|
156
|
+
config: uaGroupInfo.config || {},
|
|
155
157
|
},
|
|
156
158
|
familyName: uaGroupInfo.familyName,
|
|
157
159
|
}
|
|
@@ -193,6 +195,10 @@ const composeLayout = (component: React.ComponentType) => {
|
|
|
193
195
|
</Provider>
|
|
194
196
|
)
|
|
195
197
|
}
|
|
198
|
+
|
|
199
|
+
componentWillUnmount() {
|
|
200
|
+
removeListener()
|
|
201
|
+
}
|
|
196
202
|
}
|
|
197
203
|
|
|
198
204
|
return PanelComponent
|
|
@@ -17,6 +17,7 @@ export interface UAGroupInfo {
|
|
|
17
17
|
tyGroupId: number;
|
|
18
18
|
pId: string;
|
|
19
19
|
dps: any;
|
|
20
|
+
config: any;
|
|
20
21
|
}
|
|
21
22
|
declare function simpleSetDps<T>(dispatch: Dispatch<any>): (deviceId: string, dps: any) => Promise<Result<T>>;
|
|
22
23
|
declare function simpleSetDp<T>(dispatch: Dispatch<any>): (deviceId: string, dp: string, value: any) => Promise<Result<T>>;
|
|
@@ -32,6 +33,8 @@ declare const useDeviceInfo: () => DevInfo<DpState>;
|
|
|
32
33
|
declare const useTimeSchedule: () => [v: symbol | undefined, f: any];
|
|
33
34
|
declare const useEnergieverbrauch: () => (object | undefined)[];
|
|
34
35
|
export declare const useEngergyGeneration: () => boolean;
|
|
36
|
+
export declare function useUAGroupInfo(): UAGroupInfo;
|
|
37
|
+
export declare function useGroupConfig<T>(): [T, (dps: any, newConfig: T) => Promise<Result<any>>];
|
|
35
38
|
export declare const ldvModules: import("@reduxjs/toolkit").Reducer<NativeProps, import("@reduxjs/toolkit").AnyAction>;
|
|
36
39
|
export declare const setNativeProps: import("@reduxjs/toolkit").ActionCreatorWithPayload<NativeProps, string>, setGroupNativeProps: import("@reduxjs/toolkit").ActionCreatorWithPayload<NativeProps, string>, setDps: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, string>, setTimeSchedule: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, string>, setEnergieverbrauch: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, string>;
|
|
37
40
|
export { simpleSetDps, simpleSetDp, useDeviceId, useDeviceInfo, useDp, useDps, useFamilyName, useTimeSchedule, useEnergieverbrauch, };
|
|
@@ -24,6 +24,7 @@ export interface UAGroupInfo {
|
|
|
24
24
|
tyGroupId: number
|
|
25
25
|
pId: string
|
|
26
26
|
dps: any
|
|
27
|
+
config: any
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
const initialState: NativeProps = {
|
|
@@ -37,6 +38,7 @@ const initialState: NativeProps = {
|
|
|
37
38
|
tyGroupId: -1,
|
|
38
39
|
pId: '',
|
|
39
40
|
dps: {},
|
|
41
|
+
config: {},
|
|
40
42
|
},
|
|
41
43
|
timeSchedule: Symbol(),
|
|
42
44
|
energieverbrauch: {},
|
|
@@ -56,7 +58,7 @@ const nativePropsSlice = createSlice({
|
|
|
56
58
|
if (!!action.payload.familyName) {
|
|
57
59
|
state.familyName = action.payload.familyName
|
|
58
60
|
}
|
|
59
|
-
if (!!action.payload.deviceInfo.
|
|
61
|
+
if (!!action.payload.deviceInfo.pId) {
|
|
60
62
|
state.deviceInfo.pId = action.payload.deviceInfo.pId
|
|
61
63
|
}
|
|
62
64
|
state.deviceInfo.dps = {...state.deviceInfo.dps, ...action.payload.deviceInfo.dps}
|
|
@@ -66,10 +68,14 @@ const nativePropsSlice = createSlice({
|
|
|
66
68
|
if (!!action.payload.familyName) {
|
|
67
69
|
state.familyName = action.payload.familyName
|
|
68
70
|
}
|
|
69
|
-
if (!!action.payload.uaGroupInfo.
|
|
71
|
+
if (!!action.payload.uaGroupInfo.pId) {
|
|
70
72
|
state.uaGroupInfo.pId = action.payload.uaGroupInfo.pId
|
|
71
73
|
}
|
|
72
74
|
state.uaGroupInfo.dps = {...state.uaGroupInfo.dps, ...action.payload.uaGroupInfo.dps}
|
|
75
|
+
state.uaGroupInfo.config = action.payload.uaGroupInfo.config
|
|
76
|
+
},
|
|
77
|
+
setGroupConfig: (state, action: PayloadAction<any>) => {
|
|
78
|
+
state.uaGroupInfo.config = action.payload
|
|
73
79
|
},
|
|
74
80
|
setDps(state, action: PayloadAction<any>) {
|
|
75
81
|
const dpKeys = Object.keys(action.payload)
|
|
@@ -186,6 +192,26 @@ export const useEngergyGeneration = () => {
|
|
|
186
192
|
return productList.some(val => val === productId)
|
|
187
193
|
}
|
|
188
194
|
|
|
195
|
+
export function useUAGroupInfo(): UAGroupInfo {
|
|
196
|
+
return useSelector(state => state.ldvModules.uaGroupInfo)
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export function useGroupConfig<T>(): [T, (dps: any, newConfig: T) => Promise<Result<any>>] {
|
|
200
|
+
const config = useUAGroupInfo().config as T
|
|
201
|
+
const dispatch = useDispatch()
|
|
202
|
+
const {setGroupConfig} = nativePropsSlice.actions
|
|
203
|
+
const setConfig = useCallback(async (dps: any, newConfig: T) => {
|
|
204
|
+
// 发送控制命令
|
|
205
|
+
const res = await NativeApi.groupControl(JSON.stringify(dps), JSON.stringify(newConfig))
|
|
206
|
+
if (res.success) {
|
|
207
|
+
// 只在结果成功时才改变 redux 数据
|
|
208
|
+
dispatch(setGroupConfig(newConfig))
|
|
209
|
+
}
|
|
210
|
+
return res
|
|
211
|
+
}, [])
|
|
212
|
+
return [config, setConfig]
|
|
213
|
+
}
|
|
214
|
+
|
|
189
215
|
export const ldvModules = nativePropsSlice.reducer
|
|
190
216
|
|
|
191
217
|
export const {
|