@ledvance/base 1.1.13 → 1.1.15
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/.prettierrc.js +0 -0
- package/package.json +1 -1
- package/src/api/native.d.ts +5 -0
- package/src/api/native.ts +193 -160
- package/src/api/nativeEventEmitter.ts +54 -54
- package/src/components/Card.tsx +25 -25
- package/src/components/Cell.tsx +32 -32
- package/src/components/ColorAdjustView.tsx +44 -44
- package/src/components/ColorTempAdjustView.tsx +37 -37
- package/src/components/ColorsLine.d.ts +7 -0
- package/src/components/ColorsLine.tsx +48 -0
- package/src/components/DeleteButton.d.ts +1 -1
- package/src/components/DeleteButton.tsx +27 -27
- package/src/components/Dialog.tsx +28 -28
- package/src/components/FanAdjustView.tsx +115 -105
- package/src/components/InfoText.tsx +29 -29
- package/src/components/LampAdjustView.tsx +52 -52
- package/src/components/LinearGradientLine.tsx +53 -53
- package/src/components/MoodColorsLine.d.ts +9 -0
- package/src/components/MoodColorsLine.tsx +38 -0
- package/src/components/Page.tsx +34 -34
- package/src/components/Popup.tsx +17 -17
- package/src/components/Segmented.d.ts +2 -2
- package/src/components/Segmented.tsx +66 -65
- package/src/components/Spacer.tsx +5 -5
- package/src/components/Tag.tsx +42 -42
- package/src/components/TextButton.d.ts +1 -1
- package/src/components/TextButton.tsx +23 -23
- package/src/components/TextField.tsx +58 -58
- package/src/components/connect.tsx +10 -10
- package/src/components/ldvColorBrightness.tsx +12 -12
- package/src/components/ldvColorSlider.tsx +109 -109
- package/src/components/ldvPickerView.tsx +70 -70
- package/src/components/ldvPresetView.tsx +68 -68
- package/src/components/ldvSaturation.tsx +14 -14
- package/src/components/ldvSlider.d.ts +3 -3
- package/src/components/ldvSlider.tsx +93 -93
- package/src/components/ldvSwitch.tsx +35 -35
- package/src/components/ldvTemperatureSlider.tsx +120 -120
- package/src/components/ldvTopBar.tsx +50 -50
- package/src/components/ldvTopName.tsx +44 -44
- package/src/components/segmentControl.tsx +59 -59
- package/src/components/weekSelect.tsx +76 -76
- package/src/composeLayout.tsx +165 -165
- package/src/i18n/index.ts +12 -12
- package/src/i18n/strings.ts +11004 -11004
- package/src/main.tsx +4 -4
- package/src/models/GlobalParams.ts +7 -7
- package/src/models/TuyaApi.d.ts +3 -3
- package/src/models/TuyaApi.ts +61 -61
- package/src/models/combine.ts +7 -7
- package/src/models/configureStore.ts +14 -14
- package/src/models/index.ts +4 -4
- package/src/models/modules/NativePropsSlice.tsx +170 -169
- package/src/models/modules/Result.ts +8 -8
- package/src/models/modules/common.ts +90 -90
- package/src/res/index.ts +35 -35
- package/src/utils/ColorParser.ts +150 -150
- package/src/utils/ColorUtils.tsx +414 -414
- package/src/utils/Support.d.ts +9 -0
- package/src/utils/Support.ts +85 -0
- package/src/utils/cctUtils.d.ts +1 -0
- package/src/utils/cctUtils.ts +111 -0
- package/src/utils/common.ts +186 -174
- package/src/utils/index.ts +123 -123
|
@@ -9,210 +9,210 @@ import {GlobalParams} from '../GlobalParams'
|
|
|
9
9
|
import {snakeCase} from 'lodash'
|
|
10
10
|
|
|
11
11
|
export interface NativeProps {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
familyName: string
|
|
13
|
+
deviceInfo: DeviceInfo
|
|
14
|
+
uaGroupInfo: UAGroupInfo
|
|
15
|
+
timeSchedule?: symbol
|
|
16
|
+
energieverbrauch?: object
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
export interface DeviceInfo {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
devId: string
|
|
21
|
+
pId: string
|
|
22
|
+
dps: any
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
export interface UAGroupInfo {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
tyGroupId: number
|
|
27
|
+
pId: string
|
|
28
|
+
dps: any
|
|
29
|
+
config: any
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
const initialState: NativeProps = {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
33
|
+
familyName: '',
|
|
34
|
+
deviceInfo: {
|
|
35
|
+
devId: '',
|
|
36
|
+
pId: '',
|
|
37
|
+
dps: {},
|
|
38
|
+
},
|
|
39
|
+
uaGroupInfo: {
|
|
40
|
+
tyGroupId: -1,
|
|
41
|
+
pId: '',
|
|
42
|
+
dps: {},
|
|
43
|
+
config: {},
|
|
44
|
+
},
|
|
45
|
+
timeSchedule: Symbol(),
|
|
46
|
+
energieverbrauch: {},
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
// energy generation
|
|
50
50
|
const productList = [
|
|
51
|
-
|
|
51
|
+
'rcqe1i17x0vrvws7',
|
|
52
52
|
]
|
|
53
53
|
|
|
54
54
|
const nativePropsSlice = createSlice({
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
},
|
|
88
|
-
setTimeSchedule(state, action: PayloadAction<any>) {
|
|
89
|
-
state.timeSchedule = action.payload
|
|
90
|
-
},
|
|
91
|
-
setEnergieverbrauch(state, action: PayloadAction<any>) {
|
|
92
|
-
state.energieverbrauch = action.payload
|
|
93
|
-
},
|
|
55
|
+
name: 'ldvModules',
|
|
56
|
+
initialState: initialState,
|
|
57
|
+
reducers: {
|
|
58
|
+
setNativeProps: (state, action: PayloadAction<NativeProps>) => {
|
|
59
|
+
state.deviceInfo.devId = action.payload.deviceInfo.devId
|
|
60
|
+
if (!!action.payload.familyName) {
|
|
61
|
+
state.familyName = action.payload.familyName
|
|
62
|
+
}
|
|
63
|
+
if (!!action.payload.deviceInfo.pId) {
|
|
64
|
+
state.deviceInfo.pId = action.payload.deviceInfo.pId
|
|
65
|
+
}
|
|
66
|
+
state.deviceInfo.dps = {...state.deviceInfo.dps, ...action.payload.deviceInfo.dps}
|
|
67
|
+
},
|
|
68
|
+
setGroupNativeProps: (state, action: PayloadAction<NativeProps>) => {
|
|
69
|
+
state.uaGroupInfo.tyGroupId = action.payload.uaGroupInfo.tyGroupId
|
|
70
|
+
if (!!action.payload.familyName) {
|
|
71
|
+
state.familyName = action.payload.familyName
|
|
72
|
+
}
|
|
73
|
+
if (!!action.payload.uaGroupInfo.pId) {
|
|
74
|
+
state.uaGroupInfo.pId = action.payload.uaGroupInfo.pId
|
|
75
|
+
}
|
|
76
|
+
state.uaGroupInfo.dps = {...state.uaGroupInfo.dps, ...action.payload.uaGroupInfo.dps}
|
|
77
|
+
state.uaGroupInfo.config = action.payload.uaGroupInfo.config
|
|
78
|
+
},
|
|
79
|
+
setGroupConfig: (state, action: PayloadAction<any>) => {
|
|
80
|
+
state.uaGroupInfo.config = action.payload
|
|
81
|
+
},
|
|
82
|
+
setDps(state, action: PayloadAction<any>) {
|
|
83
|
+
const dpKeys = Object.keys(action.payload)
|
|
84
|
+
dpKeys.forEach(dp => {
|
|
85
|
+
state.deviceInfo.dps[dp] = action.payload[dp]
|
|
86
|
+
})
|
|
94
87
|
},
|
|
88
|
+
setTimeSchedule(state, action: PayloadAction<any>) {
|
|
89
|
+
state.timeSchedule = action.payload
|
|
90
|
+
},
|
|
91
|
+
setEnergieverbrauch(state, action: PayloadAction<any>) {
|
|
92
|
+
state.energieverbrauch = action.payload
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
95
|
})
|
|
96
96
|
|
|
97
97
|
type AsyncBlockType<T> = () => Promise<DpsResult<T>>
|
|
98
98
|
type SyncBlockType<T> = () => DpsResult<T>
|
|
99
99
|
|
|
100
100
|
function asyncSetDps<T>(dispatch: Dispatch<any>, block: AsyncBlockType<T> | SyncBlockType<T>): Promise<Result<T>> {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
101
|
+
return new Promise<Result<T>>(async (res, _rej) => {
|
|
102
|
+
const dpsResult = await block()
|
|
103
|
+
if (dpsResult.result.success) {
|
|
104
|
+
// 只在结果成功时才改变 redux 数据
|
|
105
|
+
dispatch(setDps(dpsResult.dps))
|
|
106
|
+
}
|
|
107
|
+
res(dpsResult.result)
|
|
108
|
+
})
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
function simpleSetDps<T>(dispatch: Dispatch<any>): (deviceId: string, dps: any) => Promise<Result<T>> {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
112
|
+
return (deviceId, dps) => {
|
|
113
|
+
return asyncSetDps(dispatch, async () => {
|
|
114
|
+
console.log('发送dp数据:', deviceId, JSON.stringify(dps))
|
|
115
|
+
const res = await NativeApi.setDps(deviceId, dps)
|
|
116
|
+
if (res.result) {
|
|
117
|
+
return {
|
|
118
|
+
result: {success: true},
|
|
119
|
+
dps: dps,
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
result: {success: false, msg: res.msg},
|
|
124
|
+
}
|
|
125
|
+
})
|
|
126
|
+
}
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
function simpleSetDp<T>(dispatch: Dispatch<any>): (deviceId: string, dp: string, value: any) => Promise<Result<T>> {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
130
|
+
return (deviceId, dp, value) => {
|
|
131
|
+
const fun = simpleSetDps<T>(dispatch)
|
|
132
|
+
return fun(deviceId, {[dp]: value})
|
|
133
|
+
}
|
|
134
134
|
}
|
|
135
135
|
|
|
136
136
|
const useDeviceId = () => {
|
|
137
|
-
|
|
137
|
+
return useSelector(store => store.ldvModules.deviceInfo.devId)
|
|
138
138
|
}
|
|
139
139
|
|
|
140
140
|
const useFamilyName: () => string = () => {
|
|
141
|
-
|
|
141
|
+
return useSelector(store => store.ldvModules.familyName)
|
|
142
142
|
}
|
|
143
143
|
|
|
144
144
|
function useDp<T, R>(dp: string): [T, (value: T) => Promise<Result<R>>] {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
145
|
+
const deviceId = useDeviceId()
|
|
146
|
+
const dispatch = useDispatch()
|
|
147
|
+
const dpValue = useSelector(store => store.ldvModules.deviceInfo.dps[dp])
|
|
148
|
+
const setDp = useCallback((dpValue: T) => {
|
|
149
|
+
return simpleSetDp<R>(dispatch)(deviceId, dp, dpValue)
|
|
150
|
+
}, [])
|
|
151
|
+
return [dpValue, setDp]
|
|
152
152
|
}
|
|
153
153
|
|
|
154
154
|
function useDps<R>(): [any, (dps: any) => Promise<Result<R>>] {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
155
|
+
const deviceId = useDeviceId()
|
|
156
|
+
const dispatch = useDispatch()
|
|
157
|
+
const dps = useSelector(store => store.ldvModules.deviceInfo.dps)
|
|
158
|
+
const setDps = useCallback((dps: any) => {
|
|
159
|
+
return simpleSetDps<R>(dispatch)(deviceId, dps)
|
|
160
|
+
}, [])
|
|
161
|
+
return [dps, setDps]
|
|
162
162
|
}
|
|
163
163
|
|
|
164
164
|
interface DpState {
|
|
165
|
-
|
|
165
|
+
switch: boolean;
|
|
166
166
|
|
|
167
|
-
|
|
167
|
+
[dpCode: string]: DpValue;
|
|
168
168
|
}
|
|
169
169
|
|
|
170
170
|
const useDeviceInfo: () => DevInfo<DpState> = () => {
|
|
171
|
-
|
|
171
|
+
return useSelector(state => state.devInfo)
|
|
172
172
|
}
|
|
173
173
|
|
|
174
174
|
const useTimeSchedule = (): [v: symbol | undefined, f: any] => {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
175
|
+
const dps = useSelector(store => store.ldvModules.timeSchedule)
|
|
176
|
+
const dispatch = useDispatch()
|
|
177
|
+
const setTimeScheduleFn = (value: Symbol) => {
|
|
178
|
+
dispatch(setTimeSchedule(value))
|
|
179
|
+
}
|
|
180
|
+
return [dps, setTimeScheduleFn]
|
|
181
181
|
}
|
|
182
182
|
|
|
183
183
|
const useEnergieverbrauch = () => {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
184
|
+
const dps = useSelector(store => store.ldvModules.energieverbrauch)
|
|
185
|
+
const dispatch = useDispatch()
|
|
186
|
+
const setEnergieverbrauchFn = (value) => {
|
|
187
|
+
dispatch(setEnergieverbrauch(value))
|
|
188
|
+
}
|
|
189
|
+
return [dps, setEnergieverbrauchFn]
|
|
190
190
|
}
|
|
191
191
|
|
|
192
192
|
export const useEngergyGeneration = () => {
|
|
193
|
-
|
|
194
|
-
|
|
193
|
+
const {productId} = useDeviceInfo()
|
|
194
|
+
return productList.some(val => val === productId)
|
|
195
195
|
}
|
|
196
196
|
|
|
197
197
|
export function useUAGroupInfo(): UAGroupInfo {
|
|
198
|
-
|
|
198
|
+
return useSelector(state => state.ldvModules.uaGroupInfo)
|
|
199
199
|
}
|
|
200
200
|
|
|
201
201
|
export function useGroupConfig<T>(): [T, (dps: any, newConfig: T) => Promise<Result<any>>] {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
202
|
+
const tyGroupId = useUAGroupInfo().tyGroupId
|
|
203
|
+
const config = useUAGroupInfo().config as T
|
|
204
|
+
const dispatch = useDispatch()
|
|
205
|
+
const {setGroupConfig} = nativePropsSlice.actions
|
|
206
|
+
const setConfig = useCallback(async (dps: any, newConfig: T) => {
|
|
207
|
+
// 发送控制命令
|
|
208
|
+
const res = await NativeApi.groupControl(tyGroupId, JSON.stringify(dps), JSON.stringify(newConfig))
|
|
209
|
+
if (res.success) {
|
|
210
|
+
// 只在结果成功时才改变 redux 数据
|
|
211
|
+
dispatch(setGroupConfig(newConfig))
|
|
212
|
+
}
|
|
213
|
+
return res
|
|
214
|
+
}, [])
|
|
215
|
+
return [config, setConfig]
|
|
216
216
|
}
|
|
217
217
|
|
|
218
218
|
/**
|
|
@@ -223,40 +223,41 @@ export function useGroupConfig<T>(): [T, (dps: any, newConfig: T) => Promise<Res
|
|
|
223
223
|
*/
|
|
224
224
|
export function useGroupConfigFeature<GC, GCPT extends { [K in keyof GC]: GC[K] }[keyof GC]>
|
|
225
225
|
(key: keyof GC, extraDps: any = {}): [GCPT, (value: GCPT, dpValue: any) => Promise<Result<any>>] {
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
226
|
+
const [groupConfig, setGroupConfig] = useGroupConfig<GC>()
|
|
227
|
+
const setGroupConfigFeature = async (value: GCPT, dpValue: any) => {
|
|
228
|
+
return await setGroupConfig(
|
|
229
|
+
{
|
|
230
|
+
[GlobalParams.dpSchemaMap[snakeCase(key as string)].dp]: dpValue,
|
|
231
|
+
...extraDps,
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
...groupConfig,
|
|
235
|
+
[key]: value,
|
|
236
|
+
},
|
|
237
|
+
)
|
|
238
|
+
}
|
|
239
|
+
return [groupConfig[key] as GCPT, setGroupConfigFeature]
|
|
240
240
|
}
|
|
241
241
|
|
|
242
242
|
export const ldvModules = nativePropsSlice.reducer
|
|
243
243
|
|
|
244
244
|
export const {
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
245
|
+
setNativeProps,
|
|
246
|
+
setGroupNativeProps,
|
|
247
|
+
setDps,
|
|
248
|
+
setTimeSchedule,
|
|
249
|
+
setEnergieverbrauch,
|
|
250
250
|
} = nativePropsSlice.actions
|
|
251
251
|
|
|
252
252
|
export {
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
253
|
+
asyncSetDps,
|
|
254
|
+
simpleSetDps,
|
|
255
|
+
simpleSetDp,
|
|
256
|
+
useDeviceId,
|
|
257
|
+
useDeviceInfo,
|
|
258
|
+
useDp,
|
|
259
|
+
useDps,
|
|
260
|
+
useFamilyName,
|
|
261
|
+
useTimeSchedule,
|
|
262
|
+
useEnergieverbrauch,
|
|
262
263
|
}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
export interface Result<T> {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
success: boolean;
|
|
3
|
+
data?: T | undefined,
|
|
4
|
+
msg?: string | undefined
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
export interface DpsResult<T> {
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
result: Result<T>,
|
|
9
|
+
dps?: any | undefined
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export interface NativeResult<T> {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
result: boolean
|
|
14
|
+
data?: T
|
|
15
|
+
msg?: string
|
|
16
16
|
}
|
|
@@ -14,16 +14,16 @@ import {ldvModules} from './NativePropsSlice'
|
|
|
14
14
|
const {putDeviceData} = TYSdk.device
|
|
15
15
|
|
|
16
16
|
export interface DpState {
|
|
17
|
-
|
|
17
|
+
switch: boolean;
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
[dpCode: string]: DpValue;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
export interface Log {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
strCodes: string;
|
|
24
|
+
strIds: string;
|
|
25
|
+
time: string;
|
|
26
|
+
isSend: boolean;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
type Logs = Array<Log>;
|
|
@@ -42,12 +42,12 @@ const consoleChange = createAction('CONSOLECHNAGE')
|
|
|
42
42
|
const clearConsole = createAction('CLEARCONSOLE')
|
|
43
43
|
|
|
44
44
|
export const actions = {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
45
|
+
devInfoChange,
|
|
46
|
+
deviceChange,
|
|
47
|
+
responseUpdateDp,
|
|
48
|
+
updateDp,
|
|
49
|
+
consoleChange,
|
|
50
|
+
clearConsole,
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
export type Actions = { [K in keyof typeof actions]: ReturnType<typeof actions[K]> };
|
|
@@ -56,106 +56,106 @@ export type Actions = { [K in keyof typeof actions]: ReturnType<typeof actions[K
|
|
|
56
56
|
* reducers
|
|
57
57
|
*/
|
|
58
58
|
const dpState = handleActions<DpState, UpdateDpStatePayload | UpdateDevInfoPayload>(
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
},
|
|
66
|
-
|
|
67
|
-
[responseUpdateDp.toString()]: (state, action: Actions['responseUpdateDp']) => ({
|
|
68
|
-
...state,
|
|
69
|
-
...action.payload,
|
|
70
|
-
}),
|
|
59
|
+
{
|
|
60
|
+
[devInfoChange.toString()]: (state, action: Actions['devInfoChange']) => {
|
|
61
|
+
return {
|
|
62
|
+
...state,
|
|
63
|
+
...action.payload.state,
|
|
64
|
+
}
|
|
71
65
|
},
|
|
72
|
-
|
|
66
|
+
|
|
67
|
+
[responseUpdateDp.toString()]: (state, action: Actions['responseUpdateDp']) => ({
|
|
68
|
+
...state,
|
|
69
|
+
...action.payload,
|
|
70
|
+
}),
|
|
71
|
+
},
|
|
72
|
+
{} as DpState,
|
|
73
73
|
)
|
|
74
74
|
|
|
75
75
|
const devInfo = handleActions<DevInfo<DpState>>(
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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
88
|
)
|
|
89
89
|
|
|
90
90
|
let isSend = false
|
|
91
91
|
|
|
92
92
|
const formatLogs = (state: Logs, action: { payload: UpdateDpStatePayload }, send: boolean) => {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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
108
|
}
|
|
109
109
|
|
|
110
110
|
const logs = handleActions<Logs, undefined | UpdateDpStatePayload | DevInfo>(
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
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()]: () => [],
|
|
111
|
+
{
|
|
112
|
+
[consoleChange.toString()]: state => {
|
|
113
|
+
isSend = true
|
|
114
|
+
return state
|
|
133
115
|
},
|
|
134
|
-
|
|
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
135
|
)
|
|
136
136
|
|
|
137
137
|
export const reducers = {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
138
|
+
dpState,
|
|
139
|
+
devInfo,
|
|
140
|
+
logs,
|
|
141
|
+
ldvModules,
|
|
142
142
|
}
|
|
143
143
|
|
|
144
144
|
/**
|
|
145
145
|
* epics
|
|
146
146
|
*/
|
|
147
147
|
const dpUpdateEpic$ = (action$: ActionsObservable<Actions['updateDp']>) => {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
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
159
|
}
|
|
160
160
|
|
|
161
161
|
export const epics = [dpUpdateEpic$]
|