@eohjsc/react-native-smart-city 0.3.22 → 0.3.23
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/index.js +2 -0
- package/package.json +2 -1
- package/src/Images/Common/buttonLeftCurtain.png +0 -0
- package/src/Images/Common/buttonLeftCurtain@2x.png +0 -0
- package/src/Images/Common/buttonLeftCurtain@3x.png +0 -0
- package/src/commons/Action/ItemQuickAction.js +1 -12
- package/src/commons/Action/__test__/ItemQuickAction.test.js +1 -1
- package/src/commons/ActionGroup/ColorPickerTemplate.js +2 -9
- package/src/commons/ActionGroup/CurtainButtonTemplate.js +5 -4
- package/src/commons/ActionGroup/CurtainButtonTemplateStyle.js +5 -0
- package/src/commons/ActionGroup/NumberUpDownActionTemplate.js +6 -16
- package/src/commons/ActionGroup/OnOffSmartLock/OnOffSmartLock.js +7 -4
- package/src/commons/ActionGroup/OnOffTemplate/index.js +6 -12
- package/src/commons/ActionGroup/OptionsDropdownActionTemplate.js +5 -2
- package/src/commons/ActionGroup/SliderRangeTemplate.js +4 -9
- package/src/commons/ActionGroup/StatesGridActionTemplate.js +7 -10
- package/src/commons/ActionGroup/TimerActionTemplate.js +11 -4
- package/src/commons/ActionGroup/TwoButtonTemplate/index.js +12 -15
- package/src/commons/ActionGroup/__test__/NumberUpDownTemplate.test.js +37 -2
- package/src/commons/ActionGroup/__test__/OnOffButtonTemplate.test.js +7 -0
- package/src/commons/ActionGroup/__test__/OnOffSmartLock.test.js +15 -2
- package/src/commons/ActionGroup/__test__/OnOffTemplate.test.js +8 -1
- package/src/commons/ActionGroup/__test__/OptionsDropdownTemplate.test.js +8 -1
- package/src/commons/ActionGroup/__test__/StatesGridActionTemplate.test.js +7 -0
- package/src/commons/ActionGroup/__test__/TimerActionTemplate.test.js +8 -1
- package/src/commons/ActionGroup/__test__/TimerActionTemplateWithutConfigValue.test.js +7 -0
- package/src/commons/ActionGroup/__test__/TwoButtonTemplate.test.js +7 -0
- package/src/commons/ActionGroup/__test__/index.test.js +8 -1
- package/src/commons/Device/ItemDevice.js +79 -35
- package/src/commons/MediaPlayerDetail/index.js +5 -0
- package/src/commons/RowItem/index.js +6 -2
- package/src/commons/RowItem/styles.js +1 -0
- package/src/commons/SubUnit/Favorites/index.js +22 -5
- package/src/commons/SubUnit/ShortDetail.js +19 -5
- package/src/commons/SubUnit/__test__/Favorites.test.js +1 -0
- package/src/commons/SubUnit/__test__/ShortDetail.test.js +1 -0
- package/src/configs/API.js +2 -2
- package/src/configs/Constants.js +8 -2
- package/src/configs/SCConfig.js +4 -0
- package/src/context/actionType.ts +4 -3
- package/src/context/mockStore.ts +10 -3
- package/src/context/reducer.ts +17 -12
- package/src/hoc/index.js +3 -0
- package/src/hoc/withRemoteControl.js +10 -0
- package/src/hooks/Common/index.js +2 -2
- package/src/hooks/Common/useDevicesStatus.js +57 -0
- package/src/hooks/Common/useGGHomeDeviceConnected.js +3 -3
- package/src/hooks/IoT/__test__/useGGHomeConnection.test.js +1 -2
- package/src/hooks/IoT/index.js +9 -1
- package/src/hooks/IoT/useGGHomeConnection.js +0 -1
- package/src/hooks/IoT/useUnwatchLGDeviceConfigControl.js +29 -0
- package/src/hooks/IoT/useWatchConfigs.js +34 -0
- package/src/iot/Monitor.js +13 -20
- package/src/iot/RemoteControl/GoogleHome.js +12 -13
- package/src/iot/RemoteControl/LG.js +1 -0
- package/src/iot/RemoteControl/__test__/GoogleHome.test.js +7 -2
- package/src/navigations/UnitStack.js +13 -0
- package/src/screens/AddNewAction/SelectAction.js +1 -1
- package/src/screens/AddNewAction/SetupSensor.js +4 -0
- package/src/screens/AddNewGateway/PlugAndPlay/ConnectWifiWarning.js +44 -78
- package/src/screens/AddNewGateway/PlugAndPlay/GatewayWifiList.js +15 -35
- package/src/screens/AddNewGateway/PlugAndPlay/__test__/GatewayWifiList.test.js +2 -0
- package/src/screens/AllCamera/__test__/index.test.js +1 -1
- package/src/screens/Device/__test__/detail.test.js +1 -54
- package/src/screens/Device/components/SensorConnectStatusViewHeader.js +18 -8
- package/src/screens/Device/detail.js +22 -12
- package/src/screens/Device/hooks/__test__/useEvaluateValue.test.js +102 -0
- package/src/screens/Device/hooks/useDeviceWatchConfigControl.js +20 -0
- package/src/screens/Device/utils/index.js +45 -0
- package/src/screens/Device/utils/index.test.js +111 -0
- package/src/screens/MoveToAnotherSubUnit/__test__/index.test.js +0 -2
- package/src/screens/Notification/__test__/NotificationItem.test.js +84 -19
- package/src/screens/Notification/components/NotificationItem.js +64 -31
- package/src/screens/SubUnit/AddSubUnit.js +2 -1
- package/src/screens/Unit/AddMenu.js +4 -0
- package/src/screens/Unit/__test__/CheckSendEmail.test.js +12 -0
- package/src/screens/Unit/__test__/Detail.test.js +2 -3
- package/src/screens/Unit/components/MyUnitDevice/index.js +3 -2
- package/src/screens/UnitSummary/components/3PPowerConsumption/index.js +4 -2
- package/src/utils/I18n/translations/en.json +5 -1
- package/src/utils/I18n/translations/vi.json +4 -0
- package/src/hooks/Common/useSensorsStatus.js +0 -62
package/index.js
CHANGED
|
@@ -18,6 +18,7 @@ import MyPinnedSharedUnit from './src/commons/Dashboard/MyPinnedSharedUnit';
|
|
|
18
18
|
import MyUnit from './src/commons/Dashboard/MyUnit';
|
|
19
19
|
import SharedUnit from './src/commons/Unit/SharedUnit';
|
|
20
20
|
import { Action } from './src/context/actionType';
|
|
21
|
+
import { withRemoteControl } from './src/hoc';
|
|
21
22
|
|
|
22
23
|
export {
|
|
23
24
|
AddSubUnitStack,
|
|
@@ -42,4 +43,5 @@ export {
|
|
|
42
43
|
MyUnit,
|
|
43
44
|
SCWrapper,
|
|
44
45
|
Action,
|
|
46
|
+
withRemoteControl,
|
|
45
47
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eohjsc/react-native-smart-city",
|
|
3
3
|
"title": "React Native Smart Home",
|
|
4
|
-
"version": "0.3.
|
|
4
|
+
"version": "0.3.23",
|
|
5
5
|
"description": "TODO",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"files": [
|
|
@@ -140,6 +140,7 @@
|
|
|
140
140
|
"pluralize": "^8.0.0",
|
|
141
141
|
"postinstall": "^0.7.0",
|
|
142
142
|
"pusher-js": "^7.0.3",
|
|
143
|
+
"pusher-js-auth": "^4.0.1",
|
|
143
144
|
"querystring": "^0.2.0",
|
|
144
145
|
"react-content-loader": "^6.0.3",
|
|
145
146
|
"react-dom": "^17.0.1",
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -2,7 +2,6 @@ import React, { memo, useCallback, useEffect, useState } from 'react';
|
|
|
2
2
|
import { TouchableOpacity, View } from 'react-native';
|
|
3
3
|
import { TESTID } from '../../configs/Constants';
|
|
4
4
|
import { useSCContextSelector } from '../../context';
|
|
5
|
-
import { watchMultiConfigs } from '../../iot/Monitor';
|
|
6
5
|
import { useRemoteControl } from '../../hooks/IoT';
|
|
7
6
|
import { useConfigGlobalState } from '../../iot/states';
|
|
8
7
|
import IconComponent from '../IconComponent';
|
|
@@ -42,13 +41,6 @@ const ItemQuickAction = memo(({ sensor, wrapperStyle, setStatus }) => {
|
|
|
42
41
|
[sensor, revertActionUpdate]
|
|
43
42
|
);
|
|
44
43
|
|
|
45
|
-
useEffect(() => {
|
|
46
|
-
sensor.quick_action &&
|
|
47
|
-
sensor.quick_action.config_id &&
|
|
48
|
-
sensor.device_type !== 'GOOGLE_HOME' &&
|
|
49
|
-
watchMultiConfigs([sensor.quick_action.config_id]);
|
|
50
|
-
}, [sensor.quick_action, sensor?.device_type]);
|
|
51
|
-
|
|
52
44
|
useEffect(() => {
|
|
53
45
|
if (!sensor.quick_action) {
|
|
54
46
|
return;
|
|
@@ -57,14 +49,11 @@ const ItemQuickAction = memo(({ sensor, wrapperStyle, setStatus }) => {
|
|
|
57
49
|
return;
|
|
58
50
|
}
|
|
59
51
|
const configValue = configValues[sensor.quick_action.config_id];
|
|
60
|
-
statusCallback(configValue);
|
|
52
|
+
statusCallback(configValue?.value);
|
|
61
53
|
}, [sensor, configValues, statusCallback]);
|
|
62
54
|
const userId = useSCContextSelector((state) => state?.auth.account.user.id);
|
|
63
55
|
const onActionPress = useCallback(() => {
|
|
64
56
|
sendRemoteCommand(sensor, action, null, userId);
|
|
65
|
-
sensor.quick_action &&
|
|
66
|
-
sensor.device_type !== 'GOOGLE_HOME' &&
|
|
67
|
-
watchMultiConfigs([sensor.quick_action.config_id]);
|
|
68
57
|
setIsSendingCommand(true);
|
|
69
58
|
|
|
70
59
|
if (!sensor.quick_action) {
|
|
@@ -328,7 +328,7 @@ describe('Test ItemQuickAction', () => {
|
|
|
328
328
|
|
|
329
329
|
test('listen to config value for update action', () => {
|
|
330
330
|
const globalStates = require('../../../iot/states');
|
|
331
|
-
globalStates.useConfigGlobalState = () => [{ 51: true }, null];
|
|
331
|
+
globalStates.useConfigGlobalState = () => [{ 51: { value: true } }, null];
|
|
332
332
|
|
|
333
333
|
const mockSetStatus = jest.fn();
|
|
334
334
|
|
|
@@ -2,7 +2,6 @@ import React, { memo, useState, useEffect } from 'react';
|
|
|
2
2
|
import { View } from 'react-native';
|
|
3
3
|
import styles from './ColorPickerTemplateStyles';
|
|
4
4
|
import ColorPicker from 'react-native-wheel-color-picker';
|
|
5
|
-
import { watchMultiConfigs } from '../../iot/Monitor';
|
|
6
5
|
import { useConfigGlobalState } from '../../iot/states';
|
|
7
6
|
|
|
8
7
|
let isFirstTime = true;
|
|
@@ -41,18 +40,12 @@ const ColorPickerTemplate = memo(({ actionGroup, doAction, sensor }) => {
|
|
|
41
40
|
useEffect(() => {
|
|
42
41
|
const { config } = configuration;
|
|
43
42
|
const configValue = configValues[config];
|
|
44
|
-
if (configValue && isFirstTime) {
|
|
45
|
-
setValueColorComplete(`#${configValue?.toString(16)}`);
|
|
43
|
+
if (configValue?.value && isFirstTime) {
|
|
44
|
+
setValueColorComplete(`#${configValue?.value?.toString(16)}`);
|
|
46
45
|
}
|
|
47
46
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
48
47
|
}, [configValues]);
|
|
49
48
|
|
|
50
|
-
useEffect(() => {
|
|
51
|
-
if (sensor?.is_managed_by_backend && sensor.device_type !== 'GOOGLE_HOME') {
|
|
52
|
-
watchMultiConfigs([configuration.config]);
|
|
53
|
-
}
|
|
54
|
-
}, [sensor, configuration.config]);
|
|
55
|
-
|
|
56
49
|
useEffect(() => {
|
|
57
50
|
return () => (isFirstTime = true);
|
|
58
51
|
}, []);
|
|
@@ -58,7 +58,7 @@ const CurtainButtonTemplate = memo(({ actionGroup, doAction, sensor }) => {
|
|
|
58
58
|
style: styles.buttonActionCurtain,
|
|
59
59
|
icon: Images.buttonLeftCurtain,
|
|
60
60
|
text: text1,
|
|
61
|
-
onPress:
|
|
61
|
+
onPress: onButtonClosePress,
|
|
62
62
|
testID: TESTID.BUTTON_TEMPLATE_1,
|
|
63
63
|
},
|
|
64
64
|
{
|
|
@@ -72,7 +72,7 @@ const CurtainButtonTemplate = memo(({ actionGroup, doAction, sensor }) => {
|
|
|
72
72
|
style: styles.buttonActionCurtain,
|
|
73
73
|
icon: Images.buttonRightCurtain,
|
|
74
74
|
text: text3,
|
|
75
|
-
onPress:
|
|
75
|
+
onPress: onButtonOpenPress,
|
|
76
76
|
testID: TESTID.BUTTON_TEMPLATE_3,
|
|
77
77
|
},
|
|
78
78
|
];
|
|
@@ -82,11 +82,12 @@ const CurtainButtonTemplate = memo(({ actionGroup, doAction, sensor }) => {
|
|
|
82
82
|
{buttons.map((item, index) => (
|
|
83
83
|
<TouchableOpacity
|
|
84
84
|
testID={item.testID}
|
|
85
|
-
style={item
|
|
85
|
+
style={item?.style}
|
|
86
86
|
onPress={item.onPress}
|
|
87
87
|
underlayColor={Colors.Gray2}
|
|
88
88
|
>
|
|
89
|
-
<Image source={item
|
|
89
|
+
<Image source={item?.icon} />
|
|
90
|
+
<Text style={styles.textCurtain}>{item?.text}</Text>
|
|
90
91
|
</TouchableOpacity>
|
|
91
92
|
))}
|
|
92
93
|
</>
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { StyleSheet } from 'react-native';
|
|
2
|
+
import { Colors } from '../../configs';
|
|
2
3
|
|
|
3
4
|
export default StyleSheet.create({
|
|
4
5
|
wrap: {
|
|
@@ -43,4 +44,8 @@ export default StyleSheet.create({
|
|
|
43
44
|
justifyContent: 'center',
|
|
44
45
|
marginTop: 15,
|
|
45
46
|
},
|
|
47
|
+
textCurtain: {
|
|
48
|
+
fontSize: 16,
|
|
49
|
+
color: Colors.Gray8,
|
|
50
|
+
},
|
|
46
51
|
});
|
|
@@ -5,6 +5,7 @@ import { Colors } from '../../configs';
|
|
|
5
5
|
|
|
6
6
|
import Text from '../Text';
|
|
7
7
|
import { useConfigGlobalState } from '../../iot/states';
|
|
8
|
+
import { useUnwatchLGDeviceConfigControl } from '../../hooks/IoT';
|
|
8
9
|
import styles from './NumberUpDownActionTemplateStyle';
|
|
9
10
|
import { watchMultiConfigs } from '../../iot/Monitor';
|
|
10
11
|
import { DEVICE_TYPE, TESTID } from '../../configs/Constants';
|
|
@@ -25,27 +26,14 @@ const NumberUpDownActionTemplate = ({ actionGroup, doAction, sensor }) => {
|
|
|
25
26
|
const valueDefault = 28;
|
|
26
27
|
const [value, setValue] = useState(valueDefault);
|
|
27
28
|
|
|
28
|
-
useEffect(() => {
|
|
29
|
-
if (sensor?.device_type === DEVICE_TYPE.LG_THINQ) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
if (
|
|
33
|
-
!!config &&
|
|
34
|
-
sensor?.is_managed_by_backend &&
|
|
35
|
-
sensor.device_type !== DEVICE_TYPE.GOOGLE_HOME
|
|
36
|
-
) {
|
|
37
|
-
watchMultiConfigs([config]);
|
|
38
|
-
}
|
|
39
|
-
}, [sensor, config]);
|
|
40
|
-
|
|
41
29
|
useEffect(() => {
|
|
42
30
|
if (!config) {
|
|
43
31
|
return;
|
|
44
32
|
}
|
|
45
33
|
|
|
46
34
|
const configValue = configValues[config];
|
|
47
|
-
if (configValue !== null && configValue !== undefined) {
|
|
48
|
-
setValue(configValue);
|
|
35
|
+
if (configValue?.value !== null && configValue?.value !== undefined) {
|
|
36
|
+
setValue(configValue.value);
|
|
49
37
|
}
|
|
50
38
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
51
39
|
}, [JSON.stringify(configValues)]);
|
|
@@ -70,7 +58,7 @@ const NumberUpDownActionTemplate = ({ actionGroup, doAction, sensor }) => {
|
|
|
70
58
|
}
|
|
71
59
|
|
|
72
60
|
config &&
|
|
73
|
-
sensor.device_type
|
|
61
|
+
sensor.device_type === DEVICE_TYPE.LG_THINQ &&
|
|
74
62
|
watchMultiConfigs([config]);
|
|
75
63
|
},
|
|
76
64
|
[
|
|
@@ -82,6 +70,8 @@ const NumberUpDownActionTemplate = ({ actionGroup, doAction, sensor }) => {
|
|
|
82
70
|
]
|
|
83
71
|
);
|
|
84
72
|
|
|
73
|
+
useUnwatchLGDeviceConfigControl(sensor, [config]);
|
|
74
|
+
|
|
85
75
|
const doActionUp = useCallback(async () => {
|
|
86
76
|
const actionName = `${sensor?.name} temp up`;
|
|
87
77
|
const newValue = checkMinMax(value + 1);
|
|
@@ -7,8 +7,9 @@ import styles from './OnOffSmartLockStyle';
|
|
|
7
7
|
import ButtonLock from '../../../../assets/images/Device/button-lock.svg';
|
|
8
8
|
import ButtonUnLock from '../../../../assets/images/Device/button-unlock.svg';
|
|
9
9
|
import { useConfigGlobalState } from '../../../iot/states';
|
|
10
|
+
import { useUnwatchLGDeviceConfigControl } from '../../../hooks/IoT';
|
|
10
11
|
import { watchMultiConfigs } from '../../../iot/Monitor';
|
|
11
|
-
import { TESTID } from '../../../configs/Constants';
|
|
12
|
+
import { DEVICE_TYPE, TESTID } from '../../../configs/Constants';
|
|
12
13
|
|
|
13
14
|
const OnOffSmartLock = memo(({ actionGroup, doAction, sensor }) => {
|
|
14
15
|
const t = useTranslations();
|
|
@@ -36,7 +37,7 @@ const OnOffSmartLock = memo(({ actionGroup, doAction, sensor }) => {
|
|
|
36
37
|
}
|
|
37
38
|
if (sensor?.is_managed_by_backend) {
|
|
38
39
|
configuration.config &&
|
|
39
|
-
sensor.device_type
|
|
40
|
+
sensor.device_type === DEVICE_TYPE.LG_THINQ &&
|
|
40
41
|
watchMultiConfigs([configuration.config]);
|
|
41
42
|
}
|
|
42
43
|
}
|
|
@@ -52,13 +53,15 @@ const OnOffSmartLock = memo(({ actionGroup, doAction, sensor }) => {
|
|
|
52
53
|
sensor?.device_type,
|
|
53
54
|
]);
|
|
54
55
|
|
|
56
|
+
useUnwatchLGDeviceConfigControl(sensor, [configuration.config]);
|
|
57
|
+
|
|
55
58
|
useEffect(() => {
|
|
56
59
|
const { is_on_value, config } = configuration;
|
|
57
60
|
const configValue = configValues[config];
|
|
58
61
|
if (is_on_value && is_on_value.length) {
|
|
59
|
-
setisUnlock(is_on_value.includes(configValue));
|
|
62
|
+
setisUnlock(is_on_value.includes(configValue?.value));
|
|
60
63
|
} else {
|
|
61
|
-
setisUnlock(configValue);
|
|
64
|
+
setisUnlock(configValue?.value);
|
|
62
65
|
}
|
|
63
66
|
}, [configValues, configuration]);
|
|
64
67
|
|
|
@@ -3,6 +3,7 @@ import { DEVICE_TYPE } from '../../../configs/Constants';
|
|
|
3
3
|
|
|
4
4
|
import { watchMultiConfigs } from '../../../iot/Monitor';
|
|
5
5
|
import { useConfigGlobalState } from '../../../iot/states';
|
|
6
|
+
import { useUnwatchLGDeviceConfigControl } from '../../../hooks/IoT';
|
|
6
7
|
import OnOffButtonTemplate from './OnOffButtonTemplate';
|
|
7
8
|
import OnOffSimpleTemplate from './OnOffSimpleTemplate';
|
|
8
9
|
|
|
@@ -30,9 +31,9 @@ const OnOffTemplate = memo(({ actionGroup, doAction, sensor }) => {
|
|
|
30
31
|
const { is_on_value, config } = configuration;
|
|
31
32
|
const configValue = configValues[config];
|
|
32
33
|
if (is_on_value && is_on_value.length > 0) {
|
|
33
|
-
return is_on_value.includes(configValue);
|
|
34
|
+
return is_on_value.includes(configValue?.value);
|
|
34
35
|
}
|
|
35
|
-
return !!configValue;
|
|
36
|
+
return !!configValue?.value;
|
|
36
37
|
}, [configValues, configuration]);
|
|
37
38
|
|
|
38
39
|
const [isOn, setIsOn] = useState(false);
|
|
@@ -99,7 +100,7 @@ const OnOffTemplate = memo(({ actionGroup, doAction, sensor }) => {
|
|
|
99
100
|
updateStatusFromPusher();
|
|
100
101
|
if (sensor?.is_managed_by_backend) {
|
|
101
102
|
configuration?.config &&
|
|
102
|
-
sensor?.device_type
|
|
103
|
+
sensor?.device_type === DEVICE_TYPE.LG_THINQ &&
|
|
103
104
|
watchMultiConfigs([configuration?.config]);
|
|
104
105
|
}
|
|
105
106
|
}, [
|
|
@@ -114,6 +115,8 @@ const OnOffTemplate = memo(({ actionGroup, doAction, sensor }) => {
|
|
|
114
115
|
sensor?.is_managed_by_backend,
|
|
115
116
|
]);
|
|
116
117
|
|
|
118
|
+
useUnwatchLGDeviceConfigControl(sensor, [configuration?.config]);
|
|
119
|
+
|
|
117
120
|
useEffect(() => {
|
|
118
121
|
setIsOn(getIsOnValue());
|
|
119
122
|
}, [getIsOnValue]);
|
|
@@ -122,15 +125,6 @@ const OnOffTemplate = memo(({ actionGroup, doAction, sensor }) => {
|
|
|
122
125
|
temp = isOn;
|
|
123
126
|
}, [isOn]);
|
|
124
127
|
|
|
125
|
-
useEffect(() => {
|
|
126
|
-
if (sensor?.device_type === DEVICE_TYPE.LG_THINQ) {
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
if (sensor?.is_managed_by_backend && sensor.device_type !== 'GOOGLE_HOME') {
|
|
130
|
-
watchMultiConfigs([configuration.config]);
|
|
131
|
-
}
|
|
132
|
-
}, [sensor, configuration.config, getIsOnValue]);
|
|
133
|
-
|
|
134
128
|
useEffect(() => {
|
|
135
129
|
if (sensor?.device_type !== DEVICE_TYPE.LG_THINQ) {
|
|
136
130
|
setTempIsOn(getIsOnValue());
|
|
@@ -7,6 +7,7 @@ import Text from '../../commons/Text';
|
|
|
7
7
|
import { AlertAction, RadioCircle } from '../../commons';
|
|
8
8
|
import { useDropdownAction } from './hooks/useDropdownAction';
|
|
9
9
|
import { useConfigGlobalState } from '../../iot/states';
|
|
10
|
+
import { useUnwatchLGDeviceConfigControl } from '../../hooks/IoT';
|
|
10
11
|
import styles from './OptionsDropdownActionTemplateStyle';
|
|
11
12
|
import { watchMultiConfigs } from '../../iot/Monitor';
|
|
12
13
|
import { DEVICE_TYPE, TESTID } from '../../configs/Constants';
|
|
@@ -32,7 +33,7 @@ const OptionsDropdownActionTemplate = ({ actionGroup, doAction, sensor }) => {
|
|
|
32
33
|
const [configValues, setConfigValues] = useConfigGlobalState('configValues');
|
|
33
34
|
const checkIcon = /\d/.test(icon); // to do check icon svg and icon antDesign
|
|
34
35
|
const selectedOption = useMemo(() => {
|
|
35
|
-
const currentValue = configValues[configuration.config];
|
|
36
|
+
const currentValue = configValues[configuration.config]?.value;
|
|
36
37
|
if (currentValue === null || currentValue === undefined) {
|
|
37
38
|
return configuration.options[0];
|
|
38
39
|
}
|
|
@@ -70,7 +71,7 @@ const OptionsDropdownActionTemplate = ({ actionGroup, doAction, sensor }) => {
|
|
|
70
71
|
doAction(action_data, data, actionName);
|
|
71
72
|
if (sensor?.is_managed_by_backend) {
|
|
72
73
|
configuration.config &&
|
|
73
|
-
sensor.device_type
|
|
74
|
+
sensor.device_type === DEVICE_TYPE.LG_THINQ &&
|
|
74
75
|
watchMultiConfigs([configuration.config]);
|
|
75
76
|
}
|
|
76
77
|
hideAlertAction();
|
|
@@ -87,6 +88,8 @@ const OptionsDropdownActionTemplate = ({ actionGroup, doAction, sensor }) => {
|
|
|
87
88
|
title,
|
|
88
89
|
]);
|
|
89
90
|
|
|
91
|
+
useUnwatchLGDeviceConfigControl(sensor, [configuration.config]);
|
|
92
|
+
|
|
90
93
|
const iconKit = !!icon_kit_data && icon_kit_data.icon;
|
|
91
94
|
|
|
92
95
|
const displaySelected = useMemo(() => {
|
|
@@ -6,7 +6,6 @@ import Text from '../Text';
|
|
|
6
6
|
import { Colors } from '../../configs';
|
|
7
7
|
import SvgBrightness from '../../../assets/images/brightness.svg';
|
|
8
8
|
import SliderRange from 'react-native-slider';
|
|
9
|
-
import { watchMultiConfigs } from '../../iot/Monitor';
|
|
10
9
|
import { useConfigGlobalState } from '../../iot/states';
|
|
11
10
|
|
|
12
11
|
const SliderRangeTemplate = memo(({ actionGroup, doAction, sensor }) => {
|
|
@@ -33,18 +32,14 @@ const SliderRangeTemplate = memo(({ actionGroup, doAction, sensor }) => {
|
|
|
33
32
|
useEffect(() => {
|
|
34
33
|
const { config } = configuration;
|
|
35
34
|
const configValue = configValues[config];
|
|
36
|
-
let
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
let valueBrness = configValue?.value;
|
|
36
|
+
let valueTemp = valueBrness;
|
|
37
|
+
if (valueBrness > 0) {
|
|
38
|
+
valueTemp = Math.round((valueBrness / 254) * 100);
|
|
39
39
|
}
|
|
40
40
|
setValueBrightness(valueTemp);
|
|
41
41
|
}, [configuration.config, configValues, configuration]);
|
|
42
42
|
|
|
43
|
-
useEffect(() => {
|
|
44
|
-
if (sensor?.is_managed_by_backend && sensor.device_type !== 'GOOGLE_HOME') {
|
|
45
|
-
watchMultiConfigs([configuration.config]);
|
|
46
|
-
}
|
|
47
|
-
}, [sensor, configuration.config]);
|
|
48
43
|
return (
|
|
49
44
|
<View style={styles.viewBrightness}>
|
|
50
45
|
<View style={styles.LeftBrightness}>
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import React, { useCallback,
|
|
1
|
+
import React, { useCallback, useMemo } from 'react';
|
|
2
2
|
import { View, TouchableOpacity } from 'react-native';
|
|
3
3
|
import { Colors } from '../../configs';
|
|
4
4
|
|
|
5
5
|
import Text from '../Text';
|
|
6
6
|
import { useConfigGlobalState } from '../../iot/states';
|
|
7
|
+
import { useUnwatchLGDeviceConfigControl } from '../../hooks/IoT';
|
|
7
8
|
import { watchMultiConfigs } from '../../iot/Monitor';
|
|
8
9
|
import IconComponent from '../IconComponent';
|
|
9
10
|
import styles from './StatesGridActionTemplateStyle';
|
|
10
|
-
import { TESTID } from '../../configs/Constants';
|
|
11
|
+
import { DEVICE_TYPE, TESTID } from '../../configs/Constants';
|
|
11
12
|
import SvgClean from '../../../assets/images/Device/clean.svg';
|
|
12
13
|
import SvgCirculator from '../../../assets/images/Device/circulator.svg';
|
|
13
14
|
import SvgAuo from '../../../assets/images/Device/auto.svg';
|
|
@@ -46,7 +47,7 @@ const GridItem = ({ item, index, length, doAction, sensor, title }) => {
|
|
|
46
47
|
doAction(actionData, null, actionName);
|
|
47
48
|
if (sensor?.is_managed_by_backend) {
|
|
48
49
|
config &&
|
|
49
|
-
sensor.device_type
|
|
50
|
+
sensor.device_type === DEVICE_TYPE.LG_THINQ &&
|
|
50
51
|
watchMultiConfigs([config]);
|
|
51
52
|
}
|
|
52
53
|
},
|
|
@@ -61,6 +62,8 @@ const GridItem = ({ item, index, length, doAction, sensor, title }) => {
|
|
|
61
62
|
]
|
|
62
63
|
);
|
|
63
64
|
|
|
65
|
+
useUnwatchLGDeviceConfigControl(sensor, [config]);
|
|
66
|
+
|
|
64
67
|
const iconKit = !!icon_kit_data && icon_kit_data.icon;
|
|
65
68
|
|
|
66
69
|
const iconSvg = useMemo(() => {
|
|
@@ -117,7 +120,7 @@ const StatesGridActionTemplate = ({
|
|
|
117
120
|
|
|
118
121
|
const options = useMemo(() => {
|
|
119
122
|
return (configuration?.options || []).map((option) => {
|
|
120
|
-
if (configValues[option?.config] === option?.is_on_value) {
|
|
123
|
+
if (configValues[option?.config]?.value === option?.is_on_value) {
|
|
121
124
|
return {
|
|
122
125
|
...option,
|
|
123
126
|
active: true,
|
|
@@ -127,12 +130,6 @@ const StatesGridActionTemplate = ({
|
|
|
127
130
|
});
|
|
128
131
|
}, [configuration, configValues]);
|
|
129
132
|
|
|
130
|
-
useEffect(() => {
|
|
131
|
-
if (sensor?.is_managed_by_backend && sensor.device_type !== 'GOOGLE_HOME') {
|
|
132
|
-
watchMultiConfigs(configuration.options.map((option) => option.config));
|
|
133
|
-
}
|
|
134
|
-
}, [sensor.is_managed_by_backend, sensor.device_type, configuration.options]);
|
|
135
|
-
|
|
136
133
|
return (
|
|
137
134
|
<View style={styles.wrap}>
|
|
138
135
|
<Text type="H4" style={styles.textModeMargin}>
|
|
@@ -12,7 +12,9 @@ import styles from './TimerActionTemplateStyles';
|
|
|
12
12
|
import Text from '../Text';
|
|
13
13
|
import { Colors } from '../../configs';
|
|
14
14
|
import { useConfigGlobalState } from '../../iot/states';
|
|
15
|
+
import { useUnwatchLGDeviceConfigControl } from '../../hooks/IoT';
|
|
15
16
|
import BottomScrollPicker from '../BottomScrollPicker';
|
|
17
|
+
import { DEVICE_TYPE } from '../../configs/Constants';
|
|
16
18
|
|
|
17
19
|
const TimerActionTemplate = ({ actionGroup = {}, doAction, sensor = {} }) => {
|
|
18
20
|
const t = useTranslations();
|
|
@@ -22,8 +24,8 @@ const TimerActionTemplate = ({ actionGroup = {}, doAction, sensor = {} }) => {
|
|
|
22
24
|
|
|
23
25
|
// eslint-disable-next-line no-unused-vars
|
|
24
26
|
const [configValues, setConfigValues] = useConfigGlobalState('configValues');
|
|
25
|
-
const configHour = configValues[configuration.config_hour];
|
|
26
|
-
const configMinute = configValues[configuration.config_minute];
|
|
27
|
+
const configHour = configValues[configuration.config_hour]?.value;
|
|
28
|
+
const configMinute = configValues[configuration.config_minute]?.value;
|
|
27
29
|
|
|
28
30
|
const dataTime = useMemo(() => {
|
|
29
31
|
if (
|
|
@@ -94,7 +96,7 @@ const TimerActionTemplate = ({ actionGroup = {}, doAction, sensor = {} }) => {
|
|
|
94
96
|
if (sensor.is_managed_by_backend) {
|
|
95
97
|
hour !== undefined &&
|
|
96
98
|
minute !== undefined &&
|
|
97
|
-
sensor.device_type !==
|
|
99
|
+
sensor.device_type !== DEVICE_TYPE.LG_THINQ &&
|
|
98
100
|
watchMultiConfigs([
|
|
99
101
|
configuration.config_hour,
|
|
100
102
|
configuration.config_minute,
|
|
@@ -116,7 +118,7 @@ const TimerActionTemplate = ({ actionGroup = {}, doAction, sensor = {} }) => {
|
|
|
116
118
|
doAction(configuration.action_data, JSON.stringify({ hour }));
|
|
117
119
|
if (
|
|
118
120
|
sensor.is_managed_by_backend &&
|
|
119
|
-
sensor.device_type !==
|
|
121
|
+
sensor.device_type !== DEVICE_TYPE.LG_THINQ
|
|
120
122
|
) {
|
|
121
123
|
hour && watchMultiConfigs([configuration.config_hour]);
|
|
122
124
|
}
|
|
@@ -130,6 +132,11 @@ const TimerActionTemplate = ({ actionGroup = {}, doAction, sensor = {} }) => {
|
|
|
130
132
|
]
|
|
131
133
|
);
|
|
132
134
|
|
|
135
|
+
useUnwatchLGDeviceConfigControl(sensor, [
|
|
136
|
+
configuration.config_minute,
|
|
137
|
+
configuration.config_hour,
|
|
138
|
+
]);
|
|
139
|
+
|
|
133
140
|
const onConfirmTime = useCallback(
|
|
134
141
|
(timeData) => {
|
|
135
142
|
onHideTime();
|
|
@@ -6,6 +6,7 @@ import { Colors } from '../../../configs';
|
|
|
6
6
|
import { DEVICE_TYPE, TESTID } from '../../../configs/Constants';
|
|
7
7
|
import { watchMultiConfigs } from '../../../iot/Monitor';
|
|
8
8
|
import { useConfigGlobalState } from '../../../iot/states';
|
|
9
|
+
import { useUnwatchLGDeviceConfigControl } from '../../../hooks/IoT';
|
|
9
10
|
import Text from '../../Text';
|
|
10
11
|
import styles from './TwoButtonTemplateStyles';
|
|
11
12
|
|
|
@@ -37,7 +38,7 @@ const TwoButtonTemplate = memo(({ actionGroup, doAction, sensor }) => {
|
|
|
37
38
|
}
|
|
38
39
|
if (sensor?.is_managed_by_backend) {
|
|
39
40
|
configuration.config &&
|
|
40
|
-
sensor.device_type
|
|
41
|
+
sensor.device_type === DEVICE_TYPE.LG_THINQ &&
|
|
41
42
|
watchMultiConfigs([configuration.config]);
|
|
42
43
|
}
|
|
43
44
|
}, [
|
|
@@ -58,7 +59,10 @@ const TwoButtonTemplate = memo(({ actionGroup, doAction, sensor }) => {
|
|
|
58
59
|
await doAction(button2?.action_on_data, null, actionName('start'));
|
|
59
60
|
}
|
|
60
61
|
}
|
|
61
|
-
if (
|
|
62
|
+
if (
|
|
63
|
+
sensor?.is_managed_by_backend &&
|
|
64
|
+
sensor.device_type === DEVICE_TYPE.LG_THINQ
|
|
65
|
+
) {
|
|
62
66
|
configuration.config && watchMultiConfigs([configuration.config]);
|
|
63
67
|
}
|
|
64
68
|
}, [
|
|
@@ -72,20 +76,22 @@ const TwoButtonTemplate = memo(({ actionGroup, doAction, sensor }) => {
|
|
|
72
76
|
sensor?.device_type,
|
|
73
77
|
]);
|
|
74
78
|
|
|
79
|
+
useUnwatchLGDeviceConfigControl(sensor, [configuration.config]);
|
|
80
|
+
|
|
75
81
|
useEffect(() => {
|
|
76
82
|
const configValue1 = configValues[button1?.config];
|
|
77
83
|
const configValue2 = configValues[button2?.config];
|
|
78
84
|
if (button1?.is_on_value && button1?.is_on_value.length > 0) {
|
|
79
|
-
setIsOn(button1?.is_on_value.includes(configValue1));
|
|
85
|
+
setIsOn(button1?.is_on_value.includes(configValue1?.value));
|
|
80
86
|
return;
|
|
81
87
|
}
|
|
82
88
|
if (button2?.is_on_value && button2?.is_on_value.length > 0) {
|
|
83
|
-
setIsStart(button2?.is_on_value.includes(configValue2));
|
|
89
|
+
setIsStart(button2?.is_on_value.includes(configValue2?.value));
|
|
84
90
|
return;
|
|
85
91
|
}
|
|
86
92
|
|
|
87
|
-
setIsOn(configValue1);
|
|
88
|
-
setIsStart(configValue2);
|
|
93
|
+
setIsOn(configValue1?.value);
|
|
94
|
+
setIsStart(configValue2?.value);
|
|
89
95
|
}, [
|
|
90
96
|
configuration.config,
|
|
91
97
|
configValues,
|
|
@@ -97,15 +103,6 @@ const TwoButtonTemplate = memo(({ actionGroup, doAction, sensor }) => {
|
|
|
97
103
|
button2?.is_on_value,
|
|
98
104
|
]);
|
|
99
105
|
|
|
100
|
-
useEffect(() => {
|
|
101
|
-
if (sensor?.device_type === DEVICE_TYPE.LG_THINQ) {
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
if (sensor?.is_managed_by_backend && sensor.device_type !== 'GOOGLE_HOME') {
|
|
105
|
-
watchMultiConfigs([configuration.config]);
|
|
106
|
-
}
|
|
107
|
-
}, [sensor, configuration.config]);
|
|
108
|
-
|
|
109
106
|
const RenderTwoButtonAction = () => {
|
|
110
107
|
const buttons = [
|
|
111
108
|
{
|
|
@@ -9,9 +9,16 @@ import NumberUpDownActionTemplate from '../NumberUpDownActionTemplate';
|
|
|
9
9
|
jest.mock('../../../iot/Monitor');
|
|
10
10
|
|
|
11
11
|
jest.mock('../../../iot/states', () => ({
|
|
12
|
-
useConfigGlobalState: () => [{ 5: 25 }, null],
|
|
12
|
+
useConfigGlobalState: () => [{ 5: { value: 25 } }, null],
|
|
13
13
|
}));
|
|
14
14
|
|
|
15
|
+
jest.mock('@react-navigation/native', () => {
|
|
16
|
+
return {
|
|
17
|
+
...jest.requireActual('@react-navigation/native'),
|
|
18
|
+
useFocusEffect: jest.fn(),
|
|
19
|
+
};
|
|
20
|
+
});
|
|
21
|
+
|
|
15
22
|
describe('Test NumberUpDownActionTemplate', () => {
|
|
16
23
|
const action_data = {
|
|
17
24
|
color: '#00979D',
|
|
@@ -90,6 +97,31 @@ describe('Test NumberUpDownActionTemplate', () => {
|
|
|
90
97
|
expect(watchMultiConfigs).not.toBeCalled();
|
|
91
98
|
});
|
|
92
99
|
|
|
100
|
+
test('do action not call watchConfigs cause device_type not lq_thinq', async () => {
|
|
101
|
+
const mockDoAction = jest.fn();
|
|
102
|
+
await act(async () => {
|
|
103
|
+
wrapper = await create(
|
|
104
|
+
<NumberUpDownActionTemplate
|
|
105
|
+
actionGroup={actionGroup}
|
|
106
|
+
doAction={mockDoAction}
|
|
107
|
+
sensor={{
|
|
108
|
+
is_managed_by_backend: true,
|
|
109
|
+
device_type: DEVICE_TYPE.ZIGBEE,
|
|
110
|
+
}}
|
|
111
|
+
/>
|
|
112
|
+
);
|
|
113
|
+
});
|
|
114
|
+
const instance = wrapper.root;
|
|
115
|
+
const touchs = instance.findAllByType(TouchableOpacity);
|
|
116
|
+
expect(touchs).toHaveLength(2);
|
|
117
|
+
|
|
118
|
+
await act(async () => {
|
|
119
|
+
await touchs[0].props.onPress();
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
expect(watchMultiConfigs).not.toBeCalled();
|
|
123
|
+
});
|
|
124
|
+
|
|
93
125
|
test('do action watchConfigs cause allow_config_store_value true', async () => {
|
|
94
126
|
const mockDoAction = jest.fn();
|
|
95
127
|
actionGroup.configuration.allow_config_store_value = true;
|
|
@@ -98,7 +130,10 @@ describe('Test NumberUpDownActionTemplate', () => {
|
|
|
98
130
|
<NumberUpDownActionTemplate
|
|
99
131
|
actionGroup={actionGroup}
|
|
100
132
|
doAction={mockDoAction}
|
|
101
|
-
sensor={{
|
|
133
|
+
sensor={{
|
|
134
|
+
is_managed_by_backend: true,
|
|
135
|
+
device_type: DEVICE_TYPE.LG_THINQ,
|
|
136
|
+
}}
|
|
102
137
|
/>
|
|
103
138
|
);
|
|
104
139
|
});
|
|
@@ -15,6 +15,13 @@ jest.mock('react', () => ({
|
|
|
15
15
|
useState: jest.fn(),
|
|
16
16
|
}));
|
|
17
17
|
|
|
18
|
+
jest.mock('@react-navigation/native', () => {
|
|
19
|
+
return {
|
|
20
|
+
...jest.requireActual('@react-navigation/native'),
|
|
21
|
+
useFocusEffect: jest.fn(),
|
|
22
|
+
};
|
|
23
|
+
});
|
|
24
|
+
|
|
18
25
|
describe('Test OneBigButtonTemplate', () => {
|
|
19
26
|
const action_on_data = {
|
|
20
27
|
color: '#00979D',
|