@eohjsc/react-native-smart-city 0.3.22 → 0.3.25
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 +14 -21
- package/src/commons/ActionGroup/CurtainButtonTemplateStyle.js +5 -0
- package/src/commons/ActionGroup/NumberUpDownActionTemplate.js +12 -24
- package/src/commons/ActionGroup/OnOffSmartLock/OnOffSmartLock.js +10 -17
- package/src/commons/ActionGroup/OnOffTemplate/index.js +10 -35
- package/src/commons/ActionGroup/OneBigButtonTemplate.js +2 -3
- package/src/commons/ActionGroup/OptionsDropdownActionTemplate.js +7 -8
- package/src/commons/ActionGroup/SliderRangeTemplate.js +3 -10
- package/src/commons/ActionGroup/StatesGridActionTemplate.js +9 -24
- package/src/commons/ActionGroup/ThreeButtonTemplate.js +6 -9
- package/src/commons/ActionGroup/TimerActionTemplate.js +11 -4
- package/src/commons/ActionGroup/TwoButtonTemplate/index.js +18 -33
- package/src/commons/ActionGroup/__test__/CurtainButtonTemplate.test.js +3 -15
- package/src/commons/ActionGroup/__test__/NumberUpDownTemplate.test.js +38 -4
- package/src/commons/ActionGroup/__test__/OnOffButtonTemplate.test.js +7 -0
- package/src/commons/ActionGroup/__test__/OnOffSmartLock.test.js +17 -12
- package/src/commons/ActionGroup/__test__/OnOffTemplate.test.js +11 -16
- package/src/commons/ActionGroup/__test__/OneBigButtonTemplate.test.js +1 -1
- package/src/commons/ActionGroup/__test__/OptionsDropdownTemplate.test.js +11 -10
- package/src/commons/ActionGroup/__test__/StatesGridActionTemplate.test.js +8 -7
- 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 +17 -2
- package/src/commons/ActionGroup/__test__/index.test.js +15 -18
- package/src/commons/ConnectingProcess/index.js +6 -25
- package/src/commons/Device/HistoryChart.js +8 -6
- 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/SubUnit/Favorites/index.js +22 -5
- package/src/commons/SubUnit/ShortDetail.js +31 -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 +3 -3
- package/src/configs/Constants.js +12 -2
- package/src/configs/SCConfig.js +4 -0
- package/src/context/actionType.ts +5 -3
- package/src/context/mockStore.ts +10 -3
- package/src/context/reducer.ts +26 -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/__test__/useRemoteControl.test.js +9 -11
- package/src/hooks/IoT/index.js +9 -1
- package/src/hooks/IoT/useGGHomeConnection.js +0 -1
- package/src/hooks/IoT/useRemoteControl.js +2 -3
- 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/Internet.js +1 -8
- package/src/iot/RemoteControl/LG.js +1 -0
- package/src/iot/RemoteControl/__test__/GoogleHome.test.js +7 -2
- package/src/navigations/UnitStack.js +24 -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/components/SensorDisplayItem.js +2 -2
- package/src/screens/Device/detail.js +22 -19
- 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/PlayBackCamera/Timer.js +3 -0
- package/src/screens/PlayBackCamera/__test__/index.test.js +8 -1
- package/src/screens/PlayBackCamera/index.js +86 -49
- package/src/screens/SubUnit/AddSubUnit.js +2 -1
- package/src/screens/Unit/AddMenu.js +4 -0
- package/src/screens/Unit/Detail.js +16 -10
- 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 +4 -2
- package/src/screens/Unit/components/__test__/AutomateScript.test.js +116 -0
- 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.25",
|
|
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
|
}, []);
|
|
@@ -9,11 +9,8 @@ import { Colors, Images } from '../../configs';
|
|
|
9
9
|
const CurtainButtonTemplate = memo(({ actionGroup, doAction, sensor }) => {
|
|
10
10
|
const { configuration } = actionGroup;
|
|
11
11
|
const {
|
|
12
|
-
text_open,
|
|
13
12
|
open_action_data,
|
|
14
|
-
text_stop,
|
|
15
13
|
stop_action_data,
|
|
16
|
-
text_close,
|
|
17
14
|
close_action_data,
|
|
18
15
|
action_off_data,
|
|
19
16
|
action_on_data,
|
|
@@ -26,31 +23,26 @@ const CurtainButtonTemplate = memo(({ actionGroup, doAction, sensor }) => {
|
|
|
26
23
|
const [lock, setLock] = useState(false);
|
|
27
24
|
|
|
28
25
|
const onButtonOpenPress = useCallback(() => {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}, [open_action_data, text_open, doAction, sensor?.name]);
|
|
26
|
+
doAction(open_action_data, null);
|
|
27
|
+
}, [open_action_data, doAction]);
|
|
32
28
|
|
|
33
29
|
const onButtonStopPress = useCallback(() => {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}, [stop_action_data, text_stop, doAction, sensor?.name]);
|
|
30
|
+
doAction(stop_action_data, null);
|
|
31
|
+
}, [stop_action_data, doAction]);
|
|
37
32
|
|
|
38
33
|
const onButtonClosePress = useCallback(() => {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}, [close_action_data, text_close, doAction, sensor?.name]);
|
|
34
|
+
doAction(close_action_data, null);
|
|
35
|
+
}, [close_action_data, doAction]);
|
|
42
36
|
|
|
43
37
|
const onChangeSwitch = useCallback(() => {
|
|
44
38
|
if (lock) {
|
|
45
|
-
const actionName = `${sensor?.name} unlock`;
|
|
46
39
|
setLock(false);
|
|
47
|
-
doAction(action_off_data, null
|
|
40
|
+
doAction(action_off_data, null);
|
|
48
41
|
return;
|
|
49
42
|
}
|
|
50
|
-
|
|
51
|
-
doAction(action_on_data, null, actionName);
|
|
43
|
+
doAction(action_on_data, null);
|
|
52
44
|
setLock(true);
|
|
53
|
-
}, [action_off_data, action_on_data, doAction, lock
|
|
45
|
+
}, [action_off_data, action_on_data, doAction, lock]);
|
|
54
46
|
|
|
55
47
|
const RenderThreeButtonActions = () => {
|
|
56
48
|
const buttons = [
|
|
@@ -58,7 +50,7 @@ const CurtainButtonTemplate = memo(({ actionGroup, doAction, sensor }) => {
|
|
|
58
50
|
style: styles.buttonActionCurtain,
|
|
59
51
|
icon: Images.buttonLeftCurtain,
|
|
60
52
|
text: text1,
|
|
61
|
-
onPress:
|
|
53
|
+
onPress: onButtonClosePress,
|
|
62
54
|
testID: TESTID.BUTTON_TEMPLATE_1,
|
|
63
55
|
},
|
|
64
56
|
{
|
|
@@ -72,7 +64,7 @@ const CurtainButtonTemplate = memo(({ actionGroup, doAction, sensor }) => {
|
|
|
72
64
|
style: styles.buttonActionCurtain,
|
|
73
65
|
icon: Images.buttonRightCurtain,
|
|
74
66
|
text: text3,
|
|
75
|
-
onPress:
|
|
67
|
+
onPress: onButtonOpenPress,
|
|
76
68
|
testID: TESTID.BUTTON_TEMPLATE_3,
|
|
77
69
|
},
|
|
78
70
|
];
|
|
@@ -82,11 +74,12 @@ const CurtainButtonTemplate = memo(({ actionGroup, doAction, sensor }) => {
|
|
|
82
74
|
{buttons.map((item, index) => (
|
|
83
75
|
<TouchableOpacity
|
|
84
76
|
testID={item.testID}
|
|
85
|
-
style={item
|
|
77
|
+
style={item?.style}
|
|
86
78
|
onPress={item.onPress}
|
|
87
79
|
underlayColor={Colors.Gray2}
|
|
88
80
|
>
|
|
89
|
-
<Image source={item
|
|
81
|
+
<Image source={item?.icon} />
|
|
82
|
+
<Text style={styles.textCurtain}>{item?.text}</Text>
|
|
90
83
|
</TouchableOpacity>
|
|
91
84
|
))}
|
|
92
85
|
</>
|
|
@@ -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,33 +26,20 @@ 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)]);
|
|
52
40
|
|
|
53
41
|
const doActionAndWatchConfig = useCallback(
|
|
54
|
-
async (actionData, actionValue
|
|
42
|
+
async (actionData, actionValue) => {
|
|
55
43
|
let data = actionValue;
|
|
56
44
|
if (sensor.device_type !== DEVICE_TYPE.GOOGLE_HOME) {
|
|
57
45
|
data = { temperature: actionValue };
|
|
@@ -61,7 +49,7 @@ const NumberUpDownActionTemplate = ({ actionGroup, doAction, sensor }) => {
|
|
|
61
49
|
}
|
|
62
50
|
data = JSON.stringify(data);
|
|
63
51
|
}
|
|
64
|
-
await doAction(actionData, data
|
|
52
|
+
await doAction(actionData, data);
|
|
65
53
|
if (!sensor?.is_managed_by_backend) {
|
|
66
54
|
return;
|
|
67
55
|
}
|
|
@@ -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,19 +70,19 @@ const NumberUpDownActionTemplate = ({ actionGroup, doAction, sensor }) => {
|
|
|
82
70
|
]
|
|
83
71
|
);
|
|
84
72
|
|
|
73
|
+
useUnwatchLGDeviceConfigControl(sensor, [config]);
|
|
74
|
+
|
|
85
75
|
const doActionUp = useCallback(async () => {
|
|
86
|
-
const actionName = `${sensor?.name} temp up`;
|
|
87
76
|
const newValue = checkMinMax(value + 1);
|
|
88
|
-
doActionAndWatchConfig(action_data, newValue
|
|
77
|
+
doActionAndWatchConfig(action_data, newValue);
|
|
89
78
|
setValue(newValue);
|
|
90
|
-
}, [
|
|
79
|
+
}, [checkMinMax, value, doActionAndWatchConfig, action_data]);
|
|
91
80
|
|
|
92
81
|
const doActionDown = useCallback(async () => {
|
|
93
|
-
const actionName = `${sensor?.name} temp down`;
|
|
94
82
|
const newValue = checkMinMax(value - 1);
|
|
95
|
-
doActionAndWatchConfig(action_data, newValue
|
|
83
|
+
doActionAndWatchConfig(action_data, newValue);
|
|
96
84
|
setValue(newValue);
|
|
97
|
-
}, [
|
|
85
|
+
}, [checkMinMax, value, doActionAndWatchConfig, action_data]);
|
|
98
86
|
|
|
99
87
|
const checkMinMax = useCallback(
|
|
100
88
|
(tempValue) => {
|
|
@@ -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();
|
|
@@ -20,45 +21,37 @@ const OnOffSmartLock = memo(({ actionGroup, doAction, sensor }) => {
|
|
|
20
21
|
const handleActionSmartLock = useCallback(async () => {
|
|
21
22
|
if (action_on_data && action_off_data) {
|
|
22
23
|
if (isUnlock) {
|
|
23
|
-
let actionName = `${
|
|
24
|
-
sensor?.name
|
|
25
|
-
} ${actionGroup?.title?.toLowerCase()} lock`;
|
|
26
|
-
actionName = actionName.replace(/\s+/g, ' ').trim();
|
|
27
24
|
const dataLock = { door_lock: 0 };
|
|
28
|
-
await doAction(action_on_data, JSON.stringify(dataLock)
|
|
25
|
+
await doAction(action_on_data, JSON.stringify(dataLock));
|
|
29
26
|
} else {
|
|
30
|
-
let actionName = `${
|
|
31
|
-
sensor?.name
|
|
32
|
-
} ${actionGroup?.title?.toLowerCase()} unlock`;
|
|
33
|
-
actionName = actionName.replace(/\s+/g, ' ').trim();
|
|
34
27
|
const dataUnlock = { door_lock: 1 };
|
|
35
|
-
await doAction(action_off_data, JSON.stringify(dataUnlock)
|
|
28
|
+
await doAction(action_off_data, JSON.stringify(dataUnlock));
|
|
36
29
|
}
|
|
37
30
|
if (sensor?.is_managed_by_backend) {
|
|
38
31
|
configuration.config &&
|
|
39
|
-
sensor.device_type
|
|
32
|
+
sensor.device_type === DEVICE_TYPE.LG_THINQ &&
|
|
40
33
|
watchMultiConfigs([configuration.config]);
|
|
41
34
|
}
|
|
42
35
|
}
|
|
43
36
|
}, [
|
|
44
|
-
actionGroup?.title,
|
|
45
37
|
action_off_data,
|
|
46
38
|
action_on_data,
|
|
47
39
|
doAction,
|
|
48
40
|
isUnlock,
|
|
49
|
-
sensor?.name,
|
|
50
41
|
configuration,
|
|
51
42
|
sensor?.is_managed_by_backend,
|
|
52
|
-
sensor
|
|
43
|
+
sensor.device_type,
|
|
53
44
|
]);
|
|
54
45
|
|
|
46
|
+
useUnwatchLGDeviceConfigControl(sensor, [configuration.config]);
|
|
47
|
+
|
|
55
48
|
useEffect(() => {
|
|
56
49
|
const { is_on_value, config } = configuration;
|
|
57
50
|
const configValue = configValues[config];
|
|
58
51
|
if (is_on_value && is_on_value.length) {
|
|
59
|
-
setisUnlock(is_on_value.includes(configValue));
|
|
52
|
+
setisUnlock(is_on_value.includes(configValue?.value));
|
|
60
53
|
} else {
|
|
61
|
-
setisUnlock(configValue);
|
|
54
|
+
setisUnlock(configValue?.value);
|
|
62
55
|
}
|
|
63
56
|
}, [configValues, configuration]);
|
|
64
57
|
|
|
@@ -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);
|
|
@@ -44,32 +45,14 @@ const OnOffTemplate = memo(({ actionGroup, doAction, sensor }) => {
|
|
|
44
45
|
}, 2500);
|
|
45
46
|
};
|
|
46
47
|
|
|
47
|
-
const actionName = useCallback(
|
|
48
|
-
(text) => {
|
|
49
|
-
const actionNameType = `${
|
|
50
|
-
sensor?.name
|
|
51
|
-
} ${actionGroup?.title?.toLowerCase()} ${text}`;
|
|
52
|
-
return actionNameType.replace(/\s+/g, ' ').trim();
|
|
53
|
-
},
|
|
54
|
-
[actionGroup?.title, sensor?.name]
|
|
55
|
-
);
|
|
56
|
-
|
|
57
48
|
const triggerAction = useCallback(async () => {
|
|
58
49
|
switch (sensor?.device_type) {
|
|
59
50
|
case DEVICE_TYPE.ZIGBEE:
|
|
60
51
|
if (action_on_data && action_off_data) {
|
|
61
52
|
if (isOn) {
|
|
62
|
-
await doAction(
|
|
63
|
-
action_off_data,
|
|
64
|
-
JSON.stringify({ state: 0 }),
|
|
65
|
-
actionName('off')
|
|
66
|
-
);
|
|
53
|
+
await doAction(action_off_data, JSON.stringify({ state: 0 }));
|
|
67
54
|
} else {
|
|
68
|
-
await doAction(
|
|
69
|
-
action_on_data,
|
|
70
|
-
JSON.stringify({ state: 1 }),
|
|
71
|
-
actionName('on')
|
|
72
|
-
);
|
|
55
|
+
await doAction(action_on_data, JSON.stringify({ state: 1 }));
|
|
73
56
|
}
|
|
74
57
|
}
|
|
75
58
|
break;
|
|
@@ -89,9 +72,9 @@ const OnOffTemplate = memo(({ actionGroup, doAction, sensor }) => {
|
|
|
89
72
|
}
|
|
90
73
|
if (action_on_data && action_off_data) {
|
|
91
74
|
if (isOn) {
|
|
92
|
-
await doAction(action_off_data, null
|
|
75
|
+
await doAction(action_off_data, null);
|
|
93
76
|
} else {
|
|
94
|
-
await doAction(action_on_data, null
|
|
77
|
+
await doAction(action_on_data, null);
|
|
95
78
|
}
|
|
96
79
|
}
|
|
97
80
|
break;
|
|
@@ -99,11 +82,10 @@ const OnOffTemplate = memo(({ actionGroup, doAction, sensor }) => {
|
|
|
99
82
|
updateStatusFromPusher();
|
|
100
83
|
if (sensor?.is_managed_by_backend) {
|
|
101
84
|
configuration?.config &&
|
|
102
|
-
sensor?.device_type
|
|
85
|
+
sensor?.device_type === DEVICE_TYPE.LG_THINQ &&
|
|
103
86
|
watchMultiConfigs([configuration?.config]);
|
|
104
87
|
}
|
|
105
88
|
}, [
|
|
106
|
-
actionName,
|
|
107
89
|
action_data,
|
|
108
90
|
action_off_data,
|
|
109
91
|
action_on_data,
|
|
@@ -114,6 +96,8 @@ const OnOffTemplate = memo(({ actionGroup, doAction, sensor }) => {
|
|
|
114
96
|
sensor?.is_managed_by_backend,
|
|
115
97
|
]);
|
|
116
98
|
|
|
99
|
+
useUnwatchLGDeviceConfigControl(sensor, [configuration?.config]);
|
|
100
|
+
|
|
117
101
|
useEffect(() => {
|
|
118
102
|
setIsOn(getIsOnValue());
|
|
119
103
|
}, [getIsOnValue]);
|
|
@@ -122,15 +106,6 @@ const OnOffTemplate = memo(({ actionGroup, doAction, sensor }) => {
|
|
|
122
106
|
temp = isOn;
|
|
123
107
|
}, [isOn]);
|
|
124
108
|
|
|
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
109
|
useEffect(() => {
|
|
135
110
|
if (sensor?.device_type !== DEVICE_TYPE.LG_THINQ) {
|
|
136
111
|
setTempIsOn(getIsOnValue());
|
|
@@ -11,9 +11,8 @@ const OneBigButtonTemplate = memo(({ actionGroup, doAction, sensor }) => {
|
|
|
11
11
|
const { text, action_data } = configuration || {};
|
|
12
12
|
|
|
13
13
|
const onPressDoAction = useCallback(() => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}, [action_data, text, doAction, sensor?.name]);
|
|
14
|
+
doAction(action_data, null);
|
|
15
|
+
}, [action_data, doAction]);
|
|
17
16
|
|
|
18
17
|
return (
|
|
19
18
|
<>
|
|
@@ -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
|
}
|
|
@@ -59,18 +60,16 @@ const OptionsDropdownActionTemplate = ({ actionGroup, doAction, sensor }) => {
|
|
|
59
60
|
const onDone = useCallback(() => {
|
|
60
61
|
const newOption = options[selectedIndex];
|
|
61
62
|
const value = getOptionValue(newOption);
|
|
62
|
-
let actionName = `${sensor?.name} ${title?.toLowerCase()} ${value}`;
|
|
63
|
-
actionName = actionName.replace(/\s+/g, ' ').trim();
|
|
64
63
|
|
|
65
64
|
let data = JSON.stringify({ level: value, key_code: newOption?.value_int });
|
|
66
65
|
if (sensor.device_type === DEVICE_TYPE.GOOGLE_HOME) {
|
|
67
66
|
data = value;
|
|
68
67
|
}
|
|
69
68
|
|
|
70
|
-
doAction(action_data, data
|
|
69
|
+
doAction(action_data, data);
|
|
71
70
|
if (sensor?.is_managed_by_backend) {
|
|
72
71
|
configuration.config &&
|
|
73
|
-
sensor.device_type
|
|
72
|
+
sensor.device_type === DEVICE_TYPE.LG_THINQ &&
|
|
74
73
|
watchMultiConfigs([configuration.config]);
|
|
75
74
|
}
|
|
76
75
|
hideAlertAction();
|
|
@@ -82,11 +81,11 @@ const OptionsDropdownActionTemplate = ({ actionGroup, doAction, sensor }) => {
|
|
|
82
81
|
options,
|
|
83
82
|
selectedIndex,
|
|
84
83
|
sensor?.is_managed_by_backend,
|
|
85
|
-
sensor
|
|
86
|
-
sensor?.device_type,
|
|
87
|
-
title,
|
|
84
|
+
sensor.device_type,
|
|
88
85
|
]);
|
|
89
86
|
|
|
87
|
+
useUnwatchLGDeviceConfigControl(sensor, [configuration.config]);
|
|
88
|
+
|
|
90
89
|
const iconKit = !!icon_kit_data && icon_kit_data.icon;
|
|
91
90
|
|
|
92
91
|
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,12 @@ const SliderRangeTemplate = memo(({ actionGroup, doAction, sensor }) => {
|
|
|
33
32
|
useEffect(() => {
|
|
34
33
|
const { config } = configuration;
|
|
35
34
|
const configValue = configValues[config];
|
|
36
|
-
let
|
|
37
|
-
if (
|
|
38
|
-
|
|
35
|
+
let valueBrness = configValue?.value;
|
|
36
|
+
if (valueBrness >= 0) {
|
|
37
|
+
setValueBrightness(valueBrness);
|
|
39
38
|
}
|
|
40
|
-
setValueBrightness(valueTemp);
|
|
41
39
|
}, [configuration.config, configValues, configuration]);
|
|
42
40
|
|
|
43
|
-
useEffect(() => {
|
|
44
|
-
if (sensor?.is_managed_by_backend && sensor.device_type !== 'GOOGLE_HOME') {
|
|
45
|
-
watchMultiConfigs([configuration.config]);
|
|
46
|
-
}
|
|
47
|
-
}, [sensor, configuration.config]);
|
|
48
41
|
return (
|
|
49
42
|
<View style={styles.viewBrightness}>
|
|
50
43
|
<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';
|
|
@@ -39,28 +40,18 @@ const GridItem = ({ item, index, length, doAction, sensor, title }) => {
|
|
|
39
40
|
|
|
40
41
|
const doActionAndWatchConfig = useCallback(
|
|
41
42
|
(actionData) => {
|
|
42
|
-
|
|
43
|
-
sensor?.name
|
|
44
|
-
} ${title?.toLowerCase()} ${text?.toLowerCase()}`;
|
|
45
|
-
actionName = actionName.replace(/\s+/g, ' ').trim();
|
|
46
|
-
doAction(actionData, null, actionName);
|
|
43
|
+
doAction(actionData, null);
|
|
47
44
|
if (sensor?.is_managed_by_backend) {
|
|
48
45
|
config &&
|
|
49
|
-
sensor.device_type
|
|
46
|
+
sensor.device_type === DEVICE_TYPE.LG_THINQ &&
|
|
50
47
|
watchMultiConfigs([config]);
|
|
51
48
|
}
|
|
52
49
|
},
|
|
53
|
-
[
|
|
54
|
-
config,
|
|
55
|
-
doAction,
|
|
56
|
-
sensor?.is_managed_by_backend,
|
|
57
|
-
sensor?.name,
|
|
58
|
-
sensor?.device_type,
|
|
59
|
-
text,
|
|
60
|
-
title,
|
|
61
|
-
]
|
|
50
|
+
[config, doAction, sensor?.is_managed_by_backend, sensor.device_type]
|
|
62
51
|
);
|
|
63
52
|
|
|
53
|
+
useUnwatchLGDeviceConfigControl(sensor, [config]);
|
|
54
|
+
|
|
64
55
|
const iconKit = !!icon_kit_data && icon_kit_data.icon;
|
|
65
56
|
|
|
66
57
|
const iconSvg = useMemo(() => {
|
|
@@ -117,7 +108,7 @@ const StatesGridActionTemplate = ({
|
|
|
117
108
|
|
|
118
109
|
const options = useMemo(() => {
|
|
119
110
|
return (configuration?.options || []).map((option) => {
|
|
120
|
-
if (configValues[option?.config] === option?.is_on_value) {
|
|
111
|
+
if (configValues[option?.config]?.value === option?.is_on_value) {
|
|
121
112
|
return {
|
|
122
113
|
...option,
|
|
123
114
|
active: true,
|
|
@@ -127,12 +118,6 @@ const StatesGridActionTemplate = ({
|
|
|
127
118
|
});
|
|
128
119
|
}, [configuration, configValues]);
|
|
129
120
|
|
|
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
121
|
return (
|
|
137
122
|
<View style={styles.wrap}>
|
|
138
123
|
<Text type="H4" style={styles.textModeMargin}>
|
|
@@ -30,19 +30,16 @@ const ThreeButtonTemplate = memo(({ actionGroup, doAction, sensor }) => {
|
|
|
30
30
|
);
|
|
31
31
|
};
|
|
32
32
|
const onButton1Press = useCallback(() => {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}, [action1_data, text1, doAction, sensor?.name]);
|
|
33
|
+
doAction(action1_data, null);
|
|
34
|
+
}, [action1_data, doAction]);
|
|
36
35
|
|
|
37
36
|
const onButton2Press = useCallback(() => {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}, [action2_data, text2, doAction, sensor?.name]);
|
|
37
|
+
doAction(action2_data, null);
|
|
38
|
+
}, [action2_data, doAction]);
|
|
41
39
|
|
|
42
40
|
const onButton3Press = useCallback(() => {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}, [action3_data, text3, doAction, sensor?.name]);
|
|
41
|
+
doAction(action3_data, null);
|
|
42
|
+
}, [action3_data, doAction]);
|
|
46
43
|
|
|
47
44
|
const onChangeSwitch = useCallback(() => {
|
|
48
45
|
if (lock) {
|