@ledvance/ui-biz-bundle 1.1.69 → 1.1.70

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.
Files changed (226) hide show
  1. package/.babelrc +31 -31
  2. package/.eslintignore +5 -5
  3. package/.eslintrc.js +27 -27
  4. package/.prettierrc.js +1 -1
  5. package/.versionrc +5 -5
  6. package/package.json +74 -74
  7. package/rn-cli.config.js +8 -8
  8. package/src/hooks/DeviceDpStateHooks.d.ts +14 -14
  9. package/src/hooks/DeviceDpStateHooks.ts +50 -50
  10. package/src/modules/biorhythm/BiorhythmActions.d.ts +8 -8
  11. package/src/modules/biorhythm/BiorhythmActions.ts +324 -324
  12. package/src/modules/biorhythm/BiorhythmBean.d.ts +58 -58
  13. package/src/modules/biorhythm/BiorhythmBean.ts +230 -230
  14. package/src/modules/biorhythm/BiorhythmEditPage.d.ts +14 -14
  15. package/src/modules/biorhythm/BiorhythmEditPage.tsx +324 -324
  16. package/src/modules/biorhythm/BiorhythmPage.d.ts +10 -10
  17. package/src/modules/biorhythm/BiorhythmPage.tsx +796 -796
  18. package/src/modules/biorhythm/IconSelect.d.ts +2 -2
  19. package/src/modules/biorhythm/IconSelect.tsx +81 -81
  20. package/src/modules/biorhythm/Router.ts +34 -34
  21. package/src/modules/biorhythm/circular/ItemIcon.d.ts +22 -22
  22. package/src/modules/biorhythm/circular/ItemIcon.tsx +172 -172
  23. package/src/modules/biorhythm/circular/Progress.d.ts +24 -24
  24. package/src/modules/biorhythm/circular/Progress.tsx +411 -411
  25. package/src/modules/biorhythm/circular/TimeCircular.d.ts +11 -11
  26. package/src/modules/biorhythm/circular/TimeCircular.tsx +70 -70
  27. package/src/modules/biorhythm/iconListData.d.ts +7 -7
  28. package/src/modules/biorhythm/iconListData.ts +29 -29
  29. package/src/modules/biorhythm/pIdList.d.ts +2 -2
  30. package/src/modules/biorhythm/pIdList.ts +35 -35
  31. package/src/modules/biorhythm/res/BiologicalRes.d.ts +43 -43
  32. package/src/modules/biorhythm/res/BiologicalRes.ts +41 -41
  33. package/src/modules/config/ldvConfig.d.ts +2 -2
  34. package/src/modules/config/ldvConfig.tsx +18 -18
  35. package/src/modules/fixedTime/FixedTimeActions.ts +173 -173
  36. package/src/modules/fixedTime/FixedTimeDetailPage.tsx +372 -372
  37. package/src/modules/fixedTime/FixedTimePage.tsx +213 -213
  38. package/src/modules/fixedTime/Router.ts +26 -26
  39. package/src/modules/flags/FlagActions.ts +267 -267
  40. package/src/modules/flags/FlagEditPage.tsx +441 -441
  41. package/src/modules/flags/FlagInfo.tsx +563 -563
  42. package/src/modules/flags/FlagItem.tsx +90 -90
  43. package/src/modules/flags/FlagPage.tsx +277 -277
  44. package/src/modules/flags/Router.ts +25 -25
  45. package/src/modules/history/HistoryPage.d.ts +2 -2
  46. package/src/modules/history/HistoryPage.tsx +261 -261
  47. package/src/modules/history/Router.ts +16 -16
  48. package/src/modules/history/SwitchHistoryPageActions.d.ts +14 -14
  49. package/src/modules/history/SwitchHistoryPageActions.ts +76 -76
  50. package/src/modules/mood/AddMoodPage.d.ts +10 -10
  51. package/src/modules/mood/AddMoodPage.tsx +792 -792
  52. package/src/modules/mood/DynamicMoodEditorPage.d.ts +6 -6
  53. package/src/modules/mood/DynamicMoodEditorPage.tsx +561 -561
  54. package/src/modules/mood/FantasyMood.tsx +176 -176
  55. package/src/modules/mood/FantasyMoodEditPage.tsx +582 -582
  56. package/src/modules/mood/FantasyMoodItem.tsx +104 -104
  57. package/src/modules/mood/FantasyRouter.ts +35 -35
  58. package/src/modules/mood/MixMood/AddMixMoodPage.tsx +247 -247
  59. package/src/modules/mood/MixMood/MixMoodActions.ts +128 -128
  60. package/src/modules/mood/MixMood/MixMoodEditPage.tsx +721 -721
  61. package/src/modules/mood/MixMood/MixMoodItem.tsx +134 -134
  62. package/src/modules/mood/MixMood/MixMoodPage.tsx +326 -326
  63. package/src/modules/mood/MixMood/MixSceneBeans.ts +364 -364
  64. package/src/modules/mood/MixMood/RecommendMixMoodItem.tsx +69 -69
  65. package/src/modules/mood/MixMood/Router.ts +44 -44
  66. package/src/modules/mood/MoodItem.d.ts +11 -11
  67. package/src/modules/mood/MoodItem.tsx +114 -114
  68. package/src/modules/mood/MoodPage.d.ts +16 -16
  69. package/src/modules/mood/MoodPage.tsx +296 -296
  70. package/src/modules/mood/RecommendMoodItem.d.ts +13 -13
  71. package/src/modules/mood/RecommendMoodItem.tsx +74 -74
  72. package/src/modules/mood/Router.ts +53 -53
  73. package/src/modules/mood/StaticMoodEditorPage.d.ts +16 -16
  74. package/src/modules/mood/StaticMoodEditorPage.tsx +320 -320
  75. package/src/modules/mood/tools.d.ts +3 -3
  76. package/src/modules/mood/tools.ts +11 -11
  77. package/src/modules/music/MusicDataBean.d.ts +47 -47
  78. package/src/modules/music/MusicDataBean.ts +167 -167
  79. package/src/modules/music/MusicManager.d.ts +27 -27
  80. package/src/modules/music/MusicManager.ts +207 -207
  81. package/src/modules/music/MusicPage.d.ts +10 -10
  82. package/src/modules/music/MusicPage.tsx +347 -347
  83. package/src/modules/music/MusicPageActions.d.ts +35 -35
  84. package/src/modules/music/MusicPageActions.ts +317 -317
  85. package/src/modules/music/Router.ts +16 -16
  86. package/src/modules/music/SelecetGenre.d.ts +7 -7
  87. package/src/modules/music/SelecetGenre.tsx +63 -63
  88. package/src/modules/music/color.d.ts +2 -2
  89. package/src/modules/music/color.ts +73 -73
  90. package/src/modules/music/res/index.d.ts +10 -10
  91. package/src/modules/music/res/index.ts +9 -9
  92. package/src/modules/powerOnBehavior/PowerOnBehaviorActions.ts +11 -11
  93. package/src/modules/powerOnBehavior/PowerOnBehaviorPage.tsx +173 -173
  94. package/src/modules/powerOnBehavior/Router.ts +16 -16
  95. package/src/modules/randomTime/RandomTimeActions.ts +160 -160
  96. package/src/modules/randomTime/RandomTimeDetailPage.tsx +337 -337
  97. package/src/modules/randomTime/RandomTimePage.tsx +214 -214
  98. package/src/modules/randomTime/Router.ts +25 -25
  99. package/src/modules/randomTime/Summary.tsx +122 -122
  100. package/src/modules/scene/SceneAction.d.ts +13 -13
  101. package/src/modules/scene/SceneAction.ts +473 -473
  102. package/src/modules/scene/SceneDetailPage.d.ts +1 -1
  103. package/src/modules/scene/SceneDetailPage.tsx +421 -421
  104. package/src/modules/scene/SceneInfo.d.ts +72 -72
  105. package/src/modules/scene/SceneInfo.ts +1059 -1059
  106. package/src/modules/scene/ScenePage.d.ts +7 -7
  107. package/src/modules/scene/ScenePage.tsx +147 -147
  108. package/src/modules/select/SelectPage.d.ts +12 -12
  109. package/src/modules/select/SelectPage.tsx +137 -137
  110. package/src/modules/sleepWakeup/DeviceState.d.ts +9 -9
  111. package/src/modules/sleepWakeup/DeviceState.tsx +99 -99
  112. package/src/modules/sleepWakeup/LdvScheduleItem.d.ts +15 -15
  113. package/src/modules/sleepWakeup/LdvScheduleItem.tsx +176 -176
  114. package/src/modules/sleepWakeup/Router.ts +25 -25
  115. package/src/modules/sleepWakeup/SleepWakeUpActions.d.ts +2 -2
  116. package/src/modules/sleepWakeup/SleepWakeUpActions.ts +180 -180
  117. package/src/modules/sleepWakeup/SleepWakeUpDetailPage.d.ts +2 -2
  118. package/src/modules/sleepWakeup/SleepWakeUpDetailPage.tsx +616 -616
  119. package/src/modules/sleepWakeup/SleepWakeUpPage.d.ts +13 -13
  120. package/src/modules/sleepWakeup/SleepWakeUpPage.tsx +424 -424
  121. package/src/modules/sleepWakeup/utils.d.ts +44 -44
  122. package/src/modules/sleepWakeup/utils.ts +253 -253
  123. package/src/modules/timeSchedule/DeviceState.d.ts +17 -17
  124. package/src/modules/timeSchedule/DeviceState.tsx +94 -94
  125. package/src/modules/timeSchedule/LdvScheduleItem.d.ts +15 -15
  126. package/src/modules/timeSchedule/LdvScheduleItem.tsx +130 -130
  127. package/src/modules/timeSchedule/ManualSetting.d.ts +14 -14
  128. package/src/modules/timeSchedule/ManualSetting.tsx +219 -219
  129. package/src/modules/timeSchedule/MoodSetting.d.ts +11 -11
  130. package/src/modules/timeSchedule/MoodSetting.tsx +228 -228
  131. package/src/modules/timeSchedule/Router.ts +25 -25
  132. package/src/modules/timeSchedule/ScheduleScene.d.ts +6 -6
  133. package/src/modules/timeSchedule/ScheduleScene.tsx +144 -144
  134. package/src/modules/timeSchedule/SingleLightView.d.ts +12 -12
  135. package/src/modules/timeSchedule/SingleLightView.tsx +175 -175
  136. package/src/modules/timeSchedule/TimeScheduleBean.d.ts +14 -14
  137. package/src/modules/timeSchedule/TimeScheduleBean.ts +18 -18
  138. package/src/modules/timeSchedule/TimeScheduleEditpage.d.ts +6 -6
  139. package/src/modules/timeSchedule/TimeScheduleEditpage.tsx +765 -765
  140. package/src/modules/timeSchedule/TimeSchedulePage.d.ts +13 -13
  141. package/src/modules/timeSchedule/TimeSchedulePage.tsx +358 -358
  142. package/src/modules/timeSchedule/components/ColorList.ts +23 -23
  143. package/src/modules/timeSchedule/components/LampSwitchCard.tsx +106 -106
  144. package/src/modules/timeSchedule/mix/MixLightActions.d.ts +3 -3
  145. package/src/modules/timeSchedule/mix/MixLightActions.ts +49 -49
  146. package/src/modules/timeSchedule/mix/MixLightBean.d.ts +10 -10
  147. package/src/modules/timeSchedule/mix/MixLightBean.ts +9 -9
  148. package/src/modules/timeSchedule/mix/MixLightView.d.ts +7 -7
  149. package/src/modules/timeSchedule/mix/MixLightView.tsx +197 -197
  150. package/src/modules/timeSchedule/utils.d.ts +1 -1
  151. package/src/modules/timeSchedule/utils.ts +6 -6
  152. package/src/modules/timer/Router.ts +16 -16
  153. package/src/modules/timer/TimerPage.d.ts +11 -11
  154. package/src/modules/timer/TimerPage.tsx +384 -384
  155. package/src/modules/timer/TimerPageAction.d.ts +22 -22
  156. package/src/modules/timer/TimerPageAction.ts +131 -131
  157. package/src/navigation/Routers.d.ts +15 -15
  158. package/src/navigation/Routers.ts +46 -46
  159. package/src/navigation/tools.d.ts +9 -9
  160. package/src/navigation/tools.ts +21 -21
  161. package/src/newModules/biorhythm/BiorhythmActions.ts +62 -11
  162. package/src/newModules/biorhythm/BiorhythmPage.tsx +1 -4
  163. package/src/newModules/childLock/ChildLockPage.tsx +97 -97
  164. package/src/newModules/childLock/Router.ts +16 -16
  165. package/src/newModules/energyConsumption/EnergyConsumptionActions.ts +23 -23
  166. package/src/newModules/energyConsumption/EnergyConsumptionChart.tsx +84 -84
  167. package/src/newModules/energyConsumption/EnergyConsumptionDetail.tsx +322 -322
  168. package/src/newModules/energyConsumption/EnergyConsumptionPage.tsx +393 -393
  169. package/src/newModules/energyConsumption/Router.ts +34 -34
  170. package/src/newModules/energyConsumption/co2Data.ts +23655 -23655
  171. package/src/newModules/energyConsumption/component/BarChart.tsx +93 -93
  172. package/src/newModules/energyConsumption/component/EnergyModal.tsx +284 -284
  173. package/src/newModules/energyConsumption/component/Overview.tsx +118 -118
  174. package/src/newModules/fixedTime/FixedTimeActions.ts +241 -241
  175. package/src/newModules/fixedTime/FixedTimeDetailPage.tsx +345 -345
  176. package/src/newModules/fixedTime/FixedTimePage.tsx +302 -302
  177. package/src/newModules/fixedTime/Router.ts +25 -25
  178. package/src/newModules/lightMode/LightModePage.tsx +204 -204
  179. package/src/newModules/lightMode/Router.ts +16 -16
  180. package/src/newModules/mood/AddMoodPage.tsx +194 -194
  181. package/src/newModules/mood/DynamicMoodEditorPage.tsx +650 -650
  182. package/src/newModules/mood/Interface.ts +220 -220
  183. package/src/newModules/mood/MixDynamicMoodEditor.tsx +786 -786
  184. package/src/newModules/mood/MoodActions.ts +232 -232
  185. package/src/newModules/mood/MoodInfo.ts +2151 -2151
  186. package/src/newModules/mood/MoodItem.tsx +160 -160
  187. package/src/newModules/mood/MoodPage.tsx +386 -386
  188. package/src/newModules/mood/MoodParse.ts +443 -443
  189. package/src/newModules/mood/RecommendMoodItem.tsx +81 -81
  190. package/src/newModules/mood/Router.ts +43 -43
  191. package/src/newModules/mood/StaticMoodEditorPage.tsx +290 -290
  192. package/src/newModules/overchargeSwitch/OverchargeSwitchPage.tsx +96 -96
  193. package/src/newModules/overchargeSwitch/Router.ts +16 -16
  194. package/src/newModules/powerOnBehavior/LightBehaviorPage.tsx +266 -266
  195. package/src/newModules/powerOnBehavior/PlugBehaviorPage.tsx +173 -173
  196. package/src/newModules/powerOnBehavior/PowerOnBehaviorActions.ts +106 -106
  197. package/src/newModules/powerOnBehavior/Router.ts +27 -27
  198. package/src/newModules/randomTime/RandomTimeActions.ts +238 -238
  199. package/src/newModules/randomTime/RandomTimeDetailPage.tsx +325 -325
  200. package/src/newModules/randomTime/RandomTimePage.tsx +299 -299
  201. package/src/newModules/randomTime/Router.ts +25 -25
  202. package/src/newModules/randomTime/Summary.tsx +116 -116
  203. package/src/newModules/remoteControl/RemoteControlActions.ts +5 -5
  204. package/src/newModules/remoteControl/RemoteControlPage.tsx +51 -51
  205. package/src/newModules/remoteControl/Router.ts +15 -15
  206. package/src/newModules/select/Route.ts +16 -16
  207. package/src/newModules/select/SelectPage.d.ts +12 -12
  208. package/src/newModules/select/SelectPage.tsx +137 -137
  209. package/src/newModules/sleepWakeUp/Interface.ts +69 -69
  210. package/src/newModules/sleepWakeUp/Router.ts +24 -24
  211. package/src/newModules/sleepWakeUp/SleepWakeUpActions.ts +317 -317
  212. package/src/newModules/sleepWakeUp/SleepWakeUpDetailPage.tsx +661 -661
  213. package/src/newModules/sleepWakeUp/SleepWakeUpPage.tsx +455 -455
  214. package/src/newModules/sleepWakeUp/utils.ts +253 -253
  215. package/src/newModules/swithInching/Router.ts +16 -16
  216. package/src/newModules/swithInching/SwithInching.tsx +231 -231
  217. package/src/newModules/swithInching/SwithInchingAction.ts +55 -55
  218. package/src/newModules/swithInching/pickerView.tsx +91 -91
  219. package/src/newModules/timeSchedule/Interface.ts +142 -142
  220. package/src/newModules/timeSchedule/Router.ts +25 -25
  221. package/src/newModules/timeSchedule/TimeScheduleActions.ts +53 -53
  222. package/src/newModules/timeSchedule/TimeScheduleDetailPage.tsx +648 -648
  223. package/src/newModules/timeSchedule/TimeSchedulePage.tsx +253 -253
  224. package/src/newModules/timeSchedule/components/ManuaSettings.tsx +460 -460
  225. package/src/newModules/timeSchedule/components/ScheduleCard.tsx +125 -125
  226. package/tsconfig.json +50 -50
@@ -1,324 +1,324 @@
1
- import {
2
- BiorhythmBean,
3
- BiorhythmGradientType,
4
- BiorhythmGradientTypeMap,
5
- BiorhythmGradientTypeMap2,
6
- colorTemperatureValue,
7
- colorTempPercent,
8
- getDefRepeatPeriod,
9
- Period,
10
- Plan,
11
- RemoteBiorhythmBean,
12
- } from './BiorhythmBean'
13
- import {useDispatch} from 'react-redux'
14
- import {Dispatch, useEffect, useState} from 'react'
15
- import {NativeResult, Result} from '@ledvance/base/src/models/modules/Result'
16
- import {asyncSetDps, useDeviceId, useDp} from '@ledvance/base/src/models/modules/NativePropsSlice'
17
- import {getFeature, NativeApi, putFeature} from '@ledvance/base/src/api/native'
18
- import {setBiorhythmDp} from '../../hooks/DeviceDpStateHooks'
19
- import {hex2Int, spliceByStep} from '@ledvance/base/src/utils/common'
20
- import I18n from '@ledvance/base/src/i18n'
21
- import BiologicalRes from './res/BiologicalRes'
22
- import dayjs from 'dayjs'
23
-
24
- type UseBiorhythmType = (dpKey: string) => [BiorhythmBean, SetBiorhythmType];
25
- type SetBiorhythmType = (deviceId: string, biorhythmObj: BiorhythmBean) => Promise<Result<any>>;
26
- let rhythmTimer: undefined | number = undefined
27
- export const useBiorhythm: UseBiorhythmType = (dpKey: string) => {
28
- const [dp] = useDp<string, any>(dpKey)
29
- const deviceId = useDeviceId()
30
- const [biorhythmState, setBiorhythmState] = useState(dp2Obj(dp))
31
- useEffect(() => {
32
- rhythmTimer = setTimeout(() =>{
33
- getRemoteBiorhythm(deviceId, biorhythmState).then(res => {
34
- if (res.success && res.data) {
35
- setBiorhythmState(dto2Vo(res.data))
36
- }
37
- })
38
- }, 400)
39
- return () =>{
40
- if(rhythmTimer) clearTimeout(rhythmTimer)
41
- }
42
- }, [dp])
43
- return [biorhythmState, setBiorhythm(useDispatch(), dpKey)]
44
- }
45
-
46
- const biorhythmFeatureId = 'Biorhythm'
47
-
48
- async function getRemoteBiorhythm(deviceId: string, defBiorhythmState: BiorhythmBean): Promise<Result<RemoteBiorhythmBean>> {
49
- const res: NativeResult<RemoteBiorhythmBean> = await getFeature(deviceId, biorhythmFeatureId)
50
- if (!(!!res.data)) {
51
- const defData = vo2Dto(defBiorhythmState)
52
- const pushRes = await putFeature(deviceId, biorhythmFeatureId, defData)
53
- if (pushRes.result) {
54
- return getRemoteBiorhythm(deviceId, defBiorhythmState)
55
- }
56
- return {
57
- success: false,
58
- msg: pushRes.msg,
59
- }
60
- }
61
- return {
62
- success: true,
63
- data: res.data,
64
- }
65
- }
66
-
67
- const setBiorhythm = (dispatch: Dispatch<any>, dpKey: string) => (deviceId: string, biorhythmObj: BiorhythmBean) =>
68
- asyncSetDps(dispatch, async () => {
69
- const dpValue = obj2Dp(biorhythmObj)
70
- const putFeatureRes = await putFeature(deviceId, biorhythmFeatureId, vo2Dto(biorhythmObj))
71
- if (putFeatureRes.result) {
72
- const controlResult: any = await setBiorhythmDp(deviceId, dpKey, dpValue)
73
- return {
74
- result: {success: controlResult.result},
75
- dps: {[dpKey]: dpValue},
76
- }
77
- }
78
- return {
79
- result: {success: false},
80
- }
81
- })
82
-
83
- export const userOperation = async (deviceId: string, value: boolean) => {
84
- const currentTime = dayjs().format('YYYY-MM-DD')
85
- const json = JSON.stringify({status: value, suspendTime: value && currentTime || ''})
86
- return await NativeApi.putJson(deviceId, 'suspendTime', json)
87
- }
88
-
89
- export function dp2Obj(dp: string): BiorhythmBean {
90
- if (!dp || dp === '0000000000') {
91
- return dp2Obj('0000007f0501060000000000000001061e00000000141901090000000000646401140000000000503201171e000000000000')
92
- }
93
- let dpCopy = dp
94
- // 版本
95
- hex2Int(dpCopy.slice(0, 2))
96
- dpCopy = dpCopy.slice(2)
97
- // 开关
98
- const enable = hex2Int(dpCopy.slice(0, 2)) === 1
99
- dpCopy = dpCopy.slice(2)
100
- // 模式:00 全程渐变,0F 直接渐变
101
- const gradient =
102
- dpCopy.slice(0, 2).toLowerCase() === '00'
103
- ? BiorhythmGradientType.EntireGradient
104
- : BiorhythmGradientType.DirectGradient
105
- dpCopy = dpCopy.slice(2)
106
- // 重复周期
107
- const repeatPeriod: Period[] = hex2Int(dpCopy.slice(0, 2))
108
- .toString(2)
109
- .padStart(7, '0')
110
- .split('')
111
- .reverse()
112
- .map((p, index) => {
113
- return {
114
- index: index === 0 ? 7 : index,
115
- title: getRepeatPeriodTitleByIndex(index),
116
- enabled: p === '1',
117
- }
118
- })
119
- dpCopy = dpCopy.slice(2)
120
- // 节点个数 (每个节点长度18),最多8个节点
121
- hex2Int(dpCopy.slice(0, 2))
122
- dpCopy = dpCopy.slice(2)
123
- // 节点列表
124
- const planList: Plan[] = dpCopy === '00' ? [] : spliceByStep(dpCopy, 18).map((planHex, index) => {
125
- let hex = planHex
126
- // 节点开关
127
- const enable = hex2Int(hex.slice(0, 2)) === 1
128
- hex = hex.slice(2)
129
- // 小时
130
- const hour = hex2Int(hex.slice(0, 2)).toString().padStart(2, '0')
131
- hex = hex.slice(2)
132
- // 分钟
133
- const minute = hex2Int(hex.slice(0, 2)).toString().padStart(2, '0')
134
- hex = hex.slice(2)
135
- const startTime = `${hour}:${minute}`
136
- // 色调 (色相)
137
- hex2Int(hex.slice(0, 4))
138
- hex = hex.slice(4)
139
- // 饱和度
140
- hex2Int(hex.slice(0, 2))
141
- hex = hex.slice(2)
142
- // 明度
143
- hex2Int(hex.slice(0, 2))
144
- hex = hex.slice(2)
145
- // 亮度
146
- const brightness = hex2Int(hex.slice(0, 2))
147
- hex = hex.slice(2)
148
- // 色温
149
- const colorTemperature = hex2Int(hex.slice(0, 2))
150
- return {
151
- id: index,
152
- enable: enable,
153
- icon: getNodeIconByIndex(index),
154
- startTime: startTime,
155
- name: getNodeNameByIndex(index),
156
- colorTemperature: colorTemperature,
157
- brightness: brightness,
158
- action: [
159
- {
160
- uri: 'model/attribute/set/LightCtrl/ColorTemperature',
161
- startValue: `${colorTemperatureValue(colorTemperature)}`,
162
- },
163
- {
164
- uri: 'model/attribute/set/LightCtrl/Brightness',
165
- startValue: `${brightness}`,
166
- },
167
- ],
168
- }
169
- })
170
- return {
171
- enable: enable,
172
- gradient: gradient,
173
- repeatPeriod: repeatPeriod,
174
- planList: planList,
175
- }
176
- }
177
-
178
- function getNodeNameByIndex(index: number): string {
179
- switch (index) {
180
- case 0:
181
- return I18n.getLang('bio_ryhthm_default_field_text')
182
- case 1:
183
- return I18n.getLang('bio_ryhthm_default_field_text2')
184
- case 2:
185
- return I18n.getLang('bio_ryhthm_default_field_text3')
186
- case 3:
187
- return I18n.getLang('bio_ryhthm_default_field_text4')
188
- case 4:
189
- return I18n.getLang('bio_ryhthm_default_field_text5')
190
- default:
191
- return `Node ${index + 1}`
192
- }
193
- }
194
-
195
- function getNodeIconByIndex(index: number): string {
196
- switch (index) {
197
- case 0:
198
- return BiologicalRes.rhythm_icon1
199
- case 1:
200
- return BiologicalRes.rhythm_icon2
201
- case 2:
202
- return BiologicalRes.rhythm_icon3
203
- case 3:
204
- return BiologicalRes.rhythm_icon4
205
- case 4:
206
- return BiologicalRes.rhythm_icon12
207
- case 5:
208
- return BiologicalRes.rhythm_icon1
209
- case 6:
210
- return BiologicalRes.rhythm_icon2
211
- case 7:
212
- return BiologicalRes.rhythm_icon3
213
- default:
214
- return BiologicalRes.rhythm_icon1
215
- }
216
- }
217
-
218
- function getRepeatPeriodTitleByIndex(index: number): string {
219
- let title = ''
220
- switch (index) {
221
- case 0:
222
- title = I18n.getLang('bio_ryhthm_default_weekday7_text')
223
- break
224
- case 1:
225
- title = I18n.getLang('bio_ryhthm_default_weekday1_text')
226
- break
227
- case 2:
228
- title = I18n.getLang('bio_ryhthm_default_weekday2_text')
229
- break
230
- case 3:
231
- title = I18n.getLang('bio_ryhthm_default_weekday3_text')
232
- break
233
- case 4:
234
- title = I18n.getLang('bio_ryhthm_default_weekday4_text')
235
- break
236
- case 5:
237
- title = I18n.getLang('bio_ryhthm_default_weekday5_text')
238
- break
239
- case 6:
240
- title = I18n.getLang('bio_ryhthm_default_weekday6_text')
241
- break
242
- }
243
- return title
244
- }
245
-
246
- function obj2Dp(obj: BiorhythmBean): string {
247
- const versionHex = '00'
248
- const enableHex = obj.enable ? '01' : '00'
249
- const gradientHex = obj.gradient === BiorhythmGradientType.EntireGradient ? '00' : '0F'
250
- const repeatPeriodHex = parseInt(
251
- obj.repeatPeriod
252
- .map(p => (p.enabled ? '1' : '0'))
253
- .reverse()
254
- .join(''),
255
- 2,
256
- )
257
- .toString(16)
258
- .padStart(2, '0')
259
- const planCountHex = obj.planList.length.toString(16).padStart(2, '0')
260
- const planListHex = obj.planList
261
- .map(plan => {
262
- const enableHex = plan.enable ? '01' : '00'
263
- const startTime = plan.startTime.split(':')
264
- const hourHex = parseInt(startTime[0]).toString(16).padStart(2, '0')
265
- const minuteHex = parseInt(startTime[1]).toString(16).padStart(2, '0')
266
- const hsvHex = '00000000'
267
- const brightnessHex = plan.brightness.toString(16).padStart(2, '0')
268
- const colorTemperatureHex = plan.colorTemperature.toString(16).padStart(2, '0')
269
- return enableHex + hourHex + minuteHex + hsvHex + brightnessHex + colorTemperatureHex
270
- })
271
- .join('')
272
- return versionHex + enableHex + gradientHex + repeatPeriodHex + planCountHex + planListHex
273
- }
274
-
275
- /**
276
- * BiorhythmBean 转 RemoteBiorhythmBean
277
- */
278
- function vo2Dto(biorhythmBean: BiorhythmBean): RemoteBiorhythmBean {
279
- return {
280
- enable: biorhythmBean.enable,
281
- repeatPeriod: biorhythmBean.repeatPeriod.filter(r => r.enabled).map(r => r.index),
282
- gradientWay: BiorhythmGradientTypeMap[biorhythmBean.gradient],
283
- rhythmPlan: biorhythmBean.planList.map(plan => {
284
- return {
285
- name: plan.name,
286
- rhythmIcon: plan.icon,
287
- enable: plan.enable,
288
- startTime: plan.startTime,
289
- sustain: plan.id, // 持续时间涂鸦这边没有,直接用来存ID
290
- action: plan.action,
291
- iconId: plan.iconId,
292
- }
293
- }),
294
- }
295
- }
296
-
297
- /**
298
- * RemoteBiorhythmBean 转 BiorhythmBean
299
- */
300
- function dto2Vo(remoteBiorhythmBean: RemoteBiorhythmBean): BiorhythmBean {
301
- return {
302
- enable: remoteBiorhythmBean.enable,
303
- repeatPeriod: getDefRepeatPeriod().map(repeatItem => {
304
- return {
305
- ...repeatItem,
306
- enabled: remoteBiorhythmBean.repeatPeriod.includes(repeatItem.index),
307
- }
308
- }),
309
- gradient: BiorhythmGradientTypeMap2[remoteBiorhythmBean.gradientWay],
310
- planList: remoteBiorhythmBean.rhythmPlan.map(plan => {
311
- return {
312
- id: plan.sustain,
313
- enable: plan.enable,
314
- icon: plan.rhythmIcon,
315
- startTime: plan.startTime,
316
- name: plan.name,
317
- colorTemperature: colorTempPercent(parseInt(plan.action[0].startValue)),
318
- brightness: parseInt(plan.action[1].startValue),
319
- action: plan.action,
320
- iconId: plan.iconId,
321
- }
322
- }),
323
- }
324
- }
1
+ import {
2
+ BiorhythmBean,
3
+ BiorhythmGradientType,
4
+ BiorhythmGradientTypeMap,
5
+ BiorhythmGradientTypeMap2,
6
+ colorTemperatureValue,
7
+ colorTempPercent,
8
+ getDefRepeatPeriod,
9
+ Period,
10
+ Plan,
11
+ RemoteBiorhythmBean,
12
+ } from './BiorhythmBean'
13
+ import {useDispatch} from 'react-redux'
14
+ import {Dispatch, useEffect, useState} from 'react'
15
+ import {NativeResult, Result} from '@ledvance/base/src/models/modules/Result'
16
+ import {asyncSetDps, useDeviceId, useDp} from '@ledvance/base/src/models/modules/NativePropsSlice'
17
+ import {getFeature, NativeApi, putFeature} from '@ledvance/base/src/api/native'
18
+ import {setBiorhythmDp} from '../../hooks/DeviceDpStateHooks'
19
+ import {hex2Int, spliceByStep} from '@ledvance/base/src/utils/common'
20
+ import I18n from '@ledvance/base/src/i18n'
21
+ import BiologicalRes from './res/BiologicalRes'
22
+ import dayjs from 'dayjs'
23
+
24
+ type UseBiorhythmType = (dpKey: string) => [BiorhythmBean, SetBiorhythmType];
25
+ type SetBiorhythmType = (deviceId: string, biorhythmObj: BiorhythmBean) => Promise<Result<any>>;
26
+ let rhythmTimer: undefined | number = undefined
27
+ export const useBiorhythm: UseBiorhythmType = (dpKey: string) => {
28
+ const [dp] = useDp<string, any>(dpKey)
29
+ const deviceId = useDeviceId()
30
+ const [biorhythmState, setBiorhythmState] = useState(dp2Obj(dp))
31
+ useEffect(() => {
32
+ rhythmTimer = setTimeout(() =>{
33
+ getRemoteBiorhythm(deviceId, biorhythmState).then(res => {
34
+ if (res.success && res.data) {
35
+ setBiorhythmState(dto2Vo(res.data))
36
+ }
37
+ })
38
+ }, 400)
39
+ return () =>{
40
+ if(rhythmTimer) clearTimeout(rhythmTimer)
41
+ }
42
+ }, [dp])
43
+ return [biorhythmState, setBiorhythm(useDispatch(), dpKey)]
44
+ }
45
+
46
+ const biorhythmFeatureId = 'Biorhythm'
47
+
48
+ async function getRemoteBiorhythm(deviceId: string, defBiorhythmState: BiorhythmBean): Promise<Result<RemoteBiorhythmBean>> {
49
+ const res: NativeResult<RemoteBiorhythmBean> = await getFeature(deviceId, biorhythmFeatureId)
50
+ if (!(!!res.data)) {
51
+ const defData = vo2Dto(defBiorhythmState)
52
+ const pushRes = await putFeature(deviceId, biorhythmFeatureId, defData)
53
+ if (pushRes.result) {
54
+ return getRemoteBiorhythm(deviceId, defBiorhythmState)
55
+ }
56
+ return {
57
+ success: false,
58
+ msg: pushRes.msg,
59
+ }
60
+ }
61
+ return {
62
+ success: true,
63
+ data: res.data,
64
+ }
65
+ }
66
+
67
+ const setBiorhythm = (dispatch: Dispatch<any>, dpKey: string) => (deviceId: string, biorhythmObj: BiorhythmBean) =>
68
+ asyncSetDps(dispatch, async () => {
69
+ const dpValue = obj2Dp(biorhythmObj)
70
+ const putFeatureRes = await putFeature(deviceId, biorhythmFeatureId, vo2Dto(biorhythmObj))
71
+ if (putFeatureRes.result) {
72
+ const controlResult: any = await setBiorhythmDp(deviceId, dpKey, dpValue)
73
+ return {
74
+ result: {success: controlResult.result},
75
+ dps: {[dpKey]: dpValue},
76
+ }
77
+ }
78
+ return {
79
+ result: {success: false},
80
+ }
81
+ })
82
+
83
+ export const userOperation = async (deviceId: string, value: boolean) => {
84
+ const currentTime = dayjs().format('YYYY-MM-DD')
85
+ const json = JSON.stringify({status: value, suspendTime: value && currentTime || ''})
86
+ return await NativeApi.putJson(deviceId, 'suspendTime', json)
87
+ }
88
+
89
+ export function dp2Obj(dp: string): BiorhythmBean {
90
+ if (!dp || dp === '0000000000') {
91
+ return dp2Obj('0000007f0501060000000000000001061e00000000141901090000000000646401140000000000503201171e000000000000')
92
+ }
93
+ let dpCopy = dp
94
+ // 版本
95
+ hex2Int(dpCopy.slice(0, 2))
96
+ dpCopy = dpCopy.slice(2)
97
+ // 开关
98
+ const enable = hex2Int(dpCopy.slice(0, 2)) === 1
99
+ dpCopy = dpCopy.slice(2)
100
+ // 模式:00 全程渐变,0F 直接渐变
101
+ const gradient =
102
+ dpCopy.slice(0, 2).toLowerCase() === '00'
103
+ ? BiorhythmGradientType.EntireGradient
104
+ : BiorhythmGradientType.DirectGradient
105
+ dpCopy = dpCopy.slice(2)
106
+ // 重复周期
107
+ const repeatPeriod: Period[] = hex2Int(dpCopy.slice(0, 2))
108
+ .toString(2)
109
+ .padStart(7, '0')
110
+ .split('')
111
+ .reverse()
112
+ .map((p, index) => {
113
+ return {
114
+ index: index === 0 ? 7 : index,
115
+ title: getRepeatPeriodTitleByIndex(index),
116
+ enabled: p === '1',
117
+ }
118
+ })
119
+ dpCopy = dpCopy.slice(2)
120
+ // 节点个数 (每个节点长度18),最多8个节点
121
+ hex2Int(dpCopy.slice(0, 2))
122
+ dpCopy = dpCopy.slice(2)
123
+ // 节点列表
124
+ const planList: Plan[] = dpCopy === '00' ? [] : spliceByStep(dpCopy, 18).map((planHex, index) => {
125
+ let hex = planHex
126
+ // 节点开关
127
+ const enable = hex2Int(hex.slice(0, 2)) === 1
128
+ hex = hex.slice(2)
129
+ // 小时
130
+ const hour = hex2Int(hex.slice(0, 2)).toString().padStart(2, '0')
131
+ hex = hex.slice(2)
132
+ // 分钟
133
+ const minute = hex2Int(hex.slice(0, 2)).toString().padStart(2, '0')
134
+ hex = hex.slice(2)
135
+ const startTime = `${hour}:${minute}`
136
+ // 色调 (色相)
137
+ hex2Int(hex.slice(0, 4))
138
+ hex = hex.slice(4)
139
+ // 饱和度
140
+ hex2Int(hex.slice(0, 2))
141
+ hex = hex.slice(2)
142
+ // 明度
143
+ hex2Int(hex.slice(0, 2))
144
+ hex = hex.slice(2)
145
+ // 亮度
146
+ const brightness = hex2Int(hex.slice(0, 2))
147
+ hex = hex.slice(2)
148
+ // 色温
149
+ const colorTemperature = hex2Int(hex.slice(0, 2))
150
+ return {
151
+ id: index,
152
+ enable: enable,
153
+ icon: getNodeIconByIndex(index),
154
+ startTime: startTime,
155
+ name: getNodeNameByIndex(index),
156
+ colorTemperature: colorTemperature,
157
+ brightness: brightness,
158
+ action: [
159
+ {
160
+ uri: 'model/attribute/set/LightCtrl/ColorTemperature',
161
+ startValue: `${colorTemperatureValue(colorTemperature)}`,
162
+ },
163
+ {
164
+ uri: 'model/attribute/set/LightCtrl/Brightness',
165
+ startValue: `${brightness}`,
166
+ },
167
+ ],
168
+ }
169
+ })
170
+ return {
171
+ enable: enable,
172
+ gradient: gradient,
173
+ repeatPeriod: repeatPeriod,
174
+ planList: planList,
175
+ }
176
+ }
177
+
178
+ function getNodeNameByIndex(index: number): string {
179
+ switch (index) {
180
+ case 0:
181
+ return I18n.getLang('bio_ryhthm_default_field_text')
182
+ case 1:
183
+ return I18n.getLang('bio_ryhthm_default_field_text2')
184
+ case 2:
185
+ return I18n.getLang('bio_ryhthm_default_field_text3')
186
+ case 3:
187
+ return I18n.getLang('bio_ryhthm_default_field_text4')
188
+ case 4:
189
+ return I18n.getLang('bio_ryhthm_default_field_text5')
190
+ default:
191
+ return `Node ${index + 1}`
192
+ }
193
+ }
194
+
195
+ function getNodeIconByIndex(index: number): string {
196
+ switch (index) {
197
+ case 0:
198
+ return BiologicalRes.rhythm_icon1
199
+ case 1:
200
+ return BiologicalRes.rhythm_icon2
201
+ case 2:
202
+ return BiologicalRes.rhythm_icon3
203
+ case 3:
204
+ return BiologicalRes.rhythm_icon4
205
+ case 4:
206
+ return BiologicalRes.rhythm_icon12
207
+ case 5:
208
+ return BiologicalRes.rhythm_icon1
209
+ case 6:
210
+ return BiologicalRes.rhythm_icon2
211
+ case 7:
212
+ return BiologicalRes.rhythm_icon3
213
+ default:
214
+ return BiologicalRes.rhythm_icon1
215
+ }
216
+ }
217
+
218
+ function getRepeatPeriodTitleByIndex(index: number): string {
219
+ let title = ''
220
+ switch (index) {
221
+ case 0:
222
+ title = I18n.getLang('bio_ryhthm_default_weekday7_text')
223
+ break
224
+ case 1:
225
+ title = I18n.getLang('bio_ryhthm_default_weekday1_text')
226
+ break
227
+ case 2:
228
+ title = I18n.getLang('bio_ryhthm_default_weekday2_text')
229
+ break
230
+ case 3:
231
+ title = I18n.getLang('bio_ryhthm_default_weekday3_text')
232
+ break
233
+ case 4:
234
+ title = I18n.getLang('bio_ryhthm_default_weekday4_text')
235
+ break
236
+ case 5:
237
+ title = I18n.getLang('bio_ryhthm_default_weekday5_text')
238
+ break
239
+ case 6:
240
+ title = I18n.getLang('bio_ryhthm_default_weekday6_text')
241
+ break
242
+ }
243
+ return title
244
+ }
245
+
246
+ function obj2Dp(obj: BiorhythmBean): string {
247
+ const versionHex = '00'
248
+ const enableHex = obj.enable ? '01' : '00'
249
+ const gradientHex = obj.gradient === BiorhythmGradientType.EntireGradient ? '00' : '0F'
250
+ const repeatPeriodHex = parseInt(
251
+ obj.repeatPeriod
252
+ .map(p => (p.enabled ? '1' : '0'))
253
+ .reverse()
254
+ .join(''),
255
+ 2,
256
+ )
257
+ .toString(16)
258
+ .padStart(2, '0')
259
+ const planCountHex = obj.planList.length.toString(16).padStart(2, '0')
260
+ const planListHex = obj.planList
261
+ .map(plan => {
262
+ const enableHex = plan.enable ? '01' : '00'
263
+ const startTime = plan.startTime.split(':')
264
+ const hourHex = parseInt(startTime[0]).toString(16).padStart(2, '0')
265
+ const minuteHex = parseInt(startTime[1]).toString(16).padStart(2, '0')
266
+ const hsvHex = '00000000'
267
+ const brightnessHex = plan.brightness.toString(16).padStart(2, '0')
268
+ const colorTemperatureHex = plan.colorTemperature.toString(16).padStart(2, '0')
269
+ return enableHex + hourHex + minuteHex + hsvHex + brightnessHex + colorTemperatureHex
270
+ })
271
+ .join('')
272
+ return versionHex + enableHex + gradientHex + repeatPeriodHex + planCountHex + planListHex
273
+ }
274
+
275
+ /**
276
+ * BiorhythmBean 转 RemoteBiorhythmBean
277
+ */
278
+ function vo2Dto(biorhythmBean: BiorhythmBean): RemoteBiorhythmBean {
279
+ return {
280
+ enable: biorhythmBean.enable,
281
+ repeatPeriod: biorhythmBean.repeatPeriod.filter(r => r.enabled).map(r => r.index),
282
+ gradientWay: BiorhythmGradientTypeMap[biorhythmBean.gradient],
283
+ rhythmPlan: biorhythmBean.planList.map(plan => {
284
+ return {
285
+ name: plan.name,
286
+ rhythmIcon: plan.icon,
287
+ enable: plan.enable,
288
+ startTime: plan.startTime,
289
+ sustain: plan.id, // 持续时间涂鸦这边没有,直接用来存ID
290
+ action: plan.action,
291
+ iconId: plan.iconId,
292
+ }
293
+ }),
294
+ }
295
+ }
296
+
297
+ /**
298
+ * RemoteBiorhythmBean 转 BiorhythmBean
299
+ */
300
+ function dto2Vo(remoteBiorhythmBean: RemoteBiorhythmBean): BiorhythmBean {
301
+ return {
302
+ enable: remoteBiorhythmBean.enable,
303
+ repeatPeriod: getDefRepeatPeriod().map(repeatItem => {
304
+ return {
305
+ ...repeatItem,
306
+ enabled: remoteBiorhythmBean.repeatPeriod.includes(repeatItem.index),
307
+ }
308
+ }),
309
+ gradient: BiorhythmGradientTypeMap2[remoteBiorhythmBean.gradientWay],
310
+ planList: remoteBiorhythmBean.rhythmPlan.map(plan => {
311
+ return {
312
+ id: plan.sustain,
313
+ enable: plan.enable,
314
+ icon: plan.rhythmIcon,
315
+ startTime: plan.startTime,
316
+ name: plan.name,
317
+ colorTemperature: colorTempPercent(parseInt(plan.action[0].startValue)),
318
+ brightness: parseInt(plan.action[1].startValue),
319
+ action: plan.action,
320
+ iconId: plan.iconId,
321
+ }
322
+ }),
323
+ }
324
+ }