@ledvance/base 1.0.1
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/.babelrc +31 -0
- package/.eslintignore +6 -0
- package/.eslintrc.js +27 -0
- package/.prettierignore +0 -0
- package/.prettierrc.js +1 -0
- package/.versionrc +5 -0
- package/package.json +71 -0
- package/rn-cli.config.js +8 -0
- package/src/api/native.d.ts +16 -0
- package/src/api/native.ts +161 -0
- package/src/api/nativeEventEmitter.d.ts +2 -0
- package/src/api/nativeEventEmitter.ts +24 -0
- package/src/components/Card.d.ts +9 -0
- package/src/components/Card.tsx +35 -0
- package/src/components/Cell.d.ts +9 -0
- package/src/components/Cell.tsx +41 -0
- package/src/components/ColorAdjustView.d.ts +9 -0
- package/src/components/ColorAdjustView.tsx +66 -0
- package/src/components/ColorTempAdjustView.d.ts +12 -0
- package/src/components/ColorTempAdjustView.tsx +55 -0
- package/src/components/Dialog.d.ts +10 -0
- package/src/components/Dialog.tsx +39 -0
- package/src/components/InfoText.d.ts +10 -0
- package/src/components/InfoText.tsx +44 -0
- package/src/components/LampAdjustView.d.ts +13 -0
- package/src/components/LampAdjustView.tsx +76 -0
- package/src/components/LinearGradientLine.d.ts +9 -0
- package/src/components/LinearGradientLine.tsx +65 -0
- package/src/components/Page.d.ts +11 -0
- package/src/components/Page.tsx +35 -0
- package/src/components/Spacer.d.ts +7 -0
- package/src/components/Spacer.tsx +14 -0
- package/src/components/Tag.d.ts +8 -0
- package/src/components/Tag.tsx +57 -0
- package/src/components/TextButton.d.ts +9 -0
- package/src/components/TextButton.tsx +32 -0
- package/src/components/TextField.d.ts +5 -0
- package/src/components/TextField.tsx +74 -0
- package/src/components/connect.d.ts +10 -0
- package/src/components/connect.tsx +20 -0
- package/src/components/ldvColorBrightness.d.ts +1 -0
- package/src/components/ldvColorBrightness.tsx +18 -0
- package/src/components/ldvColorSlider.d.ts +14 -0
- package/src/components/ldvColorSlider.tsx +132 -0
- package/src/components/ldvPickerView.d.ts +10 -0
- package/src/components/ldvPickerView.tsx +68 -0
- package/src/components/ldvPresetView.d.ts +2 -0
- package/src/components/ldvPresetView.tsx +89 -0
- package/src/components/ldvSaturation.d.ts +2 -0
- package/src/components/ldvSaturation.tsx +23 -0
- package/src/components/ldvSlider.d.ts +15 -0
- package/src/components/ldvSlider.tsx +104 -0
- package/src/components/ldvSwitch.d.ts +9 -0
- package/src/components/ldvSwitch.tsx +48 -0
- package/src/components/ldvTemperatureSlider.d.ts +13 -0
- package/src/components/ldvTemperatureSlider.tsx +140 -0
- package/src/components/ldvTopBar.d.ts +9 -0
- package/src/components/ldvTopBar.tsx +64 -0
- package/src/components/ldvTopName.d.ts +7 -0
- package/src/components/ldvTopName.tsx +47 -0
- package/src/components/segmentControl.d.ts +1 -0
- package/src/components/segmentControl.tsx +66 -0
- package/src/components/weekSelect.d.ts +7 -0
- package/src/components/weekSelect.tsx +95 -0
- package/src/composeLayout.tsx +148 -0
- package/src/i18n/index.d.ts +16 -0
- package/src/i18n/index.ts +36 -0
- package/src/i18n/strings.d.ts +3139 -0
- package/src/i18n/strings.ts +3234 -0
- package/src/main.tsx +9 -0
- package/src/models/GlobalParams.d.ts +14 -0
- package/src/models/GlobalParams.ts +15 -0
- package/src/models/TuyaApi.d.ts +17 -0
- package/src/models/TuyaApi.ts +37 -0
- package/src/models/combine.d.ts +26 -0
- package/src/models/combine.ts +17 -0
- package/src/models/configureStore.d.ts +9 -0
- package/src/models/configureStore.ts +33 -0
- package/src/models/index.d.ts +31 -0
- package/src/models/index.ts +22 -0
- package/src/models/modules/NativePropsSlice.d.ts +25 -0
- package/src/models/modules/NativePropsSlice.tsx +145 -0
- package/src/models/modules/Result.d.ts +14 -0
- package/src/models/modules/Result.ts +16 -0
- package/src/models/modules/common.d.ts +44 -0
- package/src/models/modules/common.ts +161 -0
- package/src/res/index.d.ts +38 -0
- package/src/res/index.ts +37 -0
- package/src/utils/ColorParser.d.ts +66 -0
- package/src/utils/ColorParser.ts +190 -0
- package/src/utils/ColorUtils.d.ts +71 -0
- package/src/utils/ColorUtils.tsx +449 -0
- package/src/utils/common.d.ts +11 -0
- package/src/utils/common.ts +54 -0
- package/src/utils/index.d.ts +24 -0
- package/src/utils/index.ts +164 -0
- package/tsconfig.json +51 -0
package/src/main.tsx
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import {createNavigator, GlobalTheme, NavigationRoute} from 'tuya-panel-kit'
|
|
2
|
+
import composeLayout from './composeLayout'
|
|
3
|
+
|
|
4
|
+
export function Navigation(router: NavigationRoute[]) {
|
|
5
|
+
return composeLayout(createNavigator<{ theme: GlobalTheme }>({
|
|
6
|
+
router: router,
|
|
7
|
+
screenOptions: {},
|
|
8
|
+
}))
|
|
9
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
interface DpSchemaProperty extends Record<string, any> {
|
|
2
|
+
type: string;
|
|
3
|
+
}
|
|
4
|
+
export interface DpSchema {
|
|
5
|
+
name: string;
|
|
6
|
+
dp: number;
|
|
7
|
+
type: string;
|
|
8
|
+
mode: string;
|
|
9
|
+
property: DpSchemaProperty;
|
|
10
|
+
}
|
|
11
|
+
export declare class GlobalParams {
|
|
12
|
+
static dpSchemaMap: Record<string, DpSchema>;
|
|
13
|
+
}
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
interface DpSchemaProperty extends Record<string, any> {
|
|
2
|
+
type: string
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export interface DpSchema {
|
|
6
|
+
name: string
|
|
7
|
+
dp: number
|
|
8
|
+
type: string
|
|
9
|
+
mode: string
|
|
10
|
+
property: DpSchemaProperty
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export class GlobalParams {
|
|
14
|
+
static dpSchemaMap: Record<string, DpSchema> = {}
|
|
15
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface PagingResult<T> {
|
|
2
|
+
data: T;
|
|
3
|
+
hasNext: boolean;
|
|
4
|
+
currentOffset: number;
|
|
5
|
+
}
|
|
6
|
+
export interface DpReportSataResData {
|
|
7
|
+
dps: DpReportSataData[];
|
|
8
|
+
hasNext: boolean;
|
|
9
|
+
total: number;
|
|
10
|
+
}
|
|
11
|
+
export interface DpReportSataData {
|
|
12
|
+
timeStamp: number;
|
|
13
|
+
dpId: number;
|
|
14
|
+
timeStr: string;
|
|
15
|
+
value: string;
|
|
16
|
+
}
|
|
17
|
+
export declare function getDpReportSataData(deviceId: string, dpIds: string[], offset: number, limit: number, sortType?: 'ASC' | 'DESC'): Promise<DpReportSataResData>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import {commonApi} from '@tuya/tuya-panel-api'
|
|
2
|
+
|
|
3
|
+
export interface PagingResult<T> {
|
|
4
|
+
data: T
|
|
5
|
+
hasNext: boolean
|
|
6
|
+
currentOffset: number
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface DpReportSataResData {
|
|
10
|
+
dps: DpReportSataData[]
|
|
11
|
+
hasNext: boolean
|
|
12
|
+
total: number
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface DpReportSataData {
|
|
16
|
+
timeStamp: number
|
|
17
|
+
dpId: number
|
|
18
|
+
timeStr: string
|
|
19
|
+
value: string
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export async function getDpReportSataData(
|
|
23
|
+
deviceId: string,
|
|
24
|
+
dpIds: string[],
|
|
25
|
+
offset: number,
|
|
26
|
+
limit: number,
|
|
27
|
+
sortType?: 'ASC' | 'DESC',
|
|
28
|
+
): Promise<DpReportSataResData> {
|
|
29
|
+
const params = {
|
|
30
|
+
devId: deviceId,
|
|
31
|
+
dpIds: dpIds.join(','),
|
|
32
|
+
offset: offset,
|
|
33
|
+
limit: limit,
|
|
34
|
+
sortType: sortType || 'DESC',
|
|
35
|
+
}
|
|
36
|
+
return commonApi.statApi.getDpReportLog(params)
|
|
37
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export declare const reducers: {
|
|
2
|
+
dpState: import("redux-actions").ReduxCompatibleReducer<import("./modules/common").DpState, import("tuya-panel-kit").DevInfo<Record<string, import("tuya-panel-kit").DpType>> | (Partial<import("./modules/common").DpState> & {
|
|
3
|
+
[key: string]: string | number | boolean;
|
|
4
|
+
})>;
|
|
5
|
+
devInfo: import("redux-actions").ReduxCompatibleReducer<import("tuya-panel-kit").DevInfo<import("./modules/common").DpState>, import("tuya-panel-kit").DevInfo<import("./modules/common").DpState>>;
|
|
6
|
+
logs: import("redux-actions").ReduxCompatibleReducer<import("./modules/common").Log[], import("tuya-panel-kit").DevInfo<Record<string, import("tuya-panel-kit").DpType>> | (Partial<import("./modules/common").DpState> & {
|
|
7
|
+
[key: string]: string | number | boolean;
|
|
8
|
+
}) | undefined>;
|
|
9
|
+
ldvModules: import("@reduxjs/toolkit").Reducer<import("./modules/NativePropsSlice").NativeProps, import("@reduxjs/toolkit").AnyAction>;
|
|
10
|
+
};
|
|
11
|
+
declare type Reducers = typeof reducers;
|
|
12
|
+
export declare type ReduxState = {
|
|
13
|
+
[K in keyof Reducers]: ReturnType<Reducers[K]>;
|
|
14
|
+
};
|
|
15
|
+
export declare const rootReducers: import("redux").Reducer<import("redux").CombinedState<{
|
|
16
|
+
dpState: import("./modules/common").DpState;
|
|
17
|
+
devInfo: import("tuya-panel-kit").DevInfo<import("./modules/common").DpState>;
|
|
18
|
+
logs: import("./modules/common").Log[];
|
|
19
|
+
ldvModules: import("./modules/NativePropsSlice").NativeProps;
|
|
20
|
+
}>, import("redux").AnyAction>;
|
|
21
|
+
export declare const rootEpics: import("redux-observable").Epic<import("redux-actions").Action<Partial<import("./modules/common").DpState> & {
|
|
22
|
+
[key: string]: string | number | boolean;
|
|
23
|
+
}>, import("redux-actions").Action<Partial<import("./modules/common").DpState> & {
|
|
24
|
+
[key: string]: string | number | boolean;
|
|
25
|
+
}>, void, any>;
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { combineReducers } from 'redux';
|
|
2
|
+
import { combineEpics } from 'redux-observable';
|
|
3
|
+
import { reducers as commonReducers, epics as commonEpics } from './modules/common';
|
|
4
|
+
|
|
5
|
+
export const reducers = {
|
|
6
|
+
...commonReducers,
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
type Reducers = typeof reducers;
|
|
10
|
+
|
|
11
|
+
export type ReduxState = { [K in keyof Reducers]: ReturnType<Reducers[K]> };
|
|
12
|
+
|
|
13
|
+
export const rootReducers = combineReducers(reducers);
|
|
14
|
+
|
|
15
|
+
const allEpics = [...commonEpics];
|
|
16
|
+
|
|
17
|
+
export const rootEpics = combineEpics(...allEpics);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ReduxState } from './combine';
|
|
2
|
+
export default function configureStore(initialState?: Partial<ReduxState>): import("redux").Store<import("redux").CombinedState<{
|
|
3
|
+
dpState: import("./modules/common").DpState;
|
|
4
|
+
devInfo: import("tuya-panel-kit").DevInfo<import("./modules/common").DpState>;
|
|
5
|
+
logs: import("./modules/common").Log[];
|
|
6
|
+
ldvModules: import("./modules/NativePropsSlice").NativeProps;
|
|
7
|
+
}>, import("redux").AnyAction> & {
|
|
8
|
+
dispatch: unknown;
|
|
9
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import {applyMiddleware, compose, createStore} from 'redux'
|
|
2
|
+
import {createLogger} from 'redux-logger'
|
|
3
|
+
import {createEpicMiddleware} from 'redux-observable'
|
|
4
|
+
import {ReduxState, rootEpics, rootReducers} from './combine'
|
|
5
|
+
|
|
6
|
+
const epicMiddleware = createEpicMiddleware()
|
|
7
|
+
|
|
8
|
+
const mWindow: any = window
|
|
9
|
+
|
|
10
|
+
const isDebuggingInChrome = __DEV__ && !!mWindow.navigator.userAgent
|
|
11
|
+
const logger = createLogger({
|
|
12
|
+
predicate: () => isDebuggingInChrome,
|
|
13
|
+
collapsed: true,
|
|
14
|
+
duration: true,
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
const middleware = isDebuggingInChrome ? [epicMiddleware, logger] : [epicMiddleware]
|
|
18
|
+
|
|
19
|
+
export default function configureStore(initialState?: Partial<ReduxState>) {
|
|
20
|
+
const appliedMiddleware = applyMiddleware(...middleware)
|
|
21
|
+
|
|
22
|
+
const store = createStore(
|
|
23
|
+
rootReducers,
|
|
24
|
+
initialState,
|
|
25
|
+
compose(
|
|
26
|
+
appliedMiddleware,
|
|
27
|
+
isDebuggingInChrome && mWindow.devToolsExtension ? mWindow.devToolsExtension() : (f: any) => f,
|
|
28
|
+
),
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
epicMiddleware.run(rootEpics)
|
|
32
|
+
return store
|
|
33
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ReduxState } from './combine';
|
|
2
|
+
export * from './combine';
|
|
3
|
+
export * from './configureStore';
|
|
4
|
+
declare const actions: {
|
|
5
|
+
common: {
|
|
6
|
+
devInfoChange: import("redux-actions").ActionFunction1<import("tuya-panel-kit").DevInfo<Record<string, import("tuya-panel-kit").DpType>>, import("redux-actions").Action<import("tuya-panel-kit").DevInfo<Record<string, import("tuya-panel-kit").DpType>>>>;
|
|
7
|
+
deviceChange: import("redux-actions").ActionFunction1<import("tuya-panel-kit").DevInfo<Record<string, import("tuya-panel-kit").DpType>>, import("redux-actions").Action<import("tuya-panel-kit").DevInfo<Record<string, import("tuya-panel-kit").DpType>>>>;
|
|
8
|
+
responseUpdateDp: import("redux-actions").ActionFunction1<Partial<import("./modules/common").DpState> & {
|
|
9
|
+
[key: string]: string | number | boolean;
|
|
10
|
+
}, import("redux-actions").Action<Partial<import("./modules/common").DpState> & {
|
|
11
|
+
[key: string]: string | number | boolean;
|
|
12
|
+
}>>;
|
|
13
|
+
updateDp: import("redux-actions").ActionFunction1<Partial<import("./modules/common").DpState> & {
|
|
14
|
+
[key: string]: string | number | boolean;
|
|
15
|
+
}, import("redux-actions").Action<Partial<import("./modules/common").DpState> & {
|
|
16
|
+
[key: string]: string | number | boolean;
|
|
17
|
+
}>>;
|
|
18
|
+
consoleChange: import("redux-actions").ActionFunctionAny<import("redux-actions").Action<any>>;
|
|
19
|
+
clearConsole: import("redux-actions").ActionFunctionAny<import("redux-actions").Action<any>>;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
export { actions };
|
|
23
|
+
export declare const store: import("redux").Store<import("redux").CombinedState<{
|
|
24
|
+
dpState: import("./modules/common").DpState;
|
|
25
|
+
devInfo: import("tuya-panel-kit").DevInfo<import("./modules/common").DpState>;
|
|
26
|
+
logs: import("./modules/common").Log[];
|
|
27
|
+
ldvModules: import("./modules/NativePropsSlice").NativeProps;
|
|
28
|
+
}>, import("redux").AnyAction> & {
|
|
29
|
+
dispatch: unknown;
|
|
30
|
+
};
|
|
31
|
+
export declare function useSelector<TSelected>(selector: (state: ReduxState) => TSelected, equalityFn?: (left: TSelected, right: TSelected) => boolean): TSelected;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import {shallowEqual, useSelector as useSelectorBase} from 'react-redux'
|
|
2
|
+
import {actions as CommonActions} from './modules/common'
|
|
3
|
+
import {ReduxState} from './combine'
|
|
4
|
+
import configureStore from './configureStore'
|
|
5
|
+
|
|
6
|
+
export * from './combine'
|
|
7
|
+
export * from './configureStore'
|
|
8
|
+
|
|
9
|
+
const actions = {
|
|
10
|
+
common: CommonActions,
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export {actions}
|
|
14
|
+
|
|
15
|
+
export const store = configureStore()
|
|
16
|
+
|
|
17
|
+
export function useSelector<TSelected>(
|
|
18
|
+
selector: (state: ReduxState) => TSelected,
|
|
19
|
+
equalityFn?: (left: TSelected, right: TSelected) => boolean,
|
|
20
|
+
) {
|
|
21
|
+
return useSelectorBase<ReduxState, TSelected>(selector, equalityFn || shallowEqual)
|
|
22
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Dispatch } from 'react';
|
|
2
|
+
import { Result } from './Result';
|
|
3
|
+
import { DevInfo, DpValue } from 'tuya-panel-kit';
|
|
4
|
+
export interface NativeProps {
|
|
5
|
+
devId: string;
|
|
6
|
+
pId: string;
|
|
7
|
+
dps: any;
|
|
8
|
+
familyName: string;
|
|
9
|
+
timeSchedule?: symbol;
|
|
10
|
+
}
|
|
11
|
+
declare function simpleSetDps<T>(dispatch: Dispatch<any>): (deviceId: string, dps: any) => Promise<Result<T>>;
|
|
12
|
+
declare function simpleSetDp<T>(dispatch: Dispatch<any>): (deviceId: string, dp: string, value: any) => Promise<Result<T>>;
|
|
13
|
+
declare const useDeviceId: () => string;
|
|
14
|
+
declare const useFamilyName: () => string;
|
|
15
|
+
declare function useDp<T, R>(dp: string): [T, (value: T) => Promise<Result<R>>];
|
|
16
|
+
declare function useDps<R>(): [any, (dps: any) => Promise<Result<R>>];
|
|
17
|
+
interface DpState {
|
|
18
|
+
switch: boolean;
|
|
19
|
+
[dpCode: string]: DpValue;
|
|
20
|
+
}
|
|
21
|
+
declare const useDeviceInfo: () => DevInfo<DpState>;
|
|
22
|
+
declare const useTimeSchedule: () => symbol | undefined;
|
|
23
|
+
export declare const ldvModules: import("@reduxjs/toolkit").Reducer<NativeProps, import("@reduxjs/toolkit").AnyAction>;
|
|
24
|
+
export declare const setNativeProps: import("@reduxjs/toolkit").ActionCreatorWithPayload<NativeProps, string>, setDps: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, string>, setTimeSchedule: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, string>;
|
|
25
|
+
export { simpleSetDps, simpleSetDp, useDeviceId, useDeviceInfo, useDp, useDps, useFamilyName, useTimeSchedule, };
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import {createSlice, PayloadAction} from '@reduxjs/toolkit'
|
|
2
|
+
import {useSelector} from '../index'
|
|
3
|
+
import {Dispatch, useCallback} from 'react'
|
|
4
|
+
import {DpsResult, Result} from './Result'
|
|
5
|
+
import {DevInfo, DpValue} from 'tuya-panel-kit'
|
|
6
|
+
import {NativeApi} from '../../api/native'
|
|
7
|
+
import {useDispatch} from 'react-redux'
|
|
8
|
+
|
|
9
|
+
export interface NativeProps {
|
|
10
|
+
devId: string,
|
|
11
|
+
pId: string,
|
|
12
|
+
dps: any,
|
|
13
|
+
familyName: string,
|
|
14
|
+
timeSchedule?: symbol;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const initialState: NativeProps = {
|
|
18
|
+
devId: '',
|
|
19
|
+
pId: '',
|
|
20
|
+
dps: {},
|
|
21
|
+
familyName: '',
|
|
22
|
+
timeSchedule: Symbol(),
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const nativePropsSlice = createSlice({
|
|
26
|
+
name: 'ldvModules',
|
|
27
|
+
initialState: initialState,
|
|
28
|
+
reducers: {
|
|
29
|
+
setNativeProps: (state, action: PayloadAction<NativeProps>) => {
|
|
30
|
+
state.devId = action.payload.devId
|
|
31
|
+
if (!!action.payload.familyName) {
|
|
32
|
+
state.familyName = action.payload.familyName
|
|
33
|
+
}
|
|
34
|
+
if (!!action.payload.pId) {
|
|
35
|
+
state.pId = action.payload.pId
|
|
36
|
+
}
|
|
37
|
+
state.dps = {...state.dps, ...action.payload.dps}
|
|
38
|
+
},
|
|
39
|
+
setDps(state, action: PayloadAction<any>) {
|
|
40
|
+
const dpKeys = Object.keys(action.payload)
|
|
41
|
+
dpKeys.forEach(dp => {
|
|
42
|
+
state.dps[dp] = action.payload[dp]
|
|
43
|
+
})
|
|
44
|
+
},
|
|
45
|
+
setTimeSchedule(state, action: PayloadAction<any>) {
|
|
46
|
+
state.timeSchedule = action.payload.timeSchedule
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
type AsyncBlockType<T> = () => Promise<DpsResult<T>>
|
|
52
|
+
type SyncBlockType<T> = () => DpsResult<T>
|
|
53
|
+
|
|
54
|
+
function asyncSetDps<T>(dispatch: Dispatch<any>, block: AsyncBlockType<T> | SyncBlockType<T>): Promise<Result<T>> {
|
|
55
|
+
return new Promise<Result<T>>(async (res, _rej) => {
|
|
56
|
+
const dpsResult = await block()
|
|
57
|
+
if (dpsResult.result.success) {
|
|
58
|
+
// 只在结果成功时才改变 redux 数据
|
|
59
|
+
dispatch(setDps(dpsResult.dps))
|
|
60
|
+
}
|
|
61
|
+
res(dpsResult.result)
|
|
62
|
+
})
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function simpleSetDps<T>(dispatch: Dispatch<any>): (deviceId: string, dps: any) => Promise<Result<T>> {
|
|
66
|
+
return (deviceId, dps) => {
|
|
67
|
+
return asyncSetDps(dispatch, async () => {
|
|
68
|
+
console.log('发送dp数据:', deviceId, JSON.stringify(dps))
|
|
69
|
+
const res = await NativeApi.setDps(deviceId, dps)
|
|
70
|
+
if (res.result) {
|
|
71
|
+
return {
|
|
72
|
+
result: {success: true},
|
|
73
|
+
dps: dps,
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
result: {success: false, msg: res.msg},
|
|
78
|
+
}
|
|
79
|
+
})
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function simpleSetDp<T>(dispatch: Dispatch<any>): (deviceId: string, dp: string, value: any) => Promise<Result<T>> {
|
|
84
|
+
return (deviceId, dp, value) => {
|
|
85
|
+
const fun = simpleSetDps<T>(dispatch)
|
|
86
|
+
return fun(deviceId, {[dp]: value})
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const useDeviceId = () => {
|
|
91
|
+
return useSelector(store => store.ldvModules.devId)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const useFamilyName: () => string = () => {
|
|
95
|
+
return useSelector(store => store.ldvModules.familyName)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function useDp<T, R>(dp: string): [T, (value: T) => Promise<Result<R>>] {
|
|
99
|
+
const deviceId = useDeviceId()
|
|
100
|
+
const dispatch = useDispatch()
|
|
101
|
+
const dpValue = useSelector(store => store.ldvModules.dps[dp])
|
|
102
|
+
const setDp = useCallback((dpValue: T) => {
|
|
103
|
+
return simpleSetDp<R>(dispatch)(deviceId, dp, dpValue)
|
|
104
|
+
}, [])
|
|
105
|
+
return [dpValue, setDp]
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function useDps<R>(): [any, (dps: any) => Promise<Result<R>>] {
|
|
109
|
+
const deviceId = useDeviceId()
|
|
110
|
+
const dispatch = useDispatch()
|
|
111
|
+
const dps = useSelector(store => store.ldvModules.dps)
|
|
112
|
+
const setDps = useCallback((dps: any) => {
|
|
113
|
+
return simpleSetDps<R>(dispatch)(deviceId, dps)
|
|
114
|
+
}, [])
|
|
115
|
+
return [dps, setDps]
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
interface DpState {
|
|
119
|
+
switch: boolean;
|
|
120
|
+
|
|
121
|
+
[dpCode: string]: DpValue;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const useDeviceInfo: () => DevInfo<DpState> = () => {
|
|
125
|
+
return useSelector(state => state.devInfo)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const useTimeSchedule = () => {
|
|
129
|
+
return useSelector(store => store.ldvModules.timeSchedule)
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export const ldvModules = nativePropsSlice.reducer
|
|
133
|
+
|
|
134
|
+
export const {setNativeProps, setDps, setTimeSchedule} = nativePropsSlice.actions
|
|
135
|
+
|
|
136
|
+
export {
|
|
137
|
+
simpleSetDps,
|
|
138
|
+
simpleSetDp,
|
|
139
|
+
useDeviceId,
|
|
140
|
+
useDeviceInfo,
|
|
141
|
+
useDp,
|
|
142
|
+
useDps,
|
|
143
|
+
useFamilyName,
|
|
144
|
+
useTimeSchedule,
|
|
145
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface Result<T> {
|
|
2
|
+
success: boolean;
|
|
3
|
+
data?: T | undefined;
|
|
4
|
+
msg?: string | undefined;
|
|
5
|
+
}
|
|
6
|
+
export interface DpsResult<T> {
|
|
7
|
+
result: Result<T>;
|
|
8
|
+
dps?: any | undefined;
|
|
9
|
+
}
|
|
10
|
+
export interface NativeResult<T> {
|
|
11
|
+
result: boolean;
|
|
12
|
+
data?: T;
|
|
13
|
+
msg?: string;
|
|
14
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface Result<T> {
|
|
2
|
+
success: boolean;
|
|
3
|
+
data?: T | undefined,
|
|
4
|
+
msg?: string | undefined
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface DpsResult<T> {
|
|
8
|
+
result: Result<T>,
|
|
9
|
+
dps?: any | undefined
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface NativeResult<T> {
|
|
13
|
+
result: boolean
|
|
14
|
+
data?: T
|
|
15
|
+
msg?: string
|
|
16
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { DevInfo, DpValue } from 'tuya-panel-kit';
|
|
2
|
+
import { Observable } from 'rxjs/Observable';
|
|
3
|
+
import { ActionsObservable } from 'redux-observable';
|
|
4
|
+
import 'rxjs/add/observable/fromPromise';
|
|
5
|
+
import 'rxjs/add/observable/of';
|
|
6
|
+
import 'rxjs/add/observable/merge';
|
|
7
|
+
import 'rxjs/add/operator/catch';
|
|
8
|
+
import 'rxjs/add/operator/map';
|
|
9
|
+
import 'rxjs/add/operator/mergeMap';
|
|
10
|
+
import 'rxjs/add/operator/partition';
|
|
11
|
+
export interface DpState {
|
|
12
|
+
switch: boolean;
|
|
13
|
+
[dpCode: string]: DpValue;
|
|
14
|
+
}
|
|
15
|
+
export interface Log {
|
|
16
|
+
strCodes: string;
|
|
17
|
+
strIds: string;
|
|
18
|
+
time: string;
|
|
19
|
+
isSend: boolean;
|
|
20
|
+
}
|
|
21
|
+
declare type Logs = Array<Log>;
|
|
22
|
+
declare type UpdateDevInfoPayload = DevInfo;
|
|
23
|
+
declare type UpdateDpStatePayload = Partial<DpState> & {
|
|
24
|
+
[key: string]: DpValue;
|
|
25
|
+
};
|
|
26
|
+
export declare const actions: {
|
|
27
|
+
devInfoChange: import("redux-actions").ActionFunction1<UpdateDevInfoPayload, import("redux-actions").Action<UpdateDevInfoPayload>>;
|
|
28
|
+
deviceChange: import("redux-actions").ActionFunction1<UpdateDevInfoPayload, import("redux-actions").Action<UpdateDevInfoPayload>>;
|
|
29
|
+
responseUpdateDp: import("redux-actions").ActionFunction1<UpdateDpStatePayload, import("redux-actions").Action<UpdateDpStatePayload>>;
|
|
30
|
+
updateDp: import("redux-actions").ActionFunction1<UpdateDpStatePayload, import("redux-actions").Action<UpdateDpStatePayload>>;
|
|
31
|
+
consoleChange: import("redux-actions").ActionFunctionAny<import("redux-actions").Action<any>>;
|
|
32
|
+
clearConsole: import("redux-actions").ActionFunctionAny<import("redux-actions").Action<any>>;
|
|
33
|
+
};
|
|
34
|
+
export declare type Actions = {
|
|
35
|
+
[K in keyof typeof actions]: ReturnType<typeof actions[K]>;
|
|
36
|
+
};
|
|
37
|
+
export declare const reducers: {
|
|
38
|
+
dpState: import("redux-actions").ReduxCompatibleReducer<DpState, UpdateDevInfoPayload | UpdateDpStatePayload>;
|
|
39
|
+
devInfo: import("redux-actions").ReduxCompatibleReducer<DevInfo<DpState>, DevInfo<DpState>>;
|
|
40
|
+
logs: import("redux-actions").ReduxCompatibleReducer<Logs, DevInfo<Record<string, import("tuya-panel-kit").DpType>> | UpdateDpStatePayload | undefined>;
|
|
41
|
+
ldvModules: import("@reduxjs/toolkit").Reducer<import("./NativePropsSlice").NativeProps, import("@reduxjs/toolkit").AnyAction>;
|
|
42
|
+
};
|
|
43
|
+
export declare const epics: ((action$: ActionsObservable<Actions['updateDp']>) => Observable<import("redux-actions").Action<UpdateDpStatePayload>>)[];
|
|
44
|
+
export {};
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import {DevInfo, DpValue, TYSdk} from 'tuya-panel-kit'
|
|
2
|
+
import {createAction, handleActions} from 'redux-actions'
|
|
3
|
+
import {Observable} from 'rxjs/Observable'
|
|
4
|
+
import {ActionsObservable} from 'redux-observable'
|
|
5
|
+
import 'rxjs/add/observable/fromPromise'
|
|
6
|
+
import 'rxjs/add/observable/of'
|
|
7
|
+
import 'rxjs/add/observable/merge'
|
|
8
|
+
import 'rxjs/add/operator/catch'
|
|
9
|
+
import 'rxjs/add/operator/map'
|
|
10
|
+
import 'rxjs/add/operator/mergeMap'
|
|
11
|
+
import 'rxjs/add/operator/partition'
|
|
12
|
+
import {ldvModules} from './NativePropsSlice'
|
|
13
|
+
|
|
14
|
+
const {putDeviceData} = TYSdk.device
|
|
15
|
+
|
|
16
|
+
export interface DpState {
|
|
17
|
+
switch: boolean;
|
|
18
|
+
|
|
19
|
+
[dpCode: string]: DpValue;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface Log {
|
|
23
|
+
strCodes: string;
|
|
24
|
+
strIds: string;
|
|
25
|
+
time: string;
|
|
26
|
+
isSend: boolean;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
type Logs = Array<Log>;
|
|
30
|
+
|
|
31
|
+
type UpdateDevInfoPayload = DevInfo;
|
|
32
|
+
type UpdateDpStatePayload = Partial<DpState> & { [key: string]: DpValue }; // 保证起码有一个键值对存在
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* actions
|
|
36
|
+
*/
|
|
37
|
+
const devInfoChange = createAction<UpdateDevInfoPayload>('_DEVINFOCHANGE_')
|
|
38
|
+
const deviceChange = createAction<UpdateDevInfoPayload>('_DEVICECHANGED_')
|
|
39
|
+
const responseUpdateDp = createAction<UpdateDpStatePayload>('RESPONSE_UPDATE_DP')
|
|
40
|
+
const updateDp = createAction<UpdateDpStatePayload>('CHANGE_DP')
|
|
41
|
+
const consoleChange = createAction('CONSOLECHNAGE')
|
|
42
|
+
const clearConsole = createAction('CLEARCONSOLE')
|
|
43
|
+
|
|
44
|
+
export const actions = {
|
|
45
|
+
devInfoChange,
|
|
46
|
+
deviceChange,
|
|
47
|
+
responseUpdateDp,
|
|
48
|
+
updateDp,
|
|
49
|
+
consoleChange,
|
|
50
|
+
clearConsole,
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export type Actions = { [K in keyof typeof actions]: ReturnType<typeof actions[K]> };
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* reducers
|
|
57
|
+
*/
|
|
58
|
+
const dpState = handleActions<DpState, UpdateDpStatePayload | UpdateDevInfoPayload>(
|
|
59
|
+
{
|
|
60
|
+
[devInfoChange.toString()]: (state, action: Actions['devInfoChange']) => {
|
|
61
|
+
return {
|
|
62
|
+
...state,
|
|
63
|
+
...action.payload.state,
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
|
|
67
|
+
[responseUpdateDp.toString()]: (state, action: Actions['responseUpdateDp']) => ({
|
|
68
|
+
...state,
|
|
69
|
+
...action.payload,
|
|
70
|
+
}),
|
|
71
|
+
},
|
|
72
|
+
{} as DpState,
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
const devInfo = handleActions<DevInfo<DpState>>(
|
|
76
|
+
{
|
|
77
|
+
[devInfoChange.toString()]: (state, action) => ({
|
|
78
|
+
...state,
|
|
79
|
+
...action.payload,
|
|
80
|
+
}),
|
|
81
|
+
|
|
82
|
+
[deviceChange.toString()]: (state, action) => ({
|
|
83
|
+
...state,
|
|
84
|
+
...action.payload,
|
|
85
|
+
}),
|
|
86
|
+
},
|
|
87
|
+
{} as DevInfo<DpState>,
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
let isSend = false
|
|
91
|
+
|
|
92
|
+
const formatLogs = (state: Logs, action: { payload: UpdateDpStatePayload }, send: boolean) => {
|
|
93
|
+
const ret = Object.keys(action.payload).reduce((obj, p) => {
|
|
94
|
+
const id = TYSdk.device.getDpIdByCode(p)
|
|
95
|
+
return {...obj, [id]: action.payload[p]}
|
|
96
|
+
}, {})
|
|
97
|
+
const strIds = JSON.stringify(ret, null, 2)
|
|
98
|
+
const strCodes = JSON.stringify(action.payload, null, 2)
|
|
99
|
+
const date = new Date()
|
|
100
|
+
const time = `[${[
|
|
101
|
+
date.getHours(),
|
|
102
|
+
date.getMinutes(),
|
|
103
|
+
date.getSeconds(),
|
|
104
|
+
date.getMilliseconds(),
|
|
105
|
+
].join(':')}]`
|
|
106
|
+
const s = [{strCodes, strIds, time, isSend: send}, ...state]
|
|
107
|
+
return s.slice(0, 30)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const logs = handleActions<Logs, undefined | UpdateDpStatePayload | DevInfo>(
|
|
111
|
+
{
|
|
112
|
+
[consoleChange.toString()]: state => {
|
|
113
|
+
isSend = true
|
|
114
|
+
return state
|
|
115
|
+
},
|
|
116
|
+
|
|
117
|
+
[updateDp.toString()]: (state, action: Actions['updateDp']) => {
|
|
118
|
+
isSend = true
|
|
119
|
+
return formatLogs(state, action, isSend)
|
|
120
|
+
},
|
|
121
|
+
|
|
122
|
+
[devInfoChange.toString()]: (state, action: Actions['devInfoChange']) => {
|
|
123
|
+
const formatAction = {payload: action.payload.state}
|
|
124
|
+
return formatLogs(state, formatAction, isSend)
|
|
125
|
+
},
|
|
126
|
+
|
|
127
|
+
[responseUpdateDp.toString()]: (state, action: Actions['responseUpdateDp']) => {
|
|
128
|
+
isSend = false
|
|
129
|
+
return formatLogs(state, action, isSend)
|
|
130
|
+
},
|
|
131
|
+
|
|
132
|
+
[clearConsole.toString()]: () => [],
|
|
133
|
+
},
|
|
134
|
+
[],
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
export const reducers = {
|
|
138
|
+
dpState,
|
|
139
|
+
devInfo,
|
|
140
|
+
logs,
|
|
141
|
+
ldvModules,
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* epics
|
|
146
|
+
*/
|
|
147
|
+
const dpUpdateEpic$ = (action$: ActionsObservable<Actions['updateDp']>) => {
|
|
148
|
+
return action$.ofType(updateDp.toString()).mergeMap(action => {
|
|
149
|
+
const {payload} = action
|
|
150
|
+
const [success, error] = Observable.fromPromise(putDeviceData(payload))
|
|
151
|
+
.catch(() => Observable.of(responseUpdateDp({})))
|
|
152
|
+
.partition((x: { success: boolean }) => x.success)
|
|
153
|
+
|
|
154
|
+
return Observable.merge(
|
|
155
|
+
success.map(() => responseUpdateDp(payload)), // 如果每次操作都必须等到上报以后再更新,可以注释掉本段代码
|
|
156
|
+
error.map(() => responseUpdateDp({})),
|
|
157
|
+
)
|
|
158
|
+
})
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export const epics = [dpUpdateEpic$]
|