@ledvance/ui-biz-bundle 1.1.56 → 1.1.58

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 (70) hide show
  1. package/package.json +2 -1
  2. package/src/modules/biorhythm/Router.ts +34 -0
  3. package/src/modules/fixedTime/Router.ts +26 -0
  4. package/src/modules/flags/FlagInfo.tsx +25 -25
  5. package/src/modules/flags/FlagPage.tsx +1 -1
  6. package/src/modules/flags/Router.ts +25 -0
  7. package/src/modules/history/Router.ts +16 -0
  8. package/src/modules/mood/FantasyRouter.ts +35 -0
  9. package/src/modules/mood/MixMood/Router.ts +44 -0
  10. package/src/modules/mood/Router.ts +53 -0
  11. package/src/modules/music/Router.ts +16 -0
  12. package/src/modules/powerOnBehavior/Router.ts +16 -0
  13. package/src/modules/randomTime/Router.ts +25 -0
  14. package/src/modules/sleepWakeup/Router.ts +25 -0
  15. package/src/modules/timeSchedule/Router.ts +25 -0
  16. package/src/modules/timer/Router.ts +16 -0
  17. package/src/navigation/Routers.d.ts +0 -7
  18. package/src/navigation/Routers.ts +15 -304
  19. package/src/newModules/childLock/ChildLockPage.tsx +97 -0
  20. package/src/newModules/childLock/Router.ts +16 -0
  21. package/src/newModules/energyConsumption/EnergyConsumptionActions.ts +23 -0
  22. package/src/newModules/energyConsumption/EnergyConsumptionChart.tsx +84 -0
  23. package/src/newModules/energyConsumption/EnergyConsumptionDetail.tsx +321 -0
  24. package/src/newModules/energyConsumption/EnergyConsumptionPage.tsx +392 -0
  25. package/src/newModules/energyConsumption/Router.ts +34 -0
  26. package/src/newModules/energyConsumption/co2Data.ts +23655 -0
  27. package/src/newModules/energyConsumption/component/BarChart.tsx +93 -0
  28. package/src/newModules/energyConsumption/component/EnergyModal.tsx +282 -0
  29. package/src/newModules/energyConsumption/component/Overview.tsx +116 -0
  30. package/src/newModules/fixedTime/FixedTimeActions.ts +234 -0
  31. package/src/newModules/fixedTime/FixedTimeDetailPage.tsx +341 -0
  32. package/src/newModules/fixedTime/FixedTimePage.tsx +231 -0
  33. package/src/newModules/fixedTime/Router.ts +25 -0
  34. package/src/newModules/lightMode/LightModePage.tsx +204 -0
  35. package/src/newModules/lightMode/Router.ts +16 -0
  36. package/src/newModules/mood/AddMoodPage.tsx +178 -0
  37. package/src/newModules/mood/DynamicMoodEditorPage.tsx +653 -0
  38. package/src/newModules/mood/Interface.ts +219 -0
  39. package/src/newModules/mood/MixDynamicMoodEditor.tsx +781 -0
  40. package/src/newModules/mood/MoodActions.ts +235 -0
  41. package/src/newModules/mood/MoodInfo.ts +2151 -0
  42. package/src/newModules/mood/MoodItem.tsx +148 -0
  43. package/src/newModules/mood/MoodPage.tsx +385 -0
  44. package/src/newModules/mood/MoodParse.ts +442 -0
  45. package/src/newModules/mood/RecommendMoodItem.tsx +68 -0
  46. package/src/newModules/mood/Router.ts +53 -0
  47. package/src/newModules/mood/StaticMoodEditorPage.tsx +343 -0
  48. package/src/newModules/mood/tools.ts +12 -0
  49. package/src/newModules/overchargeSwitch/OverchargeSwitchPage.tsx +96 -0
  50. package/src/newModules/overchargeSwitch/Router.ts +16 -0
  51. package/src/newModules/powerOnBehavior/LightBehaviorPage.tsx +266 -0
  52. package/src/newModules/powerOnBehavior/PlugBehaviorPage.tsx +173 -0
  53. package/src/newModules/powerOnBehavior/PowerOnBehaviorActions.ts +106 -0
  54. package/src/newModules/powerOnBehavior/Router.ts +16 -0
  55. package/src/newModules/randomTime/RandomTimeActions.ts +232 -0
  56. package/src/newModules/randomTime/RandomTimeDetailPage.tsx +322 -0
  57. package/src/newModules/randomTime/RandomTimePage.tsx +230 -0
  58. package/src/newModules/randomTime/Router.ts +25 -0
  59. package/src/newModules/randomTime/Summary.tsx +116 -0
  60. package/src/newModules/swithInching/Router.ts +16 -0
  61. package/src/newModules/swithInching/SwithInching.tsx +231 -0
  62. package/src/newModules/swithInching/SwithInchingAction.ts +55 -0
  63. package/src/newModules/swithInching/pickerView.tsx +91 -0
  64. package/src/newModules/timeSchedule/Interface.ts +111 -0
  65. package/src/newModules/timeSchedule/Router.ts +25 -0
  66. package/src/newModules/timeSchedule/TimeScheduleActions.ts +53 -0
  67. package/src/newModules/timeSchedule/TimeScheduleDetailPage.tsx +662 -0
  68. package/src/newModules/timeSchedule/TimeSchedulePage.tsx +222 -0
  69. package/src/newModules/timeSchedule/components/ManuaSettings.tsx +259 -0
  70. package/src/newModules/timeSchedule/components/ScheduleCard.tsx +109 -0
@@ -0,0 +1,235 @@
1
+ import { NativeApi, getFeature, putFeature } from '@ledvance/base/src/api/native';
2
+ import {
3
+ DefMoodOption,
4
+ LightCategory,
5
+ MixRemoteMoodInfo,
6
+ MoodDps,
7
+ MoodInfo,
8
+ MoodUIInfo,
9
+ RemoteMoodInfo,
10
+ } from './Interface';
11
+ import { parseJSON } from '@tuya/tuya-panel-lamp-sdk/lib/utils';
12
+ import { getDefMoodList } from './MoodInfo';
13
+ import {
14
+ MixCeilingDpObj,
15
+ MixDp2Obj,
16
+ MixObj2Dp,
17
+ dp2Obj,
18
+ obj2Dp,
19
+ stripDp2Obj,
20
+ stripObj2Dp,
21
+ } from './MoodParse';
22
+ import { useDp, useDps } from '@ledvance/base/src/models/modules/NativePropsSlice';
23
+ import { useState } from 'react';
24
+ import { useUpdateEffect } from 'ahooks';
25
+ import { WorkMode } from '@ledvance/base/src/utils/interface';
26
+ import { Result } from '@ledvance/base/src/models/modules/Result';
27
+
28
+ const SceneFeatureId = 'SimplifyScene';
29
+ const MixLightSceneListFeatureId = 'MixLightSceneList';
30
+
31
+ export const useWorkMode = (dp: string): [WorkMode, (value: WorkMode) => Promise<Result<any>>] => {
32
+ return useDp(dp);
33
+ };
34
+
35
+ export const setRemoteMoodList = async (
36
+ devId: string,
37
+ isFeature: boolean,
38
+ remoteSceneList: RemoteMoodInfo[] | MixRemoteMoodInfo[],
39
+ featureId: string
40
+ ) => {
41
+ if (isFeature) {
42
+ const res = await putFeature(devId, featureId, remoteSceneList);
43
+ return {
44
+ success: res.result,
45
+ msg: res.msg,
46
+ data: res.data,
47
+ };
48
+ } else {
49
+ const res = await NativeApi.putJson(devId, featureId, JSON.stringify(remoteSceneList));
50
+ return res;
51
+ }
52
+ };
53
+
54
+ const getMoodInfo = (mainDp: string, option: LightCategory, secondaryDp: string) => {
55
+ const moodInfo = !!(option.isStringLight || option.isStripLight)
56
+ ? stripDp2Obj(mainDp, option.isStringLight)
57
+ : option.isMixLight
58
+ ? MixDp2Obj(mainDp)
59
+ : option.isCeilingLight
60
+ ? MixCeilingDpObj(mainDp, secondaryDp)
61
+ : dp2Obj(mainDp, option.isFanLight, option.isUVCFan);
62
+ return moodInfo;
63
+ };
64
+
65
+ const getMoodDp = (moodInfo: MoodUIInfo, option: LightCategory) => {
66
+ const moodDp = !!(option.isStringLight || option.isStripLight)
67
+ ? stripObj2Dp(moodInfo, option.isStringLight)
68
+ : option.isMixLight
69
+ ? MixObj2Dp(moodInfo)
70
+ : obj2Dp(moodInfo, option.isFanLight, option.isUVCFan);
71
+ return moodDp;
72
+ };
73
+
74
+ const remoteMoodInfo2MoodUIState = (
75
+ remoteMoodInfo,
76
+ index: number,
77
+ option: DefMoodOption
78
+ ): MoodUIInfo => {
79
+ const moodInfo = option.isMixLight
80
+ ? MixDp2Obj(remoteMoodInfo.value)
81
+ : getMoodInfo(remoteMoodInfo.i, option, remoteMoodInfo.s);
82
+ return {
83
+ name: option.isMixLight ? remoteMoodInfo.name : remoteMoodInfo.n,
84
+ image: '',
85
+ ...moodInfo,
86
+ };
87
+ };
88
+
89
+ export const getRemoteMoodList = async (
90
+ devId: string,
91
+ option: DefMoodOption,
92
+ featureId = SceneFeatureId
93
+ ) => {
94
+ const isFeature = !(option.isCeilingLight || option.isStringLight || option.isStripLight);
95
+ if (isFeature) {
96
+ const moodFeatureId = option.isMixLight ? MixLightSceneListFeatureId : SceneFeatureId;
97
+ // await setRemoteMoodList(devId, isFeature, getDefMoodList(option), moodFeatureId);
98
+ const res = await getFeature(devId, moodFeatureId);
99
+ if (!res.result) {
100
+ return { success: false };
101
+ }
102
+ if (!res.data) {
103
+ const result = await setRemoteMoodList(
104
+ devId,
105
+ isFeature,
106
+ getDefMoodList(option),
107
+ moodFeatureId
108
+ );
109
+ if (!result.success) {
110
+ return { success: false };
111
+ }
112
+ return {
113
+ success: true,
114
+ data: result.data.map((item, index) => remoteMoodInfo2MoodUIState(item, index, option)),
115
+ };
116
+ }
117
+ return {
118
+ success: true,
119
+ data: res.data.map((item, index) => remoteMoodInfo2MoodUIState(item, index, option)),
120
+ };
121
+ } else {
122
+ const moodFeatureId = option.isCeilingLight ? SceneFeatureId : featureId;
123
+ const res = await NativeApi.getJson(devId, moodFeatureId);
124
+ const isNormalData = Array.isArray(parseJSON(res?.data));
125
+ if (res.success && isNormalData) {
126
+ return {
127
+ success: true,
128
+ data:
129
+ res.data &&
130
+ parseJSON(res.data).map((item, index) => remoteMoodInfo2MoodUIState(item, index, option)),
131
+ };
132
+ } else {
133
+ if (res.msg?.includes('资源未找到') || !isNormalData) {
134
+ const defaultScene = getDefMoodList(option);
135
+ const res = await setRemoteMoodList(devId, isFeature, defaultScene, moodFeatureId);
136
+ if (res.success) {
137
+ return {
138
+ success: true,
139
+ data: defaultScene.map((item, index) =>
140
+ remoteMoodInfo2MoodUIState(item, index, option)
141
+ ),
142
+ };
143
+ }
144
+ return { success: false };
145
+ }
146
+ return { success: false };
147
+ }
148
+ }
149
+ };
150
+
151
+ export const useMoodScene = (
152
+ mainDp: string,
153
+ option: LightCategory,
154
+ secondaryDp?: string
155
+ ): [MoodInfo, (moodInfo: MoodUIInfo, moodDps: MoodDps) => Promise<Result<any>>] => {
156
+ const [dps, setDps] = useDps();
157
+ const main = dps[mainDp];
158
+ const secondary = secondaryDp ? dps[secondaryDp] : '';
159
+ const [moodState, setMoodState] = useState(getMoodInfo(main, option, secondary));
160
+
161
+ useUpdateEffect(() => {
162
+ setMoodState(getMoodInfo(main, option, secondary));
163
+ }, [main, secondary]);
164
+
165
+ const setMoodFn = (moodInfo: MoodUIInfo, moodDps: MoodDps) => {
166
+ const dps = {};
167
+ if (
168
+ (option.isCeilingLight && moodInfo.mainLamp && moodInfo.mainLamp.nodes.length) ||
169
+ !option.isCeilingLight
170
+ ) {
171
+ const mainHex = getMoodDp(moodInfo, option);
172
+ dps[moodDps.mainDp] = mainHex;
173
+ dps[moodDps.mainWorkMode] = WorkMode.Scene;
174
+ dps[moodDps.mainSwitch] = true;
175
+ }
176
+ if (
177
+ option.isCeilingLight &&
178
+ moodInfo.secondaryLamp &&
179
+ moodInfo.secondaryLamp.nodes.length &&
180
+ moodDps.secondaryDp
181
+ ) {
182
+ const secondaryHex = stripObj2Dp({
183
+ ...moodInfo,
184
+ mainLamp: moodInfo.secondaryLamp,
185
+ });
186
+ dps[moodDps.secondaryDp] = secondaryHex;
187
+ if (moodDps.secondaryWorkMode) dps[moodDps.secondaryWorkMode] = WorkMode.Scene;
188
+ if (moodDps.secondarySwitch) dps[moodDps.secondarySwitch] = true;
189
+ }
190
+ return setDps(dps);
191
+ };
192
+ return [moodState, setMoodFn];
193
+ };
194
+
195
+ export const saveMoodList = (
196
+ devId: string,
197
+ moodList: MoodUIInfo[],
198
+ option: LightCategory,
199
+ featureId = SceneFeatureId
200
+ ) => {
201
+ const remoteMoods: any = moodList.map(s => {
202
+ if (option.isMixLight) {
203
+ return {
204
+ name: s.name,
205
+ image: '',
206
+ value: MixObj2Dp(s),
207
+ };
208
+ }
209
+ return {
210
+ n: s.name,
211
+ i: getMoodDp(s, option),
212
+ s: option.isCeilingLight
213
+ ? stripObj2Dp({
214
+ ...s,
215
+ mainLamp: s.secondaryLamp,
216
+ })
217
+ : '',
218
+ t: 0,
219
+ e: false,
220
+ };
221
+ });
222
+ const isFeature = !(
223
+ option.isCeilingLight ||
224
+ option.isStringLight ||
225
+ option.isStripLight ||
226
+ option.isMatterLight ||
227
+ option.isUVCFan
228
+ );
229
+ const moodFeatureId = !!(option.isStringLight || option.isStripLight)
230
+ ? featureId
231
+ : option.isMixLight
232
+ ? MixLightSceneListFeatureId
233
+ : SceneFeatureId;
234
+ return setRemoteMoodList(devId, isFeature, remoteMoods, moodFeatureId);
235
+ };