@eohjsc/react-native-smart-city 0.3.40 → 0.3.42
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/assets/images/AddNewDevice/gateway-icon.svg +12 -0
- package/package.json +1 -1
- package/src/commons/AlertAction/index.js +22 -5
- package/src/commons/Device/FlatListItems.js +1 -1
- package/src/commons/Device/PMSensor/PMSensorIndicatior.js +1 -1
- package/src/commons/Device/WindSpeed/Anemometer/index.js +21 -17
- package/src/commons/Header/HeaderCustom.js +9 -6
- package/src/commons/OneTapTemplate/__test__/OptionsDropdownActionTemplate.test.js +1 -1
- package/src/commons/Processing/__test__/Connecting.test.js +1 -1
- package/src/commons/Processing/index.js +60 -6
- package/src/commons/Processing/styles.js +19 -0
- package/src/commons/SelectGateway/index.js +63 -21
- package/src/commons/SelectGateway/styles.js +25 -4
- package/src/commons/SelectSubUnit/index.js +2 -3
- package/src/commons/SelectSubUnit/styles.js +1 -3
- package/src/commons/SubUnit/ShortDetail.js +8 -6
- package/src/commons/SubUnit/__test__/ShortDetail.test.js +3 -2
- package/src/commons/UnitSummary/ConfigHistoryChart/index.js +5 -2
- package/src/configs/AccessibilityLabel.js +1 -0
- package/src/hooks/Explore/useKeyboardAnimated.js +13 -22
- package/src/hooks/IoT/__test__/useRemoteControl.test.js +1 -1
- package/src/hooks/IoT/useRemoteControl.js +9 -2
- package/src/iot/RemoteControl/HomeAssistant.js +1 -1
- package/src/screens/AddCommon/__test__/SelectSubUnit.test.js +2 -2
- package/src/screens/AddNewGateway/ConnectingDevice.js +24 -3
- package/src/screens/AddNewGateway/ConnectingModbusDevice.js +43 -19
- package/src/screens/AddNewGateway/ConnectingWifiDevice.js +28 -26
- package/src/screens/AddNewGateway/ConnectingWifiGuide.js +5 -4
- package/src/screens/AddNewGateway/ConnectingZigbeeDevice.js +5 -5
- package/src/screens/AddNewGateway/PlugAndPlay/ConnectRouterGuide.js +7 -7
- package/src/screens/AddNewGateway/PlugAndPlay/__test__/ConnectRouterGuide.test.js +69 -0
- package/src/screens/AddNewGateway/PlugAndPlay/__test__/ZigbeeDeviceConnectGuide.test.js +71 -0
- package/src/screens/AddNewGateway/RenameNewDevices.js +88 -59
- package/src/screens/AddNewGateway/RenameNewDevicesStyles.js +18 -14
- package/src/screens/AddNewGateway/ScanGatewayQR.js +2 -1
- package/src/screens/AddNewGateway/ScanModbusQR.js +10 -6
- package/src/screens/AddNewGateway/ScanWifiDeviceQR.js +3 -3
- package/src/screens/AddNewGateway/SelectDeviceSubUnit.js +4 -4
- package/src/screens/AddNewGateway/SelectDeviceType.js +18 -18
- package/src/screens/AddNewGateway/SelectModbusGateway.js +17 -4
- package/src/screens/AddNewGateway/SelectZigbeeGateway.js +3 -3
- package/src/screens/AddNewGateway/ShareWifiPassword.js +23 -4
- package/src/screens/AddNewGateway/__test__/ConnectingWifiDevice.test.js +5 -1
- package/src/screens/AddNewGateway/__test__/ConnectingWifiGuide.test.js +6 -2
- package/src/screens/AddNewGateway/__test__/ConnectingZigbeeDevice.test.js +12 -5
- package/src/screens/AddNewGateway/__test__/RenameNewDevices.test.js +92 -9
- package/src/screens/AddNewGateway/__test__/ScanModbusQR.test.js +1 -3
- package/src/screens/AddNewGateway/__test__/SelectDeviceType.test.js +3 -1
- package/src/screens/AddNewGateway/__test__/SelectModbusGateway.test.js +7 -3
- package/src/screens/AddNewGateway/__test__/SelectZigbeeGateway.test.js +6 -2
- package/src/screens/Device/EditDevice/index.js +4 -8
- package/src/screens/Explore/index.js +22 -7
- package/src/screens/HanetCamera/MemberInfo.js +4 -8
- package/src/screens/ScriptDetail/index.js +3 -8
- package/src/screens/SubUnit/Detail.js +2 -1
- package/src/screens/SubUnit/EditSubUnit.js +22 -41
- package/src/screens/SubUnit/__test__/EditSubUnit.test.js +51 -59
- package/src/screens/Unit/AddMenu.js +1 -1
- package/src/screens/Unit/Detail.js +3 -1
- package/src/screens/Unit/ManageUnit.js +25 -47
- package/src/screens/Unit/ManageUnitStyles.js +0 -4
- package/src/screens/Unit/__test__/ManageUnit.test.js +6 -14
- package/src/utils/I18n/translations/en.json +21 -3
- package/src/utils/I18n/translations/vi.json +20 -2
- package/src/hooks/Common/useKeyboardShowTranslation.js +0 -120
- package/src/utils/runTiming.js +0 -52
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import React, { memo, useCallback, useEffect, useState } from 'react';
|
|
2
|
-
import { TouchableOpacity, View } from 'react-native';
|
|
2
|
+
import { ScrollView, TouchableOpacity, View } from 'react-native';
|
|
3
3
|
import { IconOutline } from '@ant-design/icons-react-native';
|
|
4
4
|
import { useTranslations } from '../../hooks/Common/useTranslations';
|
|
5
5
|
|
|
6
6
|
import { Colors } from '../../configs';
|
|
7
7
|
import Text from '../../commons/Text';
|
|
8
8
|
import AddDeviceIcon from '../../../assets/images/Popover/Dashboard/AddDevice.svg';
|
|
9
|
+
import GatewayIcon from '../../../assets/images/AddNewDevice/gateway-icon.svg';
|
|
9
10
|
import _TextInput from '../../commons/Form/TextInput';
|
|
10
11
|
import { useNavigation } from '@react-navigation/native';
|
|
11
12
|
import AccessibilityLabel from '../../configs/AccessibilityLabel';
|
|
@@ -13,12 +14,15 @@ import Routes from '../../utils/Route';
|
|
|
13
14
|
import styles from './RenameNewDevicesStyles';
|
|
14
15
|
import { axiosGet, axiosPost } from '../../utils/Apis/axios';
|
|
15
16
|
import API from '../../configs/API';
|
|
17
|
+
import { HeaderCustom } from '../../commons/Header';
|
|
18
|
+
import { useMemo } from 'react';
|
|
16
19
|
|
|
17
20
|
const RenameNewDevices = memo(({ route }) => {
|
|
18
21
|
const t = useTranslations();
|
|
19
22
|
const navigation = useNavigation();
|
|
20
23
|
|
|
21
|
-
const { unitId,
|
|
24
|
+
const { unitId, subUnit, chipId, sensorId, addDeviceType } =
|
|
25
|
+
route?.params || {};
|
|
22
26
|
|
|
23
27
|
const [info, setInfo] = useState({});
|
|
24
28
|
|
|
@@ -29,32 +33,35 @@ const RenameNewDevices = memo(({ route }) => {
|
|
|
29
33
|
params: {
|
|
30
34
|
unitId: unitId,
|
|
31
35
|
routeName: 'DashboardStack',
|
|
32
|
-
stationId:
|
|
36
|
+
stationId: subUnit?.id,
|
|
37
|
+
isSuccessfullyConnected: true,
|
|
33
38
|
},
|
|
34
39
|
});
|
|
35
|
-
}, [info, navigation,
|
|
40
|
+
}, [info, navigation, subUnit, unitId]);
|
|
36
41
|
|
|
37
42
|
useEffect(() => {
|
|
38
43
|
(async () => {
|
|
39
|
-
|
|
44
|
+
let params = new URLSearchParams();
|
|
45
|
+
if (sensorId) {
|
|
46
|
+
params.append('sensor', sensorId);
|
|
47
|
+
}
|
|
48
|
+
const { success, data } = await axiosGet(
|
|
49
|
+
API.CHIP.RENAME_DEVICES(chipId),
|
|
50
|
+
{
|
|
51
|
+
params,
|
|
52
|
+
}
|
|
53
|
+
);
|
|
40
54
|
if (success) {
|
|
41
55
|
setInfo(data);
|
|
42
56
|
}
|
|
43
57
|
})();
|
|
44
|
-
}, [chipId, sensorId]);
|
|
58
|
+
}, [chipId, sensorId, subUnit]);
|
|
45
59
|
|
|
46
60
|
const updateItemName = (type, sensor_index, end_device_index) => (value) => {
|
|
47
61
|
setInfo((currentInfo) => {
|
|
48
62
|
if (type === 'chip') {
|
|
49
63
|
return { ...currentInfo, name: value };
|
|
50
64
|
}
|
|
51
|
-
if (type === 'sensor') {
|
|
52
|
-
currentInfo.sensors[sensor_index] = {
|
|
53
|
-
...currentInfo.sensors[sensor_index],
|
|
54
|
-
name: value,
|
|
55
|
-
};
|
|
56
|
-
return { ...currentInfo };
|
|
57
|
-
}
|
|
58
65
|
if (type === 'end_device') {
|
|
59
66
|
currentInfo.sensors[sensor_index].end_devices[end_device_index] = {
|
|
60
67
|
...currentInfo.sensors[sensor_index].end_devices[end_device_index],
|
|
@@ -68,63 +75,85 @@ const RenameNewDevices = memo(({ route }) => {
|
|
|
68
75
|
});
|
|
69
76
|
};
|
|
70
77
|
|
|
78
|
+
const scrollviewHeight = useMemo(() => {
|
|
79
|
+
const baseHeight = 40;
|
|
80
|
+
let contentItems = 1;
|
|
81
|
+
|
|
82
|
+
if (addDeviceType !== 'gateway') {
|
|
83
|
+
info?.sensors?.map(
|
|
84
|
+
(sensor) => (contentItems += sensor?.end_devices?.length)
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
return baseHeight + contentItems * 43;
|
|
88
|
+
}, [addDeviceType, info.sensors]);
|
|
89
|
+
|
|
71
90
|
const renameLabel = AccessibilityLabel.CONNECTED_DEVICE_RENAME_DEVICE;
|
|
72
91
|
|
|
73
92
|
return (
|
|
74
93
|
<View style={styles.container}>
|
|
94
|
+
<HeaderCustom
|
|
95
|
+
title={t('connect_device')}
|
|
96
|
+
isShowSeparator
|
|
97
|
+
isCanBack={false}
|
|
98
|
+
/>
|
|
75
99
|
<View style={styles.content}>
|
|
76
100
|
<IconOutline name="check-circle" size={28} color={Colors.Green6} />
|
|
77
101
|
<Text semibold color={Colors.Black} size={20} style={styles.textStatus}>
|
|
78
102
|
{t('successfully_connected')}
|
|
79
103
|
</Text>
|
|
80
|
-
{
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
textInputStyle={styles.textItem}
|
|
106
|
-
onChange={updateItemName('sensor', sensor_index)}
|
|
107
|
-
/>
|
|
104
|
+
<Text size={14} color={Colors.Gray9} style={styles.textStation}>
|
|
105
|
+
{subUnit?.name}
|
|
106
|
+
</Text>
|
|
107
|
+
<View style={{ ...styles.devicesWrapper, height: scrollviewHeight }}>
|
|
108
|
+
<ScrollView>
|
|
109
|
+
{addDeviceType === 'gateway' ? (
|
|
110
|
+
<View style={styles.boxDevice}>
|
|
111
|
+
<GatewayIcon width={43} height={43} />
|
|
112
|
+
{info.can_rename ? (
|
|
113
|
+
<_TextInput
|
|
114
|
+
accessibilityLabel={`${renameLabel}-chip`}
|
|
115
|
+
value={info.name}
|
|
116
|
+
textInputStyle={styles.textItem}
|
|
117
|
+
onChange={updateItemName('chip')}
|
|
118
|
+
/>
|
|
119
|
+
) : (
|
|
120
|
+
<Text
|
|
121
|
+
size={14}
|
|
122
|
+
color={Colors.Gray9}
|
|
123
|
+
style={styles.textStation}
|
|
124
|
+
accessibilityLabel={`${renameLabel}-chip-name`}
|
|
125
|
+
>
|
|
126
|
+
{info.name}
|
|
127
|
+
</Text>
|
|
128
|
+
)}
|
|
108
129
|
</View>
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
130
|
+
) : (
|
|
131
|
+
!!info?.sensors?.length &&
|
|
132
|
+
info.sensors.map((sensor, sensor_index) =>
|
|
133
|
+
(sensor?.end_devices || []).map(
|
|
134
|
+
(end_device, end_device_index) => (
|
|
135
|
+
<View style={styles.boxDevice} key={`${end_device?.id}`}>
|
|
136
|
+
<AddDeviceIcon width={43} height={43} />
|
|
137
|
+
<_TextInput
|
|
138
|
+
accessibilityLabel={`${renameLabel}-end_device-${end_device?.id}`}
|
|
139
|
+
value={end_device?.name}
|
|
140
|
+
textInputStyle={styles.textItem}
|
|
141
|
+
onChange={updateItemName(
|
|
142
|
+
'end_device',
|
|
143
|
+
sensor_index,
|
|
144
|
+
end_device_index
|
|
145
|
+
)}
|
|
146
|
+
/>
|
|
147
|
+
</View>
|
|
148
|
+
)
|
|
124
149
|
)
|
|
125
|
-
)
|
|
126
|
-
|
|
127
|
-
|
|
150
|
+
)
|
|
151
|
+
)}
|
|
152
|
+
</ScrollView>
|
|
153
|
+
</View>
|
|
154
|
+
<Text size={16} color={Colors.Gray8} style={styles.textRename}>
|
|
155
|
+
{t('click_on_box_to_rename_device')}
|
|
156
|
+
</Text>
|
|
128
157
|
</View>
|
|
129
158
|
<TouchableOpacity
|
|
130
159
|
style={styles.btnDone}
|
|
@@ -4,12 +4,14 @@ import { Colors } from '../../configs';
|
|
|
4
4
|
const styles = StyleSheet.create({
|
|
5
5
|
container: {
|
|
6
6
|
flex: 1,
|
|
7
|
-
backgroundColor: Colors.
|
|
8
|
-
justifyContent: '
|
|
7
|
+
backgroundColor: Colors.White,
|
|
8
|
+
justifyContent: 'space-between',
|
|
9
9
|
alignItems: 'center',
|
|
10
10
|
},
|
|
11
11
|
boxDevice: {
|
|
12
|
-
|
|
12
|
+
width: 250,
|
|
13
|
+
flexDirection: 'row',
|
|
14
|
+
paddingLeft: 16,
|
|
13
15
|
borderWidth: 1,
|
|
14
16
|
borderRadius: 10,
|
|
15
17
|
borderColor: Colors.Gray4,
|
|
@@ -23,16 +25,25 @@ const styles = StyleSheet.create({
|
|
|
23
25
|
shadowOpacity: 1,
|
|
24
26
|
shadowRadius: 12,
|
|
25
27
|
elevation: 2,
|
|
28
|
+
marginBottom: 16,
|
|
26
29
|
},
|
|
27
30
|
device: {
|
|
28
31
|
flexDirection: 'row',
|
|
29
32
|
alignItems: 'center',
|
|
30
33
|
},
|
|
34
|
+
textItem: {
|
|
35
|
+
borderWidth: 0,
|
|
36
|
+
textAlign: 'center',
|
|
37
|
+
marginTop: -20,
|
|
38
|
+
fontSize: 16,
|
|
39
|
+
lineHeight: 24,
|
|
40
|
+
maxWidth: 170,
|
|
41
|
+
},
|
|
31
42
|
content: {
|
|
32
43
|
flex: 1,
|
|
33
|
-
backgroundColor: Colors.Gray19,
|
|
34
44
|
justifyContent: 'center',
|
|
35
45
|
alignItems: 'center',
|
|
46
|
+
marginBottom: 24,
|
|
36
47
|
},
|
|
37
48
|
btnDone: {
|
|
38
49
|
height: 48,
|
|
@@ -57,19 +68,12 @@ const styles = StyleSheet.create({
|
|
|
57
68
|
textInput: {
|
|
58
69
|
marginTop: 0,
|
|
59
70
|
},
|
|
60
|
-
roomName: {
|
|
61
|
-
borderWidth: 0,
|
|
62
|
-
borderBottomWidth: 1,
|
|
63
|
-
borderBottomColor: Colors.Primary,
|
|
64
|
-
paddingLeft: 0,
|
|
65
|
-
fontSize: 16,
|
|
66
|
-
lineHeight: 24,
|
|
67
|
-
margin: 0,
|
|
68
|
-
padding: 0,
|
|
69
|
-
},
|
|
70
71
|
wrapRename: {
|
|
71
72
|
marginHorizontal: 16,
|
|
72
73
|
},
|
|
74
|
+
devicesWrapper: {
|
|
75
|
+
paddingHorizontal: 16,
|
|
76
|
+
},
|
|
73
77
|
});
|
|
74
78
|
|
|
75
79
|
export default styles;
|
|
@@ -13,7 +13,7 @@ const ScanGatewayQR = memo(({ route }) => {
|
|
|
13
13
|
const { navigate, goBack } = useNavigation();
|
|
14
14
|
|
|
15
15
|
const onScan = useCallback(
|
|
16
|
-
(body, setLoading) => {
|
|
16
|
+
async (body, setLoading) => {
|
|
17
17
|
let data;
|
|
18
18
|
try {
|
|
19
19
|
data = JSON.parse(body);
|
|
@@ -31,6 +31,7 @@ const ScanGatewayQR = memo(({ route }) => {
|
|
|
31
31
|
unitId,
|
|
32
32
|
stationId,
|
|
33
33
|
qrData: data,
|
|
34
|
+
addDeviceType: 'gateway',
|
|
34
35
|
});
|
|
35
36
|
setLoading(true);
|
|
36
37
|
},
|
|
@@ -14,7 +14,7 @@ import { Colors } from '../../configs';
|
|
|
14
14
|
|
|
15
15
|
const ScanModbusQR = memo(({ route }) => {
|
|
16
16
|
const t = useTranslations();
|
|
17
|
-
const { unitId,
|
|
17
|
+
const { unitId, subUnit } = route?.params || {};
|
|
18
18
|
const { navigate, goBack } = useNavigation();
|
|
19
19
|
const [showPopupGuide, setShowPopupGuide, setHidePopupGuide] = useBoolean();
|
|
20
20
|
const [isInvalidQrCode, setIsInvalidQrCode] = useState(false);
|
|
@@ -35,16 +35,20 @@ const ScanModbusQR = memo(({ route }) => {
|
|
|
35
35
|
setLoading(false);
|
|
36
36
|
return;
|
|
37
37
|
}
|
|
38
|
-
navigate(Routes.
|
|
38
|
+
navigate(Routes.SelectModbusGateway, {
|
|
39
39
|
unitId,
|
|
40
|
-
|
|
41
|
-
chipId,
|
|
40
|
+
subUnit,
|
|
42
41
|
qrData: data,
|
|
43
42
|
});
|
|
44
43
|
},
|
|
45
|
-
[navigate, unitId,
|
|
44
|
+
[navigate, unitId, subUnit]
|
|
46
45
|
);
|
|
47
46
|
|
|
47
|
+
const handleCancel = useCallback(() => {
|
|
48
|
+
setHidePopupGuide();
|
|
49
|
+
goBack();
|
|
50
|
+
}, [goBack, setHidePopupGuide]);
|
|
51
|
+
|
|
48
52
|
const onRetry = useCallback(() => {
|
|
49
53
|
if (isInvalidQrCode) {
|
|
50
54
|
setIsInvalidQrCode(false);
|
|
@@ -74,7 +78,7 @@ const ScanModbusQR = memo(({ route }) => {
|
|
|
74
78
|
</View>
|
|
75
79
|
<ViewButtonBottom
|
|
76
80
|
leftTitle={t('cancel')}
|
|
77
|
-
onLeftClick={
|
|
81
|
+
onLeftClick={handleCancel}
|
|
78
82
|
rightTitle={t('ok')}
|
|
79
83
|
onRightClick={setHidePopupGuide}
|
|
80
84
|
/>
|
|
@@ -6,7 +6,7 @@ import { useNavigation } from '@react-navigation/native';
|
|
|
6
6
|
import InvalidQRCode from '../ScanChipQR/components/InvalidQRCode';
|
|
7
7
|
|
|
8
8
|
const ScanWifiDeviceQR = memo(({ route }) => {
|
|
9
|
-
const { unitId,
|
|
9
|
+
const { unitId, subUnit } = route?.params || {};
|
|
10
10
|
const [isInvalidQrCode, setIsInvalidQrCode] = useState(false);
|
|
11
11
|
const { navigate, goBack } = useNavigation();
|
|
12
12
|
|
|
@@ -27,12 +27,12 @@ const ScanWifiDeviceQR = memo(({ route }) => {
|
|
|
27
27
|
}
|
|
28
28
|
navigate(Routes.ConnectingWifiGuide, {
|
|
29
29
|
unitId,
|
|
30
|
-
|
|
30
|
+
subUnit,
|
|
31
31
|
qrData: data,
|
|
32
32
|
});
|
|
33
33
|
setLoading(true);
|
|
34
34
|
},
|
|
35
|
-
[navigate, unitId,
|
|
35
|
+
[navigate, unitId, subUnit]
|
|
36
36
|
);
|
|
37
37
|
|
|
38
38
|
const onRetry = useCallback(() => {
|
|
@@ -17,21 +17,21 @@ const SelectDeviceSubUnit = ({ route }) => {
|
|
|
17
17
|
navigation.navigate(Routes.ScanWifiDeviceQR, {
|
|
18
18
|
unitId,
|
|
19
19
|
unitName,
|
|
20
|
-
|
|
20
|
+
subUnit,
|
|
21
21
|
});
|
|
22
22
|
break;
|
|
23
23
|
case DEVICE_TYPE.MODBUS:
|
|
24
|
-
navigation.navigate(Routes.
|
|
24
|
+
navigation.navigate(Routes.ScanModbusQR, {
|
|
25
25
|
unitId,
|
|
26
26
|
unitName,
|
|
27
|
-
|
|
27
|
+
subUnit,
|
|
28
28
|
});
|
|
29
29
|
break;
|
|
30
30
|
case DEVICE_TYPE.ZIGBEE:
|
|
31
31
|
navigation.navigate(Routes.ConnectRouterGuide, {
|
|
32
32
|
unitId,
|
|
33
33
|
unitName,
|
|
34
|
-
|
|
34
|
+
subUnit,
|
|
35
35
|
});
|
|
36
36
|
break;
|
|
37
37
|
}
|
|
@@ -53,7 +53,7 @@ const SelectDeviceGrid = ({ options, onSelect }) => {
|
|
|
53
53
|
|
|
54
54
|
const SelectDeviceType = ({ route }) => {
|
|
55
55
|
const t = useTranslations();
|
|
56
|
-
const { unitId, unitName,
|
|
56
|
+
const { unitId, unitName, subUnit } = route?.params || {};
|
|
57
57
|
const { navigate, goBack } = useNavigation();
|
|
58
58
|
const [addType, setAddType] = useState();
|
|
59
59
|
const [selectedAddType, setSelectedAddType] = useState();
|
|
@@ -73,11 +73,13 @@ const SelectDeviceType = ({ route }) => {
|
|
|
73
73
|
{
|
|
74
74
|
id: 2,
|
|
75
75
|
image: <AddWifiDeviceIcon width={60} height={60} />,
|
|
76
|
-
route:
|
|
76
|
+
route: subUnit?.id
|
|
77
|
+
? Routes.ScanWifiDeviceQR
|
|
78
|
+
: Routes.SelectDeviceSubUnit,
|
|
77
79
|
data: {
|
|
78
80
|
unitId,
|
|
79
81
|
unitName,
|
|
80
|
-
|
|
82
|
+
subUnit,
|
|
81
83
|
deviceType: DEVICE_TYPE.WIFI_DEVICE,
|
|
82
84
|
},
|
|
83
85
|
title: t('wifi_device'),
|
|
@@ -86,13 +88,11 @@ const SelectDeviceType = ({ route }) => {
|
|
|
86
88
|
{
|
|
87
89
|
id: 3,
|
|
88
90
|
image: <AddModbusDeviceIcon width={60} height={60} />,
|
|
89
|
-
route:
|
|
90
|
-
? Routes.SelectModbusGateway
|
|
91
|
-
: Routes.SelectDeviceSubUnit,
|
|
91
|
+
route: subUnit?.id ? Routes.ScanModbusQR : Routes.SelectDeviceSubUnit,
|
|
92
92
|
data: {
|
|
93
93
|
unitId,
|
|
94
94
|
unitName,
|
|
95
|
-
|
|
95
|
+
subUnit,
|
|
96
96
|
deviceType: DEVICE_TYPE.MODBUS,
|
|
97
97
|
},
|
|
98
98
|
title: t('modbus'),
|
|
@@ -101,24 +101,24 @@ const SelectDeviceType = ({ route }) => {
|
|
|
101
101
|
{
|
|
102
102
|
id: 4,
|
|
103
103
|
image: <AddZigbeeDeviceIcon width={60} height={60} />,
|
|
104
|
-
route:
|
|
104
|
+
route: subUnit?.id
|
|
105
105
|
? Routes.ConnectRouterGuide
|
|
106
106
|
: Routes.SelectDeviceSubUnit,
|
|
107
107
|
data: {
|
|
108
108
|
unitId,
|
|
109
109
|
unitName,
|
|
110
|
-
|
|
110
|
+
subUnit,
|
|
111
111
|
deviceType: DEVICE_TYPE.ZIGBEE,
|
|
112
112
|
},
|
|
113
113
|
title: t('zigbee'),
|
|
114
114
|
subtitle: t('device_connect_remotely_to_the_gateway'),
|
|
115
115
|
},
|
|
116
116
|
];
|
|
117
|
-
if (!!
|
|
117
|
+
if (!!subUnit?.id) {
|
|
118
118
|
list.shift();
|
|
119
119
|
}
|
|
120
120
|
return list;
|
|
121
|
-
}, [
|
|
121
|
+
}, [t, unitId, unitName, subUnit]);
|
|
122
122
|
|
|
123
123
|
const onRight = useCallback(() => {
|
|
124
124
|
if (selectedAddType?.route && selectedAddType?.data) {
|
|
@@ -139,14 +139,14 @@ const SelectDeviceType = ({ route }) => {
|
|
|
139
139
|
<HeaderCustom title={t('choose_type_of_device')} isShowSeparator />
|
|
140
140
|
<View style={styles.contentContainer}>
|
|
141
141
|
<SelectDeviceGrid options={listDeviceType} onSelect={handleOnSelect} />
|
|
142
|
-
<ViewButtonBottom
|
|
143
|
-
leftTitle={t('previous')}
|
|
144
|
-
onLeftClick={goBack}
|
|
145
|
-
rightTitle={t('text_next')}
|
|
146
|
-
rightDisabled={!addType}
|
|
147
|
-
onRightClick={onRight}
|
|
148
|
-
/>
|
|
149
142
|
</View>
|
|
143
|
+
<ViewButtonBottom
|
|
144
|
+
leftTitle={t('cancel')}
|
|
145
|
+
onLeftClick={goBack}
|
|
146
|
+
rightTitle={t('text_next')}
|
|
147
|
+
rightDisabled={!addType}
|
|
148
|
+
onRightClick={onRight}
|
|
149
|
+
/>
|
|
150
150
|
</SafeAreaView>
|
|
151
151
|
);
|
|
152
152
|
};
|
|
@@ -7,22 +7,35 @@ import Routes from '../../utils/Route';
|
|
|
7
7
|
const SelectModbusGateway = ({ route }) => {
|
|
8
8
|
const t = useTranslations();
|
|
9
9
|
const navigation = useNavigation();
|
|
10
|
-
const { unitId,
|
|
10
|
+
const { unitId, unitName, subUnit, qrData } = route?.params || {};
|
|
11
11
|
|
|
12
12
|
const onPressNext = useCallback(
|
|
13
13
|
(gateway) => {
|
|
14
|
-
navigation.navigate(Routes.
|
|
14
|
+
navigation.navigate(Routes.ConnectingModbusDevice, {
|
|
15
15
|
unitId,
|
|
16
|
-
|
|
16
|
+
subUnit,
|
|
17
17
|
chipId: gateway.id,
|
|
18
|
+
qrData,
|
|
18
19
|
});
|
|
19
20
|
},
|
|
20
|
-
[navigation, unitId,
|
|
21
|
+
[navigation, unitId, subUnit, qrData]
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
const onPressOk = useCallback(
|
|
25
|
+
(gateway) => {
|
|
26
|
+
navigation.navigate(Routes.SelectDeviceType, {
|
|
27
|
+
unitId,
|
|
28
|
+
unitName,
|
|
29
|
+
subUnit,
|
|
30
|
+
});
|
|
31
|
+
},
|
|
32
|
+
[navigation, subUnit, unitId, unitName]
|
|
21
33
|
);
|
|
22
34
|
|
|
23
35
|
return (
|
|
24
36
|
<SelectGateway
|
|
25
37
|
onPressNext={onPressNext}
|
|
38
|
+
onPressOk={onPressOk}
|
|
26
39
|
title={t('text_select_a_gateway')}
|
|
27
40
|
subTitle={t('text_select_a_gateway')}
|
|
28
41
|
unitId={unitId}
|
|
@@ -7,17 +7,17 @@ import Routes from '../../utils/Route';
|
|
|
7
7
|
const SelectZigbeeGateway = ({ route }) => {
|
|
8
8
|
const t = useTranslations();
|
|
9
9
|
const navigation = useNavigation();
|
|
10
|
-
const { unitId,
|
|
10
|
+
const { unitId, subUnit } = route?.params || {};
|
|
11
11
|
|
|
12
12
|
const onPressNext = useCallback(
|
|
13
13
|
(gateway) => {
|
|
14
14
|
navigation.navigate(Routes.ZigbeeDeviceConnectGuide, {
|
|
15
15
|
unitId,
|
|
16
|
-
|
|
16
|
+
subUnit,
|
|
17
17
|
chipId: gateway.id,
|
|
18
18
|
});
|
|
19
19
|
},
|
|
20
|
-
[navigation, unitId,
|
|
20
|
+
[navigation, unitId, subUnit]
|
|
21
21
|
);
|
|
22
22
|
|
|
23
23
|
return (
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useCallback, useState } from 'react';
|
|
1
|
+
import React, { useCallback, useRef, useState } from 'react';
|
|
2
2
|
import WifiManager from 'react-native-wifi-reborn';
|
|
3
3
|
import { Alert, ScrollView, TouchableOpacity, View } from 'react-native';
|
|
4
4
|
import dgram from 'react-native-udp';
|
|
@@ -42,7 +42,8 @@ const WifiItem = ({ item, setIsShowPopupPassword, setSelectedWifi }) => {
|
|
|
42
42
|
};
|
|
43
43
|
|
|
44
44
|
const ShareWifiPassword = ({ route }) => {
|
|
45
|
-
const { wifiList, unitId,
|
|
45
|
+
const { wifiList, unitId, subUnit, qrData, addDeviceType } =
|
|
46
|
+
route?.params || {};
|
|
46
47
|
const t = useTranslations();
|
|
47
48
|
const navigation = useNavigation();
|
|
48
49
|
|
|
@@ -78,9 +79,16 @@ const ShareWifiPassword = ({ route }) => {
|
|
|
78
79
|
[selectedWifiPassword, selectedWifi]
|
|
79
80
|
);
|
|
80
81
|
|
|
82
|
+
const isWrongPassword = useRef(true);
|
|
83
|
+
|
|
81
84
|
const handleSocketOnMsg = useCallback(
|
|
82
85
|
(currentSsid, msg) => {
|
|
83
86
|
const data = JSON.parse(msg.toString());
|
|
87
|
+
if (isWrongPassword.current && data.status === 'error') {
|
|
88
|
+
Alert.alert('', t('wrong_wifi_password'));
|
|
89
|
+
isWrongPassword.current = false;
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
84
92
|
if (!Object.prototype.hasOwnProperty.call(data, 'gateway')) {
|
|
85
93
|
return false;
|
|
86
94
|
}
|
|
@@ -96,23 +104,34 @@ const ShareWifiPassword = ({ route }) => {
|
|
|
96
104
|
clearInterval(checkWifiInterval);
|
|
97
105
|
navigation.navigate(Routes.ConnectingWifiDevice, {
|
|
98
106
|
unitId,
|
|
99
|
-
|
|
107
|
+
subUnit,
|
|
100
108
|
gateway: gatewayInfo,
|
|
101
109
|
qrData: qrData,
|
|
102
110
|
selectedWifi: {
|
|
103
111
|
ssid: selectedWifi,
|
|
104
112
|
password: selectedWifiPassword,
|
|
105
113
|
},
|
|
114
|
+
addDeviceType,
|
|
106
115
|
});
|
|
107
116
|
}
|
|
108
117
|
}, 1000);
|
|
109
118
|
|
|
110
119
|
return true;
|
|
111
120
|
},
|
|
112
|
-
[
|
|
121
|
+
[
|
|
122
|
+
addDeviceType,
|
|
123
|
+
navigation,
|
|
124
|
+
qrData,
|
|
125
|
+
selectedWifi,
|
|
126
|
+
selectedWifiPassword,
|
|
127
|
+
subUnit,
|
|
128
|
+
t,
|
|
129
|
+
unitId,
|
|
130
|
+
]
|
|
113
131
|
);
|
|
114
132
|
|
|
115
133
|
const onPasswordReady = useCallback(async () => {
|
|
134
|
+
isWrongPassword.current = true;
|
|
116
135
|
const socket = dgram.createSocket({ type: 'udp4' });
|
|
117
136
|
socket.bind(54321);
|
|
118
137
|
let currentSsid;
|
|
@@ -41,10 +41,13 @@ describe('Test connecting wifi device', () => {
|
|
|
41
41
|
});
|
|
42
42
|
|
|
43
43
|
beforeEach(() => {
|
|
44
|
+
jest.useFakeTimers();
|
|
44
45
|
route = {
|
|
45
46
|
params: {
|
|
46
47
|
unitId: 1,
|
|
47
|
-
|
|
48
|
+
subUnit: {
|
|
49
|
+
id: 2,
|
|
50
|
+
},
|
|
48
51
|
gateway: {},
|
|
49
52
|
qrData: {},
|
|
50
53
|
selectedWifi: {},
|
|
@@ -58,6 +61,7 @@ describe('Test connecting wifi device', () => {
|
|
|
58
61
|
});
|
|
59
62
|
const instance = tree.root;
|
|
60
63
|
expect(instance.findAllByType(Processing)).toHaveLength(1);
|
|
64
|
+
jest.runAllTimers();
|
|
61
65
|
expect(mock.history.post).toHaveLength(1);
|
|
62
66
|
});
|
|
63
67
|
});
|
|
@@ -177,7 +177,9 @@ describe('test share wifi password', () => {
|
|
|
177
177
|
params: {
|
|
178
178
|
qrData: { org_slug: 'eoh', prefix: 'robot' },
|
|
179
179
|
unitId: 1,
|
|
180
|
-
|
|
180
|
+
subUnit: {
|
|
181
|
+
id: 1,
|
|
182
|
+
},
|
|
181
183
|
},
|
|
182
184
|
};
|
|
183
185
|
await act(async () => {
|
|
@@ -201,7 +203,9 @@ describe('test share wifi password', () => {
|
|
|
201
203
|
|
|
202
204
|
expect(mockedNavigate).toBeCalledWith('ShareWifiPassword', {
|
|
203
205
|
unitId: 1,
|
|
204
|
-
|
|
206
|
+
subUnit: {
|
|
207
|
+
id: 1,
|
|
208
|
+
},
|
|
205
209
|
wifiList: [{ ssid: 'wifi 1' }, { ssid: 'wifi.2' }],
|
|
206
210
|
qrData: { org_slug: 'eoh', prefix: 'robot' },
|
|
207
211
|
});
|