@ledvance/ui-biz-bundle 1.1.135 → 1.1.136

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "name": "@ledvance/ui-biz-bundle",
5
5
  "pid": [],
6
6
  "uiid": "",
7
- "version": "1.1.135",
7
+ "version": "1.1.136",
8
8
  "scripts": {},
9
9
  "dependencies": {
10
10
  "@ledvance/base": "^1.x",
@@ -23,7 +23,7 @@ const SwitchInching = (props: { theme?: ThemeType }) => {
23
23
  const navigation = useNavigation()
24
24
  const [switchInching, setSwitchInching] = useSwitchInching(params.switchIngCode)
25
25
  const [checkConflict, resolveConflict] = useConflictTask(params.conflictDps, true)
26
- const [countdowns, setCountdowns] = useCountdowns(params.countdownCode || params.channelConfig?.map(item => item.countdownCode) || [])
26
+ const [countdowns, setCountdowns] = useCountdowns(params.countdownCode || params.channelConfig.map(item => item.countdownCode))
27
27
  const timeRef = useRef({
28
28
  minute: '00',
29
29
  second: '00',
@@ -41,23 +41,23 @@ const SwitchInching = (props: { theme?: ThemeType }) => {
41
41
  const updateTime = (minute?: string, second?: string) => {
42
42
  if (minute !== undefined) timeRef.current.minute = minute;
43
43
  if (second !== undefined) timeRef.current.second = second;
44
-
44
+
45
45
  if (!Number(timeRef.current.minute) && Number(timeRef.current.second) < 1) {
46
46
  timeRef.current.second = '01';
47
47
  }
48
-
48
+
49
49
  if (Number(timeRef.current.minute) === 60) {
50
50
  timeRef.current.second = '00';
51
51
  }
52
-
52
+
53
53
  const time = Number(timeRef.current.minute) * 60 + Number(timeRef.current.second);
54
54
  const newSwitchInchingItem = {
55
55
  ...state.switchInchingItem,
56
56
  time
57
57
  };
58
-
58
+
59
59
  updateState({ switchInchingItem: newSwitchInchingItem });
60
-
60
+
61
61
  };
62
62
 
63
63
  const switchInchingItem = useMemo(() => {
@@ -73,11 +73,8 @@ const SwitchInching = (props: { theme?: ThemeType }) => {
73
73
  const saveInchingConfig = async (item: SwitchInchingItem) => {
74
74
  const updatedSwitchInching = [...switchInching];
75
75
  const existingItemIndex = updatedSwitchInching.findIndex(item => item.channel === state.channel);
76
- if (existingItemIndex === -1) {
77
- updatedSwitchInching.push(item);
78
- } else {
79
- updatedSwitchInching[existingItemIndex] = item;
80
- }
76
+ updatedSwitchInching[existingItemIndex] = item;
77
+ console.log('updatedSwitchInching', updatedSwitchInching)
81
78
  await setSwitchInching(updatedSwitchInching)
82
79
  }
83
80
 
@@ -146,18 +143,18 @@ const SwitchInching = (props: { theme?: ThemeType }) => {
146
143
  >
147
144
  <ScrollView nestedScrollEnabled={true}>
148
145
  {params.channelConfig && params.channelConfig.length > 1 && <>
149
- <Segmented
150
- style={{ marginHorizontal: cx(24) }}
151
- options={params.channelConfig.map(item => ({
152
- label: item.channelTitle,
153
- value: item.channel
154
- }))}
155
- value={state.channel}
156
- onChange={v => {
157
- updateState({ channel: Number(v) })
158
- }}
159
- />
160
- <Spacer />
146
+ <Segmented
147
+ style={{ marginHorizontal: cx(24) }}
148
+ options={params.channelConfig.map(item => ({
149
+ label: item.channelTitle,
150
+ value: item.channel
151
+ }))}
152
+ value={state.channel}
153
+ onChange={v => {
154
+ updateState({ channel: Number(v) })
155
+ }}
156
+ />
157
+ <Spacer />
161
158
  </>}
162
159
  <View style={styles.switchContainer}>
163
160
  <View style={styles.switchCardContainer}>
@@ -3,15 +3,14 @@ import { Result } from "@ledvance/base/src/models/modules/Result"
3
3
  import { useDp } from "@ledvance/base/src/models/modules/NativePropsSlice";
4
4
  import { spliceByStep } from '@ledvance/base/src/utils/common';
5
5
  import { Utils } from '@tuya/tuya-panel-lamp-sdk'
6
- import {useEffect, useState} from "react";
7
6
 
8
7
  const { to16 } = Utils
9
8
  export interface SwitchInchingPageParams {
10
9
  switchIngCode: string
11
10
  countdownCode?: string
12
11
  channelConfig?: {
13
- countdownCode: string
14
- channelTitle: string
12
+ countdownCode: string
13
+ channelTitle: string
15
14
  channel: number
16
15
  }[]
17
16
  conflictDps: {
@@ -32,20 +31,20 @@ export function useCountdowns(countdownCodes: string | string[]): [Record<string
32
31
  const codes = Array.isArray(countdownCodes) ? countdownCodes : [countdownCodes];
33
32
  const countdownValues: Record<string, number> = {};
34
33
  const dpSetters: Record<string, (value: number) => Promise<Result<any>>> = {};
35
-
34
+
36
35
  for (const code of codes) {
37
36
  const [value, setDp] = useDp<number, any>(code);
38
37
  countdownValues[code] = value;
39
38
  dpSetters[code] = setDp;
40
39
  }
41
-
40
+
42
41
  const setCountdown = async (countdownCode: string, value: number) => {
43
42
  if (dpSetters[countdownCode]) {
44
43
  return await dpSetters[countdownCode](value);
45
44
  }
46
45
  return { success: false, msg: 'Countdown code not found' } as Result<any>;
47
46
  };
48
-
47
+
49
48
  return [countdownValues, setCountdown];
50
49
  }
51
50
 
@@ -57,19 +56,15 @@ export const defSwitchInching = [{ enable: false, channel: 0, time: 1 }]
57
56
 
58
57
  export const useSwitchInching = (switchInchingCode: string) => {
59
58
  const [hex, setHex] = useSwitchInchingHex(switchInchingCode)
60
- const [value, setValue] = useState(defSwitchInching)
61
- useEffect(() => {
62
- const switching = hex ? spliceByStep(Buffer.from(hex, 'base64').toString('hex'), 6).map(item => {
63
- const powerInfo = parseInt(`${item.slice(0, 2)}`, 16).toString(2).padStart(8, '0');
64
- const powerBits = powerInfo.split('');
65
- const enable = !!Number(powerBits[powerBits.length - 1]);
66
- // 通道号
67
- const channel = parseInt(powerBits.slice(1, powerBits.length - 1).join(''), 2);
68
- const time = parseInt(item.slice(2, 6), 16)
69
- return { enable, channel, time }
70
- }) : defSwitchInching
71
- setValue(switching)
72
- }, [hex]);
59
+ const switching = hex ? spliceByStep(Buffer.from(hex, 'base64').toString('hex'), 6).map(item => {
60
+ const powerInfo = parseInt(`${item.slice(0, 2)}`, 16).toString(2).padStart(8, '0');
61
+ const powerBits = powerInfo.split('');
62
+ const enable = !!Number(powerBits[powerBits.length - 1]);
63
+ // 通道号
64
+ const channel = parseInt(powerBits.slice(1, powerBits.length - 1).join(''), 2);
65
+ const time = parseInt(item.slice(2, 6), 16)
66
+ return { enable, channel, time }
67
+ }) : defSwitchInching
73
68
 
74
69
  const setSwitchInching = (switching: SwitchInchingItem[]) => {
75
70
  const inchingString = switching.map(item => {
@@ -80,9 +75,8 @@ export const useSwitchInching = (switchInchingCode: string) => {
80
75
  return powerChannelStr + timeHex
81
76
  }).join('')
82
77
  const inchingHex = Buffer.from(inchingString, 'hex').toString('base64')
83
- setValue(switching)
84
78
  return setHex(inchingHex)
85
79
  }
86
- return [value, setSwitchInching] as const
80
+ return [switching, setSwitchInching] as const
87
81
  }
88
82