@ledvance/base 1.1.5 → 1.1.7

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
@@ -4,7 +4,7 @@
4
4
  "name": "@ledvance/base",
5
5
  "pid": [],
6
6
  "uiid": "",
7
- "version": "1.1.5",
7
+ "version": "1.1.7",
8
8
  "scripts": {},
9
9
  "dependencies": {
10
10
  "@reduxjs/toolkit": "^1.8.6",
@@ -1,29 +1,75 @@
1
- import { NativeEventEmitter, NativeModules } from 'react-native'
2
- import { setNativeProps } from '../models/modules/NativePropsSlice'
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 listener
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
- listener = nativeEventEmitter.addListener('TYDataUpdate', (body: any) => {
30
+ deviceDPListener = nativeEventEmitter.addListener('TYDataUpdate', (event: DeviceEvent) => {
12
31
  // device info
13
- if (body.dps && body.devId && body.devId === store.getState().ldvModules.devId) {
14
- console.log('长链接刷新DP数据', body.devId, body.dps)
15
- const data = body
16
- data.dps = JSON.parse(body.dps)
17
- store.dispatch(setNativeProps(data))
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 (!!body.name && body.devId && body.devId === store.getState().ldvModules.devId) {
21
- store.dispatch(actions.common.devInfoChange({ ...store.getState().devInfo, name: body.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
- listener && listener.remove()
28
- listener = null
70
+ deviceDPListener && deviceDPListener.remove()
71
+ deviceDPListener = null
72
+
73
+ groupFeatureListener && groupFeatureListener.remove()
74
+ groupFeatureListener = null
29
75
  }
@@ -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
  }
@@ -186,15 +188,17 @@ const composeLayout = (component: React.ComponentType) => {
186
188
  <Theme theme={theme}>
187
189
  <Connect mapStateToProps={_.identity}>
188
190
  {({mapStateToProps, ...props}: { mapStateToProps: any; [_: string]: any }) => {
189
- const hasInit = Object.keys(props.dpState).length > 0
190
- // @ts-ignore
191
- return hasInit ? <NavigatorLayout {...props} /> : null
191
+ return <NavigatorLayout {...props} />
192
192
  }}
193
193
  </Connect>
194
194
  </Theme>
195
195
  </Provider>
196
196
  )
197
197
  }
198
+
199
+ componentWillUnmount() {
200
+ removeListener()
201
+ }
198
202
  }
199
203
 
200
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;
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.devId) {
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,11 @@ const nativePropsSlice = createSlice({
66
68
  if (!!action.payload.familyName) {
67
69
  state.familyName = action.payload.familyName
68
70
  }
69
- if (!!action.payload.uaGroupInfo.tyGroupId) {
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
73
76
  },
74
77
  setDps(state, action: PayloadAction<any>) {
75
78
  const dpKeys = Object.keys(action.payload)
@@ -186,6 +189,14 @@ export const useEngergyGeneration = () => {
186
189
  return productList.some(val => val === productId)
187
190
  }
188
191
 
192
+ export function useUAGroupInfo(): UAGroupInfo {
193
+ return useSelector(state => state.ldvModules.uaGroupInfo)
194
+ }
195
+
196
+ export function useGroupConfig<T>(): T {
197
+ return useUAGroupInfo().config as T
198
+ }
199
+
189
200
  export const ldvModules = nativePropsSlice.reducer
190
201
 
191
202
  export const {