@eohjsc/react-native-smart-city 0.2.86 → 0.2.89
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/Common/Calendar.svg +3 -0
- package/assets/images/Common/SmartPhone.svg +3 -0
- package/assets/images/Hanet/CaptureFaceID.svg +25 -0
- package/assets/images/Hanet/FaceFrame.svg +6 -0
- package/assets/images/brightnessBlack.svg +12 -0
- package/index.js +4 -0
- package/package.json +3 -3
- package/src/Images/SmartIr/AC.svg +14 -0
- package/src/Images/SmartIr/DIY.svg +3 -0
- package/src/Images/SmartIr/Fan.svg +10 -0
- package/src/Images/SmartIr/Fridge.svg +5 -0
- package/src/Images/SmartIr/Remote.svg +15 -0
- package/src/Images/SmartIr/SmartIr.svg +4 -0
- package/src/Images/SmartIr/TV.svg +10 -0
- package/src/Images/SmartIr/Union.svg +9 -0
- package/src/Images/SmartIr/WM.svg +11 -0
- package/src/Images/SmartIr/index.js +10 -0
- package/src/commons/ActionGroup/ColorPickerTemplate.js +51 -0
- package/src/commons/ActionGroup/ColorPickerTemplateStyles.js +17 -0
- package/src/commons/ActionGroup/OnOffSmartLock/AutoLock/AutoLockStyles.js +40 -0
- package/src/commons/ActionGroup/OnOffSmartLock/AutoLock/ButtonWrapper.js +65 -0
- package/src/commons/ActionGroup/OnOffSmartLock/AutoLock/ButtonWrapperStyles.js +43 -0
- package/src/commons/ActionGroup/OnOffSmartLock/AutoLock/__test__/index.test.js +48 -0
- package/src/commons/ActionGroup/OnOffSmartLock/AutoLock/index.js +57 -0
- package/src/commons/ActionGroup/{OnOffSmartLock.js → OnOffSmartLock/OnOffSmartLock.js} +5 -5
- package/src/commons/ActionGroup/{OnOffSmartLockStyle.js → OnOffSmartLock/OnOffSmartLockStyle.js} +1 -1
- package/src/commons/ActionGroup/OnOffSmartLock/PasscodeList/ItemPasscode.js +48 -0
- package/src/commons/ActionGroup/OnOffSmartLock/PasscodeList/ItemPasscodeStyles.js +42 -0
- package/src/commons/ActionGroup/OnOffSmartLock/PasscodeList/PasscodeListStyles.js +49 -0
- package/src/commons/ActionGroup/OnOffSmartLock/PasscodeList/index.js +66 -0
- package/src/commons/ActionGroup/OnOffSmartLock/SetupGeneratePasscode/ButtonWrapper.js +96 -0
- package/src/commons/ActionGroup/OnOffSmartLock/SetupGeneratePasscode/SetupGeneratePasscodeStyles.js +98 -0
- package/src/commons/ActionGroup/OnOffSmartLock/SetupGeneratePasscode/__test__/index.test.js +62 -0
- package/src/commons/ActionGroup/OnOffSmartLock/SetupGeneratePasscode/index.js +249 -0
- package/src/commons/ActionGroup/OnOffTemplate/index.js +4 -2
- package/src/commons/ActionGroup/OptionsDropdownActionTemplate.js +2 -1
- package/src/commons/ActionGroup/SliderRangeTemplate.js +64 -0
- package/src/commons/ActionGroup/{LightActionTemplateStyles.js → SliderRangeTemplateStyles.js} +0 -8
- package/src/commons/ActionGroup/SmartTiviActionTemplate/SmartTiviActionTemplate.js +167 -186
- package/src/commons/ActionGroup/StatesGridActionTemplate.js +2 -1
- package/src/commons/ActionGroup/index.js +7 -4
- package/src/commons/BottomSheet/index.js +2 -1
- package/src/commons/Device/DisconnectedView.js +7 -1
- package/src/commons/Device/Hanet/ItemHanetDevice.js +109 -0
- package/src/commons/Device/HistoryChart.js +2 -2
- package/src/commons/Device/HorizontalBarChart.js +7 -0
- package/src/commons/Device/ItemDevice.js +18 -15
- package/src/commons/Device/LinearChart.js +14 -41
- package/src/commons/Device/__test__/DisconnectedView.test.js +13 -2
- package/src/commons/RowItem/index.js +12 -7
- package/src/commons/SubUnit/Favorites/index.js +2 -2
- package/src/commons/SubUnit/ShortDetail.js +39 -20
- package/src/commons/WheelDateTimePicker/index.js +18 -4
- package/src/configs/API.js +23 -1
- package/src/configs/Colors.js +1 -0
- package/src/configs/Constants.js +48 -0
- package/src/configs/SCConfig.js +1 -1
- package/src/context/actionType.ts +4 -0
- package/src/context/mockStore.ts +3 -0
- package/src/context/reducer.ts +20 -0
- package/src/iot/RemoteControl/Bluetooth.js +3 -22
- package/src/iot/RemoteControl/index.js +0 -1
- package/src/navigations/HanetCameraStack.js +41 -0
- package/src/navigations/SmartIrStack.js +31 -0
- package/src/navigations/SmartLockStack.js +51 -0
- package/src/navigations/UnitStack.js +46 -4
- package/src/screens/ActivityLog/hooks/index.js +1 -1
- package/src/screens/AddCommon/__test__/SelectSubUnit.test.js +1 -1
- package/src/screens/AddNewGateway/PlugAndPlay/ConnectWifiWarning.js +79 -72
- package/src/screens/AddNewGateway/PlugAndPlay/GatewayWifiList.js +155 -27
- package/src/screens/AddNewGateway/PlugAndPlay/__test__/ConnectWifiWarning.test.js +65 -0
- package/src/screens/AddNewGateway/PlugAndPlay/__test__/GatewayWifiList.test.js +26 -2
- package/src/screens/Device/__test__/detail.test.js +0 -10
- package/src/screens/Device/components/SensorConnectStatusViewHeader.js +13 -2
- package/src/screens/Device/detail.js +118 -38
- package/src/screens/Device/hooks/useDisconnectedDevice.js +28 -16
- package/src/screens/GuestInfo/components/AccessScheduleItem.js +9 -2
- package/src/screens/GuestInfo/components/RecurringDetail.js +3 -2
- package/src/screens/GuestInfo/components/TemporaryDetail.js +3 -2
- package/src/screens/GuestInfo/styles/AccessScheduleItemStyles.js +3 -0
- package/src/screens/HanetCamera/CaptureFaceID.js +210 -0
- package/src/screens/HanetCamera/Detail.js +252 -0
- package/src/screens/HanetCamera/ManageAccess.js +173 -0
- package/src/screens/HanetCamera/MemberInfo.js +208 -0
- package/src/screens/HanetCamera/__test__/CaptureFaceID.test.js +133 -0
- package/src/screens/HanetCamera/__test__/Detail.test.js +185 -0
- package/src/screens/HanetCamera/__test__/ManageAccess.test.js +152 -0
- package/src/screens/HanetCamera/__test__/MemberInfo.test.js +178 -0
- package/src/screens/HanetCamera/components/CheckinHeader.js +37 -0
- package/src/screens/HanetCamera/hooks/__test__/useHanetCheckinData.test.js +151 -0
- package/src/screens/HanetCamera/hooks/__test__/useHanetPlaceMembers.test.js +71 -0
- package/src/screens/HanetCamera/hooks/index.js +5 -0
- package/src/screens/HanetCamera/hooks/useHanetCheckinData.js +116 -0
- package/src/screens/HanetCamera/hooks/useHanetPlaceMembers.js +86 -0
- package/src/screens/HanetCamera/hooks/useStateAlertAction.js +62 -0
- package/src/screens/HanetCamera/styles/captureFaceIDStyles.js +50 -0
- package/src/screens/HanetCamera/styles/checkinHeaderStyles.js +24 -0
- package/src/screens/HanetCamera/styles/detailStyles.js +107 -0
- package/src/screens/HanetCamera/styles/manageAccessStyles.js +49 -0
- package/src/screens/HanetCamera/styles/memberInfoStyles.js +73 -0
- package/src/screens/HanetCamera/utils/Monitor.js +52 -0
- package/src/screens/Notification/__test__/NotificationItem.test.js +1 -0
- package/src/screens/Notification/components/NotificationItem.js +16 -0
- package/src/screens/SmartIr/__test__/ButtonsBottom.test.js +31 -0
- package/src/screens/SmartIr/__test__/GroupButtonByType.test.js +80 -0
- package/src/screens/SmartIr/__test__/SelectBrand.test.js +65 -0
- package/src/screens/SmartIr/__test__/SelectDeviceType.test.js +57 -0
- package/src/screens/SmartIr/__test__/SmartIr.test.js +1 -0
- package/src/screens/SmartIr/components/GroupButtonByType/ButtonsBottom.js +45 -0
- package/src/screens/SmartIr/components/GroupButtonByType/ButtonsBottomStyles.js +31 -0
- package/src/screens/SmartIr/components/GroupButtonByType/GroupButtonByType.js +208 -0
- package/src/screens/SmartIr/components/GroupButtonByType/GroupButtonByTypeStyles.js +113 -0
- package/src/screens/SmartIr/components/SelectBrand.js +61 -0
- package/src/screens/SmartIr/components/SelectBrandStyles.js +14 -0
- package/src/screens/SmartIr/components/SelectDeviceType.js +96 -0
- package/src/screens/SmartIr/components/SelectDeviceTypeStyles.js +30 -0
- package/src/screens/SmartIr/index.js +8 -3
- package/src/screens/Unit/Detail.js +7 -11
- package/src/screens/Unit/__test__/Detail.test.js +0 -10
- package/src/screens/Unit/components/MyUnitDevice/index.js +2 -4
- package/src/screens/Unit/components/__test__/MyUnitDevice.test.js +38 -9
- package/src/utils/I18n/translations/en.json +51 -1
- package/src/utils/I18n/translations/vi.json +51 -1
- package/src/utils/Route/index.js +14 -1
- package/src/commons/ActionGroup/LightActionTemplate.js +0 -103
- package/src/commons/ActionGroup/__test__/LightActionTemplate.test.js +0 -59
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import React, { memo } from 'react';
|
|
1
|
+
import React, { memo, useContext, useEffect } from 'react';
|
|
2
2
|
import { View, StyleSheet } from 'react-native';
|
|
3
3
|
import { IconOutline } from '@ant-design/icons-react-native';
|
|
4
4
|
import { createStackNavigator } from '@react-navigation/stack';
|
|
5
|
+
import { BleManager } from 'react-native-ble-plx';
|
|
6
|
+
import NetInfo from '@react-native-community/netinfo';
|
|
5
7
|
import { get } from 'lodash';
|
|
6
8
|
|
|
7
9
|
import Text from '../commons/Text';
|
|
@@ -10,6 +12,8 @@ import { Colors, Device } from '../configs';
|
|
|
10
12
|
import Route from '../utils/Route';
|
|
11
13
|
import ActivityLogScreen from '../screens/ActivityLog';
|
|
12
14
|
import { screenOptions } from './utils';
|
|
15
|
+
import { SCContext } from '../context';
|
|
16
|
+
import { Action } from '../context/actionType';
|
|
13
17
|
|
|
14
18
|
import AQIGuide from '../screens/AQIGuide';
|
|
15
19
|
import DeviceDetail from '../screens/Device/detail';
|
|
@@ -45,11 +49,33 @@ import SetUpSensor from '../screens/AddNewAction/SetupSensor';
|
|
|
45
49
|
import EditDevice from '../screens/Device/EditDevice/index';
|
|
46
50
|
import EmergencySetting from '../screens/EmergencySetting';
|
|
47
51
|
import ConfirmUnitDeletion from '../screens/ConfirmUnitDeletion';
|
|
52
|
+
import { HanetCameraStack } from './HanetCameraStack';
|
|
48
53
|
|
|
49
54
|
const Stack = createStackNavigator();
|
|
50
55
|
|
|
56
|
+
const bleManager = new BleManager();
|
|
57
|
+
|
|
51
58
|
export const UnitStack = memo((props) => {
|
|
52
59
|
const t = useTranslations();
|
|
60
|
+
const { setAction } = useContext(SCContext);
|
|
61
|
+
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
const unsubscribe = NetInfo.addEventListener((state) => {
|
|
64
|
+
setAction(Action.SET_NETWORK_CONNECTED, state.isConnected);
|
|
65
|
+
});
|
|
66
|
+
return () => unsubscribe();
|
|
67
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
68
|
+
}, []);
|
|
69
|
+
|
|
70
|
+
useEffect(() => {
|
|
71
|
+
const subscription = bleManager.onStateChange((state) => {
|
|
72
|
+
setAction(Action.SET_BLUETOOTH_STATE, state === 'PoweredOn');
|
|
73
|
+
}, true);
|
|
74
|
+
|
|
75
|
+
return () => subscription.remove();
|
|
76
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
77
|
+
}, []);
|
|
78
|
+
|
|
53
79
|
return (
|
|
54
80
|
<Stack.Navigator
|
|
55
81
|
screenOptions={{
|
|
@@ -117,12 +143,16 @@ export const UnitStack = memo((props) => {
|
|
|
117
143
|
component={ChooseLocation}
|
|
118
144
|
options={{
|
|
119
145
|
headerShown: true,
|
|
146
|
+
headerTitleStyle: {
|
|
147
|
+
...styles.headerLocation,
|
|
148
|
+
},
|
|
120
149
|
headerTitle: () => (
|
|
121
|
-
<View style={styles.
|
|
150
|
+
<View style={styles.headerLocation}>
|
|
122
151
|
<Text type="H3" color={Colors.Gray9} bold>
|
|
123
152
|
{t('choose_on_map')}
|
|
124
153
|
</Text>
|
|
125
|
-
|
|
154
|
+
|
|
155
|
+
<Text type="H4" color={Colors.Gray8} style={styles.headerContent}>
|
|
126
156
|
{t('plan_and_zoom_to_adjust')}
|
|
127
157
|
</Text>
|
|
128
158
|
</View>
|
|
@@ -162,6 +192,13 @@ export const UnitStack = memo((props) => {
|
|
|
162
192
|
headerShown: false,
|
|
163
193
|
}}
|
|
164
194
|
/>
|
|
195
|
+
<Stack.Screen
|
|
196
|
+
name={Route.HanetCameraStack}
|
|
197
|
+
component={HanetCameraStack}
|
|
198
|
+
options={{
|
|
199
|
+
headerShown: false,
|
|
200
|
+
}}
|
|
201
|
+
/>
|
|
165
202
|
<Stack.Screen
|
|
166
203
|
name={Route.UVIndexGuide}
|
|
167
204
|
component={UVIndexGuide}
|
|
@@ -323,7 +360,12 @@ const styles = StyleSheet.create({
|
|
|
323
360
|
icLeft: {
|
|
324
361
|
marginLeft: Device.isIOS ? 8 : 0,
|
|
325
362
|
},
|
|
326
|
-
|
|
363
|
+
headerLocation: {
|
|
327
364
|
alignItems: 'center',
|
|
365
|
+
justifyContent: 'center',
|
|
366
|
+
},
|
|
367
|
+
headerContent: {
|
|
368
|
+
textAlign: 'center',
|
|
369
|
+
paddingBottom: 8,
|
|
328
370
|
},
|
|
329
371
|
});
|
|
@@ -93,9 +93,9 @@ export default ({ id, type, share, filterEnabled }) => {
|
|
|
93
93
|
setData(api.standardizeData(results));
|
|
94
94
|
} else {
|
|
95
95
|
dataTemp = dataTemp.concat(results);
|
|
96
|
-
setIsCanLoadMore(page < Math.ceil(data.count / 20));
|
|
97
96
|
setData(api.standardizeData(dataTemp));
|
|
98
97
|
}
|
|
98
|
+
setIsCanLoadMore(page < Math.ceil(data.count / 20));
|
|
99
99
|
}
|
|
100
100
|
page === 1 ? setIsRefreshing(false) : setIsLoading(false);
|
|
101
101
|
};
|
|
@@ -152,7 +152,7 @@ describe('Test SelectSubUnit container', () => {
|
|
|
152
152
|
case 'AddVconnexDevice':
|
|
153
153
|
expect(mockedNavigate).toBeCalledWith('Browser', {
|
|
154
154
|
// eslint-disable-next-line max-len
|
|
155
|
-
link: 'https://partner-api
|
|
155
|
+
link: 'https://partner-api.vconnex.vn/oauth/authorize?client_id=&redirect_uri=&response_type=code&scope=SYNCH&scope=CONTROL&scope=QUERY&state=undefined@undefined@undefined',
|
|
156
156
|
});
|
|
157
157
|
break;
|
|
158
158
|
case 'AddDeviceNewFlow':
|
|
@@ -27,6 +27,15 @@ import Routes from '../../../utils/Route';
|
|
|
27
27
|
import { SCContext } from '../../../context';
|
|
28
28
|
import { Action } from '../../../context/actionType';
|
|
29
29
|
|
|
30
|
+
const isIos = Platform.OS === 'ios';
|
|
31
|
+
const isAndroid = Platform.OS === 'android';
|
|
32
|
+
|
|
33
|
+
let socket = null;
|
|
34
|
+
if (isIos) {
|
|
35
|
+
socket = dgram.createSocket({ type: 'udp4' });
|
|
36
|
+
socket.bind(54321);
|
|
37
|
+
}
|
|
38
|
+
|
|
30
39
|
const ConnectWifiWarning = memo(({ route }) => {
|
|
31
40
|
const {
|
|
32
41
|
wifi_ssid,
|
|
@@ -60,81 +69,79 @@ const ConnectWifiWarning = memo(({ route }) => {
|
|
|
60
69
|
}, [t]);
|
|
61
70
|
|
|
62
71
|
useEffect(() => {
|
|
63
|
-
|
|
72
|
+
isAndroid && getPermissionWifiAndroid();
|
|
64
73
|
}, [getPermissionWifiAndroid]);
|
|
65
74
|
|
|
66
|
-
const handleSend = () => {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
list_wifi: data.wifi,
|
|
84
|
-
unit_id: unit_id,
|
|
85
|
-
chip_id: chip_id,
|
|
86
|
-
socket: socket,
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
socket.on('message', (msg, rinfo) => {
|
|
91
|
-
const data = JSON.parse(msg.toString());
|
|
92
|
-
if (data.hasOwnProperty('gateway')) {
|
|
93
|
-
const checkWifiInterval = setInterval(() => {
|
|
94
|
-
// eslint-disable-next-line promise/prefer-await-to-then
|
|
95
|
-
WifiManager.getCurrentWifiSSID().then(async (ssid) => {
|
|
96
|
-
if (ssid !== wifi_ssid) {
|
|
97
|
-
const IsRobot = devicePrefixName === 'ROBOT';
|
|
98
|
-
if (IsRobot) {
|
|
99
|
-
setAction(Action.IS_CONNECT_WIFI_GATEWAY, false);
|
|
100
|
-
navigate(Routes.AddDeviceStack, {
|
|
101
|
-
screen: Routes.AddCommonSelectSubUnit,
|
|
102
|
-
params: {
|
|
103
|
-
scan_sensor_data: { ...body },
|
|
104
|
-
addType: 'AddDeviceNewFlow',
|
|
105
|
-
gateway: data?.gateway,
|
|
106
|
-
unit_id: unit_id,
|
|
107
|
-
devicePrefixName: devicePrefixName,
|
|
108
|
-
wifi_ssid: wifi_ssid,
|
|
109
|
-
wifi_pass: wifi_pass,
|
|
110
|
-
},
|
|
111
|
-
});
|
|
112
|
-
clearInterval(checkWifiInterval);
|
|
113
|
-
} else {
|
|
114
|
-
setAction(Action.IS_CONNECT_WIFI_GATEWAY, false);
|
|
115
|
-
navigate(Routes.AddDeviceStack, {
|
|
116
|
-
screen: Routes.ConnectingProcess,
|
|
117
|
-
params: {
|
|
118
|
-
unit_id: unit_id,
|
|
119
|
-
unit_name: unit_name,
|
|
120
|
-
scan_sensor_data: { ...body },
|
|
121
|
-
gateway: data?.gateway,
|
|
122
|
-
devicePrefixName: devicePrefixName,
|
|
123
|
-
chip_id: chip_id,
|
|
124
|
-
},
|
|
125
|
-
});
|
|
126
|
-
clearInterval(checkWifiInterval);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
75
|
+
const handleSend = async () => {
|
|
76
|
+
let intervalSend = null;
|
|
77
|
+
if (isIos) {
|
|
78
|
+
await socket.on('message', (msg, rinfo) => {
|
|
79
|
+
clearInterval(intervalSend);
|
|
80
|
+
const data = JSON.parse(msg.toString());
|
|
81
|
+
if (data.hasOwnProperty('wifi')) {
|
|
82
|
+
navigate(Routes.GatewayWifiList, {
|
|
83
|
+
list_wifi: data.wifi,
|
|
84
|
+
unit_id: unit_id,
|
|
85
|
+
chip_id: chip_id,
|
|
86
|
+
scan_sensor_data: { ...body },
|
|
87
|
+
wifi_ssid: wifi_ssid,
|
|
88
|
+
wifi_pass: wifi_pass,
|
|
89
|
+
unit_name: unit_name,
|
|
90
|
+
devicePrefixName: devicePrefixName,
|
|
91
|
+
socket: socket,
|
|
129
92
|
});
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
intervalSend = setInterval(() => {
|
|
96
|
+
socket.send(
|
|
97
|
+
JSON.stringify({ type: 'scan', data: { wifi: '' } }),
|
|
98
|
+
undefined,
|
|
99
|
+
undefined,
|
|
100
|
+
54321,
|
|
101
|
+
'192.168.27.1',
|
|
102
|
+
undefined
|
|
103
|
+
);
|
|
104
|
+
}, 1000);
|
|
105
|
+
socket.on('error', () => {
|
|
106
|
+
ToastBottomHelper.error(t('server_error'));
|
|
107
|
+
setAction(Action.IS_CONNECT_WIFI_GATEWAY, false);
|
|
108
|
+
goBack();
|
|
109
|
+
});
|
|
110
|
+
} else {
|
|
111
|
+
const socket = dgram.createSocket({ type: 'udp4' });
|
|
112
|
+
await socket.bind(54321);
|
|
113
|
+
await socket.on('message', (msg, rinfo) => {
|
|
114
|
+
const data = JSON.parse(msg.toString());
|
|
115
|
+
if (data.hasOwnProperty('wifi')) {
|
|
116
|
+
navigate(Routes.GatewayWifiList, {
|
|
117
|
+
list_wifi: data.wifi,
|
|
118
|
+
unit_id: unit_id,
|
|
119
|
+
chip_id: chip_id,
|
|
120
|
+
scan_sensor_data: { ...body },
|
|
121
|
+
wifi_ssid: wifi_ssid,
|
|
122
|
+
wifi_pass: wifi_pass,
|
|
123
|
+
unit_name: unit_name,
|
|
124
|
+
devicePrefixName: devicePrefixName,
|
|
125
|
+
socket: socket,
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
await socket.once('listening', async () => {
|
|
130
|
+
await socket.send(
|
|
131
|
+
JSON.stringify({ type: 'scan', data: { wifi: '' } }),
|
|
132
|
+
undefined,
|
|
133
|
+
undefined,
|
|
134
|
+
54321,
|
|
135
|
+
'192.168.27.1',
|
|
136
|
+
undefined
|
|
137
|
+
);
|
|
138
|
+
});
|
|
139
|
+
socket.on('error', () => {
|
|
140
|
+
ToastBottomHelper.error(t('server_error'));
|
|
141
|
+
setAction(Action.IS_CONNECT_WIFI_GATEWAY, false);
|
|
142
|
+
goBack();
|
|
143
|
+
});
|
|
144
|
+
}
|
|
138
145
|
};
|
|
139
146
|
|
|
140
147
|
const handleConnectWifiGateway = async () => {
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
TouchableOpacity,
|
|
12
12
|
ScrollView,
|
|
13
13
|
ActivityIndicator,
|
|
14
|
+
Platform,
|
|
14
15
|
} from 'react-native';
|
|
15
16
|
import { HeaderCustom } from '../../../commons/Header';
|
|
16
17
|
import { Colors } from '../../../configs';
|
|
@@ -21,14 +22,31 @@ import ButtonPopup from '../../../commons/ButtonPopup';
|
|
|
21
22
|
import TextInputPassword from '../../../commons/Form/TextInputPassword';
|
|
22
23
|
import { SCContext, useSCContextSelector } from '../../../context';
|
|
23
24
|
import { Action } from '../../../context/actionType';
|
|
25
|
+
import { ToastBottomHelper } from '../../../utils/Utils';
|
|
26
|
+
import Routes from '../../../utils/Route';
|
|
27
|
+
import WifiManager from 'react-native-wifi-reborn';
|
|
28
|
+
import { useNavigation } from '@react-navigation/native';
|
|
29
|
+
|
|
30
|
+
const isIos = Platform.OS === 'ios';
|
|
24
31
|
|
|
25
32
|
const GatewayWifiList = memo(({ route }) => {
|
|
26
|
-
const {
|
|
33
|
+
const {
|
|
34
|
+
list_wifi,
|
|
35
|
+
socket,
|
|
36
|
+
unit_name,
|
|
37
|
+
wifi_pass,
|
|
38
|
+
wifi_ssid,
|
|
39
|
+
scan_sensor_data,
|
|
40
|
+
unit_id,
|
|
41
|
+
chip_id,
|
|
42
|
+
devicePrefixName,
|
|
43
|
+
} = route.params;
|
|
27
44
|
const t = useTranslations();
|
|
28
|
-
|
|
45
|
+
const { navigate, goBack } = useNavigation();
|
|
29
46
|
const [isShowPopupPassword, setIsShowPopupPassword] = useState(false);
|
|
30
47
|
const [password, setPassword] = useState('');
|
|
31
48
|
const [selectedWifi, setSelectedWifi] = useState('');
|
|
49
|
+
const [isSendWifi, setIsSendWifi] = useState(false);
|
|
32
50
|
const { setAction } = useContext(SCContext);
|
|
33
51
|
|
|
34
52
|
const isConnectWifiGateway = useSCContextSelector(
|
|
@@ -42,31 +60,150 @@ const GatewayWifiList = memo(({ route }) => {
|
|
|
42
60
|
|
|
43
61
|
const onPasswordChange = useCallback(
|
|
44
62
|
(password) => {
|
|
45
|
-
setPassword(password
|
|
63
|
+
setPassword(password?.toString());
|
|
46
64
|
},
|
|
47
65
|
[setPassword]
|
|
48
66
|
);
|
|
67
|
+
|
|
68
|
+
const handleSocketOnMsg = useCallback(
|
|
69
|
+
(msg) => {
|
|
70
|
+
const data = JSON.parse(msg.toString());
|
|
71
|
+
if (data.hasOwnProperty('gateway')) {
|
|
72
|
+
const checkWifiInterval = setInterval(() => {
|
|
73
|
+
// eslint-disable-next-line promise/prefer-await-to-then
|
|
74
|
+
WifiManager.getCurrentWifiSSID().then((ssid) => {
|
|
75
|
+
if (ssid !== wifi_ssid) {
|
|
76
|
+
const IsRobot = devicePrefixName === 'ROBOT';
|
|
77
|
+
if (IsRobot) {
|
|
78
|
+
setAction(Action.IS_CONNECT_WIFI_GATEWAY, false);
|
|
79
|
+
navigate(Routes.AddDeviceStack, {
|
|
80
|
+
screen: Routes.AddCommonSelectSubUnit,
|
|
81
|
+
params: {
|
|
82
|
+
scan_sensor_data: scan_sensor_data,
|
|
83
|
+
addType: 'AddDeviceNewFlow',
|
|
84
|
+
gateway: data?.gateway,
|
|
85
|
+
unit_id: unit_id,
|
|
86
|
+
devicePrefixName: devicePrefixName,
|
|
87
|
+
wifi_ssid: wifi_ssid,
|
|
88
|
+
wifi_pass: wifi_pass,
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
clearInterval(checkWifiInterval);
|
|
92
|
+
} else {
|
|
93
|
+
setAction(Action.IS_CONNECT_WIFI_GATEWAY, false);
|
|
94
|
+
navigate(Routes.AddDeviceStack, {
|
|
95
|
+
screen: Routes.ConnectingProcess,
|
|
96
|
+
params: {
|
|
97
|
+
unit_id: unit_id,
|
|
98
|
+
unit_name: unit_name,
|
|
99
|
+
scan_sensor_data: scan_sensor_data,
|
|
100
|
+
gateway: data?.gateway,
|
|
101
|
+
devicePrefixName: devicePrefixName,
|
|
102
|
+
chip_id: chip_id,
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
clearInterval(checkWifiInterval);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
}, 3000);
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
[
|
|
113
|
+
chip_id,
|
|
114
|
+
devicePrefixName,
|
|
115
|
+
navigate,
|
|
116
|
+
scan_sensor_data,
|
|
117
|
+
setAction,
|
|
118
|
+
unit_id,
|
|
119
|
+
unit_name,
|
|
120
|
+
wifi_pass,
|
|
121
|
+
wifi_ssid,
|
|
122
|
+
]
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
const sendConnect = useCallback(
|
|
126
|
+
(i) => {
|
|
127
|
+
setTimeout(async () => {
|
|
128
|
+
i++;
|
|
129
|
+
await socket.on('message', (msg, rinfo) => {
|
|
130
|
+
handleSocketOnMsg(msg);
|
|
131
|
+
});
|
|
132
|
+
socket.send(
|
|
133
|
+
JSON.stringify({
|
|
134
|
+
type: 'connect',
|
|
135
|
+
data: { wifi: { ssid: selectedWifi, pass: password } },
|
|
136
|
+
}),
|
|
137
|
+
undefined,
|
|
138
|
+
undefined,
|
|
139
|
+
54321,
|
|
140
|
+
'192.168.27.1',
|
|
141
|
+
undefined
|
|
142
|
+
);
|
|
143
|
+
if (i < 3) {
|
|
144
|
+
sendConnect(i);
|
|
145
|
+
}
|
|
146
|
+
}, 1000);
|
|
147
|
+
},
|
|
148
|
+
[handleSocketOnMsg, password, selectedWifi, socket]
|
|
149
|
+
);
|
|
150
|
+
|
|
49
151
|
const connectWifi = useCallback(async () => {
|
|
50
152
|
if (!isConnectWifiGateway) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
153
|
+
if (isIos) {
|
|
154
|
+
sendConnect(0);
|
|
155
|
+
setAction(Action.IS_CONNECT_WIFI_GATEWAY, true);
|
|
156
|
+
setIsSendWifi(true);
|
|
157
|
+
} else {
|
|
158
|
+
socket.on('message', (msg, rinfo) => {
|
|
159
|
+
handleSocketOnMsg(msg);
|
|
160
|
+
});
|
|
161
|
+
socket.send(
|
|
162
|
+
JSON.stringify({
|
|
163
|
+
type: 'connect',
|
|
164
|
+
data: { wifi: { ssid: selectedWifi, pass: password } },
|
|
165
|
+
}),
|
|
166
|
+
undefined,
|
|
167
|
+
undefined,
|
|
168
|
+
54321,
|
|
169
|
+
'192.168.27.1',
|
|
170
|
+
undefined
|
|
171
|
+
);
|
|
172
|
+
socket.on('error', () => {
|
|
173
|
+
ToastBottomHelper.error(t('server_error'));
|
|
174
|
+
setAction(Action.IS_CONNECT_WIFI_GATEWAY, false);
|
|
175
|
+
goBack();
|
|
176
|
+
});
|
|
177
|
+
setAction(Action.IS_CONNECT_WIFI_GATEWAY, true);
|
|
178
|
+
setIsSendWifi(true);
|
|
179
|
+
}
|
|
63
180
|
}
|
|
64
|
-
}, [
|
|
181
|
+
}, [
|
|
182
|
+
goBack,
|
|
183
|
+
handleSocketOnMsg,
|
|
184
|
+
isConnectWifiGateway,
|
|
185
|
+
password,
|
|
186
|
+
selectedWifi,
|
|
187
|
+
sendConnect,
|
|
188
|
+
setAction,
|
|
189
|
+
socket,
|
|
190
|
+
t,
|
|
191
|
+
]);
|
|
192
|
+
|
|
65
193
|
useEffect(() => {
|
|
66
194
|
if (!isConnectWifiGateway) {
|
|
67
195
|
setIsShowPopupPassword(false);
|
|
68
196
|
}
|
|
69
197
|
}, [isConnectWifiGateway]);
|
|
198
|
+
|
|
199
|
+
const onCloseModal = useCallback(() => {
|
|
200
|
+
if (isSendWifi) {
|
|
201
|
+
setAction(Action.IS_CONNECT_WIFI_GATEWAY, false);
|
|
202
|
+
setIsShowPopupPassword(false);
|
|
203
|
+
setIsSendWifi(false);
|
|
204
|
+
}
|
|
205
|
+
}, [isSendWifi, setAction]);
|
|
206
|
+
|
|
70
207
|
return (
|
|
71
208
|
<View style={styles.screen}>
|
|
72
209
|
<HeaderCustom title={t('connect_device')} isShowSeparator />
|
|
@@ -110,7 +247,8 @@ const GatewayWifiList = memo(({ route }) => {
|
|
|
110
247
|
secondaryTitle={t('cancel')}
|
|
111
248
|
typeSecondary={isConnectWifiGateway ? 'disabled' : 'cancel'}
|
|
112
249
|
onPressSecondary={() => setIsShowPopupPassword(false)}
|
|
113
|
-
hideClose
|
|
250
|
+
hideClose
|
|
251
|
+
onClose={isSendWifi ? onCloseModal : () => <></>}
|
|
114
252
|
>
|
|
115
253
|
<>
|
|
116
254
|
<Text>{t('enter_wifi_password')}</Text>
|
|
@@ -160,16 +298,6 @@ const styles = StyleSheet.create({
|
|
|
160
298
|
paddingVertical: 16,
|
|
161
299
|
paddingLeft: 16,
|
|
162
300
|
},
|
|
163
|
-
firstItem: {
|
|
164
|
-
paddingTop: 32,
|
|
165
|
-
paddingBottom: 16,
|
|
166
|
-
paddingLeft: 16,
|
|
167
|
-
},
|
|
168
|
-
lastItem: {
|
|
169
|
-
paddingBottom: 32,
|
|
170
|
-
paddingTop: 16,
|
|
171
|
-
paddingLeft: 16,
|
|
172
|
-
},
|
|
173
301
|
wifiIcon: {
|
|
174
302
|
paddingRight: 16,
|
|
175
303
|
},
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { act, create } from 'react-test-renderer';
|
|
3
|
+
|
|
4
|
+
import ConnectWifiWarning from '../ConnectWifiWarning';
|
|
5
|
+
import { SCProvider } from '../../../../context';
|
|
6
|
+
import { mockSCStore } from '../../../../context/mockStore';
|
|
7
|
+
import { HeaderCustom } from '../../../../commons/Header';
|
|
8
|
+
|
|
9
|
+
const mockedGoBack = jest.fn();
|
|
10
|
+
const mockedNavigate = jest.fn();
|
|
11
|
+
const mockSetState = jest.fn();
|
|
12
|
+
jest.mock('react', () => {
|
|
13
|
+
return {
|
|
14
|
+
...jest.requireActual('react'),
|
|
15
|
+
memo: (x) => x,
|
|
16
|
+
useState: jest.fn((init) => [init, mockSetState]),
|
|
17
|
+
};
|
|
18
|
+
});
|
|
19
|
+
jest.mock('react-native-udp', () => {
|
|
20
|
+
return {
|
|
21
|
+
createSocket: () => ({
|
|
22
|
+
bind: jest.fn(),
|
|
23
|
+
}),
|
|
24
|
+
};
|
|
25
|
+
});
|
|
26
|
+
jest.mock('@react-navigation/native', () => {
|
|
27
|
+
return {
|
|
28
|
+
...jest.requireActual('@react-navigation/native'),
|
|
29
|
+
useNavigation: () => ({
|
|
30
|
+
navigate: mockedNavigate,
|
|
31
|
+
goBack: mockedGoBack,
|
|
32
|
+
}),
|
|
33
|
+
useIsFocused: () => ({}),
|
|
34
|
+
};
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const wrapComponent = (route) => (
|
|
38
|
+
<SCProvider initState={mockSCStore({})}>
|
|
39
|
+
<ConnectWifiWarning route={route} />
|
|
40
|
+
</SCProvider>
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
describe('Test ConnectWifiWarning', () => {
|
|
44
|
+
let tree;
|
|
45
|
+
let route = {
|
|
46
|
+
params: {
|
|
47
|
+
wifi_ssid: 1,
|
|
48
|
+
wifi_pass: 'abc',
|
|
49
|
+
unit_id: 1,
|
|
50
|
+
chip_id: 1,
|
|
51
|
+
devicePrefixName: 'robot',
|
|
52
|
+
body: { wifi_ssid: 1 },
|
|
53
|
+
unit_name: 'abc',
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
test('create ConnectWifiWarning', async () => {
|
|
58
|
+
await act(async () => {
|
|
59
|
+
tree = await create(wrapComponent(route));
|
|
60
|
+
});
|
|
61
|
+
const instance = tree.root;
|
|
62
|
+
const headerCustom = instance.findAllByType(HeaderCustom);
|
|
63
|
+
expect(headerCustom).toHaveLength(1);
|
|
64
|
+
});
|
|
65
|
+
});
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { act, create } from 'react-test-renderer';
|
|
3
|
-
|
|
4
3
|
import GatewayWifiList from '../GatewayWifiList';
|
|
5
|
-
import { Text } from 'react-native';
|
|
4
|
+
import { Text, ScrollView, TouchableOpacity } from 'react-native';
|
|
6
5
|
import { getTranslate } from '../../../../utils/I18n';
|
|
7
6
|
import { SCProvider } from '../../../../context';
|
|
8
7
|
import { mockSCStore } from '../../../../context/mockStore';
|
|
8
|
+
import TextInputPassword from '../../../../commons/Form/TextInputPassword';
|
|
9
9
|
|
|
10
10
|
const wrapComponent = (route) => (
|
|
11
11
|
<SCProvider initState={mockSCStore({})}>
|
|
@@ -32,4 +32,28 @@ describe('Test GatewayWifiList', () => {
|
|
|
32
32
|
expect(texts[1].props.children).toEqual(getTranslate('en', 'set_network'));
|
|
33
33
|
expect(texts[3].props.children).toEqual('eoh@io');
|
|
34
34
|
});
|
|
35
|
+
test('onPress wifi', async () => {
|
|
36
|
+
await act(async () => {
|
|
37
|
+
tree = await create(wrapComponent(route));
|
|
38
|
+
});
|
|
39
|
+
const instance = tree.root;
|
|
40
|
+
const scrollView = instance.findAllByType(ScrollView);
|
|
41
|
+
expect(scrollView).toHaveLength(1);
|
|
42
|
+
const touchableOpacity = instance.findAllByType(TouchableOpacity);
|
|
43
|
+
expect(touchableOpacity).toHaveLength(6);
|
|
44
|
+
await act(async () => {
|
|
45
|
+
await touchableOpacity[1].props.onPress();
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
test('onChange TextInputPassword', async () => {
|
|
49
|
+
await act(async () => {
|
|
50
|
+
tree = await create(wrapComponent(route));
|
|
51
|
+
});
|
|
52
|
+
const instance = tree.root;
|
|
53
|
+
const textInputPassword = instance.findAllByType(TextInputPassword);
|
|
54
|
+
expect(textInputPassword).toHaveLength(1);
|
|
55
|
+
await act(async () => {
|
|
56
|
+
await textInputPassword[0].props.onChange();
|
|
57
|
+
});
|
|
58
|
+
});
|
|
35
59
|
});
|
|
@@ -43,16 +43,6 @@ jest.mock('react-redux', () => {
|
|
|
43
43
|
};
|
|
44
44
|
});
|
|
45
45
|
|
|
46
|
-
jest.mock('@react-native-community/netinfo', () => {
|
|
47
|
-
return {
|
|
48
|
-
useNetInfo: () => {
|
|
49
|
-
return {
|
|
50
|
-
isConnected: true,
|
|
51
|
-
};
|
|
52
|
-
},
|
|
53
|
-
};
|
|
54
|
-
});
|
|
55
|
-
|
|
56
46
|
jest.mock('react', () => ({
|
|
57
47
|
...jest.requireActual('react'),
|
|
58
48
|
useLayoutEffect: jest.fn(),
|
|
@@ -28,7 +28,12 @@ export const SensorConnectStatusViewHeader = (props) => {
|
|
|
28
28
|
</>
|
|
29
29
|
);
|
|
30
30
|
} else {
|
|
31
|
-
return
|
|
31
|
+
return (
|
|
32
|
+
<DisconnectedView
|
|
33
|
+
sensor={props.sensor}
|
|
34
|
+
isDeviceHasBle={props.isDeviceHasBle}
|
|
35
|
+
/>
|
|
36
|
+
);
|
|
32
37
|
}
|
|
33
38
|
} else {
|
|
34
39
|
if (props.sensor?.device_type === DEVICE_TYPE.LG_THINQ) {
|
|
@@ -50,7 +55,13 @@ export const SensorConnectStatusViewHeader = (props) => {
|
|
|
50
55
|
</>
|
|
51
56
|
);
|
|
52
57
|
} else {
|
|
53
|
-
return
|
|
58
|
+
return (
|
|
59
|
+
<DisconnectedView
|
|
60
|
+
sensor={props.sensor}
|
|
61
|
+
type={'GoogleHome'}
|
|
62
|
+
isDeviceHasBle={props.isDeviceHasBle}
|
|
63
|
+
/>
|
|
64
|
+
);
|
|
54
65
|
}
|
|
55
66
|
}
|
|
56
67
|
}
|