@eohjsc/react-native-smart-city 0.3.41 → 0.3.44
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +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/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/SubUnit/ShortDetail.js +3 -4
- package/src/commons/SubUnit/__test__/ShortDetail.test.js +1 -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/AddNewGateway/ConnectingDevice.js +24 -7
- package/src/screens/AddNewGateway/ConnectingModbusDevice.js +42 -20
- package/src/screens/AddNewGateway/ConnectingWifiDevice.js +24 -30
- package/src/screens/AddNewGateway/ConnectingWifiGuide.js +3 -3
- package/src/screens/AddNewGateway/ConnectingZigbeeDevice.js +4 -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 +6 -12
- package/src/screens/AddNewGateway/ScanModbusQR.js +9 -5
- package/src/screens/AddNewGateway/ScanWifiDeviceQR.js +3 -3
- package/src/screens/AddNewGateway/SelectDeviceSubUnit.js +4 -7
- package/src/screens/AddNewGateway/SelectDeviceType.js +18 -19
- package/src/screens/AddNewGateway/SelectModbusGateway.js +5 -8
- package/src/screens/AddNewGateway/SelectZigbeeGateway.js +3 -4
- package/src/screens/AddNewGateway/ShareWifiPassword.js +13 -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 +8 -4
- package/src/screens/AddNewGateway/__test__/RenameNewDevices.test.js +64 -0
- package/src/screens/AddNewGateway/__test__/SelectDeviceType.test.js +3 -1
- package/src/screens/AddNewGateway/__test__/SelectModbusGateway.test.js +6 -2
- package/src/screens/AddNewGateway/__test__/SelectZigbeeGateway.test.js +6 -2
- package/src/screens/Device/EditDevice/index.js +4 -8
- package/src/screens/Device/detail.js +2 -1
- 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/EditSubUnit.js +22 -41
- package/src/screens/SubUnit/__test__/EditSubUnit.test.js +51 -59
- 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 +8 -2
- package/src/utils/I18n/translations/vi.json +8 -2
- package/src/hooks/Common/useKeyboardShowTranslation.js +0 -120
- package/src/utils/runTiming.js +0 -52
|
@@ -8,15 +8,8 @@ import ConnectingDevice from './ConnectingDevice';
|
|
|
8
8
|
|
|
9
9
|
const ConnectingWifiDevice = ({ route }) => {
|
|
10
10
|
const t = useTranslations();
|
|
11
|
-
const {
|
|
12
|
-
|
|
13
|
-
stationId,
|
|
14
|
-
stationName,
|
|
15
|
-
gateway,
|
|
16
|
-
selectedWifi,
|
|
17
|
-
qrData,
|
|
18
|
-
addDeviceType,
|
|
19
|
-
} = route?.params || {};
|
|
11
|
+
const { unitId, subUnit, gateway, selectedWifi, qrData, addDeviceType } =
|
|
12
|
+
route?.params || {};
|
|
20
13
|
const [chipId, setChipId] = useState(null);
|
|
21
14
|
const { goBack } = useNavigation();
|
|
22
15
|
|
|
@@ -33,32 +26,34 @@ const ConnectingWifiDevice = ({ route }) => {
|
|
|
33
26
|
);
|
|
34
27
|
|
|
35
28
|
const onReady = useCallback(
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
29
|
+
(channelName) => {
|
|
30
|
+
const timeout = setTimeout(async () => {
|
|
31
|
+
const { success, problem, data } = await axiosPost(
|
|
32
|
+
API.UNIT.CHIP_SCAN(unitId),
|
|
33
|
+
{
|
|
34
|
+
imei: gateway?.imei,
|
|
35
|
+
secret: qrData?.secret,
|
|
36
|
+
name: gateway?.model,
|
|
37
|
+
station: subUnit?.id,
|
|
38
|
+
wifi_ssid: selectedWifi.ssid, // for storing
|
|
39
|
+
wifi_pass: selectedWifi.password, // for storing
|
|
40
|
+
channel_name: channelName,
|
|
41
|
+
}
|
|
42
|
+
);
|
|
43
|
+
if (!success) {
|
|
44
|
+
addingWifiDeviceFail(JSON.stringify(problem || data));
|
|
45
|
+
return;
|
|
47
46
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
addingWifiDeviceFail(JSON.stringify(problem || data));
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
setChipId(data.id);
|
|
47
|
+
setChipId(data.id);
|
|
48
|
+
clearTimeout(timeout);
|
|
49
|
+
}, 2000);
|
|
55
50
|
},
|
|
56
51
|
[
|
|
57
52
|
gateway,
|
|
58
53
|
selectedWifi,
|
|
59
54
|
unitId,
|
|
60
55
|
qrData?.secret,
|
|
61
|
-
|
|
56
|
+
subUnit,
|
|
62
57
|
addingWifiDeviceFail,
|
|
63
58
|
]
|
|
64
59
|
);
|
|
@@ -70,8 +65,7 @@ const ConnectingWifiDevice = ({ route }) => {
|
|
|
70
65
|
initState={t('connecting_to_device')}
|
|
71
66
|
onReady={onReady}
|
|
72
67
|
unitId={unitId}
|
|
73
|
-
|
|
74
|
-
stationName={stationName}
|
|
68
|
+
subUnit={subUnit}
|
|
75
69
|
chipId={chipId}
|
|
76
70
|
addDeviceType={addDeviceType}
|
|
77
71
|
/>
|
|
@@ -23,7 +23,7 @@ import AccessibilityLabel from '../../configs/AccessibilityLabel';
|
|
|
23
23
|
|
|
24
24
|
const ConnectingWifiGuide = ({ route }) => {
|
|
25
25
|
const t = useTranslations();
|
|
26
|
-
const { qrData, unitId,
|
|
26
|
+
const { qrData, unitId, subUnit, addDeviceType } = route?.params || {};
|
|
27
27
|
const { navigate, goBack } = useNavigation();
|
|
28
28
|
const [wifiList, setWifiList] = useState([]);
|
|
29
29
|
const [currentState, setCurrentState] = useState(0);
|
|
@@ -125,13 +125,13 @@ const ConnectingWifiGuide = ({ route }) => {
|
|
|
125
125
|
if (wifiList.length) {
|
|
126
126
|
navigate(Routes.ShareWifiPassword, {
|
|
127
127
|
unitId,
|
|
128
|
-
|
|
128
|
+
subUnit,
|
|
129
129
|
wifiList,
|
|
130
130
|
qrData: qrData,
|
|
131
131
|
addDeviceType,
|
|
132
132
|
});
|
|
133
133
|
}
|
|
134
|
-
}, [addDeviceType, navigate, qrData,
|
|
134
|
+
}, [addDeviceType, navigate, qrData, subUnit, unitId, wifiList]);
|
|
135
135
|
|
|
136
136
|
return (
|
|
137
137
|
<SafeAreaView style={styles.container}>
|
|
@@ -9,7 +9,7 @@ import ConnectingDevice from './ConnectingDevice';
|
|
|
9
9
|
const ConnectingZigbeeDevice = ({ route }) => {
|
|
10
10
|
const t = useTranslations();
|
|
11
11
|
const { goBack } = useNavigation();
|
|
12
|
-
const { unitId,
|
|
12
|
+
const { unitId, subUnit, chipId } = route?.params || {};
|
|
13
13
|
const [sensorId, setSensorId] = useState(null);
|
|
14
14
|
|
|
15
15
|
const fail = useCallback(
|
|
@@ -30,7 +30,7 @@ const ConnectingZigbeeDevice = ({ route }) => {
|
|
|
30
30
|
API.CHIP.ZIGBEE.ACCEPT_NEW_DEVICE(chipId),
|
|
31
31
|
{
|
|
32
32
|
channel_name: channelName,
|
|
33
|
-
station:
|
|
33
|
+
station: subUnit?.id,
|
|
34
34
|
unit: unitId,
|
|
35
35
|
}
|
|
36
36
|
);
|
|
@@ -41,7 +41,7 @@ const ConnectingZigbeeDevice = ({ route }) => {
|
|
|
41
41
|
}
|
|
42
42
|
setSensorId(data.id);
|
|
43
43
|
},
|
|
44
|
-
[chipId, fail,
|
|
44
|
+
[chipId, fail, subUnit, unitId]
|
|
45
45
|
);
|
|
46
46
|
|
|
47
47
|
return (
|
|
@@ -51,8 +51,7 @@ const ConnectingZigbeeDevice = ({ route }) => {
|
|
|
51
51
|
initState={t('connecting_to_gateway')}
|
|
52
52
|
onReady={onReady}
|
|
53
53
|
unitId={unitId}
|
|
54
|
-
|
|
55
|
-
stationName={stationName}
|
|
54
|
+
subUnit={subUnit}
|
|
56
55
|
chipId={chipId}
|
|
57
56
|
sensorId={sensorId}
|
|
58
57
|
/>
|
|
@@ -34,14 +34,14 @@ const ConnectRouterGuide = ({ route }) => {
|
|
|
34
34
|
{t('read_device_manual_guide')}
|
|
35
35
|
</Text>
|
|
36
36
|
</View>
|
|
37
|
-
<ViewButtonBottom
|
|
38
|
-
leftTitle={t('cancel')}
|
|
39
|
-
onLeftClick={goBack}
|
|
40
|
-
rightTitle={t('text_next')}
|
|
41
|
-
onRightClick={onRight}
|
|
42
|
-
styleButtonLeftText={styles.buttonLeftText}
|
|
43
|
-
/>
|
|
44
37
|
</View>
|
|
38
|
+
<ViewButtonBottom
|
|
39
|
+
leftTitle={t('cancel')}
|
|
40
|
+
onLeftClick={goBack}
|
|
41
|
+
rightTitle={t('text_next')}
|
|
42
|
+
onRightClick={onRight}
|
|
43
|
+
styleButtonLeftText={styles.buttonLeftText}
|
|
44
|
+
/>
|
|
45
45
|
</View>
|
|
46
46
|
);
|
|
47
47
|
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import renderer, { act, create } from 'react-test-renderer';
|
|
3
|
+
|
|
4
|
+
import ConnectRouterGuide from '../ConnectRouterGuide';
|
|
5
|
+
import { Text } from 'react-native';
|
|
6
|
+
import { getTranslate } from '../../../../utils/I18n';
|
|
7
|
+
import { SCProvider } from '../../../../context';
|
|
8
|
+
import { mockSCStore } from '../../../../context/mockStore';
|
|
9
|
+
import { ViewButtonBottom } from '../../../../commons';
|
|
10
|
+
import Routes from '../../../../utils/Route';
|
|
11
|
+
|
|
12
|
+
const mockedGoBack = jest.fn();
|
|
13
|
+
const mockedNavigate = jest.fn();
|
|
14
|
+
jest.mock('@react-navigation/native', () => {
|
|
15
|
+
return {
|
|
16
|
+
...jest.requireActual('@react-navigation/native'),
|
|
17
|
+
useNavigation: () => ({
|
|
18
|
+
navigate: mockedNavigate,
|
|
19
|
+
goBack: mockedGoBack,
|
|
20
|
+
}),
|
|
21
|
+
useIsFocused: () => ({}),
|
|
22
|
+
};
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const wrapComponent = (route) => (
|
|
26
|
+
<SCProvider initState={mockSCStore({})}>
|
|
27
|
+
<ConnectRouterGuide route={route} />
|
|
28
|
+
</SCProvider>
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
describe('Test ConnectRouterGuide', () => {
|
|
32
|
+
let tree;
|
|
33
|
+
|
|
34
|
+
beforeEach(async () => {
|
|
35
|
+
mockedNavigate.mockClear();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('create', async () => {
|
|
39
|
+
await act(async () => {
|
|
40
|
+
tree = await create(wrapComponent({ params: {} }));
|
|
41
|
+
});
|
|
42
|
+
const instance = tree.root;
|
|
43
|
+
const texts = instance.findAllByType(Text);
|
|
44
|
+
expect(texts).toHaveLength(8);
|
|
45
|
+
expect(texts[1].props.children).toEqual(
|
|
46
|
+
getTranslate('en', 'connect_to_router')
|
|
47
|
+
);
|
|
48
|
+
expect(texts[2].props.children).toEqual(
|
|
49
|
+
getTranslate('en', 'connect_router_content')
|
|
50
|
+
);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
const rightClick = async (params) => {
|
|
54
|
+
await act(async () => {
|
|
55
|
+
tree = renderer.create(wrapComponent({ params }));
|
|
56
|
+
});
|
|
57
|
+
const instance = tree.root;
|
|
58
|
+
const viewButtonBottom = instance.findByType(ViewButtonBottom);
|
|
59
|
+
await act(async () => {
|
|
60
|
+
viewButtonBottom.props.onRightClick();
|
|
61
|
+
});
|
|
62
|
+
expect(mockedNavigate).toHaveBeenCalled();
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
it('test click next', async () => {
|
|
66
|
+
await rightClick();
|
|
67
|
+
expect(mockedNavigate.mock.calls[0][0]).toEqual(Routes.SelectZigbeeGateway);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import renderer, { act, create } from 'react-test-renderer';
|
|
3
|
+
|
|
4
|
+
import ZigbeeDeviceConnectGuide from '../ZigbeeDeviceConnectGuide';
|
|
5
|
+
import { Text } from 'react-native';
|
|
6
|
+
import { getTranslate } from '../../../../utils/I18n';
|
|
7
|
+
import { SCProvider } from '../../../../context';
|
|
8
|
+
import { mockSCStore } from '../../../../context/mockStore';
|
|
9
|
+
import { ViewButtonBottom } from '../../../../commons';
|
|
10
|
+
import Routes from '../../../../utils/Route';
|
|
11
|
+
|
|
12
|
+
const mockedGoBack = jest.fn();
|
|
13
|
+
const mockedNavigate = jest.fn();
|
|
14
|
+
jest.mock('@react-navigation/native', () => {
|
|
15
|
+
return {
|
|
16
|
+
...jest.requireActual('@react-navigation/native'),
|
|
17
|
+
useNavigation: () => ({
|
|
18
|
+
navigate: mockedNavigate,
|
|
19
|
+
goBack: mockedGoBack,
|
|
20
|
+
}),
|
|
21
|
+
useIsFocused: () => ({}),
|
|
22
|
+
};
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const wrapComponent = (route) => (
|
|
26
|
+
<SCProvider initState={mockSCStore({})}>
|
|
27
|
+
<ZigbeeDeviceConnectGuide route={route} />
|
|
28
|
+
</SCProvider>
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
describe('Test ZigbeeDeviceConnectGuide', () => {
|
|
32
|
+
let tree;
|
|
33
|
+
|
|
34
|
+
beforeEach(async () => {
|
|
35
|
+
mockedNavigate.mockClear();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('create', async () => {
|
|
39
|
+
await act(async () => {
|
|
40
|
+
tree = await create(wrapComponent({ params: {} }));
|
|
41
|
+
});
|
|
42
|
+
const instance = tree.root;
|
|
43
|
+
const texts = instance.findAllByType(Text);
|
|
44
|
+
expect(texts).toHaveLength(8);
|
|
45
|
+
expect(texts[1].props.children).toEqual(
|
|
46
|
+
getTranslate('en', 'turn_on_device_to_connect')
|
|
47
|
+
);
|
|
48
|
+
expect(texts[2].props.children).toEqual(
|
|
49
|
+
getTranslate('en', 'turn_on_zigbee_device_content')
|
|
50
|
+
);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
const rightClick = async (params) => {
|
|
54
|
+
await act(async () => {
|
|
55
|
+
tree = renderer.create(wrapComponent({ params }));
|
|
56
|
+
});
|
|
57
|
+
const instance = tree.root;
|
|
58
|
+
const viewButtonBottom = instance.findByType(ViewButtonBottom);
|
|
59
|
+
await act(async () => {
|
|
60
|
+
viewButtonBottom.props.onRightClick();
|
|
61
|
+
});
|
|
62
|
+
expect(mockedNavigate).toHaveBeenCalled();
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
it('test click next', async () => {
|
|
66
|
+
await rightClick();
|
|
67
|
+
expect(mockedNavigate.mock.calls[0][0]).toEqual(
|
|
68
|
+
Routes.ConnectingZigbeeDevice
|
|
69
|
+
);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
@@ -21,7 +21,7 @@ const RenameNewDevices = memo(({ route }) => {
|
|
|
21
21
|
const t = useTranslations();
|
|
22
22
|
const navigation = useNavigation();
|
|
23
23
|
|
|
24
|
-
const { unitId,
|
|
24
|
+
const { unitId, subUnit, chipId, sensorId, addDeviceType } =
|
|
25
25
|
route?.params || {};
|
|
26
26
|
|
|
27
27
|
const [info, setInfo] = useState({});
|
|
@@ -33,10 +33,11 @@ const RenameNewDevices = memo(({ route }) => {
|
|
|
33
33
|
params: {
|
|
34
34
|
unitId: unitId,
|
|
35
35
|
routeName: 'DashboardStack',
|
|
36
|
-
stationId:
|
|
36
|
+
stationId: subUnit?.id,
|
|
37
|
+
isSuccessfullyConnected: true,
|
|
37
38
|
},
|
|
38
39
|
});
|
|
39
|
-
}, [info, navigation,
|
|
40
|
+
}, [info, navigation, subUnit, unitId]);
|
|
40
41
|
|
|
41
42
|
useEffect(() => {
|
|
42
43
|
(async () => {
|
|
@@ -54,20 +55,13 @@ const RenameNewDevices = memo(({ route }) => {
|
|
|
54
55
|
setInfo(data);
|
|
55
56
|
}
|
|
56
57
|
})();
|
|
57
|
-
}, [chipId, sensorId,
|
|
58
|
+
}, [chipId, sensorId, subUnit]);
|
|
58
59
|
|
|
59
60
|
const updateItemName = (type, sensor_index, end_device_index) => (value) => {
|
|
60
61
|
setInfo((currentInfo) => {
|
|
61
62
|
if (type === 'chip') {
|
|
62
63
|
return { ...currentInfo, name: value };
|
|
63
64
|
}
|
|
64
|
-
if (type === 'sensor') {
|
|
65
|
-
currentInfo.sensors[sensor_index] = {
|
|
66
|
-
...currentInfo.sensors[sensor_index],
|
|
67
|
-
name: value,
|
|
68
|
-
};
|
|
69
|
-
return { ...currentInfo };
|
|
70
|
-
}
|
|
71
65
|
if (type === 'end_device') {
|
|
72
66
|
currentInfo.sensors[sensor_index].end_devices[end_device_index] = {
|
|
73
67
|
...currentInfo.sensors[sensor_index].end_devices[end_device_index],
|
|
@@ -108,7 +102,7 @@ const RenameNewDevices = memo(({ route }) => {
|
|
|
108
102
|
{t('successfully_connected')}
|
|
109
103
|
</Text>
|
|
110
104
|
<Text size={14} color={Colors.Gray9} style={styles.textStation}>
|
|
111
|
-
{
|
|
105
|
+
{subUnit?.name}
|
|
112
106
|
</Text>
|
|
113
107
|
<View style={{ ...styles.devicesWrapper, height: scrollviewHeight }}>
|
|
114
108
|
<ScrollView>
|
|
@@ -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);
|
|
@@ -37,14 +37,18 @@ const ScanModbusQR = memo(({ route }) => {
|
|
|
37
37
|
}
|
|
38
38
|
navigate(Routes.SelectModbusGateway, {
|
|
39
39
|
unitId,
|
|
40
|
-
|
|
41
|
-
stationName,
|
|
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,24 +17,21 @@ const SelectDeviceSubUnit = ({ route }) => {
|
|
|
17
17
|
navigation.navigate(Routes.ScanWifiDeviceQR, {
|
|
18
18
|
unitId,
|
|
19
19
|
unitName,
|
|
20
|
-
|
|
21
|
-
stationName: subUnit?.id,
|
|
20
|
+
subUnit,
|
|
22
21
|
});
|
|
23
22
|
break;
|
|
24
23
|
case DEVICE_TYPE.MODBUS:
|
|
25
|
-
navigation.navigate(Routes.
|
|
24
|
+
navigation.navigate(Routes.ScanModbusQR, {
|
|
26
25
|
unitId,
|
|
27
26
|
unitName,
|
|
28
|
-
|
|
29
|
-
stationName: subUnit?.id,
|
|
27
|
+
subUnit,
|
|
30
28
|
});
|
|
31
29
|
break;
|
|
32
30
|
case DEVICE_TYPE.ZIGBEE:
|
|
33
31
|
navigation.navigate(Routes.ConnectRouterGuide, {
|
|
34
32
|
unitId,
|
|
35
33
|
unitName,
|
|
36
|
-
|
|
37
|
-
stationName: subUnit?.id,
|
|
34
|
+
subUnit,
|
|
38
35
|
});
|
|
39
36
|
break;
|
|
40
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,12 +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
|
-
|
|
81
|
-
stationName,
|
|
82
|
+
subUnit,
|
|
82
83
|
deviceType: DEVICE_TYPE.WIFI_DEVICE,
|
|
83
84
|
},
|
|
84
85
|
title: t('wifi_device'),
|
|
@@ -87,12 +88,11 @@ const SelectDeviceType = ({ route }) => {
|
|
|
87
88
|
{
|
|
88
89
|
id: 3,
|
|
89
90
|
image: <AddModbusDeviceIcon width={60} height={60} />,
|
|
90
|
-
route:
|
|
91
|
+
route: subUnit?.id ? Routes.ScanModbusQR : Routes.SelectDeviceSubUnit,
|
|
91
92
|
data: {
|
|
92
93
|
unitId,
|
|
93
94
|
unitName,
|
|
94
|
-
|
|
95
|
-
stationName,
|
|
95
|
+
subUnit,
|
|
96
96
|
deviceType: DEVICE_TYPE.MODBUS,
|
|
97
97
|
},
|
|
98
98
|
title: t('modbus'),
|
|
@@ -101,25 +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
|
-
|
|
111
|
-
stationName,
|
|
110
|
+
subUnit,
|
|
112
111
|
deviceType: DEVICE_TYPE.ZIGBEE,
|
|
113
112
|
},
|
|
114
113
|
title: t('zigbee'),
|
|
115
114
|
subtitle: t('device_connect_remotely_to_the_gateway'),
|
|
116
115
|
},
|
|
117
116
|
];
|
|
118
|
-
if (!!
|
|
117
|
+
if (!!subUnit?.id) {
|
|
119
118
|
list.shift();
|
|
120
119
|
}
|
|
121
120
|
return list;
|
|
122
|
-
}, [
|
|
121
|
+
}, [t, unitId, unitName, subUnit]);
|
|
123
122
|
|
|
124
123
|
const onRight = useCallback(() => {
|
|
125
124
|
if (selectedAddType?.route && selectedAddType?.data) {
|
|
@@ -140,14 +139,14 @@ const SelectDeviceType = ({ route }) => {
|
|
|
140
139
|
<HeaderCustom title={t('choose_type_of_device')} isShowSeparator />
|
|
141
140
|
<View style={styles.contentContainer}>
|
|
142
141
|
<SelectDeviceGrid options={listDeviceType} onSelect={handleOnSelect} />
|
|
143
|
-
<ViewButtonBottom
|
|
144
|
-
leftTitle={t('cancel')}
|
|
145
|
-
onLeftClick={goBack}
|
|
146
|
-
rightTitle={t('text_next')}
|
|
147
|
-
rightDisabled={!addType}
|
|
148
|
-
onRightClick={onRight}
|
|
149
|
-
/>
|
|
150
142
|
</View>
|
|
143
|
+
<ViewButtonBottom
|
|
144
|
+
leftTitle={t('cancel')}
|
|
145
|
+
onLeftClick={goBack}
|
|
146
|
+
rightTitle={t('text_next')}
|
|
147
|
+
rightDisabled={!addType}
|
|
148
|
+
onRightClick={onRight}
|
|
149
|
+
/>
|
|
151
150
|
</SafeAreaView>
|
|
152
151
|
);
|
|
153
152
|
};
|
|
@@ -7,32 +7,29 @@ import Routes from '../../utils/Route';
|
|
|
7
7
|
const SelectModbusGateway = ({ route }) => {
|
|
8
8
|
const t = useTranslations();
|
|
9
9
|
const navigation = useNavigation();
|
|
10
|
-
const { unitId, unitName,
|
|
11
|
-
route?.params || {};
|
|
10
|
+
const { unitId, unitName, subUnit, qrData } = route?.params || {};
|
|
12
11
|
|
|
13
12
|
const onPressNext = useCallback(
|
|
14
13
|
(gateway) => {
|
|
15
14
|
navigation.navigate(Routes.ConnectingModbusDevice, {
|
|
16
15
|
unitId,
|
|
17
|
-
|
|
18
|
-
stationName,
|
|
16
|
+
subUnit,
|
|
19
17
|
chipId: gateway.id,
|
|
20
18
|
qrData,
|
|
21
19
|
});
|
|
22
20
|
},
|
|
23
|
-
[navigation, unitId,
|
|
21
|
+
[navigation, unitId, subUnit, qrData]
|
|
24
22
|
);
|
|
25
23
|
|
|
26
24
|
const onPressOk = useCallback(
|
|
27
25
|
(gateway) => {
|
|
28
26
|
navigation.navigate(Routes.SelectDeviceType, {
|
|
29
|
-
stationName,
|
|
30
|
-
stationId,
|
|
31
27
|
unitId,
|
|
32
28
|
unitName,
|
|
29
|
+
subUnit,
|
|
33
30
|
});
|
|
34
31
|
},
|
|
35
|
-
[navigation,
|
|
32
|
+
[navigation, subUnit, unitId, unitName]
|
|
36
33
|
);
|
|
37
34
|
|
|
38
35
|
return (
|
|
@@ -7,18 +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
|
-
|
|
17
|
-
stationName,
|
|
16
|
+
subUnit,
|
|
18
17
|
chipId: gateway.id,
|
|
19
18
|
});
|
|
20
19
|
},
|
|
21
|
-
[navigation, unitId,
|
|
20
|
+
[navigation, unitId, subUnit]
|
|
22
21
|
);
|
|
23
22
|
|
|
24
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,7 @@ 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
46
|
route?.params || {};
|
|
47
47
|
const t = useTranslations();
|
|
48
48
|
const navigation = useNavigation();
|
|
@@ -79,9 +79,16 @@ const ShareWifiPassword = ({ route }) => {
|
|
|
79
79
|
[selectedWifiPassword, selectedWifi]
|
|
80
80
|
);
|
|
81
81
|
|
|
82
|
+
const isWrongPassword = useRef(true);
|
|
83
|
+
|
|
82
84
|
const handleSocketOnMsg = useCallback(
|
|
83
85
|
(currentSsid, msg) => {
|
|
84
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
|
+
}
|
|
85
92
|
if (!Object.prototype.hasOwnProperty.call(data, 'gateway')) {
|
|
86
93
|
return false;
|
|
87
94
|
}
|
|
@@ -97,7 +104,7 @@ const ShareWifiPassword = ({ route }) => {
|
|
|
97
104
|
clearInterval(checkWifiInterval);
|
|
98
105
|
navigation.navigate(Routes.ConnectingWifiDevice, {
|
|
99
106
|
unitId,
|
|
100
|
-
|
|
107
|
+
subUnit,
|
|
101
108
|
gateway: gatewayInfo,
|
|
102
109
|
qrData: qrData,
|
|
103
110
|
selectedWifi: {
|
|
@@ -117,12 +124,14 @@ const ShareWifiPassword = ({ route }) => {
|
|
|
117
124
|
qrData,
|
|
118
125
|
selectedWifi,
|
|
119
126
|
selectedWifiPassword,
|
|
120
|
-
|
|
127
|
+
subUnit,
|
|
128
|
+
t,
|
|
121
129
|
unitId,
|
|
122
130
|
]
|
|
123
131
|
);
|
|
124
132
|
|
|
125
133
|
const onPasswordReady = useCallback(async () => {
|
|
134
|
+
isWrongPassword.current = true;
|
|
126
135
|
const socket = dgram.createSocket({ type: 'udp4' });
|
|
127
136
|
socket.bind(54321);
|
|
128
137
|
let currentSsid;
|