@ledvance/base 1.1.7 → 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) => {
|
|
@@ -34,7 +34,7 @@ declare const useTimeSchedule: () => [v: symbol | undefined, f: any];
|
|
|
34
34
|
declare const useEnergieverbrauch: () => (object | undefined)[];
|
|
35
35
|
export declare const useEngergyGeneration: () => boolean;
|
|
36
36
|
export declare function useUAGroupInfo(): UAGroupInfo;
|
|
37
|
-
export declare function useGroupConfig<T>(): T;
|
|
37
|
+
export declare function useGroupConfig<T>(): [T, (dps: any, newConfig: T) => Promise<Result<any>>];
|
|
38
38
|
export declare const ldvModules: import("@reduxjs/toolkit").Reducer<NativeProps, import("@reduxjs/toolkit").AnyAction>;
|
|
39
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>;
|
|
40
40
|
export { simpleSetDps, simpleSetDp, useDeviceId, useDeviceInfo, useDp, useDps, useFamilyName, useTimeSchedule, useEnergieverbrauch, };
|
|
@@ -74,6 +74,9 @@ const nativePropsSlice = createSlice({
|
|
|
74
74
|
state.uaGroupInfo.dps = {...state.uaGroupInfo.dps, ...action.payload.uaGroupInfo.dps}
|
|
75
75
|
state.uaGroupInfo.config = action.payload.uaGroupInfo.config
|
|
76
76
|
},
|
|
77
|
+
setGroupConfig: (state, action: PayloadAction<any>) => {
|
|
78
|
+
state.uaGroupInfo.config = action.payload
|
|
79
|
+
},
|
|
77
80
|
setDps(state, action: PayloadAction<any>) {
|
|
78
81
|
const dpKeys = Object.keys(action.payload)
|
|
79
82
|
dpKeys.forEach(dp => {
|
|
@@ -193,8 +196,20 @@ export function useUAGroupInfo(): UAGroupInfo {
|
|
|
193
196
|
return useSelector(state => state.ldvModules.uaGroupInfo)
|
|
194
197
|
}
|
|
195
198
|
|
|
196
|
-
export function useGroupConfig<T>(): T {
|
|
197
|
-
|
|
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]
|
|
198
213
|
}
|
|
199
214
|
|
|
200
215
|
export const ldvModules = nativePropsSlice.reducer
|