@eohjsc/react-native-smart-city 0.3.48 → 0.3.50

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.
Files changed (196) hide show
  1. package/package.json +4 -4
  2. package/src/Images/DevMode/file_copy.svg +3 -0
  3. package/src/Images/DevMode/inforCode.png +0 -0
  4. package/src/Images/DevMode/inforCode@2x.png +0 -0
  5. package/src/Images/DevMode/inforCode@3x.png +0 -0
  6. package/src/commons/Action/__test__/ItemQuickAction.test.js +0 -7
  7. package/src/commons/ActionGroup/OnOffTemplate/index.js +6 -8
  8. package/src/commons/ActionGroup/SliderRangeTemplate.js +7 -2
  9. package/src/commons/ActionGroup/__test__/ColorPickerTemplate.test.js +1 -8
  10. package/src/commons/ActionGroup/__test__/OnOffTemplate.test.js +99 -1
  11. package/src/commons/ActionGroup/__test__/SliderRangeTemplate.test.js +28 -11
  12. package/src/commons/ActionTemplate/__test__/CurtainAction.test.js +64 -0
  13. package/src/commons/ActionTemplate/__test__/OnOffSmartLockAction.test.js +54 -0
  14. package/src/commons/ActionTemplate/__test__/index.test.js +0 -7
  15. package/src/commons/Dashboard/MyPinnedSharedUnit/index.js +3 -3
  16. package/src/commons/Dashboard/MyUnit/__test__/MyUnit.test.js +1 -1
  17. package/src/commons/Dashboard/MyUnit/index.js +30 -4
  18. package/src/commons/DevMode/Styles/ItemStyles.js +1 -1
  19. package/src/commons/Device/HorizontalBarChart.js +0 -1
  20. package/src/commons/Device/PMSensor/PMSensorIndicatior.js +4 -1
  21. package/src/commons/FourButtonFilterHistory/__test__/FourButtonFilterHistory.test.js +0 -7
  22. package/src/commons/Header/HeaderCustom.js +13 -6
  23. package/src/commons/MediaPlayer/__test__/index.test.js +0 -7
  24. package/src/commons/MediaPlayerDetail/__test__/MediaPlayerFull.test.js +0 -1
  25. package/src/commons/MenuActionMore/index.js +4 -1
  26. package/src/commons/NavBar/index.js +1 -1
  27. package/src/commons/OneTapTemplate/OptionsDropdownActionTemplate.js +1 -1
  28. package/src/commons/OneTapTemplate/__test__/NumberUpDownActionTemplate.test.js +0 -7
  29. package/src/commons/OneTapTemplate/__test__/OptionsDropdownActionTemplate.test.js +0 -7
  30. package/src/commons/OneTapTemplate/__test__/StatesGridActionTemplate.test.js +0 -7
  31. package/src/commons/Processing/styles.js +0 -2
  32. package/src/commons/RowItem/index.js +6 -1
  33. package/src/commons/SelectUnit/index.js +4 -1
  34. package/src/commons/Sharing/WrapHeaderScrollable.js +5 -4
  35. package/src/commons/StatusBox/styles.js +8 -3
  36. package/src/commons/SubUnit/__test__/Favorites.test.js +0 -7
  37. package/src/commons/SubUnit/__test__/ShortDetail.test.js +0 -7
  38. package/src/commons/Tabbar/__test__/index.test.js +0 -7
  39. package/src/commons/Unit/__test__/HeaderUnit.test.js +0 -5
  40. package/src/commons/UnitSummary/ConfigHistoryChart/__test__/ConfigHistoryChart.test.js +9 -9
  41. package/src/commons/UnitSummary/ConfigHistoryChart/index.js +41 -39
  42. package/src/configs/API.js +28 -0
  43. package/src/configs/AccessibilityLabel.js +13 -0
  44. package/src/configs/Colors.js +4 -0
  45. package/src/configs/Constants.js +8 -0
  46. package/src/configs/Images.js +1 -0
  47. package/src/configs/SCConfig.js +3 -0
  48. package/src/context/actionType.ts +8 -1
  49. package/src/context/mockStore.ts +8 -2
  50. package/src/context/reducer.ts +27 -4
  51. package/src/hooks/IoT/__test__/useWatchConfigs.test.js +46 -0
  52. package/src/hooks/IoT/useBluetoothConnection.js +78 -4
  53. package/src/hooks/IoT/useBluetoothDeviceConnected.js +1 -1
  54. package/src/iot/RemoteControl/Bluetooth.js +0 -16
  55. package/src/iot/RemoteControl/__test__/Bluetooth.test.js +0 -25
  56. package/src/navigations/AddDeviceStack.js +0 -5
  57. package/src/navigations/Main.js +39 -0
  58. package/src/navigations/UnitStack.js +23 -9
  59. package/src/screens/AQIGuide/index.js +2 -2
  60. package/src/screens/ActivityLog/__test__/FilterPopup.test.js +0 -7
  61. package/src/screens/ActivityLog/__test__/ItemLog.test.js +0 -7
  62. package/src/screens/ActivityLog/__test__/index.test.js +0 -7
  63. package/src/screens/ActivityLog/styles/itemLogStyles.js +1 -0
  64. package/src/screens/AddLocationMaps/__test__/index.test.js +0 -7
  65. package/src/screens/AddNewAction/SelectAction.js +22 -18
  66. package/src/screens/AddNewAction/__test__/SelectAction.test.js +35 -16
  67. package/src/screens/AddNewAction/__test__/SelectSensorDevices.test.js +0 -7
  68. package/src/screens/AddNewDevice/__test__/AddNewDevice.test.js +1 -5
  69. package/src/screens/AddNewGateway/ConnectingDevice.js +25 -3
  70. package/src/screens/AddNewGateway/ConnectingWifiGuide.js +1 -1
  71. package/src/screens/AddNewGateway/ConnectingWifiGuideStyles.js +10 -0
  72. package/src/screens/AddNewGateway/ConnectingZigbeeDevice.js +5 -6
  73. package/src/screens/AddNewGateway/ShareWifiPassword.js +2 -1
  74. package/src/screens/AddNewGateway/__test__/AddNewGateway.test.js +0 -4
  75. package/src/screens/AddNewGateway/__test__/ConnectingModbusDevice.test.js +0 -4
  76. package/src/screens/AddNewGateway/__test__/ConnectingWifiDevice.test.js +2 -5
  77. package/src/screens/AddNewGateway/__test__/ConnectingZigbeeDevice.test.js +29 -6
  78. package/src/screens/AddNewGateway/__test__/RenameNewDevices.test.js +0 -7
  79. package/src/screens/AddNewGateway/__test__/SelectDeviceType.test.js +0 -4
  80. package/src/screens/AddNewGateway/__test__/SelectModbusGateway.test.js +0 -4
  81. package/src/screens/AddNewGateway/__test__/SelectZigbeeGateway.test.js +0 -4
  82. package/src/screens/AddNewOneTap/__test__/AddNewOneTap.test.js +0 -7
  83. package/src/screens/ConfirmUnitDeletion/__test__/ConfirmUnitDeletion.test.js +0 -1
  84. package/src/screens/Device/EditDevice/__test__/EditDevice.test.js +0 -7
  85. package/src/screens/Device/__test__/detail.test.js +1 -1
  86. package/src/screens/Device/detail.js +12 -6
  87. package/src/screens/Device/hooks/useDisconnectedDevice.js +26 -7
  88. package/src/screens/EmergencyContacts/__test__/hooks.test.js +79 -0
  89. package/src/screens/Gateway/DetailConfigActionModbus/__test__/index.test.js +138 -0
  90. package/src/screens/Gateway/DetailConfigActionModbus/index.js +180 -0
  91. package/src/screens/Gateway/DetailConfigActionModbus/styles.js +9 -0
  92. package/src/screens/Gateway/DetailConfigActionZigbee/__test__/index.test.js +73 -0
  93. package/src/screens/Gateway/DetailConfigActionZigbee/index.js +62 -0
  94. package/src/screens/Gateway/DetailConfigActionZigbee/styles.js +9 -0
  95. package/src/screens/Gateway/DeviceGatewayInfo/__test__/index.test.js +73 -0
  96. package/src/screens/Gateway/DeviceGatewayInfo/index.js +96 -0
  97. package/src/screens/Gateway/DeviceGatewayInfo/styles.js +9 -0
  98. package/src/screens/Gateway/DeviceModbusDetail/__test__/index.test.js +393 -0
  99. package/src/screens/Gateway/DeviceModbusDetail/index.js +176 -0
  100. package/src/screens/Gateway/DeviceModbusDetail/styles.js +12 -0
  101. package/src/screens/Gateway/DeviceZigbeeDetail/__test__/index.test.js +265 -0
  102. package/src/screens/Gateway/DeviceZigbeeDetail/index.js +148 -0
  103. package/src/screens/Gateway/DeviceZigbeeDetail/styles.js +12 -0
  104. package/src/screens/Gateway/GatewayConnectionMethods/__test__/index.test.js +37 -0
  105. package/src/screens/Gateway/GatewayConnectionMethods/index.js +73 -0
  106. package/src/screens/Gateway/GatewayConnectionMethods/styles.js +45 -0
  107. package/src/screens/Gateway/GatewayDetail/__test__/index.test.js +298 -0
  108. package/src/screens/Gateway/GatewayDetail/index.js +148 -0
  109. package/src/screens/Gateway/GatewayDetail/styles.js +12 -0
  110. package/src/screens/Gateway/GatewayInfo/__test__/index.test.js +137 -0
  111. package/src/screens/Gateway/GatewayInfo/index.js +115 -0
  112. package/src/screens/Gateway/GatewayInfo/styles.js +9 -0
  113. package/src/screens/Gateway/__test__/index.test.js +58 -0
  114. package/src/screens/Gateway/components/Detail/__test__/index.test.js +46 -0
  115. package/src/screens/Gateway/components/Detail/index.js +62 -0
  116. package/src/screens/Gateway/components/Detail/styles.js +27 -0
  117. package/src/screens/Gateway/components/DetailActionModbus/__test__/index.test.js +49 -0
  118. package/src/screens/Gateway/components/DetailActionModbus/index.js +52 -0
  119. package/src/screens/Gateway/components/DetailActionModbus/styles.js +32 -0
  120. package/src/screens/Gateway/components/DetailConfigAction/__test__/index.test.js +59 -0
  121. package/src/screens/Gateway/components/DetailConfigAction/index.js +69 -0
  122. package/src/screens/Gateway/components/DetailConfigAction/styles.js +21 -0
  123. package/src/screens/Gateway/components/GatewayItem/__test__/index.test.js +1 -1
  124. package/src/screens/Gateway/components/GatewayItem/styles.js +4 -33
  125. package/src/screens/Gateway/components/Information/__test__/index.test.js +70 -0
  126. package/src/screens/Gateway/components/Information/index.js +116 -0
  127. package/src/screens/Gateway/components/Information/styles.js +59 -0
  128. package/src/screens/Gateway/components/RowItem/__test__/index.test.js +67 -0
  129. package/src/screens/Gateway/components/RowItem/index.js +65 -0
  130. package/src/screens/Gateway/components/RowItem/styles.js +25 -0
  131. package/src/screens/Gateway/components/TabPaneCT/__test__/index.test.js +98 -0
  132. package/src/screens/Gateway/components/TabPaneCT/index.js +134 -0
  133. package/src/screens/Gateway/components/TabPaneCT/styles.js +58 -0
  134. package/src/screens/Gateway/hooks/__test__/index.test.js +93 -0
  135. package/src/screens/Gateway/hooks/useGateway.js +110 -16
  136. package/src/screens/Gateway/index.js +19 -3
  137. package/src/screens/Gateway/styles.js +6 -8
  138. package/src/screens/Gateway/utils/index.js +16 -0
  139. package/src/screens/GuestInfo/__test__/index.test.js +0 -7
  140. package/src/screens/HanetCamera/__test__/CaptureFaceID.test.js +0 -7
  141. package/src/screens/HanetCamera/__test__/Detail.test.js +0 -7
  142. package/src/screens/HanetCamera/__test__/ManageAccess.test.js +0 -7
  143. package/src/screens/HanetCamera/__test__/MemberInfo.test.js +0 -7
  144. package/src/screens/ManageAccess/__test__/ManageAccess.test.js +0 -6
  145. package/src/screens/ManageAccess/hooks/__test__/useManageAccess.test.js +0 -7
  146. package/src/screens/MoveToAnotherSubUnit/__test__/index.test.js +0 -7
  147. package/src/screens/Notification/__test__/Notification.test.js +0 -7
  148. package/src/screens/Notification/__test__/NotificationItem.test.js +1 -0
  149. package/src/screens/Notification/components/NotificationItem.js +16 -1
  150. package/src/screens/Notification/index.js +1 -0
  151. package/src/screens/Notification/styles/indexStyles.js +3 -0
  152. package/src/screens/PlayBackCamera/__test__/index.test.js +0 -1
  153. package/src/screens/ScriptDetail/__test__/index.test.js +0 -7
  154. package/src/screens/SelectUnit/__test__/index.test.js +0 -1
  155. package/src/screens/SetSchedule/__test__/index.test.js +0 -7
  156. package/src/screens/Sharing/Components/__test__/DeviceItem.test.js +0 -7
  157. package/src/screens/Sharing/Components/__test__/ItemChangeRole.test.js +0 -7
  158. package/src/screens/Sharing/Components/__test__/TitleCheckBox.test.js +0 -7
  159. package/src/screens/Sharing/SelectPermission.js +2 -2
  160. package/src/screens/Sharing/__test__/InfoMemberUnit.test.js +0 -6
  161. package/src/screens/Sharing/hooks/__test__/index.test.js +80 -0
  162. package/src/screens/SmartAccount/ListDevice/__test__/DeviceItem.test.js +0 -7
  163. package/src/screens/SmartAccount/SuccessfullyConnected/__test__/SuccessfullyConnected.test.js +26 -7
  164. package/src/screens/SmartAccount/SuccessfullyConnected/index.js +29 -11
  165. package/src/screens/SmartIr/__test__/ButtonsBottom.test.js +0 -6
  166. package/src/screens/SmartIr/__test__/GroupButtonByType.test.js +1 -6
  167. package/src/screens/SmartIr/__test__/SelectBrand.test.js +1 -6
  168. package/src/screens/SmartIr/__test__/SelectDeviceType.test.js +1 -6
  169. package/src/screens/SubUnit/AddSubUnit.js +1 -0
  170. package/src/screens/SubUnit/ManageSubUnit.js +4 -1
  171. package/src/screens/SubUnit/hooks/__test__/useEmergencyContacts.test.js +34 -0
  172. package/src/screens/SubUnit/hooks/__test__/useManageSubUnit.test.js +0 -7
  173. package/src/screens/SyncLGDevice/__test__/AddLGDevice.test.js +1 -8
  174. package/src/screens/Template/__test__/GatewayList.test.js +1 -1
  175. package/src/screens/Template/__test__/Information.test.js +1 -1
  176. package/src/screens/Unit/Detail.js +24 -18
  177. package/src/screens/Unit/__test__/AddMenu.test.js +0 -7
  178. package/src/screens/Unit/__test__/CheckSendEmail.test.js +1 -1
  179. package/src/screens/Unit/__test__/ChooseLocation.test.js +0 -7
  180. package/src/screens/Unit/__test__/Detail.test.js +63 -26
  181. package/src/screens/Unit/__test__/SelectAddToFavorites.test.js +0 -7
  182. package/src/screens/Unit/__test__/SelectAddress.test.js +0 -7
  183. package/src/screens/Unit/__test__/SmartAccount.test.js +0 -7
  184. package/src/screens/Unit/__test__/SmartAccountItem.test.js +0 -7
  185. package/src/screens/Unit/__test__/Summaries.test.js +0 -7
  186. package/src/screens/Unit/hook/useUnitConnectRemoteDevices.js +4 -3
  187. package/src/screens/UnitSummary/components/RunningDevices/__test__/index.test.js +2 -2
  188. package/src/utils/Apis/axios.js +52 -36
  189. package/src/utils/I18n/translations/en.json +32 -0
  190. package/src/utils/I18n/translations/vi.json +33 -1
  191. package/src/utils/Route/index.js +8 -0
  192. package/src/utils/Storage.js +0 -4
  193. package/src/utils/Utils.js +1 -1
  194. package/src/utils/__test__/Utils.test.js +27 -3
  195. package/src/screens/AddNewDevice/ConnectingDevices.js +0 -62
  196. package/src/screens/AddNewDevice/__test__/ConnectingDevices.test.js +0 -110
@@ -23,13 +23,6 @@ jest.mock('@react-navigation/native', () => {
23
23
  };
24
24
  });
25
25
 
26
- jest.mock('react', () => {
27
- return {
28
- ...jest.requireActual('react'),
29
- memo: (x) => x,
30
- };
31
- });
32
-
33
26
  const wrapComponent = (route) => (
34
27
  <SCProvider initState={mockSCStore({})}>
35
28
  <SelectAction route={route} />
@@ -101,7 +94,8 @@ describe('Test SelectAction', () => {
101
94
  const config1 = 1,
102
95
  config2 = 2,
103
96
  config3 = 3,
104
- config4 = 4;
97
+ config4 = 4,
98
+ config5 = 5;
105
99
  const response = {
106
100
  status: 200,
107
101
  success: true,
@@ -152,13 +146,25 @@ describe('Test SelectAction', () => {
152
146
  text_format: '{number} \u00b0C',
153
147
  },
154
148
  },
149
+ {
150
+ title: '',
151
+ template: 'NumberUpDownActionTemplate',
152
+ configuration: {
153
+ config: config4,
154
+ allow_config_store_value: true,
155
+ action: '11111111-6c1a-452d-a1d1-87a314c20528',
156
+ min_value: 12,
157
+ max_value: 20,
158
+ text_format: '{number} \u00b0C',
159
+ },
160
+ },
155
161
  {
156
162
  title: '',
157
163
  template: 'StatesGridActionTemplate',
158
164
  configuration: {
159
165
  options: [
160
166
  {
161
- config: config4,
167
+ config: config5,
162
168
  is_on_value: 1,
163
169
  action: '800ff454-4e2a-4a38-bad6-1bded728193e',
164
170
  allow_config_store_value: true,
@@ -179,7 +185,7 @@ describe('Test SelectAction', () => {
179
185
  const renderActionItem = instance.find(
180
186
  (el) => el.props.accessibilityLabel === AccessibilityLabel.ACTION_ITEM
181
187
  );
182
- expect(renderActionItem.props.data.length).toBe(4);
188
+ expect(renderActionItem.props.data.length).toBe(5);
183
189
 
184
190
  const simpleActionOn = instance.find(
185
191
  (el) =>
@@ -209,22 +215,27 @@ describe('Test SelectAction', () => {
209
215
  await touchOpacity.props.onPress();
210
216
  });
211
217
 
212
- const buttonNumberUp = instance.find(
218
+ const buttonNumberUp = instance.findAll(
213
219
  (item) =>
214
220
  item.props.accessibilityLabel ===
215
221
  AccessibilityLabel.NUMBER_UP_DOWN_ACTION_UP &&
216
222
  item.type === TouchableOpacity
217
223
  );
218
- const buttonSaveNumberAction = instance.find(
224
+ expect(buttonNumberUp).toHaveLength(2);
225
+
226
+ const buttonSaveNumberAction = instance.findAll(
219
227
  (item) =>
220
228
  item.props.accessibilityLabel ===
221
229
  AccessibilityLabel.NUMBER_UP_DOWN_ACTION_DONE &&
222
230
  item.type === TouchableOpacity
223
231
  );
232
+ expect(buttonSaveNumberAction).toHaveLength(2);
224
233
 
225
234
  await act(async () => {
226
- await buttonNumberUp.props.onPress();
227
- await buttonSaveNumberAction.props.onPress();
235
+ await buttonNumberUp[0].props.onPress();
236
+ await buttonNumberUp[1].props.onPress();
237
+ await buttonSaveNumberAction[0].props.onPress();
238
+ await buttonSaveNumberAction[1].props.onPress();
228
239
  });
229
240
 
230
241
  const chooseMode = instance.find(
@@ -234,7 +245,7 @@ describe('Test SelectAction', () => {
234
245
  item.type === TouchableOpacity
235
246
  );
236
247
  await act(async () => {
237
- await chooseMode.props.onPress(response.data[3].configuration.options[0]);
248
+ await chooseMode.props.onPress(response.data[4].configuration.options[0]);
238
249
  });
239
250
 
240
251
  mock.onPost(API.AUTOMATE.ADD_SCRIPT_ACTION(1)).reply(200);
@@ -275,9 +286,17 @@ describe('Test SelectAction', () => {
275
286
  config_value: 29,
276
287
  },
277
288
  },
289
+ {
290
+ action: '11111111-6c1a-452d-a1d1-87a314c20528',
291
+ data: {
292
+ temperature: 28,
293
+ config_id: config4,
294
+ config_value: 28,
295
+ },
296
+ },
278
297
  {
279
298
  action: '800ff454-4e2a-4a38-bad6-1bded728193e',
280
- data: { config_id: config4, config_value: 1 },
299
+ data: { config_id: config5, config_value: 1 },
281
300
  },
282
301
  ],
283
302
  unit: 1,
@@ -32,13 +32,6 @@ jest.mock('@react-navigation/native', () => {
32
32
  };
33
33
  });
34
34
 
35
- jest.mock('react', () => {
36
- return {
37
- ...jest.requireActual('react'),
38
- memo: (x) => x,
39
- };
40
- });
41
-
42
35
  const wrapComponent = (route) => (
43
36
  <SCProvider initState={mockSCStore({})}>
44
37
  <SelectSensorDevices route={route} />
@@ -22,10 +22,6 @@ const wrapComponent = (route) => (
22
22
 
23
23
  const mock = new MockAdapter(api.axiosInstance);
24
24
 
25
- jest.mock('react', () => {
26
- return { ...jest.requireActual('react'), memo: (x) => x };
27
- });
28
-
29
25
  const mockedNavigate = jest.fn();
30
26
  const mockedGoBack = jest.fn();
31
27
 
@@ -101,7 +97,7 @@ describe('Test AddNewDevice', () => {
101
97
  });
102
98
 
103
99
  it('fetchDetails fail', async () => {
104
- mock.onGet(API.UNIT.UNIT_DETAIL(1)).reply(400);
100
+ mock.onGet(API.UNIT.UNIT_DETAIL(1)).reply(500);
105
101
  await act(async () => {
106
102
  tree = await create(wrapComponent(route));
107
103
  });
@@ -1,8 +1,12 @@
1
- import { useNavigation } from '@react-navigation/native';
2
1
  import React, { useCallback, useEffect, useState } from 'react';
2
+ import { useNavigation } from '@react-navigation/native';
3
+ import { Alert } from 'react-native';
4
+
3
5
  import Processing from '../../commons/Processing';
4
6
  import Routes from '../../utils/Route';
7
+ import { useTranslations } from '../../hooks/Common/useTranslations';
5
8
 
9
+ let timeout;
6
10
  const ConnectingDevice = ({
7
11
  title,
8
12
  fail,
@@ -13,13 +17,13 @@ const ConnectingDevice = ({
13
17
  chipId,
14
18
  sensorId,
15
19
  addDeviceType,
16
- goBack,
17
20
  showPopupTurnOnGuide,
18
21
  setHidePopupTurnOnGuide,
19
22
  setIsRecallChipScan,
20
23
  isChangeAddressSuccess,
21
24
  }) => {
22
- const { navigate } = useNavigation();
25
+ const t = useTranslations();
26
+ const { navigate, goBack } = useNavigation();
23
27
 
24
28
  const [renameParams, setRenameParams] = useState({
25
29
  unitId,
@@ -31,11 +35,29 @@ const ConnectingDevice = ({
31
35
 
32
36
  const complete = useCallback(
33
37
  (deviceInfo) => {
38
+ timeout && clearTimeout(timeout);
34
39
  navigate(Routes.RenameNewDevices, renameParams);
35
40
  },
36
41
  [navigate, renameParams]
37
42
  );
38
43
 
44
+ useEffect(() => {
45
+ timeout = setTimeout(() => {
46
+ Alert.alert(t('continue_to_wait'), t('it_has_been_5_minutes'), [
47
+ {
48
+ text: t('back'),
49
+ onPress: goBack,
50
+ },
51
+ {
52
+ text: t('continue'),
53
+ },
54
+ ]);
55
+ }, 300 * 1000); // when test, it takes more than 3 min
56
+ return () => {
57
+ clearTimeout(timeout);
58
+ };
59
+ }, [fail, goBack, t]);
60
+
39
61
  const onMessage = useCallback(
40
62
  (data) => {
41
63
  setRenameParams((oldParams) => {
@@ -99,7 +99,7 @@ const ConnectingWifiGuide = ({ route }) => {
99
99
  setWifiList(data.wifi);
100
100
  setCurrentState(0);
101
101
  clearInterval(intervalSend);
102
- socket.close();
102
+ socket?.close();
103
103
  socket = null;
104
104
  }
105
105
  });
@@ -1,4 +1,6 @@
1
+ import { Platform } from 'react-native';
1
2
  import { Dimensions, StyleSheet } from 'react-native';
3
+ import { getBottomSpace } from 'react-native-iphone-x-helper';
2
4
  import { Colors } from '../../configs';
3
5
 
4
6
  const customWidth = (Dimensions.get('window').width - 32 - 15) / 2; // set gap between flex item is 15px
@@ -55,4 +57,12 @@ export default StyleSheet.create({
55
57
  textAlign: 'center',
56
58
  lineHeight: 24,
57
59
  },
60
+ bottomButtonView: {
61
+ marginBottom:
62
+ getBottomSpace() +
63
+ Platform.select({
64
+ android: 10,
65
+ ios: -10,
66
+ }),
67
+ },
58
68
  });
@@ -1,6 +1,7 @@
1
1
  import { useNavigation } from '@react-navigation/native';
2
- import React, { useCallback, useState } from 'react';
2
+ import React, { useCallback } from 'react';
3
3
  import { Alert } from 'react-native';
4
+
4
5
  import API from '../../configs/API';
5
6
  import { useTranslations } from '../../hooks/Common/useTranslations';
6
7
  import { axiosPost } from '../../utils/Apis/axios';
@@ -10,14 +11,13 @@ const ConnectingZigbeeDevice = ({ route }) => {
10
11
  const t = useTranslations();
11
12
  const { goBack } = useNavigation();
12
13
  const { unitId, subUnit, chipId } = route?.params || {};
13
- const [sensorId, setSensorId] = useState(null);
14
14
 
15
15
  const fail = useCallback(
16
16
  (message) => {
17
17
  Alert.alert(t('fail_add_zigbee_device'), message, [
18
18
  {
19
19
  text: t('ok'),
20
- onPress: () => goBack(),
20
+ onPress: goBack,
21
21
  },
22
22
  ]);
23
23
  },
@@ -39,9 +39,8 @@ const ConnectingZigbeeDevice = ({ route }) => {
39
39
  fail(JSON.stringify(problem || data));
40
40
  return;
41
41
  }
42
- setSensorId(data.id);
43
42
  },
44
- [chipId, fail, subUnit, unitId]
43
+ [chipId, fail, subUnit?.id, unitId]
45
44
  );
46
45
 
47
46
  return (
@@ -53,7 +52,7 @@ const ConnectingZigbeeDevice = ({ route }) => {
53
52
  unitId={unitId}
54
53
  subUnit={subUnit}
55
54
  chipId={chipId}
56
- sensorId={sensorId}
55
+ sensorId={null}
57
56
  />
58
57
  );
59
58
  };
@@ -105,6 +105,7 @@ const ShareWifiPassword = ({ route }) => {
105
105
  }
106
106
  if (ssid !== currentSsid) {
107
107
  clearInterval(checkWifiInterval);
108
+ setIsShowPopupPassword(false);
108
109
  navigation.navigate(Routes.ConnectingWifiDevice, {
109
110
  unitId,
110
111
  subUnit,
@@ -149,7 +150,7 @@ const ShareWifiPassword = ({ route }) => {
149
150
 
150
151
  socket.on('message', (msg, rinfo) => {
151
152
  if (handleSocketOnMsg(currentSsid, msg)) {
152
- socket.close();
153
+ socket?.close();
153
154
  socket = null;
154
155
  }
155
156
  });
@@ -20,10 +20,6 @@ const wrapComponent = (route) => (
20
20
 
21
21
  const mock = new MockAdapter(api.axiosInstance);
22
22
 
23
- jest.mock('react', () => {
24
- return { ...jest.requireActual('react'), memo: (x) => x };
25
- });
26
-
27
23
  const mockedNavigate = jest.fn();
28
24
  const mockedGoBack = jest.fn();
29
25
 
@@ -15,10 +15,6 @@ const wrapComponent = (route) => (
15
15
 
16
16
  const mock = new MockAdapter(api.axiosInstance);
17
17
 
18
- jest.mock('react', () => {
19
- return { ...jest.requireActual('react'), memo: (x) => x };
20
- });
21
-
22
18
  const mockedNavigate = jest.fn();
23
19
  const mockedGoBack = jest.fn();
24
20
 
@@ -18,10 +18,6 @@ const wrapComponent = (route) => (
18
18
 
19
19
  const mock = new MockAdapter(api.axiosInstance);
20
20
 
21
- jest.mock('react', () => {
22
- return { ...jest.requireActual('react'), memo: (x) => x };
23
- });
24
-
25
21
  const mockedNavigate = jest.fn();
26
22
  const mockedGoBack = jest.fn();
27
23
 
@@ -64,7 +60,8 @@ describe('Test connecting wifi device', () => {
64
60
  });
65
61
  const instance = tree.root;
66
62
  expect(instance.findAllByType(Processing)).toHaveLength(1);
67
- jest.runAllTimers();
63
+ jest.runOnlyPendingTimers();
64
+
68
65
  expect(mock.history.post).toHaveLength(0);
69
66
  const connectingDevice = instance.findByType(ConnectingDevice);
70
67
  await act(async () => {
@@ -8,6 +8,7 @@ import { SCProvider } from '../../../context';
8
8
  import { mockSCStore } from '../../../context/mockStore';
9
9
  import api from '../../../utils/Apis/axios';
10
10
  import Processing from '../../../commons/Processing';
11
+ import { Alert } from 'react-native';
11
12
 
12
13
  const wrapComponent = (route) => (
13
14
  <SCProvider initState={mockSCStore({})}>
@@ -17,13 +18,21 @@ const wrapComponent = (route) => (
17
18
 
18
19
  const mock = new MockAdapter(api.axiosInstance);
19
20
 
20
- jest.mock('react', () => {
21
- return { ...jest.requireActual('react'), memo: (x) => x };
21
+ jest.mock('react-native', () => {
22
+ const RN = jest.requireActual('react-native');
23
+ return Object.setPrototypeOf(
24
+ {
25
+ Alert: {
26
+ ...RN.Alert,
27
+ alert: jest.fn(),
28
+ },
29
+ },
30
+ RN
31
+ );
22
32
  });
23
33
 
24
34
  const mockedNavigate = jest.fn();
25
35
  const mockedGoBack = jest.fn();
26
-
27
36
  jest.mock('@react-navigation/native', () => {
28
37
  return {
29
38
  ...jest.requireActual('@react-navigation/native'),
@@ -66,10 +75,21 @@ describe('Test connecting modbus device', () => {
66
75
  expect(mock.history.post).toHaveLength(1);
67
76
  });
68
77
 
69
- it('receive sensor-id from channel then rename sensor-id', async () => {
70
- mock.onPost().reply(200, {
71
- id: 1,
78
+ it('timeout', async () => {
79
+ jest.useFakeTimers();
80
+
81
+ await act(async () => {
82
+ tree = await create(wrapComponent(route));
83
+ });
84
+
85
+ await act(async () => {
86
+ jest.runOnlyPendingTimers();
72
87
  });
88
+ expect(Alert.alert).toBeCalled();
89
+ });
90
+
91
+ it('receive sensor-id from channel then rename sensor-id', async () => {
92
+ mock.onPost().reply(200, {});
73
93
  await act(async () => {
74
94
  tree = await create(wrapComponent(route));
75
95
  });
@@ -80,6 +100,9 @@ describe('Test connecting modbus device', () => {
80
100
  channel = channels[key];
81
101
  }
82
102
  }
103
+ await act(async () => {
104
+ await channel.trigger('progress', { data: { sensorId: 1 } });
105
+ });
83
106
  await act(async () => {
84
107
  await channel.trigger('progress', { success: 1 });
85
108
  });
@@ -18,13 +18,6 @@ const wrapComponent = (route) => (
18
18
 
19
19
  const mock = new MockAdapter(api.axiosInstance);
20
20
 
21
- jest.mock('react', () => {
22
- return {
23
- ...jest.requireActual('react'),
24
- memo: (x) => x,
25
- };
26
- });
27
-
28
21
  const mockedNavigate = jest.fn();
29
22
  const mockedGoBack = jest.fn();
30
23
 
@@ -15,10 +15,6 @@ const wrapComponent = (route) => (
15
15
  </SCProvider>
16
16
  );
17
17
 
18
- jest.mock('react', () => {
19
- return { ...jest.requireActual('react'), memo: (x) => x };
20
- });
21
-
22
18
  const mockedNavigate = jest.fn();
23
19
  const mockedGoBack = jest.fn();
24
20
 
@@ -13,10 +13,6 @@ const wrapComponent = (route) => (
13
13
  </SCProvider>
14
14
  );
15
15
 
16
- jest.mock('react', () => {
17
- return { ...jest.requireActual('react'), memo: (x) => x };
18
- });
19
-
20
16
  const mockedNavigate = jest.fn();
21
17
  const mockedGoBack = jest.fn();
22
18
 
@@ -13,10 +13,6 @@ const wrapComponent = (route) => (
13
13
  </SCProvider>
14
14
  );
15
15
 
16
- jest.mock('react', () => {
17
- return { ...jest.requireActual('react'), memo: (x) => x };
18
- });
19
-
20
16
  const mockedNavigate = jest.fn();
21
17
  const mockedGoBack = jest.fn();
22
18
 
@@ -36,13 +36,6 @@ jest.mock('@react-navigation/native', () => {
36
36
  };
37
37
  });
38
38
 
39
- jest.mock('react', () => {
40
- return {
41
- ...jest.requireActual('react'),
42
- memo: (x) => x,
43
- };
44
- });
45
-
46
39
  let tree;
47
40
 
48
41
  describe('test AddNewOneTap', () => {
@@ -35,7 +35,6 @@ jest.mock('react', () => {
35
35
  return {
36
36
  ...jest.requireActual('react'),
37
37
  useState: jest.fn((init) => [init, mockSetState]),
38
- memo: (x) => x,
39
38
  };
40
39
  });
41
40
 
@@ -23,13 +23,6 @@ const wrapComponent = (route) => (
23
23
 
24
24
  const mock = new MockAdapter(api.axiosInstance);
25
25
 
26
- jest.mock('react', () => {
27
- return {
28
- ...jest.requireActual('react'),
29
- memo: (x) => x,
30
- };
31
- });
32
-
33
26
  const mockPop = jest.fn();
34
27
  const mockSetSensorDetail = jest.fn();
35
28
  jest.mock('@react-navigation/native', () => {
@@ -735,7 +735,7 @@ describe('test DeviceDetail', () => {
735
735
  });
736
736
 
737
737
  it('Open popup ble when server down', async () => {
738
- store.app.isBluetoothEnabled = false;
738
+ store.bluetooth.isEnabled = false;
739
739
  data_sensor_display.items[1].configuration.configuration.action1_data.command_prefer_over_bluetooth = true;
740
740
  const responseDisplay = {
741
741
  status: 200,
@@ -101,7 +101,7 @@ const DeviceDetail = ({ route }) => {
101
101
  (state) => state.app.isNetworkConnected
102
102
  );
103
103
  const isBluetoothEnabled = useSCContextSelector((state) => {
104
- return state.app.isBluetoothEnabled;
104
+ return state.bluetooth.isEnabled;
105
105
  });
106
106
 
107
107
  const { isConnected: isEoHBackendConnected } =
@@ -165,9 +165,7 @@ const DeviceDetail = ({ route }) => {
165
165
  }, [currentUserId, unit]);
166
166
 
167
167
  const fetchUnitDetail = useCallback(async () => {
168
- const { success, data } = await axiosGet(API.UNIT.UNIT_DETAIL(unitId), {
169
- headers: { 'Cache-Control': 'no-cache' },
170
- });
168
+ const { success, data } = await axiosGet(API.UNIT.UNIT_DETAIL(unitId));
171
169
  if (success) {
172
170
  setUnit(data);
173
171
  }
@@ -181,7 +179,15 @@ const DeviceDetail = ({ route }) => {
181
179
 
182
180
  const { connectHomeAssistant } = useHomeAssistantConnection();
183
181
 
184
- const { bluetoothScanDevices } = useBluetoothConnection();
182
+ const {
183
+ permissionsGranted: bluetoothPermGranted,
184
+ requestPerm: requestBluetoothPerm,
185
+ bluetoothScanDevices,
186
+ } = useBluetoothConnection();
187
+
188
+ useEffect(() => {
189
+ isDeviceHasBle && isBluetoothEnabled && requestBluetoothPerm();
190
+ }, [isDeviceHasBle, isBluetoothEnabled, requestBluetoothPerm]);
185
191
 
186
192
  useEffect(() => {
187
193
  if (
@@ -202,7 +208,7 @@ const DeviceDetail = ({ route }) => {
202
208
  bluetoothScanDevices([bluetooth.address]);
203
209
  }
204
210
  // eslint-disable-next-line react-hooks/exhaustive-deps
205
- }, [isBluetoothEnabled, controlOptions, unit]);
211
+ }, [isBluetoothEnabled, bluetoothPermGranted, controlOptions, unit]);
206
212
 
207
213
  const fetchSensorDetail = useCallback(async () => {
208
214
  const { success, data, resp_status } = await axiosGet(
@@ -1,10 +1,12 @@
1
1
  import { useNavigation } from '@react-navigation/native';
2
- import { useCallback, useEffect } from 'react';
3
- import { Alert, Linking, Platform } from 'react-native';
2
+ import { useState, useCallback, useEffect } from 'react';
3
+ import { Linking, Platform } from 'react-native';
4
+ import AlertAsync from 'react-native-alert-async';
4
5
  import { useTranslations } from '../../../hooks/Common/useTranslations';
5
6
  import { useSCContextSelector } from '../../../context';
6
- import { enableBluetoothForAndroid } from '../../../iot/RemoteControl/Bluetooth';
7
7
  import { ToastBottomHelper } from '../../../utils/Utils';
8
+ import { enableBluetoothForAndroid } from '../../../iot/RemoteControl/Bluetooth';
9
+ import { useBluetoothConnection } from '../../../hooks/IoT';
8
10
 
9
11
  export const useDisconnectedDevice = (
10
12
  sensorName,
@@ -12,10 +14,27 @@ export const useDisconnectedDevice = (
12
14
  serverDown
13
15
  ) => {
14
16
  const t = useTranslations();
17
+ const { goBack } = useNavigation();
18
+ const [allowEnableBluetooth, setAllowEnableBluetooth] = useState(false);
19
+
15
20
  const openBluetoothIOS = () => {
16
21
  Linking.openURL('App-Prefs:Bluetooth');
17
22
  };
18
- const { goBack } = useNavigation();
23
+
24
+ const {
25
+ permissionsGranted: bluetoothPermGranted,
26
+ requestPerm: requestBluetoothPerm,
27
+ } = useBluetoothConnection();
28
+
29
+ useEffect(() => {
30
+ allowEnableBluetooth && bluetoothPermGranted && enableBluetoothForAndroid();
31
+ }, [allowEnableBluetooth, bluetoothPermGranted]);
32
+
33
+ const enableBluetooth = async () => {
34
+ setAllowEnableBluetooth(true);
35
+ !bluetoothPermGranted && (await requestBluetoothPerm());
36
+ };
37
+
19
38
  const actions =
20
39
  Platform.OS === 'ios'
21
40
  ? [
@@ -35,12 +54,12 @@ export const useDisconnectedDevice = (
35
54
  },
36
55
  {
37
56
  text: 'Open',
38
- onPress: () => enableBluetoothForAndroid(),
57
+ onPress: () => enableBluetooth(),
39
58
  },
40
59
  ];
41
60
 
42
61
  const isBluetoothEnabled = useSCContextSelector(
43
- (state) => state.app.isBluetoothEnabled
62
+ (state) => state.bluetooth.isEnabled
44
63
  );
45
64
  const isNetworkConnected = useSCContextSelector(
46
65
  (state) => state.app.isNetworkConnected
@@ -61,7 +80,7 @@ export const useDisconnectedDevice = (
61
80
  })
62
81
  );
63
82
  } else if (isBluetoothEnabled === false) {
64
- Alert.alert(
83
+ AlertAsync(
65
84
  '',
66
85
  t(
67
86
  'your_connection_to_the_server_was_disconnected_please_open_the_bluetooth_to_continue'