@ledvance/base 1.1.12 → 1.1.14

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/.prettierrc.js CHANGED
File without changes
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "name": "@ledvance/base",
5
5
  "pid": [],
6
6
  "uiid": "",
7
- "version": "1.1.12",
7
+ "version": "1.1.14",
8
8
  "scripts": {},
9
9
  "dependencies": {
10
10
  "@reduxjs/toolkit": "^1.8.6",
package/src/api/native.ts CHANGED
@@ -16,6 +16,8 @@ interface LDVDevicePanelManager {
16
16
  formatNumber: (num: number, fixed: number) => string
17
17
  getTimeZone: () => string
18
18
  groupControl: (tyGroupId: number, dps: string, config: string) => Promise<NativeResult<any>>
19
+ getFeature: (deviceId: string, featureId: string, callback: (res: NativeResult<string>) => void) => void
20
+ putFeature: (deviceId: string, featureId: string, value: any, callback: (res: NativeResult<string>) => void) => void
19
21
  }
20
22
 
21
23
  const devicePanel: LDVDevicePanelManager = NativeModules.LDVDevicePanelManager
@@ -101,6 +103,37 @@ const setDps = <T>(deviceId: string, dps: any) => {
101
103
  })
102
104
  }
103
105
 
106
+ type GetFeatureResultType = (deviceId: string, featureId: string) => Promise<NativeResult<any>>;
107
+ type SetFeatureResultType = (
108
+ deviceId: string,
109
+ featureId: string,
110
+ value: any,
111
+ ) => Promise<NativeResult<any>>;
112
+
113
+ export const getFeature: GetFeatureResultType = (deviceId: string, featureId: string) => {
114
+ return new Promise((resolve, _reject) => {
115
+ devicePanel.getFeature(deviceId, featureId, res => {
116
+ const result: NativeResult<any> = {
117
+ ...res,
118
+ data: !!res.data ? JSON.parse(res.data).value : null,
119
+ }
120
+ resolve(result)
121
+ })
122
+ })
123
+ }
124
+
125
+ export const putFeature: SetFeatureResultType = (
126
+ deviceId: string,
127
+ featureId: string,
128
+ value: any,
129
+ ) => {
130
+ return new Promise((resolve, _reject) => {
131
+ devicePanel.putFeature(deviceId, featureId, JSON.stringify({ value }), res => {
132
+ resolve(res)
133
+ })
134
+ })
135
+ }
136
+
104
137
  type DeleteDeviceResultType = (deviceId: string, isReset: boolean) => Promise<NativeResult<any>>
105
138
 
106
139
  const deleteDevice: DeleteDeviceResultType = (deviceId: string, isReset: boolean) => {
@@ -16,7 +16,7 @@ let groupFeatureListener: EmitterSubscription|null
16
16
 
17
17
  interface GroupFeatureEvent {
18
18
  tyGroupId: number
19
- config: any
19
+ config: string
20
20
  }
21
21
 
22
22
  interface DeviceEvent {
@@ -57,7 +57,7 @@ export const addListener = (store) => {
57
57
  uaGroupInfo: {
58
58
  tyGroupId: event.tyGroupId,
59
59
  pId: '',
60
- config: event.config,
60
+ config: JSON.parse(event.config),
61
61
  dps: {}
62
62
  },
63
63
  }
@@ -0,0 +1,48 @@
1
+ import { StyleProp, StyleSheet, View, ViewProps, ViewStyle } from 'react-native'
2
+ import React from 'react'
3
+ import { Utils } from 'tuya-panel-kit'
4
+
5
+ const cx = Utils.RatioUtils.convertX
6
+
7
+ interface ColorsLineProps extends ViewProps {
8
+ colors: string[]
9
+ nodeStyle?: StyleProp<ViewStyle>
10
+ }
11
+
12
+ const ColorsLine = (props: ColorsLineProps) => {
13
+ return (
14
+ <View style={[styles.root, props.style]}>
15
+ {
16
+ props.colors.map((color, index) => {
17
+ return (
18
+ <View
19
+ key={`${index}`}
20
+ style={[
21
+ styles.colorNode,
22
+ {
23
+ backgroundColor: color,
24
+ marginStart: index === 0 ? 0 : cx(5),
25
+ },
26
+ props.nodeStyle,
27
+ ]} />
28
+ )
29
+ })
30
+ }
31
+ </View>
32
+ )
33
+ }
34
+
35
+ const styles = StyleSheet.create({
36
+ root: {
37
+ flexDirection: 'row',
38
+ width: cx(295),
39
+ height: cx(24),
40
+ },
41
+ colorNode: {
42
+ flex: 1,
43
+ height: cx(24),
44
+ borderRadius: cx(8),
45
+ },
46
+ })
47
+
48
+ export default ColorsLine
@@ -0,0 +1,38 @@
1
+ import LinearGradientLine from "./LinearGradientLine"
2
+ import React from 'react'
3
+ import { Utils } from 'tuya-panel-kit'
4
+ import { StyleSheet } from 'react-native'
5
+ import ColorsLine from './ColorsLine'
6
+
7
+ const cx = Utils.RatioUtils.convertX
8
+
9
+ export type MoodColorsLineType = 'gradient' | 'separate'
10
+
11
+ interface MoodColorsLineProps {
12
+ width?: number
13
+ height?: number
14
+ type: MoodColorsLineType
15
+ colors: string[]
16
+ }
17
+
18
+ export default function MoodColorsLine(props: MoodColorsLineProps) {
19
+ const width = props.width || cx(295)
20
+ const height = props.height || cx(24)
21
+ if (props.type === 'separate' || props.colors.length < 2) {
22
+ return (<ColorsLine colors={props.colors} style={{ width, height }} />)
23
+ } else {
24
+ return (
25
+ <LinearGradientLine
26
+ width={width}
27
+ height={height}
28
+ style={styles.gradient}
29
+ colors={props.colors} />
30
+ )
31
+ }
32
+ }
33
+
34
+ const styles = StyleSheet.create({
35
+ gradient: {
36
+ borderRadius: cx(8),
37
+ },
38
+ })
@@ -153,7 +153,7 @@ const composeLayout = (component: React.ComponentType) => {
153
153
  tyGroupId: uaGroupInfo.tyGroupId,
154
154
  dps: {...dps, ...JSON.parse(uaGroupInfo.dps)},
155
155
  pId: uaGroupInfo.pId,
156
- config: uaGroupInfo.config || {},
156
+ config: JSON.parse(uaGroupInfo.config || '{}'),
157
157
  },
158
158
  familyName: uaGroupInfo.familyName,
159
159
  }
@@ -43,7 +43,7 @@ export declare function useGroupConfig<T>(): [T, (dps: any, newConfig: T) => Pro
43
43
  */
44
44
  export declare function useGroupConfigFeature<GC, GCPT extends {
45
45
  [K in keyof GC]: GC[K];
46
- }[keyof GC]>(key: keyof GC, extraDps?: any): [GCPT, (value: GCPT) => Promise<Result<any>>];
46
+ }[keyof GC]>(key: keyof GC, extraDps?: any): [GCPT, (value: GCPT, dpValue: any) => Promise<Result<any>>];
47
47
  export declare const ldvModules: import("@reduxjs/toolkit").Reducer<NativeProps, import("@reduxjs/toolkit").AnyAction>;
48
48
  export declare const setNativeProps: import("@reduxjs/toolkit").ActionCreatorWithPayload<NativeProps, string>, setGroupNativeProps: import("@reduxjs/toolkit").ActionCreatorWithPayload<NativeProps, string>, setDps: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, string>, setTimeSchedule: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, string>, setEnergieverbrauch: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, string>;
49
49
  export { simpleSetDps, simpleSetDp, useDeviceId, useDeviceInfo, useDp, useDps, useFamilyName, useTimeSchedule, useEnergieverbrauch, };
@@ -222,12 +222,12 @@ export function useGroupConfig<T>(): [T, (dps: any, newConfig: T) => Promise<Res
222
222
  * @param extraDps
223
223
  */
224
224
  export function useGroupConfigFeature<GC, GCPT extends { [K in keyof GC]: GC[K] }[keyof GC]>
225
- (key: keyof GC, extraDps: any = {}): [GCPT, (value: GCPT) => Promise<Result<any>>] {
225
+ (key: keyof GC, extraDps: any = {}): [GCPT, (value: GCPT, dpValue: any) => Promise<Result<any>>] {
226
226
  const [groupConfig, setGroupConfig] = useGroupConfig<GC>()
227
- const setGroupConfigFeature = async (value: GCPT) => {
227
+ const setGroupConfigFeature = async (value: GCPT, dpValue: any) => {
228
228
  return await setGroupConfig(
229
229
  {
230
- [GlobalParams.dpSchemaMap[snakeCase(key as string)].dp]: value,
230
+ [GlobalParams.dpSchemaMap[snakeCase(key as string)].dp]: dpValue,
231
231
  ...extraDps,
232
232
  },
233
233
  {
@@ -0,0 +1,85 @@
1
+ // 判断是否是plug
2
+ export const isPlug = (dpCodes: Record<string,string>) =>{
3
+ return !!dpCodes.switch_1
4
+ }
5
+
6
+ // 玻璃灯:支持颜色和色温灯同时调节
7
+ export const isGlassRGBWLamp = (dpCodes: Record<string,string>) => {
8
+ return !!(
9
+ !dpCodes.mix_rgbcw &&
10
+ !dpCodes.temp_value &&
11
+ dpCodes.colour_data &&
12
+ dpCodes.bright_value
13
+ );
14
+ };
15
+ // 双灯泡吸顶灯:支持颜色和色温灯同时调节
16
+ export const isMixRGBWLamp = (dpCodes: Record<string,string>) => {
17
+ return !!(
18
+ dpCodes.mix_rgbcw &&
19
+ dpCodes.colour_data &&
20
+ dpCodes.temp_value &&
21
+ dpCodes.bright_value
22
+ );
23
+ };
24
+
25
+ // 支持调节:颜色/色温+亮度
26
+ export const isRGBWLamp = (dpCodes: Record<string,string>) => {
27
+ return !!(
28
+ !dpCodes.mix_rgbcw &&
29
+ dpCodes.colour_data &&
30
+ dpCodes.temp_value &&
31
+ dpCodes.bright_value
32
+ );
33
+ };
34
+
35
+ // 支持调节:颜色/单一色温亮度
36
+ export const isRGBLamp = (dpCodes: Record<string,string>) => {
37
+ return !!(
38
+ !dpCodes.mix_rgbcw &&
39
+ !dpCodes.temp_value &&
40
+ dpCodes.colour_data &&
41
+ dpCodes.bright_value
42
+ );
43
+ };
44
+
45
+ // 支持调节:颜色
46
+ export const isOnlyRGBLamp = (dpCodes: Record<string,string>) => {
47
+ return !!(
48
+ !dpCodes.mix_rgbcw &&
49
+ !dpCodes.temp_value &&
50
+ !dpCodes.bright_value &&
51
+ dpCodes.colour_data
52
+ );
53
+ };
54
+
55
+ // 支持调节:色温+亮度
56
+ export const isTWLamp = (dpCodes: Record<string,string>) => {
57
+ return !!(
58
+ !dpCodes.mix_rgbcw &&
59
+ !dpCodes.colour_data &&
60
+ dpCodes.temp_value &&
61
+ dpCodes.bright_value
62
+ );
63
+ };
64
+
65
+ // 支持调节:单一色温亮度
66
+ export const isDIMLamp = (dpCodes: Record<string,string>) => {
67
+ return !!(
68
+ !dpCodes.mix_rgbcw &&
69
+ !dpCodes.colour_data &&
70
+ !dpCodes.temp_value &&
71
+ dpCodes.bright_value
72
+ );
73
+ };
74
+
75
+ // GARDOT灯具
76
+ export const isGARDOT = (dpCodes: Record<string,string>) => {
77
+ return !!(
78
+ dpCodes.switch_led &&
79
+ dpCodes.work_mode &&
80
+ dpCodes.colour_data &&
81
+ dpCodes.scene_data &&
82
+ dpCodes.countdown &&
83
+ dpCodes.control_data
84
+ );
85
+ };
@@ -0,0 +1,111 @@
1
+ const ccts = {
2
+ "0": "rgb(254, 172, 91)",
3
+ "1": "rgb(254, 174, 94)",
4
+ "2": "rgb(253, 176, 97)",
5
+ "3": "rgb(253, 178, 101)",
6
+ "4": "rgb(253, 180, 105)",
7
+ "5": "rgb(253, 181, 109)",
8
+ "6": "rgb(252, 183, 112)",
9
+ "7": "rgb(252, 185, 116)",
10
+ "8": "rgb(252, 187, 120)",
11
+ "9": "rgb(252, 189, 123)",
12
+ "10": "rgb(251, 191, 127)",
13
+ "11": "rgb(251, 193, 131)",
14
+ "12": "rgb(251, 194, 134)",
15
+ "13": "rgb(251, 196, 138)",
16
+ "14": "rgb(250, 198, 142)",
17
+ "15": "rgb(250, 200, 146)",
18
+ "16": "rgb(250, 202, 149)",
19
+ "17": "rgb(250, 204, 153)",
20
+ "18": "rgb(249, 206, 157)",
21
+ "19": "rgb(249, 207, 160)",
22
+ "20": "rgb(249, 209, 164)",
23
+ "21": "rgb(249, 211, 167)",
24
+ "22": "rgb(250, 213, 170)",
25
+ "23": "rgb(250, 214, 173)",
26
+ "24": "rgb(250, 216, 176)",
27
+ "25": "rgb(250, 218, 179)",
28
+ "26": "rgb(251, 220, 182)",
29
+ "27": "rgb(251, 221, 185)",
30
+ "28": "rgb(251, 223, 188)",
31
+ "29": "rgb(251, 225, 191)",
32
+ "30": "rgb(252, 227, 194)",
33
+ "31": "rgb(252, 228, 197)",
34
+ "32": "rgb(252, 230, 199)",
35
+ "33": "rgb(252, 232, 203)",
36
+ "34": "rgb(253, 234, 206)",
37
+ "35": "rgb(253, 235, 209)",
38
+ "36": "rgb(253, 237, 211)",
39
+ "37": "rgb(253, 239, 214)",
40
+ "38": "rgb(254, 241, 217)",
41
+ "39": "rgb(254, 242, 220)",
42
+ "40": "rgb(254, 244, 223)",
43
+ "41": "rgb(254, 244, 224)",
44
+ "42": "rgb(254, 245, 225)",
45
+ "43": "rgb(254, 245, 226)",
46
+ "44": "rgb(254, 245, 227)",
47
+ "45": "rgb(253, 246, 228)",
48
+ "46": "rgb(253, 246, 229)",
49
+ "47": "rgb(253, 246, 230)",
50
+ "48": "rgb(253, 246, 231)",
51
+ "49": "rgb(253, 247, 232)",
52
+ "50": "rgb(253, 247, 233)",
53
+ "51": "rgb(253, 247, 234)",
54
+ "52": "rgb(253, 248, 234)",
55
+ "53": "rgb(253, 248, 235)",
56
+ "54": "rgb(253, 248, 236)",
57
+ "55": "rgb(252, 249, 237)",
58
+ "56": "rgb(252, 249, 238)",
59
+ "57": "rgb(252, 249, 239)",
60
+ "58": "rgb(252, 249, 240)",
61
+ "59": "rgb(252, 250, 241)",
62
+ "60": "rgb(252, 250, 242)",
63
+ "61": "rgb(251, 249, 242)",
64
+ "62": "rgb(249, 248, 243)",
65
+ "63": "rgb(248, 248, 243)",
66
+ "64": "rgb(247, 247, 243)",
67
+ "65": "rgb(246, 246, 243)",
68
+ "66": "rgb(244, 245, 244)",
69
+ "67": "rgb(243, 245, 244)",
70
+ "68": "rgb(241, 244, 244)",
71
+ "69": "rgb(240, 243, 245)",
72
+ "70": "rgb(239, 242, 245)",
73
+ "71": "rgb(238, 242, 245)",
74
+ "72": "rgb(236, 241, 246)",
75
+ "73": "rgb(235, 240, 246)",
76
+ "74": "rgb(234, 239, 246)",
77
+ "75": "rgb(232, 239, 247)",
78
+ "76": "rgb(231, 238, 247)",
79
+ "77": "rgb(230, 237, 247)",
80
+ "78": "rgb(228, 236, 247)",
81
+ "79": "rgb(227, 236, 248)",
82
+ "80": "rgb(226, 235, 248)",
83
+ "81": "rgb(224, 234, 248)",
84
+ "82": "rgb(223, 233, 249)",
85
+ "83": "rgb(221, 232, 249)",
86
+ "84": "rgb(219, 231, 249)",
87
+ "85": "rgb(218, 230, 250)",
88
+ "86": "rgb(216, 230, 250)",
89
+ "87": "rgb(215, 229, 250)",
90
+ "88": "rgb(213, 228, 250)",
91
+ "89": "rgb(212, 227, 251)",
92
+ "90": "rgb(210, 226, 251)",
93
+ "91": "rgb(208, 225, 251)",
94
+ "92": "rgb(207, 224, 252)",
95
+ "93": "rgb(205, 223, 252)",
96
+ "94": "rgb(203, 222, 252)",
97
+ "95": "rgb(202, 221, 253)",
98
+ "96": "rgb(200, 221, 253)",
99
+ "97": "rgb(199, 220, 253)",
100
+ "98": "rgb(197, 219, 253)",
101
+ "99": "rgb(196, 218, 254)",
102
+ "100": "rgb(194, 217, 254)"
103
+ }
104
+
105
+ export const cctToColor = (key: string | number, brightness?: string | number) => {
106
+ let color = ccts[String(key)]
107
+ if (color && (brightness || brightness === 0)) {
108
+ color = Number(brightness) === 0 ? 'rgb(0,0,0)' : `rgba(${color.slice(4, -1)}, ${Number(brightness) / 100 < 0.1 ? 0.1 : Number(brightness) / 100})`
109
+ }
110
+ return color
111
+ }