@ledvance/ui-biz-bundle 1.1.65 → 1.1.67
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 +1 -1
- package/src/navigation/Routers.ts +1 -0
- package/src/newModules/biorhythm/BiorhythmPage.tsx +11 -7
- package/src/newModules/fixedTime/FixedTimePage.tsx +4 -3
- package/src/newModules/mood/DynamicMoodEditorPage.tsx +16 -24
- package/src/newModules/mood/Interface.ts +1 -0
- package/src/newModules/mood/MixDynamicMoodEditor.tsx +40 -41
- package/src/newModules/mood/MoodActions.ts +45 -48
- package/src/newModules/mood/MoodInfo.ts +34 -34
- package/src/newModules/mood/MoodItem.tsx +19 -7
- package/src/newModules/mood/MoodPage.tsx +31 -30
- package/src/newModules/mood/MoodParse.ts +2 -1
- package/src/newModules/mood/RecommendMoodItem.tsx +18 -5
- package/src/newModules/mood/Router.ts +6 -16
- package/src/newModules/mood/StaticMoodEditorPage.tsx +45 -105
- package/src/newModules/randomTime/RandomTimePage.tsx +4 -3
- package/src/newModules/remoteControl/RemoteControlActions.ts +6 -0
- package/src/newModules/remoteControl/RemoteControlPage.tsx +51 -0
- package/src/newModules/remoteControl/Router.ts +16 -0
- package/src/newModules/select/Route.ts +17 -0
- package/src/newModules/select/SelectPage.d.ts +12 -0
- package/src/newModules/select/SelectPage.tsx +138 -0
- package/src/newModules/sleepWakeUp/Interface.ts +70 -0
- package/src/newModules/sleepWakeUp/Router.ts +25 -0
- package/src/newModules/sleepWakeUp/SleepWakeUpActions.ts +317 -0
- package/src/newModules/sleepWakeUp/SleepWakeUpDetailPage.tsx +661 -0
- package/src/newModules/sleepWakeUp/SleepWakeUpPage.tsx +456 -0
- package/src/newModules/sleepWakeUp/utils.ts +254 -0
- package/src/newModules/mood/tools.ts +0 -12
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react'
|
|
2
|
+
import { useDp, useDeviceId } from '@ledvance/base/src/models/modules/NativePropsSlice'
|
|
3
|
+
import { getFeature, putFeature } from '@ledvance/base/src/api/native'
|
|
4
|
+
import { hex2Int, spliceByStep } from '@ledvance/base/src/utils/common'
|
|
5
|
+
import { SleepData, SleepItem, SleepUIData, SleepUIItem, WakeUpData, WakeUpItem, WakeUpUIData, WakeUpUIItem } from './Interface'
|
|
6
|
+
import { cloneDeep, padStart } from 'lodash'
|
|
7
|
+
import { parseJSON, to16 } from '@tuya/tuya-panel-lamp-sdk/lib/utils'
|
|
8
|
+
import { Result } from '@ledvance/base/src/models/modules/Result'
|
|
9
|
+
import I18n from '@ledvance/base/src/i18n'
|
|
10
|
+
const sleepPlanFeatureId = 'SleepPlan'
|
|
11
|
+
const wakeUpPlanFeatureId = 'WakeUpPlan'
|
|
12
|
+
|
|
13
|
+
// 接口失败重试
|
|
14
|
+
let retryNumber = 0
|
|
15
|
+
const putFeatureFn = async (devId, featureId, data) => {
|
|
16
|
+
let status;
|
|
17
|
+
await putFeature(devId, featureId, data).then(res => {
|
|
18
|
+
if (!res?.result && retryNumber < 3) {
|
|
19
|
+
retryNumber += 1
|
|
20
|
+
putFeatureFn(devId, featureId, data).then()
|
|
21
|
+
}
|
|
22
|
+
if (res?.result) {
|
|
23
|
+
retryNumber = 0
|
|
24
|
+
status = res?.result
|
|
25
|
+
}
|
|
26
|
+
})
|
|
27
|
+
return status
|
|
28
|
+
}
|
|
29
|
+
let wakeUpTimerId: number | undefined = undefined
|
|
30
|
+
type WakeUpType = (wakeUpDp: string, disableFeature?: boolean) => [WakeUpUIItem[], (wakeUpData: WakeUpUIData) => Promise<Result<any>>, boolean]
|
|
31
|
+
// @ts-ignore
|
|
32
|
+
export const useWakeUp: WakeUpType = (wakeUpDp, disableFeature) => {
|
|
33
|
+
const devId = useDeviceId()
|
|
34
|
+
const [wakeUp, setWakeUp]: [string, (wakeUp: string) => Promise<Result<any>>] = useDp(wakeUpDp)
|
|
35
|
+
const [wakeUpList, setWakeUpList] = useState(wakeUpDp2Obj(wakeUp)?.nodes || [])
|
|
36
|
+
const [isComplete, setIsComplete] = useState(false)
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
if(disableFeature) {
|
|
39
|
+
setIsComplete(true)
|
|
40
|
+
setWakeUpList(wakeUpDp2Obj(wakeUp)?.nodes || [])
|
|
41
|
+
return
|
|
42
|
+
}
|
|
43
|
+
wakeUpTimerId = setTimeout(() => {
|
|
44
|
+
setIsComplete(false)
|
|
45
|
+
getFeature(devId, wakeUpPlanFeatureId).then(res => {
|
|
46
|
+
setIsComplete(true)
|
|
47
|
+
if (res.result) {
|
|
48
|
+
const nodes = wakeUpDp2Obj(wakeUp)?.nodes || []
|
|
49
|
+
const uiPlan = nodes.map((item, idx) => {
|
|
50
|
+
const plan = res.data[idx]
|
|
51
|
+
const dp = parseJSON(plan?.startTime)?.dp
|
|
52
|
+
const featureItem = (plan && dp) ? plan : res.data.find(p => parseJSON(p?.startTime)?.dp)?.includes(item.nodeHex)
|
|
53
|
+
return {
|
|
54
|
+
...item,
|
|
55
|
+
id: idx,
|
|
56
|
+
name: featureItem ? featureItem?.name : `${I18n.getLang('sleepwakeschedule_field_3_Times_chips_text')} ${idx + 1}`
|
|
57
|
+
}
|
|
58
|
+
})
|
|
59
|
+
setWakeUpList(uiPlan || [])
|
|
60
|
+
}
|
|
61
|
+
})
|
|
62
|
+
}, 250)
|
|
63
|
+
|
|
64
|
+
return () =>{
|
|
65
|
+
if(wakeUpTimerId) clearTimeout(wakeUpTimerId)
|
|
66
|
+
}
|
|
67
|
+
}, [wakeUp])
|
|
68
|
+
|
|
69
|
+
const setWakeUpFn = async (wakeUp: WakeUpUIData) => {
|
|
70
|
+
const featureData = wakeUp?.nodes.map(item => {
|
|
71
|
+
return {
|
|
72
|
+
name: item.name,
|
|
73
|
+
startTime: JSON.stringify({
|
|
74
|
+
dp: wakeUpNode2Dp(item)
|
|
75
|
+
})
|
|
76
|
+
}
|
|
77
|
+
})
|
|
78
|
+
const res = await putFeature(devId, wakeUpPlanFeatureId, featureData || [])
|
|
79
|
+
if (res.result) {
|
|
80
|
+
setWakeUp(wakeUpObj2Dp(wakeUp)).then()
|
|
81
|
+
return {
|
|
82
|
+
success: true
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
success: false
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return [wakeUpList, setWakeUpFn, isComplete]
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
const wakeUpDp2Obj = (dp: string): WakeUpData | undefined => {
|
|
94
|
+
if (!dp || dp?.length <= 6) return
|
|
95
|
+
const version = hex2Int(dp.slice(0, 2))
|
|
96
|
+
const num = hex2Int(dp.slice(2, 4))
|
|
97
|
+
const nodes = spliceByStep(dp.slice(4), 24).map((plan) => {
|
|
98
|
+
const enable = !!hex2Int(plan.slice(0, 2))
|
|
99
|
+
const weeks = parseInt(plan.slice(2, 4), 16).toString(2).padStart(8, '0')
|
|
100
|
+
.split('')
|
|
101
|
+
.reverse()
|
|
102
|
+
.map(v => parseInt(v, 10))
|
|
103
|
+
const delay = hex2Int(plan.slice(4, 6))
|
|
104
|
+
const hour = hex2Int(plan.slice(6, 8))
|
|
105
|
+
const minute = hex2Int(plan.slice(8, 10))
|
|
106
|
+
const h = hex2Int(plan.slice(10, 12)) * 100 + hex2Int(plan.slice(12, 14))
|
|
107
|
+
const s = hex2Int(plan.slice(14, 16))
|
|
108
|
+
const v = hex2Int(plan.slice(16, 18))
|
|
109
|
+
const brightness = hex2Int(plan.slice(18, 20))
|
|
110
|
+
const temperature = hex2Int(plan.slice(20, 22))
|
|
111
|
+
const last = hex2Int(plan.slice(22, 24))
|
|
112
|
+
const endTime = hour * 60 + minute
|
|
113
|
+
const endMin = endTime - delay * 5
|
|
114
|
+
const startTime = endMin < 0 ? 1440 + endMin : endMin
|
|
115
|
+
const cloneWeek = cloneDeep(weeks)
|
|
116
|
+
cloneWeek.pop()
|
|
117
|
+
const weeksValue = padStart([...cloneWeek].join(''), 8, '0')
|
|
118
|
+
const weeksHex = to16(parseInt(weeksValue, 2), 2)
|
|
119
|
+
const nodeHex = plan.slice(0, 2) + weeksHex + plan.slice(4)
|
|
120
|
+
return {
|
|
121
|
+
enable, weeks, delay, hour, minute, h, s, v, brightness, temperature, last, nodeHex, isSleep: false,
|
|
122
|
+
startTime,
|
|
123
|
+
endTime,
|
|
124
|
+
isColorMode: !!(h && s && v)
|
|
125
|
+
}
|
|
126
|
+
})
|
|
127
|
+
return {
|
|
128
|
+
version,
|
|
129
|
+
num,
|
|
130
|
+
nodes
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const wakeUpObj2Dp = (wakeUp: WakeUpData) => {
|
|
135
|
+
const { version, nodes } = wakeUp
|
|
136
|
+
const versionHex = to16(version)
|
|
137
|
+
const numHex = to16(nodes.length)
|
|
138
|
+
const nodeHex = nodes.map(node => {
|
|
139
|
+
const enableHex = node.enable ? '01' : '00'
|
|
140
|
+
const weeksValue = padStart([...node.weeks].reverse().join(''), 8, '0')
|
|
141
|
+
const weeksHex = to16(parseInt(weeksValue, 2), 2)
|
|
142
|
+
const delayHex = to16(node.delay)
|
|
143
|
+
const hourHex = to16(node.hour)
|
|
144
|
+
const minuteHex = to16(node.minute)
|
|
145
|
+
const hString = node.h.toString().padStart(4, '0')
|
|
146
|
+
const h = to16(Number(hString.slice(0, 2))) + to16(Number(hString.slice(2, 4)))
|
|
147
|
+
const s = to16(node.s)
|
|
148
|
+
const v = to16(node.v)
|
|
149
|
+
const brightness = to16(node.brightness)
|
|
150
|
+
const temperature = to16(node.temperature)
|
|
151
|
+
const lastHex = to16(node.last)
|
|
152
|
+
return `${enableHex}${weeksHex}${delayHex}${hourHex}${minuteHex}${h}${s}${v}${brightness}${temperature}${lastHex}`
|
|
153
|
+
}).join('')
|
|
154
|
+
return versionHex + numHex + nodeHex
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export const wakeUpNode2Dp = (node: WakeUpItem) =>{
|
|
158
|
+
const enableHex = node.enable ? '01' : '00'
|
|
159
|
+
const cloneWeek = cloneDeep(node.weeks)
|
|
160
|
+
cloneWeek.pop()
|
|
161
|
+
const weeksValue = padStart([...cloneWeek].join(''), 8, '0')
|
|
162
|
+
const weeksHex = to16(parseInt(weeksValue, 2), 2)
|
|
163
|
+
const delayHex = to16(node.delay)
|
|
164
|
+
const hourHex = to16(node.hour)
|
|
165
|
+
const minuteHex = to16(node.minute)
|
|
166
|
+
const hString = node.h.toString().padStart(4, '0')
|
|
167
|
+
const h = to16(Number(hString.slice(0, 2))) + to16(Number(hString.slice(2, 4)))
|
|
168
|
+
const s = to16(node.s)
|
|
169
|
+
const v = to16(node.v)
|
|
170
|
+
const brightness = to16(node.brightness)
|
|
171
|
+
const temperature = to16(node.temperature)
|
|
172
|
+
const lastHex = to16(node.last)
|
|
173
|
+
return `${enableHex}${weeksHex}${delayHex}${hourHex}${minuteHex}${h}${s}${v}${brightness}${temperature}${lastHex}`
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
let sleepTimerId: number | undefined = undefined
|
|
177
|
+
type SleepModeType = (sleepDp: string, disableFeature?: boolean) => [SleepUIItem[], (sleepData: SleepUIData) => Promise<Result<any>>, boolean]
|
|
178
|
+
// @ts-ignore
|
|
179
|
+
export const useSleepMode: SleepModeType = (sleepDp, disableFeature) => {
|
|
180
|
+
const devId = useDeviceId()
|
|
181
|
+
const [sleepMode, setSleepMode]: [string, (sleep: string) => Promise<Result<any>>] = useDp(sleepDp)
|
|
182
|
+
const [sleepPlan, setSleepPlan] = useState(sleepDp2Obj(sleepMode)?.nodes || [])
|
|
183
|
+
const [isComplete, setIsComplete] = useState(false)
|
|
184
|
+
useEffect(() => {
|
|
185
|
+
if(disableFeature) {
|
|
186
|
+
setIsComplete(true)
|
|
187
|
+
setSleepPlan(sleepDp2Obj(sleepMode)?.nodes || [])
|
|
188
|
+
return
|
|
189
|
+
}
|
|
190
|
+
sleepTimerId = setTimeout(() =>{
|
|
191
|
+
setIsComplete(false)
|
|
192
|
+
getFeature(devId, sleepPlanFeatureId).then(res => {
|
|
193
|
+
setIsComplete(true)
|
|
194
|
+
if (res.result) {
|
|
195
|
+
const nodes = sleepDp2Obj(sleepMode)?.nodes || []
|
|
196
|
+
const uiPlan = nodes.map((item, idx) => {
|
|
197
|
+
const plan = res.data[idx]
|
|
198
|
+
const dp = parseJSON(plan?.startTime)?.dp
|
|
199
|
+
const featureItem = (plan && dp) ? plan : res.data.find(p => parseJSON(p?.startTime)?.dp)?.includes(item.nodeHex)
|
|
200
|
+
return {
|
|
201
|
+
...item,
|
|
202
|
+
id: idx,
|
|
203
|
+
name: featureItem ? featureItem?.name : `${I18n.getLang('sleepwakeschedule_field_3_Times_chips2_text')} ${idx + 1}`
|
|
204
|
+
}
|
|
205
|
+
})
|
|
206
|
+
setSleepPlan(uiPlan || [])
|
|
207
|
+
}
|
|
208
|
+
})
|
|
209
|
+
}, 250)
|
|
210
|
+
|
|
211
|
+
return () =>{
|
|
212
|
+
if(sleepTimerId) clearTimeout(sleepTimerId)
|
|
213
|
+
}
|
|
214
|
+
}, [sleepMode])
|
|
215
|
+
|
|
216
|
+
const setSleepPlanFn = async (sleep: SleepUIData) => {
|
|
217
|
+
const featureData = sleep?.nodes.map(item => {
|
|
218
|
+
return {
|
|
219
|
+
name: item.name,
|
|
220
|
+
startTime: JSON.stringify({
|
|
221
|
+
dp: sleepNode2Dp(item)
|
|
222
|
+
})
|
|
223
|
+
}
|
|
224
|
+
})
|
|
225
|
+
const res = await putFeature(devId, sleepPlanFeatureId, featureData || [])
|
|
226
|
+
if (res.result) {
|
|
227
|
+
setSleepMode(sleepObj2Dp(sleep)).then()
|
|
228
|
+
return {
|
|
229
|
+
success: true
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return {
|
|
233
|
+
success: false
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
return [sleepPlan, setSleepPlanFn, isComplete]
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
export const sleepDp2Obj = (dp: string): SleepData | undefined => {
|
|
240
|
+
if (!dp || dp?.length <= 6) return
|
|
241
|
+
const version = hex2Int(dp.slice(0, 2))
|
|
242
|
+
const num = hex2Int(dp.slice(2, 4))
|
|
243
|
+
const nodes = spliceByStep(dp.slice(4), 22).map(plan => {
|
|
244
|
+
const enable = !!hex2Int(plan.slice(0, 2))
|
|
245
|
+
const weeks = parseInt(plan.slice(2, 4), 16).toString(2).padStart(8, '0')
|
|
246
|
+
.split('')
|
|
247
|
+
.reverse()
|
|
248
|
+
.map(v => parseInt(v, 10))
|
|
249
|
+
const delay = hex2Int(plan.slice(4, 6))
|
|
250
|
+
const hour = hex2Int(plan.slice(6, 8))
|
|
251
|
+
const minute = hex2Int(plan.slice(8, 10))
|
|
252
|
+
const h = hex2Int(plan.slice(10, 12)) * 100 + hex2Int(plan.slice(12, 14))
|
|
253
|
+
const s = hex2Int(plan.slice(14, 16))
|
|
254
|
+
const v = hex2Int(plan.slice(16, 18))
|
|
255
|
+
const brightness = hex2Int(plan.slice(18, 20))
|
|
256
|
+
const temperature = hex2Int(plan.slice(20, 22))
|
|
257
|
+
const startTime = hour * 60 + minute
|
|
258
|
+
const endMin = startTime + delay * 5
|
|
259
|
+
const endTime = endMin > 1440 ? endMin - 1440 : endMin
|
|
260
|
+
const cloneWeek = cloneDeep(weeks)
|
|
261
|
+
cloneWeek.pop()
|
|
262
|
+
const weeksValue = padStart([...cloneWeek].join(''), 8, '0')
|
|
263
|
+
const weeksHex = to16(parseInt(weeksValue, 2), 2)
|
|
264
|
+
const nodeHex = plan.slice(0, 2) + weeksHex + plan.slice(4)
|
|
265
|
+
return {
|
|
266
|
+
enable, weeks, delay, hour, minute, h, s, v, brightness, temperature, nodeHex, isSleep: true,
|
|
267
|
+
startTime,
|
|
268
|
+
endTime,
|
|
269
|
+
isColorMode: !!(h && s && v)
|
|
270
|
+
}
|
|
271
|
+
})
|
|
272
|
+
return {
|
|
273
|
+
version,
|
|
274
|
+
num,
|
|
275
|
+
nodes
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
export const sleepObj2Dp = (sleep: SleepData) => {
|
|
280
|
+
const { version, nodes } = sleep
|
|
281
|
+
const versionHex = to16(version)
|
|
282
|
+
const numHex = to16(nodes.length)
|
|
283
|
+
const nodeHex = nodes.map(node => {
|
|
284
|
+
const enableHex = node.enable ? '01' : '00'
|
|
285
|
+
const weeksValue = padStart([...node.weeks].reverse().join(''), 8, '0')
|
|
286
|
+
const weeksHex = to16(parseInt(weeksValue, 2), 2)
|
|
287
|
+
const delayHex = to16(node.delay)
|
|
288
|
+
const hourHex = to16(node.hour)
|
|
289
|
+
const minuteHex = to16(node.minute)
|
|
290
|
+
const hString = node.h.toString().padStart(4, '0')
|
|
291
|
+
const h = to16(Number(hString.slice(0, 2))) + to16(Number(hString.slice(2, 4)))
|
|
292
|
+
const s = to16(node.s)
|
|
293
|
+
const v = to16(node.v)
|
|
294
|
+
const brightness = to16(node.brightness)
|
|
295
|
+
const temperature = to16(node.temperature)
|
|
296
|
+
return `${enableHex}${weeksHex}${delayHex}${hourHex}${minuteHex}${h}${s}${v}${brightness}${temperature}`
|
|
297
|
+
}).join('')
|
|
298
|
+
return versionHex + numHex + nodeHex
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
export const sleepNode2Dp = (node: SleepItem) => {
|
|
302
|
+
const enableHex = node.enable ? '01' : '00'
|
|
303
|
+
const cloneWeek = cloneDeep(node.weeks)
|
|
304
|
+
cloneWeek.pop()
|
|
305
|
+
const weeksValue = padStart([...cloneWeek].join(''), 8, '0')
|
|
306
|
+
const weeksHex = to16(parseInt(weeksValue, 2), 2)
|
|
307
|
+
const delayHex = to16(node.delay)
|
|
308
|
+
const hourHex = to16(node.hour)
|
|
309
|
+
const minuteHex = to16(node.minute)
|
|
310
|
+
const hString = node.h.toString().padStart(4, '0')
|
|
311
|
+
const h = to16(Number(hString.slice(0, 2))) + to16(Number(hString.slice(2, 4)))
|
|
312
|
+
const s = to16(node.s)
|
|
313
|
+
const v = to16(node.v)
|
|
314
|
+
const brightness = to16(node.brightness)
|
|
315
|
+
const temperature = to16(node.temperature)
|
|
316
|
+
return `${enableHex}${weeksHex}${delayHex}${hourHex}${minuteHex}${h}${s}${v}${brightness}${temperature}`
|
|
317
|
+
}
|