@ledvance/ui-biz-bundle 1.1.67 → 1.1.69
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 -31
- package/.eslintignore +5 -5
- package/.eslintrc.js +27 -27
- package/.prettierrc.js +1 -1
- package/.versionrc +5 -5
- package/package.json +74 -74
- package/rn-cli.config.js +8 -8
- package/src/hooks/DeviceDpStateHooks.d.ts +14 -14
- package/src/hooks/DeviceDpStateHooks.ts +50 -50
- package/src/modules/biorhythm/BiorhythmActions.d.ts +8 -8
- package/src/modules/biorhythm/BiorhythmActions.ts +324 -324
- package/src/modules/biorhythm/BiorhythmBean.d.ts +58 -58
- package/src/modules/biorhythm/BiorhythmBean.ts +230 -230
- package/src/modules/biorhythm/BiorhythmEditPage.d.ts +14 -14
- package/src/modules/biorhythm/BiorhythmEditPage.tsx +324 -324
- package/src/modules/biorhythm/BiorhythmPage.d.ts +10 -10
- package/src/modules/biorhythm/BiorhythmPage.tsx +796 -796
- package/src/modules/biorhythm/IconSelect.d.ts +2 -2
- package/src/modules/biorhythm/IconSelect.tsx +81 -81
- package/src/modules/biorhythm/Router.ts +34 -34
- package/src/modules/biorhythm/circular/ItemIcon.d.ts +22 -22
- package/src/modules/biorhythm/circular/ItemIcon.tsx +172 -172
- package/src/modules/biorhythm/circular/Progress.d.ts +24 -24
- package/src/modules/biorhythm/circular/Progress.tsx +411 -411
- package/src/modules/biorhythm/circular/TimeCircular.d.ts +11 -11
- package/src/modules/biorhythm/circular/TimeCircular.tsx +70 -70
- package/src/modules/biorhythm/iconListData.d.ts +7 -7
- package/src/modules/biorhythm/iconListData.ts +29 -29
- package/src/modules/biorhythm/pIdList.d.ts +2 -2
- package/src/modules/biorhythm/pIdList.ts +35 -35
- package/src/modules/biorhythm/res/BiologicalRes.d.ts +43 -43
- package/src/modules/biorhythm/res/BiologicalRes.ts +41 -41
- package/src/modules/config/ldvConfig.d.ts +2 -2
- package/src/modules/config/ldvConfig.tsx +18 -18
- package/src/modules/fixedTime/FixedTimeActions.ts +173 -173
- package/src/modules/fixedTime/FixedTimeDetailPage.tsx +372 -372
- package/src/modules/fixedTime/FixedTimePage.tsx +213 -213
- package/src/modules/fixedTime/Router.ts +26 -26
- package/src/modules/flags/FlagActions.ts +267 -267
- package/src/modules/flags/FlagEditPage.tsx +441 -441
- package/src/modules/flags/FlagInfo.tsx +563 -563
- package/src/modules/flags/FlagItem.tsx +90 -90
- package/src/modules/flags/FlagPage.tsx +277 -277
- package/src/modules/flags/Router.ts +25 -25
- package/src/modules/history/HistoryPage.d.ts +2 -2
- package/src/modules/history/HistoryPage.tsx +261 -261
- package/src/modules/history/Router.ts +16 -16
- package/src/modules/history/SwitchHistoryPageActions.d.ts +14 -14
- package/src/modules/history/SwitchHistoryPageActions.ts +76 -76
- package/src/modules/mood/AddMoodPage.d.ts +10 -10
- package/src/modules/mood/AddMoodPage.tsx +792 -792
- package/src/modules/mood/DynamicMoodEditorPage.d.ts +6 -6
- package/src/modules/mood/DynamicMoodEditorPage.tsx +561 -561
- package/src/modules/mood/FantasyMood.tsx +176 -176
- package/src/modules/mood/FantasyMoodEditPage.tsx +582 -582
- package/src/modules/mood/FantasyMoodItem.tsx +104 -104
- package/src/modules/mood/FantasyRouter.ts +35 -35
- package/src/modules/mood/MixMood/AddMixMoodPage.tsx +247 -247
- package/src/modules/mood/MixMood/MixMoodActions.ts +128 -128
- package/src/modules/mood/MixMood/MixMoodEditPage.tsx +721 -721
- package/src/modules/mood/MixMood/MixMoodItem.tsx +134 -134
- package/src/modules/mood/MixMood/MixMoodPage.tsx +326 -326
- package/src/modules/mood/MixMood/MixSceneBeans.ts +364 -364
- package/src/modules/mood/MixMood/RecommendMixMoodItem.tsx +69 -69
- package/src/modules/mood/MixMood/Router.ts +44 -44
- package/src/modules/mood/MoodItem.d.ts +11 -11
- package/src/modules/mood/MoodItem.tsx +114 -114
- package/src/modules/mood/MoodPage.d.ts +16 -16
- package/src/modules/mood/MoodPage.tsx +296 -296
- package/src/modules/mood/RecommendMoodItem.d.ts +13 -13
- package/src/modules/mood/RecommendMoodItem.tsx +74 -74
- package/src/modules/mood/Router.ts +53 -53
- package/src/modules/mood/StaticMoodEditorPage.d.ts +16 -16
- package/src/modules/mood/StaticMoodEditorPage.tsx +320 -320
- package/src/modules/mood/tools.d.ts +3 -3
- package/src/modules/mood/tools.ts +11 -11
- package/src/modules/music/MusicDataBean.d.ts +47 -47
- package/src/modules/music/MusicDataBean.ts +167 -167
- package/src/modules/music/MusicManager.d.ts +27 -27
- package/src/modules/music/MusicManager.ts +207 -207
- package/src/modules/music/MusicPage.d.ts +10 -10
- package/src/modules/music/MusicPage.tsx +347 -347
- package/src/modules/music/MusicPageActions.d.ts +35 -35
- package/src/modules/music/MusicPageActions.ts +317 -317
- package/src/modules/music/Router.ts +16 -16
- package/src/modules/music/SelecetGenre.d.ts +7 -7
- package/src/modules/music/SelecetGenre.tsx +63 -63
- package/src/modules/music/color.d.ts +2 -2
- package/src/modules/music/color.ts +73 -73
- package/src/modules/music/res/index.d.ts +10 -10
- package/src/modules/music/res/index.ts +9 -9
- package/src/modules/powerOnBehavior/PowerOnBehaviorActions.ts +11 -11
- package/src/modules/powerOnBehavior/PowerOnBehaviorPage.tsx +173 -173
- package/src/modules/powerOnBehavior/Router.ts +16 -16
- package/src/modules/randomTime/RandomTimeActions.ts +160 -160
- package/src/modules/randomTime/RandomTimeDetailPage.tsx +337 -337
- package/src/modules/randomTime/RandomTimePage.tsx +214 -214
- package/src/modules/randomTime/Router.ts +25 -25
- package/src/modules/randomTime/Summary.tsx +122 -122
- package/src/modules/scene/SceneAction.d.ts +13 -13
- package/src/modules/scene/SceneAction.ts +473 -473
- package/src/modules/scene/SceneDetailPage.d.ts +1 -1
- package/src/modules/scene/SceneDetailPage.tsx +421 -421
- package/src/modules/scene/SceneInfo.d.ts +72 -72
- package/src/modules/scene/SceneInfo.ts +1059 -1059
- package/src/modules/scene/ScenePage.d.ts +7 -7
- package/src/modules/scene/ScenePage.tsx +147 -147
- package/src/modules/select/SelectPage.d.ts +12 -12
- package/src/modules/select/SelectPage.tsx +137 -137
- package/src/modules/sleepWakeup/DeviceState.d.ts +9 -9
- package/src/modules/sleepWakeup/DeviceState.tsx +99 -99
- package/src/modules/sleepWakeup/LdvScheduleItem.d.ts +15 -15
- package/src/modules/sleepWakeup/LdvScheduleItem.tsx +176 -176
- package/src/modules/sleepWakeup/Router.ts +25 -25
- package/src/modules/sleepWakeup/SleepWakeUpActions.d.ts +2 -2
- package/src/modules/sleepWakeup/SleepWakeUpActions.ts +180 -180
- package/src/modules/sleepWakeup/SleepWakeUpDetailPage.d.ts +2 -2
- package/src/modules/sleepWakeup/SleepWakeUpDetailPage.tsx +616 -616
- package/src/modules/sleepWakeup/SleepWakeUpPage.d.ts +13 -13
- package/src/modules/sleepWakeup/SleepWakeUpPage.tsx +424 -424
- package/src/modules/sleepWakeup/utils.d.ts +44 -44
- package/src/modules/sleepWakeup/utils.ts +253 -253
- package/src/modules/timeSchedule/DeviceState.d.ts +17 -17
- package/src/modules/timeSchedule/DeviceState.tsx +94 -94
- package/src/modules/timeSchedule/LdvScheduleItem.d.ts +15 -15
- package/src/modules/timeSchedule/LdvScheduleItem.tsx +130 -130
- package/src/modules/timeSchedule/ManualSetting.d.ts +14 -14
- package/src/modules/timeSchedule/ManualSetting.tsx +219 -219
- package/src/modules/timeSchedule/MoodSetting.d.ts +11 -11
- package/src/modules/timeSchedule/MoodSetting.tsx +228 -228
- package/src/modules/timeSchedule/Router.ts +25 -25
- package/src/modules/timeSchedule/ScheduleScene.d.ts +6 -6
- package/src/modules/timeSchedule/ScheduleScene.tsx +144 -144
- package/src/modules/timeSchedule/SingleLightView.d.ts +12 -12
- package/src/modules/timeSchedule/SingleLightView.tsx +175 -175
- package/src/modules/timeSchedule/TimeScheduleBean.d.ts +14 -14
- package/src/modules/timeSchedule/TimeScheduleBean.ts +18 -18
- package/src/modules/timeSchedule/TimeScheduleEditpage.d.ts +6 -6
- package/src/modules/timeSchedule/TimeScheduleEditpage.tsx +765 -765
- package/src/modules/timeSchedule/TimeSchedulePage.d.ts +13 -13
- package/src/modules/timeSchedule/TimeSchedulePage.tsx +358 -358
- package/src/modules/timeSchedule/components/ColorList.ts +23 -23
- package/src/modules/timeSchedule/components/LampSwitchCard.tsx +106 -106
- package/src/modules/timeSchedule/mix/MixLightActions.d.ts +3 -3
- package/src/modules/timeSchedule/mix/MixLightActions.ts +49 -49
- package/src/modules/timeSchedule/mix/MixLightBean.d.ts +10 -10
- package/src/modules/timeSchedule/mix/MixLightBean.ts +9 -9
- package/src/modules/timeSchedule/mix/MixLightView.d.ts +7 -7
- package/src/modules/timeSchedule/mix/MixLightView.tsx +197 -197
- package/src/modules/timeSchedule/utils.d.ts +1 -1
- package/src/modules/timeSchedule/utils.ts +6 -6
- package/src/modules/timer/Router.ts +16 -16
- package/src/modules/timer/TimerPage.d.ts +11 -11
- package/src/modules/timer/TimerPage.tsx +384 -384
- package/src/modules/timer/TimerPageAction.d.ts +22 -22
- package/src/modules/timer/TimerPageAction.ts +131 -131
- package/src/navigation/Routers.d.ts +15 -15
- package/src/navigation/Routers.ts +46 -44
- package/src/navigation/tools.d.ts +9 -9
- package/src/navigation/tools.ts +21 -21
- package/src/newModules/biorhythm/BiorhythmActions.ts +374 -374
- package/src/newModules/biorhythm/BiorhythmBean.ts +230 -230
- package/src/newModules/biorhythm/BiorhythmEditPage.tsx +267 -267
- package/src/newModules/biorhythm/BiorhythmPage.tsx +642 -642
- package/src/newModules/biorhythm/IconSelect.tsx +84 -84
- package/src/newModules/biorhythm/Router.ts +33 -33
- package/src/newModules/biorhythm/circular/ItemIcon.d.ts +22 -22
- package/src/newModules/biorhythm/circular/ItemIcon.tsx +172 -172
- package/src/newModules/biorhythm/circular/Progress.d.ts +24 -24
- package/src/newModules/biorhythm/circular/Progress.tsx +371 -371
- package/src/newModules/biorhythm/circular/TimeCircular.d.ts +11 -11
- package/src/newModules/biorhythm/circular/TimeCircular.tsx +64 -64
- package/src/newModules/biorhythm/iconListData.ts +29 -29
- package/src/newModules/biorhythm/pIdList.ts +35 -35
- package/src/newModules/biorhythm/res/BiologicalRes.d.ts +43 -43
- package/src/newModules/biorhythm/res/BiologicalRes.ts +41 -41
- package/src/newModules/childLock/ChildLockPage.tsx +97 -97
- package/src/newModules/childLock/Router.ts +16 -16
- package/src/newModules/energyConsumption/EnergyConsumptionActions.ts +23 -23
- package/src/newModules/energyConsumption/EnergyConsumptionChart.tsx +84 -84
- package/src/newModules/energyConsumption/EnergyConsumptionDetail.tsx +322 -322
- package/src/newModules/energyConsumption/EnergyConsumptionPage.tsx +393 -393
- package/src/newModules/energyConsumption/Router.ts +34 -34
- package/src/newModules/energyConsumption/co2Data.ts +23655 -23655
- package/src/newModules/energyConsumption/component/BarChart.tsx +93 -93
- package/src/newModules/energyConsumption/component/EnergyModal.tsx +284 -284
- package/src/newModules/energyConsumption/component/Overview.tsx +118 -118
- package/src/newModules/fixedTime/FixedTimeActions.ts +241 -241
- package/src/newModules/fixedTime/FixedTimeDetailPage.tsx +345 -345
- package/src/newModules/fixedTime/FixedTimePage.tsx +302 -302
- package/src/newModules/fixedTime/Router.ts +25 -25
- package/src/newModules/lightMode/LightModePage.tsx +204 -204
- package/src/newModules/lightMode/Router.ts +16 -16
- package/src/newModules/mood/AddMoodPage.tsx +194 -194
- package/src/newModules/mood/DynamicMoodEditorPage.tsx +650 -650
- package/src/newModules/mood/Interface.ts +220 -220
- package/src/newModules/mood/MixDynamicMoodEditor.tsx +786 -786
- package/src/newModules/mood/MoodActions.ts +232 -232
- package/src/newModules/mood/MoodInfo.ts +2151 -2151
- package/src/newModules/mood/MoodItem.tsx +160 -160
- package/src/newModules/mood/MoodPage.tsx +386 -386
- package/src/newModules/mood/MoodParse.ts +443 -443
- package/src/newModules/mood/RecommendMoodItem.tsx +81 -81
- package/src/newModules/mood/Router.ts +43 -43
- package/src/newModules/mood/StaticMoodEditorPage.tsx +290 -290
- package/src/newModules/overchargeSwitch/OverchargeSwitchPage.tsx +96 -96
- package/src/newModules/overchargeSwitch/Router.ts +16 -16
- package/src/newModules/powerOnBehavior/LightBehaviorPage.tsx +266 -266
- package/src/newModules/powerOnBehavior/PlugBehaviorPage.tsx +173 -173
- package/src/newModules/powerOnBehavior/PowerOnBehaviorActions.ts +106 -106
- package/src/newModules/powerOnBehavior/Router.ts +27 -27
- package/src/newModules/randomTime/RandomTimeActions.ts +238 -238
- package/src/newModules/randomTime/RandomTimeDetailPage.tsx +325 -325
- package/src/newModules/randomTime/RandomTimePage.tsx +299 -299
- package/src/newModules/randomTime/Router.ts +25 -25
- package/src/newModules/randomTime/Summary.tsx +116 -116
- package/src/newModules/remoteControl/RemoteControlActions.ts +5 -5
- package/src/newModules/remoteControl/RemoteControlPage.tsx +51 -51
- package/src/newModules/remoteControl/Router.ts +15 -15
- package/src/newModules/select/Route.ts +16 -16
- package/src/newModules/select/SelectPage.d.ts +12 -12
- package/src/newModules/select/SelectPage.tsx +137 -137
- package/src/newModules/sleepWakeUp/Interface.ts +69 -69
- package/src/newModules/sleepWakeUp/Router.ts +24 -24
- package/src/newModules/sleepWakeUp/SleepWakeUpActions.ts +317 -317
- package/src/newModules/sleepWakeUp/SleepWakeUpDetailPage.tsx +661 -661
- package/src/newModules/sleepWakeUp/SleepWakeUpPage.tsx +455 -455
- package/src/newModules/sleepWakeUp/utils.ts +253 -253
- package/src/newModules/swithInching/Router.ts +16 -16
- package/src/newModules/swithInching/SwithInching.tsx +231 -231
- package/src/newModules/swithInching/SwithInchingAction.ts +55 -55
- package/src/newModules/swithInching/pickerView.tsx +91 -91
- package/src/newModules/timeSchedule/Interface.ts +142 -142
- package/src/newModules/timeSchedule/Router.ts +25 -25
- package/src/newModules/timeSchedule/TimeScheduleActions.ts +53 -53
- package/src/newModules/timeSchedule/TimeScheduleDetailPage.tsx +648 -648
- package/src/newModules/timeSchedule/TimeSchedulePage.tsx +253 -253
- package/src/newModules/timeSchedule/components/ManuaSettings.tsx +460 -460
- package/src/newModules/timeSchedule/components/ScheduleCard.tsx +125 -125
- package/tsconfig.json +50 -50
|
@@ -1,473 +1,473 @@
|
|
|
1
|
-
import { NativeResult, Result } from '@ledvance/base/src/models/modules/Result'
|
|
2
|
-
import {
|
|
3
|
-
getDefSceneList,
|
|
4
|
-
getDefFantasyScene,
|
|
5
|
-
RemoteSceneInfo,
|
|
6
|
-
SceneInfo,
|
|
7
|
-
SceneNodeInfo,
|
|
8
|
-
SceneNodeTransitionMode,
|
|
9
|
-
SceneUIState,
|
|
10
|
-
StripSceneUIState,
|
|
11
|
-
StripSceneInfo,
|
|
12
|
-
StripNodeInfo,
|
|
13
|
-
} from './SceneInfo'
|
|
14
|
-
import { getFeature, putFeature, NativeApi } from '@ledvance/base/src/api/native'
|
|
15
|
-
import { setSceneDp } from '../../hooks/DeviceDpStateHooks'
|
|
16
|
-
import { hex2Int, spliceByStep } from '@ledvance/base/src/utils/common'
|
|
17
|
-
import { asyncSetDps, useDp, useDps } from '@ledvance/base/src/models/modules/NativePropsSlice'
|
|
18
|
-
import { Dispatch, useState } from 'react'
|
|
19
|
-
import { useUpdateEffect } from 'ahooks'
|
|
20
|
-
import { useDispatch } from 'react-redux'
|
|
21
|
-
import res from '@ledvance/base/src/res'
|
|
22
|
-
import { SCENE } from '../../hooks/DeviceDpStateHooks'
|
|
23
|
-
import { Utils } from '@tuya/tuya-panel-lamp-sdk'
|
|
24
|
-
import { parseJSON } from '@tuya/tuya-panel-lamp-sdk/lib/utils'
|
|
25
|
-
const { nToHS, toFixed, sToN } = Utils
|
|
26
|
-
type SetRemoteSceneListType = (
|
|
27
|
-
deviceId: string,
|
|
28
|
-
remoteSceneList: RemoteSceneInfo[],
|
|
29
|
-
) => Promise<Result<any>>;
|
|
30
|
-
const SceneFeatureId = 'SimplifyScene'
|
|
31
|
-
|
|
32
|
-
export const setRemoteSceneList: SetRemoteSceneListType = async (
|
|
33
|
-
deviceId: string,
|
|
34
|
-
remoteSceneList: RemoteSceneInfo[],
|
|
35
|
-
) => {
|
|
36
|
-
const res = await putFeature(deviceId, SceneFeatureId, remoteSceneList)
|
|
37
|
-
return {
|
|
38
|
-
success: res.result,
|
|
39
|
-
msg: res.msg,
|
|
40
|
-
data: res.data,
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
interface LampParams {
|
|
45
|
-
isRGBWLamp?: boolean
|
|
46
|
-
isRGBLamp?: boolean
|
|
47
|
-
isOnlyRGBLamp?: boolean
|
|
48
|
-
isFanLamp?: boolean
|
|
49
|
-
isTWLamp?: boolean
|
|
50
|
-
isDIMLamp?: boolean
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export async function getRemoteSceneList(
|
|
54
|
-
deviceId: string,
|
|
55
|
-
lampParams?: LampParams,
|
|
56
|
-
isUVCFan?: boolean
|
|
57
|
-
): Promise<Result<SceneUIState[]>> {
|
|
58
|
-
const res: NativeResult<RemoteSceneInfo[]> = await getFeature(deviceId, SceneFeatureId)
|
|
59
|
-
if (!res.result) {
|
|
60
|
-
return { success: false }
|
|
61
|
-
}
|
|
62
|
-
if (!(!!res.data)) {
|
|
63
|
-
const res = await setRemoteSceneList(deviceId, getDefSceneList(
|
|
64
|
-
lampParams?.isRGBWLamp,
|
|
65
|
-
lampParams?.isRGBLamp,
|
|
66
|
-
lampParams?.isOnlyRGBLamp,
|
|
67
|
-
lampParams?.isFanLamp,
|
|
68
|
-
lampParams?.isTWLamp,
|
|
69
|
-
lampParams?.isDIMLamp,
|
|
70
|
-
))
|
|
71
|
-
if (res.success) {
|
|
72
|
-
return getRemoteSceneList(deviceId)
|
|
73
|
-
}
|
|
74
|
-
return { success: false }
|
|
75
|
-
}
|
|
76
|
-
return {
|
|
77
|
-
success: true,
|
|
78
|
-
data: res.data.map((item, index) => remoteSceneInfo2SceneUIState(item, index, !!lampParams?.isFanLamp, isUVCFan)),
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
function remoteSceneInfo2SceneUIState(
|
|
83
|
-
remoteSceneInfo: RemoteSceneInfo,
|
|
84
|
-
index: number,
|
|
85
|
-
isFanLamp: boolean,
|
|
86
|
-
isUVCFan?: boolean
|
|
87
|
-
): SceneUIState {
|
|
88
|
-
const sceneInfo = dp2Obj(remoteSceneInfo.i, isFanLamp, isUVCFan)
|
|
89
|
-
return {
|
|
90
|
-
id: sceneInfo.id,
|
|
91
|
-
fanEnable: sceneInfo.fanEnable,
|
|
92
|
-
fanSpeed: sceneInfo.fanSpeed,
|
|
93
|
-
name: remoteSceneInfo.n,
|
|
94
|
-
image: getSceneImage(index),
|
|
95
|
-
nodes: sceneInfo.nodes,
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export function dp2Obj(dp: string, isFan: boolean = false, isUVCFan?: boolean): SceneInfo {
|
|
100
|
-
let dpCopy = dp
|
|
101
|
-
let fanEnable = false
|
|
102
|
-
let fanSpeed = 0
|
|
103
|
-
const id = hex2Int(dpCopy.slice(0, 2))
|
|
104
|
-
dpCopy = dpCopy.slice(2)
|
|
105
|
-
if (isFan) {
|
|
106
|
-
fanEnable = hex2Int(dpCopy.slice(0, 2)) === 1
|
|
107
|
-
dpCopy = dpCopy.slice(2)
|
|
108
|
-
fanSpeed = hex2Int(dpCopy.slice(0, 2))
|
|
109
|
-
dpCopy = dpCopy.slice(2)
|
|
110
|
-
}
|
|
111
|
-
const nodes: SceneNodeInfo[] = spliceByStep(dpCopy, 26).map(nodeHex => {
|
|
112
|
-
let hex = nodeHex
|
|
113
|
-
const switchingInterval = isUVCFan ? 101 - hex2Int(hex.slice(0, 2)) : hex2Int(hex.slice(0, 2))
|
|
114
|
-
hex = hex.slice(2)
|
|
115
|
-
const transitionTime = isUVCFan ? 101 - hex2Int(hex.slice(0, 2)) : hex2Int(hex.slice(0, 2))
|
|
116
|
-
hex = hex.slice(2)
|
|
117
|
-
const transitionMode = hex2Int(hex.slice(0, 2))
|
|
118
|
-
hex = hex.slice(2)
|
|
119
|
-
const h = hex2Int(hex.slice(0, 4))
|
|
120
|
-
hex = hex.slice(4)
|
|
121
|
-
const s = Math.round(hex2Int(hex.slice(0, 4)) / 10)
|
|
122
|
-
hex = hex.slice(4)
|
|
123
|
-
const v = Math.round(hex2Int(hex.slice(0, 4)) / 10)
|
|
124
|
-
hex = hex.slice(4)
|
|
125
|
-
const brightness = Math.round(hex2Int(hex.slice(0, 4)) / 10)
|
|
126
|
-
hex = hex.slice(4)
|
|
127
|
-
const colorTemp = Math.round(hex2Int(hex.slice(0, 4)) / 10)
|
|
128
|
-
return {
|
|
129
|
-
switchingInterval,
|
|
130
|
-
transitionTime,
|
|
131
|
-
transitionMode,
|
|
132
|
-
h,
|
|
133
|
-
s,
|
|
134
|
-
v,
|
|
135
|
-
brightness,
|
|
136
|
-
colorTemp,
|
|
137
|
-
isColorNode: (h !== 0 || s !== 0 || v !== 0), // 色相/饱和度 不为0就是颜色节点
|
|
138
|
-
}
|
|
139
|
-
})
|
|
140
|
-
return isFan ? { id, fanEnable, fanSpeed, nodes } : { id, nodes }
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
function getSceneImage(index: number): string {
|
|
144
|
-
if (index === 0) {
|
|
145
|
-
return res.scene_goodnight
|
|
146
|
-
}
|
|
147
|
-
if (index === 1) {
|
|
148
|
-
return res.scene_reading
|
|
149
|
-
}
|
|
150
|
-
if (index === 2) {
|
|
151
|
-
return res.scene_work
|
|
152
|
-
}
|
|
153
|
-
if (index === 3) {
|
|
154
|
-
return res.scene_leisure
|
|
155
|
-
}
|
|
156
|
-
if (index === 4) {
|
|
157
|
-
return res.scene_custom1
|
|
158
|
-
}
|
|
159
|
-
if (index === 5) {
|
|
160
|
-
return res.scene_custom2
|
|
161
|
-
}
|
|
162
|
-
if (index === 6) {
|
|
163
|
-
return res.scene_work
|
|
164
|
-
}
|
|
165
|
-
if (index === 7) {
|
|
166
|
-
return res.scene_work
|
|
167
|
-
}
|
|
168
|
-
return ''
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
export function useScene(sceneDpCode: string): [
|
|
172
|
-
number,
|
|
173
|
-
(deviceId: string,
|
|
174
|
-
scene: SceneInfo,
|
|
175
|
-
sceneDpCode: string,
|
|
176
|
-
workModeDpKey: string,
|
|
177
|
-
switchDpCode: string,
|
|
178
|
-
isFanLamp: boolean,
|
|
179
|
-
isUVCFan?: boolean
|
|
180
|
-
) => Promise<Result<any>>
|
|
181
|
-
] {
|
|
182
|
-
const [dp] = useDp<string, any>(sceneDpCode)
|
|
183
|
-
const [sceneState, setSceneState] = useState<SceneInfo>(dp2Obj(dp))
|
|
184
|
-
useUpdateEffect(() => {
|
|
185
|
-
setSceneState(dp2Obj(dp))
|
|
186
|
-
}, [dp])
|
|
187
|
-
return [sceneState.id, setScene(useDispatch())]
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
const setScene = (dispatch: Dispatch<any>) => (
|
|
191
|
-
deviceId: string,
|
|
192
|
-
scene: SceneInfo,
|
|
193
|
-
sceneDpCode: string,
|
|
194
|
-
workModeDpKey: string,
|
|
195
|
-
switchDpCode: string,
|
|
196
|
-
isFanLamp: boolean,
|
|
197
|
-
isUVCFan?: boolean
|
|
198
|
-
) =>
|
|
199
|
-
asyncSetDps(dispatch, async () => {
|
|
200
|
-
const dpValue = obj2Dp(scene, isFanLamp, isUVCFan)
|
|
201
|
-
const controlResult: any = await setSceneDp(
|
|
202
|
-
deviceId,
|
|
203
|
-
dpValue,
|
|
204
|
-
sceneDpCode,
|
|
205
|
-
workModeDpKey,
|
|
206
|
-
switchDpCode,
|
|
207
|
-
)
|
|
208
|
-
return {
|
|
209
|
-
result: { success: controlResult.result },
|
|
210
|
-
dps: { [workModeDpKey]: 'scene', [sceneDpCode]: dpValue },
|
|
211
|
-
}
|
|
212
|
-
})
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
export function obj2Dp(scene: SceneInfo, isFan: boolean = false, isUVCFan?: boolean): string {
|
|
216
|
-
let fanEnableHex = ''
|
|
217
|
-
let fanSpeedHex = ''
|
|
218
|
-
const idHex = scene.id.toString(16).padStart(2, '0')
|
|
219
|
-
if (isFan) {
|
|
220
|
-
fanEnableHex = (scene.fanEnable ? 1 : 0).toString(16).padStart(2, '0')
|
|
221
|
-
fanSpeedHex = (scene.fanSpeed || 1).toString(16).padStart(2, '0')
|
|
222
|
-
}
|
|
223
|
-
const hex = idHex + fanEnableHex + fanSpeedHex + scene.nodes?.map(node => {
|
|
224
|
-
const switchingIntervalHex = (isUVCFan ? 101 - node.switchingInterval : node.switchingInterval).toString(16).padStart(2, '0')
|
|
225
|
-
const transitionTimeHex = (isUVCFan ? 101 - node.transitionTime : node.transitionTime).toString(16).padStart(2, '0')
|
|
226
|
-
const transitionModeHex = node.transitionMode.toString(16).padStart(2, '0')
|
|
227
|
-
const hHex = node.h.toString(16).padStart(4, '0')
|
|
228
|
-
const sHex = (node.s * 10).toString(16).padStart(4, '0')
|
|
229
|
-
const vHex = (node.v * 10).toString(16).padStart(4, '0')
|
|
230
|
-
const brightnessHex = (node.brightness * 10).toString(16).padStart(4, '0')
|
|
231
|
-
const colorTempHex = (node.colorTemp * 10).toString(16).padStart(4, '0')
|
|
232
|
-
return switchingIntervalHex + transitionTimeHex + transitionModeHex + hHex + sHex + vHex + brightnessHex + colorTempHex
|
|
233
|
-
}).join('')
|
|
234
|
-
return hex
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
export async function saveScene(
|
|
239
|
-
deviceId: string,
|
|
240
|
-
scene: SceneUIState,
|
|
241
|
-
transitionMode: SceneNodeTransitionMode,
|
|
242
|
-
transitionTime: number,
|
|
243
|
-
scenes: SceneUIState[],
|
|
244
|
-
isFanLamp: boolean,
|
|
245
|
-
isUVCFan?: boolean
|
|
246
|
-
) {
|
|
247
|
-
if (transitionMode === SceneNodeTransitionMode.Static) {
|
|
248
|
-
scene.nodes = [scene.nodes[0]]
|
|
249
|
-
}
|
|
250
|
-
scene.nodes.forEach(node => {
|
|
251
|
-
node.transitionMode = transitionMode
|
|
252
|
-
node.transitionTime = transitionTime
|
|
253
|
-
node.switchingInterval = transitionTime
|
|
254
|
-
if (node.isColorNode) {
|
|
255
|
-
node.brightness = 0;
|
|
256
|
-
node.colorTemp = 0;
|
|
257
|
-
} else {
|
|
258
|
-
node.h = 0
|
|
259
|
-
node.s = 0
|
|
260
|
-
node.v = 0
|
|
261
|
-
}
|
|
262
|
-
})
|
|
263
|
-
const newScenes: RemoteSceneInfo[] = scenes.map(s => {
|
|
264
|
-
const sceneTemp = s.id === scene.id ? scene : s
|
|
265
|
-
return {
|
|
266
|
-
n: sceneTemp.name,
|
|
267
|
-
i: obj2Dp(sceneTemp, isFanLamp, isUVCFan),
|
|
268
|
-
s: '',
|
|
269
|
-
t: 0,
|
|
270
|
-
e: false,
|
|
271
|
-
}
|
|
272
|
-
})
|
|
273
|
-
return await setRemoteSceneList(deviceId, newScenes)
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
const getDefaultScene = () => {
|
|
277
|
-
return {
|
|
278
|
-
version: 0,
|
|
279
|
-
// 场景号
|
|
280
|
-
id: -1,
|
|
281
|
-
// 变化方式
|
|
282
|
-
mode: 0,
|
|
283
|
-
// 速度
|
|
284
|
-
speed: 0,
|
|
285
|
-
// 段落 0 全段, 1 分段
|
|
286
|
-
segmented: 0,
|
|
287
|
-
// 循环 0 不循环, 1 循环
|
|
288
|
-
loop: 0,
|
|
289
|
-
// 过渡 0 不过渡, 1 过渡
|
|
290
|
-
excessive: 0,
|
|
291
|
-
// 拓展 other
|
|
292
|
-
expand: 0,
|
|
293
|
-
// 方向 0 顺时针方向, 1 逆时针方向
|
|
294
|
-
direction: 0,
|
|
295
|
-
// 设置 目前灯用不上
|
|
296
|
-
reserved1: 0,
|
|
297
|
-
reserved2: 0,
|
|
298
|
-
nodes: []
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
export function stripDp2Obj(dp: string, isStringLight: boolean = false): StripSceneInfo {
|
|
303
|
-
if (!dp) return getDefaultScene()
|
|
304
|
-
const version = hex2Int(dp.slice(0, 2))
|
|
305
|
-
const id = hex2Int(dp.slice(2, 4))
|
|
306
|
-
const mode = hex2Int(dp.slice(4, 6))
|
|
307
|
-
const intervalTime = hex2Int(dp.slice(6, 8))
|
|
308
|
-
const changeTime = hex2Int(dp.slice(8, 10))
|
|
309
|
-
const speed = intervalTime || changeTime
|
|
310
|
-
const optionA = hex2Int(dp.slice(10, 12)).toString(2).padStart(8, '0')
|
|
311
|
-
const segmented = sToN(optionA.slice(0,1), 2)
|
|
312
|
-
const loop = sToN(optionA.slice(1,2), 2)
|
|
313
|
-
const excessive = sToN(optionA.slice(2,3), 2)
|
|
314
|
-
const direction = sToN(optionA.slice(3,4), 2)
|
|
315
|
-
const expand = sToN(optionA.slice(4,6), 2)
|
|
316
|
-
const reserved1 = sToN(optionA.slice(6,7), 2)
|
|
317
|
-
const reserved2 = sToN(optionA.slice(7,8), 2)
|
|
318
|
-
// 这两个目前灯具用不上
|
|
319
|
-
// const optionB = toN(dp.slice(12, 14))
|
|
320
|
-
// const optionC = toN(dp.slice(14, 16))
|
|
321
|
-
let nodes = [] as StripNodeInfo[]
|
|
322
|
-
if(isStringLight){
|
|
323
|
-
nodes = spliceByStep(dp.slice(16, dp.length), 16).map(nodeHex => {
|
|
324
|
-
const v = hex2Int(nodeHex.slice(0, 2))
|
|
325
|
-
const h = hex2Int(nodeHex.slice(2, 6))
|
|
326
|
-
const s = hex2Int(nodeHex.slice(6, 8))
|
|
327
|
-
const brightness = hex2Int(nodeHex.slice(8, 12)) / 10
|
|
328
|
-
const colorTemp = hex2Int(nodeHex.slice(12, 16)) / 10
|
|
329
|
-
const isColorNode = v > 0 && brightness === 0
|
|
330
|
-
return { h, s, v, brightness, colorTemp, isColorNode }
|
|
331
|
-
})
|
|
332
|
-
}else{
|
|
333
|
-
const bright = hex2Int(dp.slice(16, 18))
|
|
334
|
-
nodes = spliceByStep(dp.slice(18, dp.length), 6).map(nodeHex => {
|
|
335
|
-
const h = hex2Int(nodeHex.slice(0, 4))
|
|
336
|
-
const s = hex2Int(nodeHex.slice(4, 6))
|
|
337
|
-
const v = bright
|
|
338
|
-
const brightness = 0
|
|
339
|
-
const colorTemp = 0
|
|
340
|
-
const isColorNode = true
|
|
341
|
-
return { h, s, v, brightness, colorTemp, isColorNode }
|
|
342
|
-
})
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
return {
|
|
346
|
-
version,
|
|
347
|
-
id,
|
|
348
|
-
mode,
|
|
349
|
-
speed,
|
|
350
|
-
direction,
|
|
351
|
-
segmented,
|
|
352
|
-
loop,
|
|
353
|
-
excessive,
|
|
354
|
-
expand,
|
|
355
|
-
reserved1,
|
|
356
|
-
reserved2,
|
|
357
|
-
nodes
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
export function stripObj2Dp(scene: StripSceneInfo, isStringLight: boolean = false) {
|
|
362
|
-
const {
|
|
363
|
-
expand = 0,
|
|
364
|
-
reserved1 = 0,
|
|
365
|
-
reserved2 = 0,
|
|
366
|
-
// mixedIds = [],
|
|
367
|
-
segmented = 0,
|
|
368
|
-
loop = 0,
|
|
369
|
-
excessive = 0,
|
|
370
|
-
direction = 0,
|
|
371
|
-
nodes
|
|
372
|
-
} = scene
|
|
373
|
-
const versionHex = nToHS(scene.version)
|
|
374
|
-
const idHex = nToHS(scene.id)
|
|
375
|
-
const modeHex = nToHS(scene.mode)
|
|
376
|
-
const intervalTimeHex = nToHS(scene.speed)
|
|
377
|
-
const changeTimeHex = nToHS(scene.speed)
|
|
378
|
-
const optionAHex = nToHS(
|
|
379
|
-
parseInt(
|
|
380
|
-
`${segmented}${loop}${excessive}${direction}${toFixed(
|
|
381
|
-
expand.toString(2),
|
|
382
|
-
2
|
|
383
|
-
)}${reserved1}${reserved2}`,
|
|
384
|
-
2
|
|
385
|
-
)
|
|
386
|
-
);
|
|
387
|
-
const optionBHex = nToHS(0)
|
|
388
|
-
const optionCHex = nToHS(0)
|
|
389
|
-
let nodeHex = ''
|
|
390
|
-
if(isStringLight){
|
|
391
|
-
nodeHex = nodes.map(node => {
|
|
392
|
-
return `${nToHS(node.v)}${nToHS(node.h, 4)}${nToHS(node.s)}${nToHS(node.brightness * 10, 4)}${nToHS(node.colorTemp * 10, 4)}`
|
|
393
|
-
}).join('')
|
|
394
|
-
}else{
|
|
395
|
-
const brightHex = nToHS(nodes[0].v)
|
|
396
|
-
nodeHex = brightHex + nodes.map(node => {
|
|
397
|
-
return `${nToHS(node.h, 4)}${nToHS(node.s)}`
|
|
398
|
-
}).join('')
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
return versionHex + idHex + modeHex + intervalTimeHex + changeTimeHex + optionAHex + optionBHex + optionCHex + nodeHex
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
export function useFantasyScene(sceneDp: string, workModeDp: string, switchDp: string, isStringLight?: boolean): [number, (scene: StripSceneInfo) => Promise<Result<any>>] {
|
|
405
|
-
const [dps, setDps]: [any, (v: any) => Promise<Result<any>>] = useDps()
|
|
406
|
-
const dp = dps[sceneDp]
|
|
407
|
-
const [sceneState, setSceneState] = useState<StripSceneInfo>(stripDp2Obj(dp, isStringLight))
|
|
408
|
-
|
|
409
|
-
useUpdateEffect(() => {
|
|
410
|
-
setSceneState(stripDp2Obj(dp, isStringLight))
|
|
411
|
-
}, [dp])
|
|
412
|
-
|
|
413
|
-
const setFantasyScene = (scene: StripSceneInfo) => {
|
|
414
|
-
const sceneHex = stripObj2Dp(scene, isStringLight)
|
|
415
|
-
return setDps({
|
|
416
|
-
[sceneDp]: sceneHex,
|
|
417
|
-
[workModeDp]: SCENE,
|
|
418
|
-
[switchDp]: true
|
|
419
|
-
})
|
|
420
|
-
}
|
|
421
|
-
return [sceneState.id, setFantasyScene]
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
type LampType = {
|
|
425
|
-
isStringLight?: boolean
|
|
426
|
-
isStripLight?: boolean
|
|
427
|
-
}
|
|
428
|
-
export async function getRemoteFantasyScene(featureId: string, devId: string, lampType: LampType) {
|
|
429
|
-
const res = await NativeApi.getJson(devId, featureId)
|
|
430
|
-
const isNormalData = Array.isArray(parseJSON(res?.data))
|
|
431
|
-
if (res.success && isNormalData) {
|
|
432
|
-
return {
|
|
433
|
-
success: true,
|
|
434
|
-
data: JSON.parse(res.data)?.map(item => remoteFantasySceneInfo2SceneUIState(item, lampType.isStringLight)),
|
|
435
|
-
}
|
|
436
|
-
} else {
|
|
437
|
-
if (res.msg?.includes('资源未找到') || !isNormalData) {
|
|
438
|
-
const defaultScene = getDefFantasyScene(lampType)
|
|
439
|
-
const res = await NativeApi.putJson(devId, featureId, JSON.stringify(defaultScene))
|
|
440
|
-
if (res.success) {
|
|
441
|
-
return {
|
|
442
|
-
success: true,
|
|
443
|
-
data: defaultScene.map(item => remoteFantasySceneInfo2SceneUIState(item, lampType.isStringLight))
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
return { success: false }
|
|
447
|
-
}
|
|
448
|
-
return { success: false }
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
function remoteFantasySceneInfo2SceneUIState(remoteScene: RemoteSceneInfo, isStringLight?: boolean): StripSceneUIState {
|
|
454
|
-
const stripSceneInfo = stripDp2Obj(remoteScene.i, isStringLight)
|
|
455
|
-
return {
|
|
456
|
-
...stripSceneInfo,
|
|
457
|
-
name: remoteScene.n,
|
|
458
|
-
image: ''
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
export function saveFantasyScene(devId: string, featureId: string, scenes: StripSceneUIState[], isStringLight?: boolean) {
|
|
463
|
-
const newScenes: RemoteSceneInfo[] = scenes.map(s => {
|
|
464
|
-
return {
|
|
465
|
-
n: s.name,
|
|
466
|
-
i: stripObj2Dp(s, isStringLight),
|
|
467
|
-
s: '',
|
|
468
|
-
t: 0,
|
|
469
|
-
e: false,
|
|
470
|
-
}
|
|
471
|
-
})
|
|
472
|
-
return NativeApi.putJson(devId, featureId, JSON.stringify(newScenes))
|
|
473
|
-
}
|
|
1
|
+
import { NativeResult, Result } from '@ledvance/base/src/models/modules/Result'
|
|
2
|
+
import {
|
|
3
|
+
getDefSceneList,
|
|
4
|
+
getDefFantasyScene,
|
|
5
|
+
RemoteSceneInfo,
|
|
6
|
+
SceneInfo,
|
|
7
|
+
SceneNodeInfo,
|
|
8
|
+
SceneNodeTransitionMode,
|
|
9
|
+
SceneUIState,
|
|
10
|
+
StripSceneUIState,
|
|
11
|
+
StripSceneInfo,
|
|
12
|
+
StripNodeInfo,
|
|
13
|
+
} from './SceneInfo'
|
|
14
|
+
import { getFeature, putFeature, NativeApi } from '@ledvance/base/src/api/native'
|
|
15
|
+
import { setSceneDp } from '../../hooks/DeviceDpStateHooks'
|
|
16
|
+
import { hex2Int, spliceByStep } from '@ledvance/base/src/utils/common'
|
|
17
|
+
import { asyncSetDps, useDp, useDps } from '@ledvance/base/src/models/modules/NativePropsSlice'
|
|
18
|
+
import { Dispatch, useState } from 'react'
|
|
19
|
+
import { useUpdateEffect } from 'ahooks'
|
|
20
|
+
import { useDispatch } from 'react-redux'
|
|
21
|
+
import res from '@ledvance/base/src/res'
|
|
22
|
+
import { SCENE } from '../../hooks/DeviceDpStateHooks'
|
|
23
|
+
import { Utils } from '@tuya/tuya-panel-lamp-sdk'
|
|
24
|
+
import { parseJSON } from '@tuya/tuya-panel-lamp-sdk/lib/utils'
|
|
25
|
+
const { nToHS, toFixed, sToN } = Utils
|
|
26
|
+
type SetRemoteSceneListType = (
|
|
27
|
+
deviceId: string,
|
|
28
|
+
remoteSceneList: RemoteSceneInfo[],
|
|
29
|
+
) => Promise<Result<any>>;
|
|
30
|
+
const SceneFeatureId = 'SimplifyScene'
|
|
31
|
+
|
|
32
|
+
export const setRemoteSceneList: SetRemoteSceneListType = async (
|
|
33
|
+
deviceId: string,
|
|
34
|
+
remoteSceneList: RemoteSceneInfo[],
|
|
35
|
+
) => {
|
|
36
|
+
const res = await putFeature(deviceId, SceneFeatureId, remoteSceneList)
|
|
37
|
+
return {
|
|
38
|
+
success: res.result,
|
|
39
|
+
msg: res.msg,
|
|
40
|
+
data: res.data,
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
interface LampParams {
|
|
45
|
+
isRGBWLamp?: boolean
|
|
46
|
+
isRGBLamp?: boolean
|
|
47
|
+
isOnlyRGBLamp?: boolean
|
|
48
|
+
isFanLamp?: boolean
|
|
49
|
+
isTWLamp?: boolean
|
|
50
|
+
isDIMLamp?: boolean
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export async function getRemoteSceneList(
|
|
54
|
+
deviceId: string,
|
|
55
|
+
lampParams?: LampParams,
|
|
56
|
+
isUVCFan?: boolean
|
|
57
|
+
): Promise<Result<SceneUIState[]>> {
|
|
58
|
+
const res: NativeResult<RemoteSceneInfo[]> = await getFeature(deviceId, SceneFeatureId)
|
|
59
|
+
if (!res.result) {
|
|
60
|
+
return { success: false }
|
|
61
|
+
}
|
|
62
|
+
if (!(!!res.data)) {
|
|
63
|
+
const res = await setRemoteSceneList(deviceId, getDefSceneList(
|
|
64
|
+
lampParams?.isRGBWLamp,
|
|
65
|
+
lampParams?.isRGBLamp,
|
|
66
|
+
lampParams?.isOnlyRGBLamp,
|
|
67
|
+
lampParams?.isFanLamp,
|
|
68
|
+
lampParams?.isTWLamp,
|
|
69
|
+
lampParams?.isDIMLamp,
|
|
70
|
+
))
|
|
71
|
+
if (res.success) {
|
|
72
|
+
return getRemoteSceneList(deviceId)
|
|
73
|
+
}
|
|
74
|
+
return { success: false }
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
success: true,
|
|
78
|
+
data: res.data.map((item, index) => remoteSceneInfo2SceneUIState(item, index, !!lampParams?.isFanLamp, isUVCFan)),
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function remoteSceneInfo2SceneUIState(
|
|
83
|
+
remoteSceneInfo: RemoteSceneInfo,
|
|
84
|
+
index: number,
|
|
85
|
+
isFanLamp: boolean,
|
|
86
|
+
isUVCFan?: boolean
|
|
87
|
+
): SceneUIState {
|
|
88
|
+
const sceneInfo = dp2Obj(remoteSceneInfo.i, isFanLamp, isUVCFan)
|
|
89
|
+
return {
|
|
90
|
+
id: sceneInfo.id,
|
|
91
|
+
fanEnable: sceneInfo.fanEnable,
|
|
92
|
+
fanSpeed: sceneInfo.fanSpeed,
|
|
93
|
+
name: remoteSceneInfo.n,
|
|
94
|
+
image: getSceneImage(index),
|
|
95
|
+
nodes: sceneInfo.nodes,
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export function dp2Obj(dp: string, isFan: boolean = false, isUVCFan?: boolean): SceneInfo {
|
|
100
|
+
let dpCopy = dp
|
|
101
|
+
let fanEnable = false
|
|
102
|
+
let fanSpeed = 0
|
|
103
|
+
const id = hex2Int(dpCopy.slice(0, 2))
|
|
104
|
+
dpCopy = dpCopy.slice(2)
|
|
105
|
+
if (isFan) {
|
|
106
|
+
fanEnable = hex2Int(dpCopy.slice(0, 2)) === 1
|
|
107
|
+
dpCopy = dpCopy.slice(2)
|
|
108
|
+
fanSpeed = hex2Int(dpCopy.slice(0, 2))
|
|
109
|
+
dpCopy = dpCopy.slice(2)
|
|
110
|
+
}
|
|
111
|
+
const nodes: SceneNodeInfo[] = spliceByStep(dpCopy, 26).map(nodeHex => {
|
|
112
|
+
let hex = nodeHex
|
|
113
|
+
const switchingInterval = isUVCFan ? 101 - hex2Int(hex.slice(0, 2)) : hex2Int(hex.slice(0, 2))
|
|
114
|
+
hex = hex.slice(2)
|
|
115
|
+
const transitionTime = isUVCFan ? 101 - hex2Int(hex.slice(0, 2)) : hex2Int(hex.slice(0, 2))
|
|
116
|
+
hex = hex.slice(2)
|
|
117
|
+
const transitionMode = hex2Int(hex.slice(0, 2))
|
|
118
|
+
hex = hex.slice(2)
|
|
119
|
+
const h = hex2Int(hex.slice(0, 4))
|
|
120
|
+
hex = hex.slice(4)
|
|
121
|
+
const s = Math.round(hex2Int(hex.slice(0, 4)) / 10)
|
|
122
|
+
hex = hex.slice(4)
|
|
123
|
+
const v = Math.round(hex2Int(hex.slice(0, 4)) / 10)
|
|
124
|
+
hex = hex.slice(4)
|
|
125
|
+
const brightness = Math.round(hex2Int(hex.slice(0, 4)) / 10)
|
|
126
|
+
hex = hex.slice(4)
|
|
127
|
+
const colorTemp = Math.round(hex2Int(hex.slice(0, 4)) / 10)
|
|
128
|
+
return {
|
|
129
|
+
switchingInterval,
|
|
130
|
+
transitionTime,
|
|
131
|
+
transitionMode,
|
|
132
|
+
h,
|
|
133
|
+
s,
|
|
134
|
+
v,
|
|
135
|
+
brightness,
|
|
136
|
+
colorTemp,
|
|
137
|
+
isColorNode: (h !== 0 || s !== 0 || v !== 0), // 色相/饱和度 不为0就是颜色节点
|
|
138
|
+
}
|
|
139
|
+
})
|
|
140
|
+
return isFan ? { id, fanEnable, fanSpeed, nodes } : { id, nodes }
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function getSceneImage(index: number): string {
|
|
144
|
+
if (index === 0) {
|
|
145
|
+
return res.scene_goodnight
|
|
146
|
+
}
|
|
147
|
+
if (index === 1) {
|
|
148
|
+
return res.scene_reading
|
|
149
|
+
}
|
|
150
|
+
if (index === 2) {
|
|
151
|
+
return res.scene_work
|
|
152
|
+
}
|
|
153
|
+
if (index === 3) {
|
|
154
|
+
return res.scene_leisure
|
|
155
|
+
}
|
|
156
|
+
if (index === 4) {
|
|
157
|
+
return res.scene_custom1
|
|
158
|
+
}
|
|
159
|
+
if (index === 5) {
|
|
160
|
+
return res.scene_custom2
|
|
161
|
+
}
|
|
162
|
+
if (index === 6) {
|
|
163
|
+
return res.scene_work
|
|
164
|
+
}
|
|
165
|
+
if (index === 7) {
|
|
166
|
+
return res.scene_work
|
|
167
|
+
}
|
|
168
|
+
return ''
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export function useScene(sceneDpCode: string): [
|
|
172
|
+
number,
|
|
173
|
+
(deviceId: string,
|
|
174
|
+
scene: SceneInfo,
|
|
175
|
+
sceneDpCode: string,
|
|
176
|
+
workModeDpKey: string,
|
|
177
|
+
switchDpCode: string,
|
|
178
|
+
isFanLamp: boolean,
|
|
179
|
+
isUVCFan?: boolean
|
|
180
|
+
) => Promise<Result<any>>
|
|
181
|
+
] {
|
|
182
|
+
const [dp] = useDp<string, any>(sceneDpCode)
|
|
183
|
+
const [sceneState, setSceneState] = useState<SceneInfo>(dp2Obj(dp))
|
|
184
|
+
useUpdateEffect(() => {
|
|
185
|
+
setSceneState(dp2Obj(dp))
|
|
186
|
+
}, [dp])
|
|
187
|
+
return [sceneState.id, setScene(useDispatch())]
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const setScene = (dispatch: Dispatch<any>) => (
|
|
191
|
+
deviceId: string,
|
|
192
|
+
scene: SceneInfo,
|
|
193
|
+
sceneDpCode: string,
|
|
194
|
+
workModeDpKey: string,
|
|
195
|
+
switchDpCode: string,
|
|
196
|
+
isFanLamp: boolean,
|
|
197
|
+
isUVCFan?: boolean
|
|
198
|
+
) =>
|
|
199
|
+
asyncSetDps(dispatch, async () => {
|
|
200
|
+
const dpValue = obj2Dp(scene, isFanLamp, isUVCFan)
|
|
201
|
+
const controlResult: any = await setSceneDp(
|
|
202
|
+
deviceId,
|
|
203
|
+
dpValue,
|
|
204
|
+
sceneDpCode,
|
|
205
|
+
workModeDpKey,
|
|
206
|
+
switchDpCode,
|
|
207
|
+
)
|
|
208
|
+
return {
|
|
209
|
+
result: { success: controlResult.result },
|
|
210
|
+
dps: { [workModeDpKey]: 'scene', [sceneDpCode]: dpValue },
|
|
211
|
+
}
|
|
212
|
+
})
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
export function obj2Dp(scene: SceneInfo, isFan: boolean = false, isUVCFan?: boolean): string {
|
|
216
|
+
let fanEnableHex = ''
|
|
217
|
+
let fanSpeedHex = ''
|
|
218
|
+
const idHex = scene.id.toString(16).padStart(2, '0')
|
|
219
|
+
if (isFan) {
|
|
220
|
+
fanEnableHex = (scene.fanEnable ? 1 : 0).toString(16).padStart(2, '0')
|
|
221
|
+
fanSpeedHex = (scene.fanSpeed || 1).toString(16).padStart(2, '0')
|
|
222
|
+
}
|
|
223
|
+
const hex = idHex + fanEnableHex + fanSpeedHex + scene.nodes?.map(node => {
|
|
224
|
+
const switchingIntervalHex = (isUVCFan ? 101 - node.switchingInterval : node.switchingInterval).toString(16).padStart(2, '0')
|
|
225
|
+
const transitionTimeHex = (isUVCFan ? 101 - node.transitionTime : node.transitionTime).toString(16).padStart(2, '0')
|
|
226
|
+
const transitionModeHex = node.transitionMode.toString(16).padStart(2, '0')
|
|
227
|
+
const hHex = node.h.toString(16).padStart(4, '0')
|
|
228
|
+
const sHex = (node.s * 10).toString(16).padStart(4, '0')
|
|
229
|
+
const vHex = (node.v * 10).toString(16).padStart(4, '0')
|
|
230
|
+
const brightnessHex = (node.brightness * 10).toString(16).padStart(4, '0')
|
|
231
|
+
const colorTempHex = (node.colorTemp * 10).toString(16).padStart(4, '0')
|
|
232
|
+
return switchingIntervalHex + transitionTimeHex + transitionModeHex + hHex + sHex + vHex + brightnessHex + colorTempHex
|
|
233
|
+
}).join('')
|
|
234
|
+
return hex
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
export async function saveScene(
|
|
239
|
+
deviceId: string,
|
|
240
|
+
scene: SceneUIState,
|
|
241
|
+
transitionMode: SceneNodeTransitionMode,
|
|
242
|
+
transitionTime: number,
|
|
243
|
+
scenes: SceneUIState[],
|
|
244
|
+
isFanLamp: boolean,
|
|
245
|
+
isUVCFan?: boolean
|
|
246
|
+
) {
|
|
247
|
+
if (transitionMode === SceneNodeTransitionMode.Static) {
|
|
248
|
+
scene.nodes = [scene.nodes[0]]
|
|
249
|
+
}
|
|
250
|
+
scene.nodes.forEach(node => {
|
|
251
|
+
node.transitionMode = transitionMode
|
|
252
|
+
node.transitionTime = transitionTime
|
|
253
|
+
node.switchingInterval = transitionTime
|
|
254
|
+
if (node.isColorNode) {
|
|
255
|
+
node.brightness = 0;
|
|
256
|
+
node.colorTemp = 0;
|
|
257
|
+
} else {
|
|
258
|
+
node.h = 0
|
|
259
|
+
node.s = 0
|
|
260
|
+
node.v = 0
|
|
261
|
+
}
|
|
262
|
+
})
|
|
263
|
+
const newScenes: RemoteSceneInfo[] = scenes.map(s => {
|
|
264
|
+
const sceneTemp = s.id === scene.id ? scene : s
|
|
265
|
+
return {
|
|
266
|
+
n: sceneTemp.name,
|
|
267
|
+
i: obj2Dp(sceneTemp, isFanLamp, isUVCFan),
|
|
268
|
+
s: '',
|
|
269
|
+
t: 0,
|
|
270
|
+
e: false,
|
|
271
|
+
}
|
|
272
|
+
})
|
|
273
|
+
return await setRemoteSceneList(deviceId, newScenes)
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
const getDefaultScene = () => {
|
|
277
|
+
return {
|
|
278
|
+
version: 0,
|
|
279
|
+
// 场景号
|
|
280
|
+
id: -1,
|
|
281
|
+
// 变化方式
|
|
282
|
+
mode: 0,
|
|
283
|
+
// 速度
|
|
284
|
+
speed: 0,
|
|
285
|
+
// 段落 0 全段, 1 分段
|
|
286
|
+
segmented: 0,
|
|
287
|
+
// 循环 0 不循环, 1 循环
|
|
288
|
+
loop: 0,
|
|
289
|
+
// 过渡 0 不过渡, 1 过渡
|
|
290
|
+
excessive: 0,
|
|
291
|
+
// 拓展 other
|
|
292
|
+
expand: 0,
|
|
293
|
+
// 方向 0 顺时针方向, 1 逆时针方向
|
|
294
|
+
direction: 0,
|
|
295
|
+
// 设置 目前灯用不上
|
|
296
|
+
reserved1: 0,
|
|
297
|
+
reserved2: 0,
|
|
298
|
+
nodes: []
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
export function stripDp2Obj(dp: string, isStringLight: boolean = false): StripSceneInfo {
|
|
303
|
+
if (!dp) return getDefaultScene()
|
|
304
|
+
const version = hex2Int(dp.slice(0, 2))
|
|
305
|
+
const id = hex2Int(dp.slice(2, 4))
|
|
306
|
+
const mode = hex2Int(dp.slice(4, 6))
|
|
307
|
+
const intervalTime = hex2Int(dp.slice(6, 8))
|
|
308
|
+
const changeTime = hex2Int(dp.slice(8, 10))
|
|
309
|
+
const speed = intervalTime || changeTime
|
|
310
|
+
const optionA = hex2Int(dp.slice(10, 12)).toString(2).padStart(8, '0')
|
|
311
|
+
const segmented = sToN(optionA.slice(0,1), 2)
|
|
312
|
+
const loop = sToN(optionA.slice(1,2), 2)
|
|
313
|
+
const excessive = sToN(optionA.slice(2,3), 2)
|
|
314
|
+
const direction = sToN(optionA.slice(3,4), 2)
|
|
315
|
+
const expand = sToN(optionA.slice(4,6), 2)
|
|
316
|
+
const reserved1 = sToN(optionA.slice(6,7), 2)
|
|
317
|
+
const reserved2 = sToN(optionA.slice(7,8), 2)
|
|
318
|
+
// 这两个目前灯具用不上
|
|
319
|
+
// const optionB = toN(dp.slice(12, 14))
|
|
320
|
+
// const optionC = toN(dp.slice(14, 16))
|
|
321
|
+
let nodes = [] as StripNodeInfo[]
|
|
322
|
+
if(isStringLight){
|
|
323
|
+
nodes = spliceByStep(dp.slice(16, dp.length), 16).map(nodeHex => {
|
|
324
|
+
const v = hex2Int(nodeHex.slice(0, 2))
|
|
325
|
+
const h = hex2Int(nodeHex.slice(2, 6))
|
|
326
|
+
const s = hex2Int(nodeHex.slice(6, 8))
|
|
327
|
+
const brightness = hex2Int(nodeHex.slice(8, 12)) / 10
|
|
328
|
+
const colorTemp = hex2Int(nodeHex.slice(12, 16)) / 10
|
|
329
|
+
const isColorNode = v > 0 && brightness === 0
|
|
330
|
+
return { h, s, v, brightness, colorTemp, isColorNode }
|
|
331
|
+
})
|
|
332
|
+
}else{
|
|
333
|
+
const bright = hex2Int(dp.slice(16, 18))
|
|
334
|
+
nodes = spliceByStep(dp.slice(18, dp.length), 6).map(nodeHex => {
|
|
335
|
+
const h = hex2Int(nodeHex.slice(0, 4))
|
|
336
|
+
const s = hex2Int(nodeHex.slice(4, 6))
|
|
337
|
+
const v = bright
|
|
338
|
+
const brightness = 0
|
|
339
|
+
const colorTemp = 0
|
|
340
|
+
const isColorNode = true
|
|
341
|
+
return { h, s, v, brightness, colorTemp, isColorNode }
|
|
342
|
+
})
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
return {
|
|
346
|
+
version,
|
|
347
|
+
id,
|
|
348
|
+
mode,
|
|
349
|
+
speed,
|
|
350
|
+
direction,
|
|
351
|
+
segmented,
|
|
352
|
+
loop,
|
|
353
|
+
excessive,
|
|
354
|
+
expand,
|
|
355
|
+
reserved1,
|
|
356
|
+
reserved2,
|
|
357
|
+
nodes
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
export function stripObj2Dp(scene: StripSceneInfo, isStringLight: boolean = false) {
|
|
362
|
+
const {
|
|
363
|
+
expand = 0,
|
|
364
|
+
reserved1 = 0,
|
|
365
|
+
reserved2 = 0,
|
|
366
|
+
// mixedIds = [],
|
|
367
|
+
segmented = 0,
|
|
368
|
+
loop = 0,
|
|
369
|
+
excessive = 0,
|
|
370
|
+
direction = 0,
|
|
371
|
+
nodes
|
|
372
|
+
} = scene
|
|
373
|
+
const versionHex = nToHS(scene.version)
|
|
374
|
+
const idHex = nToHS(scene.id)
|
|
375
|
+
const modeHex = nToHS(scene.mode)
|
|
376
|
+
const intervalTimeHex = nToHS(scene.speed)
|
|
377
|
+
const changeTimeHex = nToHS(scene.speed)
|
|
378
|
+
const optionAHex = nToHS(
|
|
379
|
+
parseInt(
|
|
380
|
+
`${segmented}${loop}${excessive}${direction}${toFixed(
|
|
381
|
+
expand.toString(2),
|
|
382
|
+
2
|
|
383
|
+
)}${reserved1}${reserved2}`,
|
|
384
|
+
2
|
|
385
|
+
)
|
|
386
|
+
);
|
|
387
|
+
const optionBHex = nToHS(0)
|
|
388
|
+
const optionCHex = nToHS(0)
|
|
389
|
+
let nodeHex = ''
|
|
390
|
+
if(isStringLight){
|
|
391
|
+
nodeHex = nodes.map(node => {
|
|
392
|
+
return `${nToHS(node.v)}${nToHS(node.h, 4)}${nToHS(node.s)}${nToHS(node.brightness * 10, 4)}${nToHS(node.colorTemp * 10, 4)}`
|
|
393
|
+
}).join('')
|
|
394
|
+
}else{
|
|
395
|
+
const brightHex = nToHS(nodes[0].v)
|
|
396
|
+
nodeHex = brightHex + nodes.map(node => {
|
|
397
|
+
return `${nToHS(node.h, 4)}${nToHS(node.s)}`
|
|
398
|
+
}).join('')
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
return versionHex + idHex + modeHex + intervalTimeHex + changeTimeHex + optionAHex + optionBHex + optionCHex + nodeHex
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
export function useFantasyScene(sceneDp: string, workModeDp: string, switchDp: string, isStringLight?: boolean): [number, (scene: StripSceneInfo) => Promise<Result<any>>] {
|
|
405
|
+
const [dps, setDps]: [any, (v: any) => Promise<Result<any>>] = useDps()
|
|
406
|
+
const dp = dps[sceneDp]
|
|
407
|
+
const [sceneState, setSceneState] = useState<StripSceneInfo>(stripDp2Obj(dp, isStringLight))
|
|
408
|
+
|
|
409
|
+
useUpdateEffect(() => {
|
|
410
|
+
setSceneState(stripDp2Obj(dp, isStringLight))
|
|
411
|
+
}, [dp])
|
|
412
|
+
|
|
413
|
+
const setFantasyScene = (scene: StripSceneInfo) => {
|
|
414
|
+
const sceneHex = stripObj2Dp(scene, isStringLight)
|
|
415
|
+
return setDps({
|
|
416
|
+
[sceneDp]: sceneHex,
|
|
417
|
+
[workModeDp]: SCENE,
|
|
418
|
+
[switchDp]: true
|
|
419
|
+
})
|
|
420
|
+
}
|
|
421
|
+
return [sceneState.id, setFantasyScene]
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
type LampType = {
|
|
425
|
+
isStringLight?: boolean
|
|
426
|
+
isStripLight?: boolean
|
|
427
|
+
}
|
|
428
|
+
export async function getRemoteFantasyScene(featureId: string, devId: string, lampType: LampType) {
|
|
429
|
+
const res = await NativeApi.getJson(devId, featureId)
|
|
430
|
+
const isNormalData = Array.isArray(parseJSON(res?.data))
|
|
431
|
+
if (res.success && isNormalData) {
|
|
432
|
+
return {
|
|
433
|
+
success: true,
|
|
434
|
+
data: JSON.parse(res.data)?.map(item => remoteFantasySceneInfo2SceneUIState(item, lampType.isStringLight)),
|
|
435
|
+
}
|
|
436
|
+
} else {
|
|
437
|
+
if (res.msg?.includes('资源未找到') || !isNormalData) {
|
|
438
|
+
const defaultScene = getDefFantasyScene(lampType)
|
|
439
|
+
const res = await NativeApi.putJson(devId, featureId, JSON.stringify(defaultScene))
|
|
440
|
+
if (res.success) {
|
|
441
|
+
return {
|
|
442
|
+
success: true,
|
|
443
|
+
data: defaultScene.map(item => remoteFantasySceneInfo2SceneUIState(item, lampType.isStringLight))
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
return { success: false }
|
|
447
|
+
}
|
|
448
|
+
return { success: false }
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
function remoteFantasySceneInfo2SceneUIState(remoteScene: RemoteSceneInfo, isStringLight?: boolean): StripSceneUIState {
|
|
454
|
+
const stripSceneInfo = stripDp2Obj(remoteScene.i, isStringLight)
|
|
455
|
+
return {
|
|
456
|
+
...stripSceneInfo,
|
|
457
|
+
name: remoteScene.n,
|
|
458
|
+
image: ''
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
export function saveFantasyScene(devId: string, featureId: string, scenes: StripSceneUIState[], isStringLight?: boolean) {
|
|
463
|
+
const newScenes: RemoteSceneInfo[] = scenes.map(s => {
|
|
464
|
+
return {
|
|
465
|
+
n: s.name,
|
|
466
|
+
i: stripObj2Dp(s, isStringLight),
|
|
467
|
+
s: '',
|
|
468
|
+
t: 0,
|
|
469
|
+
e: false,
|
|
470
|
+
}
|
|
471
|
+
})
|
|
472
|
+
return NativeApi.putJson(devId, featureId, JSON.stringify(newScenes))
|
|
473
|
+
}
|