@eohjsc/react-native-smart-city 0.7.3 → 0.7.5

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 (274) hide show
  1. package/assets/images/Automation-fill.svg +85 -0
  2. package/assets/images/Map/LocationPin.svg +10 -0
  3. package/assets/images/Scenario-filled.svg +22 -0
  4. package/assets/images/schedule-fill.svg +48 -0
  5. package/package.json +20 -17
  6. package/src/commons/Action/ItemQuickAction.js +1 -1
  7. package/src/commons/Action/__test__/ItemQuickAction.test.js +6 -6
  8. package/src/commons/ActionGroup/NumberUpDownActionTemplate.js +3 -3
  9. package/src/commons/ActionGroup/OnOffSmartLock/AutoLock/ButtonWrapper.js +3 -3
  10. package/src/commons/ActionGroup/OnOffSmartLock/PasscodeList/__test__/index.test.js +5 -5
  11. package/src/commons/ActionGroup/OnOffSmartLock/PasscodeList/index.js +3 -3
  12. package/src/commons/ActionGroup/OnOffSmartLock/SetupGeneratePasscode/ButtonWrapper.js +2 -2
  13. package/src/commons/ActionGroup/OnOffTemplate/OnOffSimpleTemplate.js +2 -2
  14. package/src/commons/ActionGroup/OptionsDropdownActionTemplate.js +2 -2
  15. package/src/commons/ActionGroup/SliderRangeTemplate.js +7 -7
  16. package/src/commons/ActionGroup/SmartTiviActionTemplate/SmartTiviActionTemplate.js +2 -2
  17. package/src/commons/ActionGroup/SmartTiviActionTemplate/component/CircleButton.js +5 -5
  18. package/src/commons/ActionGroup/SmartTiviActionTemplate/component/ControlPlay.js +5 -5
  19. package/src/commons/ActionGroup/TerminalBoxTemplate.js +2 -2
  20. package/src/commons/ActionGroup/TextBoxTemplate.js +2 -2
  21. package/src/commons/ActionGroup/ThreeButtonTemplate/__test__/ThreeButtonCircle.test.js +2 -2
  22. package/src/commons/ActionGroup/ThreeButtonTemplate/__test__/ThreeButtonDefault.test.js +2 -2
  23. package/src/commons/ActionGroup/TimerActionTemplate.js +6 -3
  24. package/src/commons/ActionGroup/TwoButtonTemplate/index.js +2 -2
  25. package/src/commons/ActionGroup/__test__/ColorPickerTemplate.test.js +9 -10
  26. package/src/commons/ActionGroup/__test__/OnOffSmartLock.test.js +5 -5
  27. package/src/commons/ActionGroup/__test__/OnOffTemplate.test.js +5 -5
  28. package/src/commons/ActionGroup/__test__/OptionsDropdownTemplate.test.js +8 -8
  29. package/src/commons/ActionGroup/__test__/StatesGridActionTemplate.test.js +3 -3
  30. package/src/commons/ActionGroup/__test__/TimerActionTemplate.test.js +6 -6
  31. package/src/commons/ActionGroup/__test__/TwoButtonTemplate.test.js +1 -1
  32. package/src/commons/ActionGroup/__test__/index.test.js +6 -6
  33. package/src/commons/ActionGroup/index.js +2 -2
  34. package/src/commons/ActionTemplate/__test__/index.test.js +4 -4
  35. package/src/commons/Automate/ItemAutomate.js +9 -41
  36. package/src/commons/Automate/ItemConditionScriptDetail.js +67 -0
  37. package/src/commons/Automate/ItemConditionScriptDetailStyles.js +46 -0
  38. package/src/commons/Automate/__test__/ItemAutomate.test.js +0 -21
  39. package/src/commons/BackDefault/index.js +2 -2
  40. package/src/commons/BottomButtonView/index.js +1 -0
  41. package/src/commons/ButtonPopup/index.js +3 -2
  42. package/src/commons/ChartAggregationOption/__test__/FourButtonFilterHistory.test.js +2 -2
  43. package/src/commons/Dashboard/MyPinnedSharedUnit/__test__/MyPinnedSharedUnit.test.js +8 -9
  44. package/src/commons/Dashboard/MyUnit/__test__/MyUnit.test.js +7 -7
  45. package/src/commons/DateTimeRangeChange/DateTimeButton.js +3 -3
  46. package/src/commons/DateTimeRangeChange/index.js +1 -1
  47. package/src/commons/Device/ConnectedViewHeader.js +2 -2
  48. package/src/commons/Device/Emergency/EmergencyDetail.js +3 -3
  49. package/src/commons/Device/Emergency/__test__/EmergencyButton.test.js +1 -1
  50. package/src/commons/Device/FlatListItems.js +20 -19
  51. package/src/commons/Device/Hanet/ItemHanetDevice.js +3 -3
  52. package/src/commons/Device/Hanet/ItemHanetDevice.test.js +3 -3
  53. package/src/commons/Device/HorizontalBarChart.js +54 -34
  54. package/src/commons/Device/ItemAddNew/index.js +2 -2
  55. package/src/commons/Device/ItemDevice.js +5 -21
  56. package/src/commons/Device/SonosSpeaker/index.js +3 -3
  57. package/src/commons/Device/WaterPurifierStatus/AlertStatusMachine.js +2 -2
  58. package/src/commons/Device/WaterQualitySensor/QualityIndicatorsItem.js +6 -2
  59. package/src/commons/DisplayChecking/index.js +2 -2
  60. package/src/commons/EmergencyButton/AlertSendConfirm.js +2 -2
  61. package/src/commons/FieldTemplate/ChooseUserField/index.js +2 -2
  62. package/src/commons/FieldTemplate/PasscodeField/__test__/index.test.js +3 -3
  63. package/src/commons/FieldTemplate/ScheduleField/__test__/index.test.js +6 -6
  64. package/src/commons/FlatListDnD/__test__/index.test.js +4 -4
  65. package/src/commons/FlatListDnD/index.js +12 -9
  66. package/src/commons/Grid/GridItem.js +10 -2
  67. package/src/commons/GroupCheckBox/__test__/GroupCheckBox.test.js +3 -3
  68. package/src/commons/Header/HeaderCustom.js +2 -2
  69. package/src/commons/Header/__test__/HeaderCT.test.js +3 -3
  70. package/src/commons/HeaderAni/index.js +2 -2
  71. package/src/commons/IconComponent/index.js +3 -3
  72. package/src/commons/ImagePicker/__test__/ImagePicker.test.js +5 -5
  73. package/src/commons/MediaPlayerDetail/__test__/MediaPlayerDetail.test.js +6 -4
  74. package/src/commons/MenuActionMore/MenuActionMoreStyles.js +2 -1
  75. package/src/commons/MenuActionMore/index.js +1 -1
  76. package/src/commons/NavBar/NavBarStyles.js +1 -1
  77. package/src/commons/NavBar/index.js +2 -2
  78. package/src/commons/OneTapTemplate/NumberUpDownActionTemplate.js +3 -3
  79. package/src/commons/OneTapTemplate/__test__/StatesGridActionTemplate.test.js +1 -1
  80. package/src/commons/Popover/__test__/index.test.js +3 -3
  81. package/src/commons/Processing/__test__/Connecting.test.js +4 -4
  82. package/src/commons/SearchLocation/index.js +3 -3
  83. package/src/commons/SelectActionCard/index.js +2 -2
  84. package/src/commons/SelectSubUnit/index.js +6 -2
  85. package/src/commons/SelectUnit/__test__/SelectUnit.test.js +5 -5
  86. package/src/commons/Sharing/BtnRemoveMember.js +2 -2
  87. package/src/commons/Sharing/StationDevicePermissions.js +2 -2
  88. package/src/commons/SubUnit/DeviceTemplate/ConfigAndEvaluation/ConfigAndEvaluation.js +2 -2
  89. package/src/commons/SubUnit/DeviceTemplate/ConfigValue/ConfigValue.js +2 -2
  90. package/src/commons/SubUnit/DeviceTemplate/EvaluationOverConfig/EvaluationOverConfig.js +2 -2
  91. package/src/commons/SubUnit/OneTap/ItemOneTap.js +6 -7
  92. package/src/commons/SubUnit/OneTap/__test__/SubUnitAutomate.test.js +0 -2
  93. package/src/commons/SubUnit/OneTap/index.js +9 -8
  94. package/src/commons/SubUnit/__test__/ShortDetail.test.js +8 -8
  95. package/src/commons/Unit/HeaderUnit/index.js +30 -22
  96. package/src/commons/Unit/SharedUnit.js +7 -7
  97. package/src/commons/Widgets/IFrame/__tests__/IFrame.test.js +9 -13
  98. package/src/commons/Widgets/IFrameWithConfig/IFrameWithConfig.js +34 -2
  99. package/src/commons/Widgets/IFrameWithConfig/__tests__/IFrameWithConfig.test.js +88 -8
  100. package/src/commons/WrapParallaxScrollView/index.js +9 -10
  101. package/src/configs/API.js +1 -1
  102. package/src/configs/AccessibilityLabel.js +2 -0
  103. package/src/configs/Constants.js +3 -3
  104. package/src/configs/Theme.js +1 -1
  105. package/src/hooks/Common/__test__/useAndroidTranslucentStatusBar.test.js +5 -5
  106. package/src/hooks/IoT/__test__/useHomeAssistantConnection.test.js +12 -12
  107. package/src/hooks/IoT/__test__/useRemoteControl.test.js +14 -7
  108. package/src/hooks/IoT/__test__/useWatchConfigs.test.js +3 -3
  109. package/src/hooks/IoT/useRemoteControl.js +24 -13
  110. package/src/hooks/useMqtt.js +2 -2
  111. package/src/iot/RemoteControl/Bluetooth.js +19 -22
  112. package/src/iot/RemoteControl/Internet.js +13 -5
  113. package/src/iot/RemoteControl/__test__/Internet.test.js +7 -7
  114. package/src/navigations/EmergencyContactsStack.js +4 -3
  115. package/src/navigations/SharedStack.js +2 -0
  116. package/src/navigations/UnitStack.js +56 -57
  117. package/src/screens/AQIGuide/index.js +0 -2
  118. package/src/screens/ActivityLog/index.js +2 -2
  119. package/src/screens/AddLocationMaps/__test__/index.test.js +12 -12
  120. package/src/screens/AddLocationMaps/index.js +16 -19
  121. package/src/screens/AddLocationMaps/indexStyle.js +1 -0
  122. package/src/screens/AddNewGateway/RenameNewDevices.js +2 -2
  123. package/src/screens/AddNewGateway/SelectDeviceType.js +1 -1
  124. package/src/screens/AddNewGateway/ShareWifiPassword.js +16 -15
  125. package/src/screens/AddNewGateway/__test__/AddNewGateway.test.js +7 -7
  126. package/src/screens/AddNewGateway/__test__/ConnectingWifiDevice.test.js +8 -8
  127. package/src/screens/AddNewGateway/__test__/ConnectingZigbeeDevice.test.js +7 -7
  128. package/src/screens/AddNewGateway/__test__/RenameNewDevices.test.js +8 -8
  129. package/src/screens/AddNewGateway/__test__/ScanGatewayQR.test.js +5 -5
  130. package/src/screens/AddNewGateway/__test__/SelectDeviceUnit.test.js +4 -4
  131. package/src/screens/AddNewGateway/__test__/SelectModbusGateway.test.js +6 -6
  132. package/src/screens/AddNewGateway/__test__/SelectZigbeeGateway.test.js +6 -6
  133. package/src/screens/AddNewGateway/__test__/ShareWifiPassword.test.js +0 -4
  134. package/src/screens/AddNewGateway/hooks/__Tests__/useWifiManage.test.js +2 -2
  135. package/src/screens/AllGateway/DetailConfigActionModbus/__test__/index.test.js +6 -6
  136. package/src/screens/AllGateway/DeviceInternalDetail/__test__/index.test.js +19 -17
  137. package/src/screens/AllGateway/DeviceModbusDetail/__test__/index.test.js +19 -17
  138. package/src/screens/AllGateway/DeviceZigbeeDetail/__test__/index.test.js +18 -16
  139. package/src/screens/AllGateway/GatewayDetail/__test__/index.test.js +43 -35
  140. package/src/screens/AllGateway/GatewayInfo/__test__/index.test.js +38 -22
  141. package/src/screens/AllGateway/__test__/index.test.js +6 -6
  142. package/src/screens/AllGateway/components/Detail/__test__/index.test.js +3 -5
  143. package/src/screens/AllGateway/components/GatewayItem/__test__/index.test.js +3 -3
  144. package/src/screens/AllGateway/components/TabPaneCT/__test__/index.test.js +6 -6
  145. package/src/screens/AllGateway/hooks/__test__/index.test.js +2 -2
  146. package/src/screens/AllGateway/test-utils.js +3 -4
  147. package/src/screens/Automate/AddNewAction/ChooseAction.js +17 -3
  148. package/src/screens/Automate/AddNewAction/ChooseConfig.js +7 -6
  149. package/src/screens/Automate/AddNewAction/NewActionWrapper.js +8 -8
  150. package/src/screens/Automate/AddNewAction/SelectControlDevices.js +30 -20
  151. package/src/screens/Automate/AddNewAction/SelectMonitorDevices.js +17 -10
  152. package/src/screens/Automate/AddNewAction/SetupConfigCondition.js +58 -44
  153. package/src/screens/Automate/AddNewAction/SetupScriptDelay.js +1 -1
  154. package/src/screens/Automate/AddNewAction/SetupScriptNotify.js +3 -3
  155. package/src/screens/Automate/AddNewAction/Styles/SetupSensorStyles.js +20 -4
  156. package/src/screens/Automate/AddNewAction/__test__/ChooseAction.test.js +12 -12
  157. package/src/screens/Automate/AddNewAction/__test__/SelectControlDevices.test.js +14 -8
  158. package/src/screens/Automate/AddNewAction/__test__/SelectMonitorDevices.test.js +13 -7
  159. package/src/screens/Automate/AddNewAction/__test__/SetupConfigCondition.test.js +54 -15
  160. package/src/screens/Automate/AddNewAction/__test__/SetupScriptDelay.test.js +9 -9
  161. package/src/screens/Automate/AddNewAction/__test__/SetupScriptNotify.test.js +39 -10
  162. package/src/screens/Automate/AddNewAutoSmart/AddTypeSmart.js +10 -10
  163. package/src/screens/Automate/AddNewAutoSmart/__test__/AddNewAutoSmart.test.js +13 -8
  164. package/src/screens/Automate/Components/InputName.js +10 -7
  165. package/src/screens/Automate/EditActionsList/__tests__/UpdateActionScript.test.js +8 -8
  166. package/src/screens/Automate/EditActionsList/__tests__/UpdateDelayScript.test.js +6 -6
  167. package/src/screens/Automate/EditActionsList/__tests__/UpdateNotifyScript.test.js +7 -7
  168. package/src/screens/Automate/EditActionsList/index.js +19 -17
  169. package/src/screens/Automate/MultiUnits.js +19 -22
  170. package/src/screens/Automate/OneTap/__test__/AddNewOneTap.test.js +18 -8
  171. package/src/screens/Automate/Scenario/__test__/AddNewOneTap.test.js +15 -7
  172. package/src/screens/Automate/ScriptDetail/Components/AddActionScript.js +14 -6
  173. package/src/screens/Automate/ScriptDetail/Components/RenameScript.js +4 -7
  174. package/src/screens/Automate/ScriptDetail/__test__/index.test.js +56 -18
  175. package/src/screens/Automate/ScriptDetail/__test__/useStarredScript.test.js +6 -6
  176. package/src/screens/Automate/ScriptDetail/index.js +105 -41
  177. package/src/screens/Automate/SetSchedule/__test__/SelectWeekday.test.js +4 -4
  178. package/src/screens/Automate/SetSchedule/__test__/index.test.js +29 -18
  179. package/src/screens/Automate/SetSchedule/components/RowItem.js +5 -5
  180. package/src/screens/Automate/SetSchedule/index.js +8 -7
  181. package/src/screens/Automate/Styles/indexStyles.js +1 -1
  182. package/src/screens/Automate/__test__/MultiUnits.test.js +1 -4
  183. package/src/screens/Automate/__test__/index.test.js +0 -1
  184. package/src/screens/Automate/index.js +36 -34
  185. package/src/screens/ChangePosition/__test__/index.test.js +6 -6
  186. package/src/screens/ChangePosition/index.js +2 -1
  187. package/src/screens/Device/EditDevice/__test__/EditDevice.test.js +13 -13
  188. package/src/screens/Device/EditDevice/index.js +4 -4
  189. package/src/screens/Device/__test__/BluetoothDevice.test.js +300 -0
  190. package/src/screens/Device/__test__/detail.test.js +14 -14
  191. package/src/screens/Device/__test__/mqttDetail.test.js +9 -9
  192. package/src/screens/Device/components/BluetoothDevice.js +135 -0
  193. package/src/screens/Device/components/SensorDisplayItem.js +9 -8
  194. package/src/screens/Device/detail.js +70 -62
  195. package/src/screens/Device/hooks/useEvaluateValue.js +1 -1
  196. package/src/screens/Drawer/Drawer.test.js +2 -2
  197. package/src/screens/Drawer/index.js +3 -3
  198. package/src/screens/EmergencyContacts/EmergencyContactsList.js +8 -4
  199. package/src/screens/EmergencyContacts/EmergencyContactsSelectContacts.js +3 -3
  200. package/src/screens/EmergencyContacts/__test__/EmergencyContactsSelectContacts.test.js +7 -7
  201. package/src/screens/EmergencySetting/components/DropDownItem.js +2 -2
  202. package/src/screens/EnterPassword/__test__/EnterPassword.test.js +8 -8
  203. package/src/screens/GuestInfo/components/RowGuestInfo.js +2 -2
  204. package/src/screens/GuestInfo/components/__test__/AccessScheduleSheet.test.js +3 -3
  205. package/src/screens/GuestInfo/index.js +2 -2
  206. package/src/screens/HanetCamera/ManageAccess.js +3 -3
  207. package/src/screens/HanetCamera/MemberInfo.js +2 -2
  208. package/src/screens/HanetCamera/__test__/Detail.test.js +9 -9
  209. package/src/screens/HanetCamera/__test__/MemberInfo.test.js +10 -10
  210. package/src/screens/HanetCamera/components/RequestFaceIDPopup.js +2 -2
  211. package/src/screens/ManageAccess/index.js +3 -3
  212. package/src/screens/MoveToAnotherSubUnit/__test__/index.test.js +9 -9
  213. package/src/screens/Notification/__test__/Notification.test.js +9 -9
  214. package/src/screens/Notification/components/NotificationItem.js +3 -4
  215. package/src/screens/Notification/index.js +3 -3
  216. package/src/screens/Notification/styles/NotificationItemStyles.js +0 -1
  217. package/src/screens/PlayBackCamera/__test__/index.test.js +1 -1
  218. package/src/screens/ScanChipQR/components/QRScan/__test__/QRScan.test.js +1 -1
  219. package/src/screens/ScanChipQR/components/QRScan/index.js +3 -3
  220. package/src/screens/SelectUnit/__test__/index.test.js +8 -8
  221. package/src/screens/SelectUnit/index.js +4 -4
  222. package/src/screens/SharedUnit/TabHeader.js +2 -2
  223. package/src/screens/Sharing/Components/EndDevice.js +3 -3
  224. package/src/screens/Sharing/UnitMemberList.js +2 -2
  225. package/src/screens/Sharing/__test__/UpdateShareDevice.test.js +7 -7
  226. package/src/screens/SideMenuDetail/__test__/index.test.js +8 -8
  227. package/src/screens/SmartAccount/Connecting/index.js +5 -5
  228. package/src/screens/SmartAccount/ListDevice/__test__/ListDevice.test.js +8 -8
  229. package/src/screens/SmartAccount/SuccessfullyConnected/__test__/SuccessfullyConnected.test.js +7 -7
  230. package/src/screens/SmartAccount/SuccessfullyConnected/index.js +2 -2
  231. package/src/screens/SmartAccount/__test__/Connecting.test.js +6 -6
  232. package/src/screens/SmartAccount/__test__/SmartAccount.test.js +10 -10
  233. package/src/screens/SmartIr/__test__/GroupButtonByType.test.js +3 -2
  234. package/src/screens/SmartIr/components/GroupButtonByType/GroupButtonByType.js +2 -2
  235. package/src/screens/SmartIr/components/SelectBrand.js +2 -2
  236. package/src/screens/SubUnit/AddSubUnit.js +28 -26
  237. package/src/screens/SubUnit/AddSubUnitStyles.js +10 -4
  238. package/src/screens/SubUnit/EditSubUnit.js +12 -11
  239. package/src/screens/SubUnit/ManageSubUnit.js +3 -3
  240. package/src/screens/SubUnit/__test__/AddSubUnit.test.js +13 -13
  241. package/src/screens/SubUnit/__test__/EditSubUnit.test.js +3 -3
  242. package/src/screens/Template/EditTemplate.js +6 -4
  243. package/src/screens/Template/__test__/EditTemplate.test.js +7 -7
  244. package/src/screens/Template/__test__/detail.test.js +4 -4
  245. package/src/screens/Template/__test__/index.test.js +1 -1
  246. package/src/screens/UVIndexGuide/index.js +2 -4
  247. package/src/screens/Unit/Detail.js +1 -5
  248. package/src/screens/Unit/MoreMenu.js +6 -5
  249. package/src/screens/Unit/SelectAddToFavorites.js +2 -2
  250. package/src/screens/Unit/SelectAddress.js +16 -12
  251. package/src/screens/Unit/Station/__test__/index.test.js +1 -1
  252. package/src/screens/Unit/__test__/MoreMenu.test.js +5 -1
  253. package/src/screens/Unit/__test__/SelectAddToFavorites.test.js +9 -9
  254. package/src/screens/Unit/__test__/SelectAddress.test.js +11 -17
  255. package/src/screens/Unit/__test__/Summaries.test.js +7 -7
  256. package/src/screens/Unit/components/AutomateScript/index.js +5 -5
  257. package/src/screens/Unit/components/ButtonWrapper/index.js +3 -3
  258. package/src/screens/Unit/components/Header/index.js +2 -2
  259. package/src/screens/Unit/components/SharedUnit/index.js +5 -5
  260. package/src/screens/Unit/components/__test__/AutomateScript.test.js +3 -3
  261. package/src/screens/Unit/components/__test__/SharedUnit.test.js +8 -8
  262. package/src/screens/Unit/hook/__test__/useUnitConnectRemoteDevices.test.js +2 -2
  263. package/src/screens/UnitSummary/components/AirQuality/index.js +6 -11
  264. package/src/screens/UnitSummary/components/WaterQuality/Item/index.js +5 -5
  265. package/src/screens/UnitSummary/index.js +6 -2
  266. package/src/utils/Apis/axios.js +5 -5
  267. package/src/utils/Functions/ShortEmail.js +1 -0
  268. package/src/utils/I18n/translations/en.js +6 -3
  269. package/src/utils/I18n/translations/vi.js +8 -4
  270. package/src/utils/__test__/Utils.test.js +16 -16
  271. package/src/utils/bluetooth.js +3 -0
  272. package/assets/images/OneTap.svg +0 -14
  273. package/assets/images/Schedule.svg +0 -39
  274. package/assets/images/ValueChange.svg +0 -49
@@ -1,18 +1,18 @@
1
+ import MockAdapter from 'axios-mock-adapter';
1
2
  import React from 'react';
2
3
  import { TouchableOpacity } from 'react-native';
3
- import { create, act } from 'react-test-renderer';
4
- import MockAdapter from 'axios-mock-adapter';
4
+ import { act, create } from 'react-test-renderer';
5
5
 
6
- import { SCProvider } from '../../../../context';
7
- import { mockSCStore } from '../../../../context/mockStore';
6
+ import { useRoute } from '@react-navigation/native';
7
+ import Toast from 'react-native-toast-message';
8
8
  import EditDevice from '..';
9
9
  import AlertAction from '../../../../commons/AlertAction';
10
10
  import _TextInput from '../../../../commons/Form/TextInput';
11
- import { AccessibilityLabel } from '../../../../configs/Constants';
12
11
  import { API } from '../../../../configs';
13
- import { useRoute } from '@react-navigation/native';
12
+ import { AccessibilityLabel } from '../../../../configs/Constants';
13
+ import { SCProvider } from '../../../../context';
14
+ import { mockSCStore } from '../../../../context/mockStore';
14
15
  import api from '../../../../utils/Apis/axios';
15
- import Toast from 'react-native-toast-message';
16
16
  import { getTranslate } from '../../../../utils/I18n';
17
17
 
18
18
  const wrapComponent = (route) => (
@@ -63,7 +63,7 @@ describe('Test EditDevice', () => {
63
63
  await act(async () => {
64
64
  textInput.props.onChange('new_name');
65
65
  });
66
- mock.onPatch(API.DEVICE.SENSOR_DETAIL(1)).reply(200, { name: 'new_name' });
66
+ mock.onPatch(API.DEVICE.DEVICE_DETAIL(1)).reply(200, { name: 'new_name' });
67
67
  await act(async () => {
68
68
  await alertAction.props.rightButtonClick();
69
69
  });
@@ -92,11 +92,11 @@ describe('Test EditDevice', () => {
92
92
  await act(async () => {
93
93
  textInput.props.onChange('new_name');
94
94
  });
95
- mock.onPatch(API.DEVICE.SENSOR_DETAIL(1)).reply(400);
95
+ mock.onPatch(API.DEVICE.DEVICE_DETAIL(1)).reply(400);
96
96
  await act(async () => {
97
97
  await alertAction.props.rightButtonClick();
98
98
  });
99
- expect(Toast.show).toBeCalledWith({
99
+ expect(Toast.show).toHaveBeenCalledWith({
100
100
  type: 'error',
101
101
  position: 'bottom',
102
102
  text1: getTranslate('en', 'rename_failed'),
@@ -120,7 +120,7 @@ describe('Test EditDevice', () => {
120
120
  await buttonDelete[0].props.onPress();
121
121
  });
122
122
  expect(alertAction.props.visible).toBeTruthy();
123
- mock.onDelete(API.DEVICE.SENSOR_DETAIL(1)).reply(204);
123
+ mock.onDelete(API.DEVICE.DEVICE_DETAIL(1)).reply(204);
124
124
  await act(async () => {
125
125
  await alertAction.props.rightButtonClick();
126
126
  });
@@ -144,11 +144,11 @@ describe('Test EditDevice', () => {
144
144
  await buttonDelete[0].props.onPress();
145
145
  });
146
146
  expect(alertAction.props.visible).toBeTruthy();
147
- mock.onDelete(API.DEVICE.SENSOR_DETAIL(1)).reply(400);
147
+ mock.onDelete(API.DEVICE.DEVICE_DETAIL(1)).reply(400);
148
148
  await act(async () => {
149
149
  await alertAction.props.rightButtonClick();
150
150
  });
151
- expect(Toast.show).toBeCalledWith({
151
+ expect(Toast.show).toHaveBeenCalledWith({
152
152
  type: 'error',
153
153
  position: 'bottom',
154
154
  text1: getTranslate('en', 'remove_failed'),
@@ -2,7 +2,7 @@ import React, { memo, useState, useCallback } from 'react';
2
2
  import { View, TouchableOpacity } from 'react-native';
3
3
  import { useTranslations } from '../../../hooks/Common/useTranslations';
4
4
  import { HeaderCustom } from '../../../commons/Header';
5
- import AntDesign from 'react-native-vector-icons/AntDesign';
5
+ import { IconOutline } from '@ant-design/icons-react-native';
6
6
  import { Colors } from '../../../configs';
7
7
  import Text from '../../../commons/Text';
8
8
  import { useRoute } from '@react-navigation/native';
@@ -30,7 +30,7 @@ const EditDevice = memo(() => {
30
30
  useEditDevice();
31
31
  const renameSensor = useCallback(async () => {
32
32
  const { success, data } = await axiosPatch(
33
- API.DEVICE.SENSOR_DETAIL(sensor?.id),
33
+ API.DEVICE.DEVICE_DETAIL(sensor?.id),
34
34
  {
35
35
  name: inputName,
36
36
  }
@@ -55,7 +55,7 @@ const EditDevice = memo(() => {
55
55
 
56
56
  const deleteSensor = useCallback(async () => {
57
57
  hideAlertAction();
58
- const { success } = await axiosDelete(API.DEVICE.SENSOR_DETAIL(sensor?.id));
58
+ const { success } = await axiosDelete(API.DEVICE.DEVICE_DETAIL(sensor?.id));
59
59
 
60
60
  if (success) {
61
61
  navigation.pop(2);
@@ -92,7 +92,7 @@ const EditDevice = memo(() => {
92
92
  <Text type="Body" Reugular color={Colors.Grey7}>
93
93
  {sensorName}
94
94
  </Text>
95
- <AntDesign
95
+ <IconOutline
96
96
  name="right"
97
97
  size={18}
98
98
  color={Colors.Gray7}
@@ -0,0 +1,300 @@
1
+ import React from 'react';
2
+ import { Alert } from 'react-native';
3
+ import { act } from 'react-test-renderer';
4
+ import MockAdapter from 'axios-mock-adapter';
5
+ import { NavigationContext } from '@react-navigation/native';
6
+
7
+ import DeviceDetail from '../detail';
8
+ import { API } from '../../../configs';
9
+ import { AccessibilityLabel } from '../../../configs/Constants';
10
+ import { SCProvider } from '../../../context';
11
+ import { mockSCStore } from '../../../context/mockStore';
12
+ import api from '../../../utils/Apis/axios';
13
+ import { useWatchConfigs } from '../../../hooks/IoT';
14
+ import { render } from '../../../../jest/render';
15
+ import { BleManager } from 'react-native-ble-plx';
16
+ import { v4 as uuidv4 } from 'uuid';
17
+ import base64 from 'react-native-base64';
18
+
19
+ const mock = new MockAdapter(api.axiosInstance);
20
+
21
+ jest.mock('../../../hooks/IoT', () => {
22
+ return {
23
+ ...jest.requireActual('../../../hooks/IoT'),
24
+ useWatchConfigs: jest.fn(),
25
+ };
26
+ });
27
+
28
+ jest.mock('../../../hooks/Common', () => {
29
+ return {
30
+ ...jest.requireActual('../../../hooks/Common'),
31
+ useHomeAssistantDeviceConnected: () => ({ isConnected: true }),
32
+ };
33
+ });
34
+
35
+ let store = mockSCStore({});
36
+
37
+ const navContextValue = {
38
+ isFocused: () => false,
39
+ addListener: jest.fn(() => jest.fn()),
40
+ };
41
+
42
+ const wrapComponent = (state, account, route) => (
43
+ <SCProvider initState={state}>
44
+ <NavigationContext.Provider
45
+ value={{
46
+ ...navContextValue,
47
+ isFocused: () => true,
48
+ }}
49
+ >
50
+ <DeviceDetail account={account} route={route} />
51
+ </NavigationContext.Provider>
52
+ </SCProvider>
53
+ );
54
+
55
+ const mockAlertShow = jest.fn();
56
+ Alert.alert = mockAlertShow;
57
+
58
+ describe('test DeviceDetail', () => {
59
+ let route;
60
+ let account;
61
+ const address = uuidv4();
62
+ const password = uuidv4();
63
+ const device = {
64
+ connect: jest.fn(() => Promise.resolve(device)),
65
+ discoverAllServicesAndCharacteristics: jest.fn(() =>
66
+ Promise.resolve(device)
67
+ ),
68
+ writeCharacteristicWithoutResponseForService: jest.fn(),
69
+ writeCharacteristicWithResponseForService: jest.fn(),
70
+ cancelConnection: jest.fn(),
71
+ readCharacteristicForService: jest.fn((service, characteristic) => ({
72
+ value: base64.encode('confirmed'),
73
+ })),
74
+ };
75
+ const bleManager = new BleManager();
76
+ bleManager.startDeviceScan.mockImplementation((uuids, options, handler) =>
77
+ handler(null, device)
78
+ );
79
+
80
+ beforeEach(() => {
81
+ device.connect.mockClear();
82
+ device.cancelConnection.mockClear();
83
+ device.discoverAllServicesAndCharacteristics.mockClear();
84
+ device.writeCharacteristicWithoutResponseForService.mockClear();
85
+ device.writeCharacteristicWithResponseForService.mockClear();
86
+ device.readCharacteristicForService.mockClear();
87
+
88
+ mock.onGet(API.DEVICE.DEVICE_DETAIL(1)).reply(200, {
89
+ id: 1,
90
+ is_enable_bluetooth: true,
91
+ remote_control_options: {
92
+ bluetooth: {
93
+ address,
94
+ password,
95
+ },
96
+ },
97
+ });
98
+
99
+ mock.onGet(API.DEVICE.DISPLAY(1)).reply(200, {
100
+ items: [
101
+ {
102
+ configuration: {
103
+ action1: '2b949045-8e03-4c07-a855-7794ade2e69c',
104
+ action1_data: {
105
+ color: '#00979D',
106
+ command_prefer_over_bluetooth: true,
107
+ command_prefer_over_googlehome: false,
108
+ command_prefer_over_internet: false,
109
+ googlehome_actions: [],
110
+ icon: 'caretup',
111
+ id: 9,
112
+ key: '2b949045-8e03-4c07-a855-7794ade2e69c',
113
+ arduino_action: {
114
+ value: 1,
115
+ pin: {
116
+ pin_number: 2,
117
+ },
118
+ },
119
+ },
120
+ action2: '38347d5e-4418-4ab0-978c-c82f4c034897',
121
+ action2_data: {
122
+ color: '#00979D',
123
+ command_prefer_over_bluetooth: false,
124
+ command_prefer_over_googlehome: false,
125
+ command_prefer_over_internet: true,
126
+ googlehome_actions: [],
127
+ icon: 'stop',
128
+ id: 11,
129
+ key: '38347d5e-4418-4ab0-978c-c82f4c034897',
130
+ },
131
+ action3: 'a492e08c-8cb1-44ee-8ea0-46aaca4e5141',
132
+ action3_data: {
133
+ color: '#00979D',
134
+ command_prefer_over_bluetooth: false,
135
+ command_prefer_over_googlehome: false,
136
+ command_prefer_over_internet: true,
137
+ googlehome_actions: [],
138
+ icon: 'caretdown',
139
+ id: 10,
140
+ key: 'a492e08c-8cb1-44ee-8ea0-46aaca4e5141',
141
+ },
142
+ icon1: 'caretup',
143
+ icon2: 'stop',
144
+ icon3: 'caretdown',
145
+ text1: 'UP',
146
+ text2: 'STOP/UNLOCK',
147
+ text3: 'DOWN',
148
+ },
149
+ id: 19,
150
+ order: 2,
151
+ template: 'three_button_action_template',
152
+ type: 'action',
153
+ },
154
+ ],
155
+ side_menu_items: [{ id: 1, order: 1, name: 'Setup generate passcode' }],
156
+ });
157
+ route = {
158
+ params: {
159
+ unitData: {
160
+ id: 1,
161
+ name: 'Unit name',
162
+ address: '298 Dien Bien Phu',
163
+ remote_control_options: {
164
+ googlehome: [
165
+ {
166
+ config_maps: [],
167
+ auth: {},
168
+ chip_id: 1,
169
+ },
170
+ ],
171
+ },
172
+ },
173
+ station: {
174
+ id: 2,
175
+ name: 'Station name',
176
+ },
177
+ sensorData: {
178
+ id: 1,
179
+ is_managed_by_backend: true,
180
+ station: { id: 2, name: 'Station name' },
181
+ name: 'Sensor name',
182
+ chip_id: 1,
183
+ },
184
+ title: 'Button',
185
+ },
186
+ };
187
+ account = {
188
+ token: 'abc',
189
+ };
190
+ jest.useFakeTimers();
191
+
192
+ const setState = jest.fn();
193
+ const useLayoutEffectSpy = jest.spyOn(React, 'useLayoutEffect');
194
+ useLayoutEffectSpy.mockImplementation(() => setState);
195
+ useWatchConfigs.mockReset();
196
+ });
197
+
198
+ it('scan bluetooth if available', async () => {
199
+ await render(wrapComponent(store, account, route));
200
+ jest.runAllTimers();
201
+ expect(bleManager.stopDeviceScan).toHaveBeenCalledTimes(2);
202
+ expect(bleManager.startDeviceScan).toHaveBeenCalledTimes(1);
203
+ expect(bleManager.startDeviceScan.mock.calls[0][0]).toEqual([address]);
204
+ });
205
+
206
+ it('connect to first device', async () => {
207
+ await render(wrapComponent(store, account, route));
208
+ jest.runAllTimers();
209
+ expect(bleManager.stopDeviceScan).toHaveBeenCalledTimes(2);
210
+ expect(device.connect).toHaveBeenCalledTimes(1);
211
+ expect(device.discoverAllServicesAndCharacteristics).toHaveBeenCalledTimes(
212
+ 1
213
+ );
214
+ expect(
215
+ device.writeCharacteristicWithoutResponseForService
216
+ ).toHaveBeenCalledTimes(1);
217
+ expect(
218
+ device.writeCharacteristicWithResponseForService
219
+ ).toHaveBeenCalledTimes(1);
220
+ expect(
221
+ base64.decode(
222
+ device.writeCharacteristicWithoutResponseForService.mock.calls[0][2]
223
+ )
224
+ ).toEqual('start');
225
+ const confirmMessage =
226
+ device.writeCharacteristicWithResponseForService.mock.calls[0][2];
227
+ expect(base64.decode(confirmMessage).substring(0, 7)).toEqual('confirm');
228
+ });
229
+
230
+ it('disconnect when leave screen', async () => {
231
+ const { unmount } = await render(wrapComponent(store, account, route));
232
+ jest.runAllTimers();
233
+ await act(async () => {
234
+ unmount();
235
+ });
236
+ expect(device.cancelConnection).toHaveBeenCalledTimes(1);
237
+ });
238
+
239
+ it('fail scan', async () => {
240
+ bleManager.startDeviceScan.mockImplementationOnce(
241
+ (uuids, options, handler) => handler('error', device)
242
+ );
243
+ await render(wrapComponent(store, account, route));
244
+ jest.runAllTimers();
245
+ expect(bleManager.stopDeviceScan).toHaveBeenCalledTimes(1);
246
+ expect(device.connect).toHaveBeenCalledTimes(0);
247
+ });
248
+
249
+ it('control arduino pin device', async () => {
250
+ const { root } = await render(wrapComponent(store, account, route));
251
+ jest.runAllTimers();
252
+ const button = root.findByProps({
253
+ accessibilityLabel: AccessibilityLabel.BUTTON_TEMPLATE_1,
254
+ });
255
+ device.writeCharacteristicWithResponseForService.mockClear();
256
+ device.writeCharacteristicWithoutResponseForService.mockClear();
257
+ await act(async () => {
258
+ await button.props.onPress();
259
+ });
260
+ expect(
261
+ device.writeCharacteristicWithResponseForService
262
+ ).toHaveBeenCalledTimes(1);
263
+ });
264
+
265
+ it('control arduino pin fail', async () => {
266
+ device.readCharacteristicForService.mockReturnValue({ value: 'wrong' });
267
+ const { root } = await render(wrapComponent(store, account, route));
268
+ jest.runAllTimers();
269
+ const button = root.findByProps({
270
+ accessibilityLabel: AccessibilityLabel.BUTTON_TEMPLATE_1,
271
+ });
272
+ device.writeCharacteristicWithResponseForService.mockClear();
273
+ device.writeCharacteristicWithoutResponseForService.mockClear();
274
+ await act(async () => {
275
+ await button.props.onPress();
276
+ });
277
+ expect(
278
+ device.writeCharacteristicWithResponseForService
279
+ ).toHaveBeenCalledTimes(0);
280
+ });
281
+
282
+ it('control after fail scan', async () => {
283
+ bleManager.startDeviceScan.mockImplementationOnce(
284
+ (uuids, options, handler) => handler('error', device)
285
+ );
286
+ const { root } = await render(wrapComponent(store, account, route));
287
+ jest.runAllTimers();
288
+ const button = root.findByProps({
289
+ accessibilityLabel: AccessibilityLabel.BUTTON_TEMPLATE_1,
290
+ });
291
+ device.writeCharacteristicWithResponseForService.mockClear();
292
+ device.writeCharacteristicWithoutResponseForService.mockClear();
293
+ await act(async () => {
294
+ await button.props.onPress();
295
+ });
296
+ expect(
297
+ device.writeCharacteristicWithResponseForService
298
+ ).toHaveBeenCalledTimes(0);
299
+ });
300
+ });
@@ -1,24 +1,23 @@
1
+ import { NavigationContext, useNavigation } from '@react-navigation/native';
2
+ import MockAdapter from 'axios-mock-adapter';
1
3
  import React from 'react';
2
4
  import { Alert, ScrollView } from 'react-native';
3
5
  import { act, create } from 'react-test-renderer';
4
- import MockAdapter from 'axios-mock-adapter';
5
- import { NavigationContext, useNavigation } from '@react-navigation/native';
6
-
7
- import DeviceDetail from '../detail';
8
- import { API } from '../../../configs';
6
+ import { AlertAction, ButtonPopup, MenuActionMore } from '../../../commons';
7
+ import CurrentRainSensor from '../../../commons/Device/RainningSensor/CurrentRainSensor';
9
8
  import { AlertSendConfirm } from '../../../commons/EmergencyButton/AlertSendConfirm';
10
9
  import { AlertSent } from '../../../commons/EmergencyButton/AlertSent';
11
- import { AlertAction, ButtonPopup, MenuActionMore } from '../../../commons';
12
- import { AccessibilityLabel } from '../../../configs/Constants';
13
10
  import Text from '../../../commons/Text';
14
- import AntDesign from 'react-native-vector-icons/AntDesign';
15
- import CurrentRainSensor from '../../../commons/Device/RainningSensor/CurrentRainSensor';
16
- import { getTranslate } from '../../../utils/I18n';
11
+ import { API } from '../../../configs';
12
+ import { AccessibilityLabel } from '../../../configs/Constants';
17
13
  import { SCProvider } from '../../../context';
18
14
  import { mockSCStore } from '../../../context/mockStore';
19
- import Routes from '../../../utils/Route';
20
- import api from '../../../utils/Apis/axios';
21
15
  import { useWatchConfigs } from '../../../hooks/IoT';
16
+ import api from '../../../utils/Apis/axios';
17
+ import { getTranslate } from '../../../utils/I18n';
18
+ import Routes from '../../../utils/Route';
19
+ import DeviceDetail from '../detail';
20
+ import { IconOutline } from '@ant-design/icons-react-native';
22
21
 
23
22
  const mock = new MockAdapter(api.axiosInstance);
24
23
 
@@ -352,7 +351,8 @@ describe('test DeviceDetail', () => {
352
351
  const buttonPopupIcon = instance.find(
353
352
  (el) =>
354
353
  el.props.accessibilityLabel ===
355
- AccessibilityLabel.BUTTON_POPUP_RESOLVED_ICON && el.type === AntDesign
354
+ AccessibilityLabel.BUTTON_POPUP_RESOLVED_ICON &&
355
+ el.type === IconOutline
356
356
  );
357
357
  expect(buttonPopupTitle.props.children).toEqual([
358
358
  'Unit name',
@@ -755,7 +755,7 @@ describe('test DeviceDetail', () => {
755
755
  await act(async () => {
756
756
  await create(wrapComponent(store, account, route));
757
757
  });
758
- expect(mockAlertShow).not.toBeCalled();
758
+ expect(mockAlertShow).not.toHaveBeenCalled();
759
759
  });
760
760
 
761
761
  it('Test fetchUnitDetail', async () => {
@@ -1,22 +1,22 @@
1
+ import { NavigationContext } from '@react-navigation/native';
2
+ import MockAdapter from 'axios-mock-adapter';
3
+ import mqtt from 'precompiled-mqtt/dist/mqtt.browser';
1
4
  import React from 'react';
2
5
  import { Alert } from 'react-native';
3
6
  import { act, create } from 'react-test-renderer';
4
- import MockAdapter from 'axios-mock-adapter';
5
- import mqtt from 'precompiled-mqtt/dist/mqtt.browser';
6
- import { NavigationContext } from '@react-navigation/native';
7
7
 
8
- import DeviceDetail from '../detail';
8
+ import QualityIndicatorItem from '../../../commons/Device/WaterQualitySensor/QualityIndicatorsItem';
9
9
  import { API } from '../../../configs';
10
10
  import { SCProvider } from '../../../context';
11
11
  import { mockSCStore } from '../../../context/mockStore';
12
+ import { watchMultiConfigs } from '../../../iot/Monitor';
13
+ import { setConfigGlobalState } from '../../../iot/states';
12
14
  import api from '../../../utils/Apis/axios';
13
15
  import {
14
- gatewayDataFactory,
15
16
  configDataFactory,
17
+ gatewayDataFactory,
16
18
  } from '../../../utils/FactoryGateway';
17
- import QualityIndicatorItem from '../../../commons/Device/WaterQualitySensor/QualityIndicatorsItem';
18
- import { watchMultiConfigs } from '../../../iot/Monitor';
19
- import { setConfigGlobalState } from '../../../iot/states';
19
+ import DeviceDetail from '../detail';
20
20
 
21
21
  const mock = new MockAdapter(api.axiosInstance);
22
22
 
@@ -194,7 +194,7 @@ describe('test DeviceDetail', () => {
194
194
  await act(async () => {
195
195
  tree.unmount();
196
196
  });
197
- expect(client.end).toBeCalled();
197
+ expect(client.end).toHaveBeenCalled();
198
198
  });
199
199
 
200
200
  const _receiveDataOnDeviceDetail = async (widgetConfigs, topic, message) => {
@@ -0,0 +1,135 @@
1
+ /* eslint-disable no-console */
2
+ // console log is required for debug, this feature has a lot of debugging
3
+ import { useCallback, useEffect, useRef, useState } from 'react';
4
+ import base64 from 'react-native-base64';
5
+ import { ScanMode } from 'react-native-ble-plx';
6
+ import md5 from 'md5';
7
+ import { bleManager } from '../../../utils/bluetooth';
8
+
9
+ const CHARACTERISTIC_CONFIRM_CODE_UUID = '6ee26cfb-b42f-43ae-9ecf-f70d84bbd64f';
10
+ const CHARACTERISTIC_CONTROL_UUID = 'f0e7aa38-e466-42af-b4c7-5e6ec5c9a614';
11
+
12
+ export const useBluetoothDevice = (device) => {
13
+ const serviceUuid = device?.remote_control_options?.bluetooth?.address;
14
+ const password = device?.remote_control_options?.bluetooth?.password;
15
+ const deviceRef = useRef(null);
16
+ const [isConnected, setIsConnected] = useState(false);
17
+
18
+ useEffect(() => {
19
+ // on unmount, disconnect bluetooth, so it can be reused again
20
+ return () => {
21
+ if (isConnected) {
22
+ deviceRef.current.cancelConnection();
23
+ }
24
+ };
25
+ }, [isConnected]);
26
+
27
+ const control = useCallback(
28
+ (action, data) => {
29
+ if (!isConnected) {
30
+ return;
31
+ }
32
+
33
+ const value =
34
+ data?.value === undefined ? action.arduino_action.value : data?.value;
35
+ const message = `${action.arduino_action.pin.pin_number};${value}`;
36
+
37
+ console.log('control', message);
38
+
39
+ deviceRef.current.writeCharacteristicWithResponseForService(
40
+ serviceUuid,
41
+ CHARACTERISTIC_CONTROL_UUID,
42
+ base64.encode(message)
43
+ );
44
+ },
45
+ [isConnected, serviceUuid]
46
+ );
47
+
48
+ const sendConfirmCode = useCallback(
49
+ async (instanceCode) => {
50
+ console.log(`sendConfirmCode ${instanceCode}`);
51
+ const confirmCode = md5(`${password}${instanceCode}`);
52
+
53
+ await deviceRef.current.writeCharacteristicWithResponseForService(
54
+ serviceUuid,
55
+ CHARACTERISTIC_CONFIRM_CODE_UUID,
56
+ base64.encode('confirm' + confirmCode)
57
+ );
58
+ const result = await deviceRef.current.readCharacteristicForService(
59
+ serviceUuid,
60
+ CHARACTERISTIC_CONFIRM_CODE_UUID
61
+ );
62
+ const resultText = base64.decode(result.value);
63
+ console.log(resultText);
64
+ if (resultText.includes('confirmed')) {
65
+ setIsConnected(true);
66
+ return true;
67
+ }
68
+ return false;
69
+ },
70
+ [password, serviceUuid]
71
+ );
72
+
73
+ const askInstanceCode = useCallback(async () => {
74
+ console.log('askInstanceCode');
75
+
76
+ await deviceRef.current.writeCharacteristicWithoutResponseForService(
77
+ serviceUuid,
78
+ CHARACTERISTIC_CONFIRM_CODE_UUID,
79
+ base64.encode('start')
80
+ );
81
+ const response = await deviceRef.current.readCharacteristicForService(
82
+ serviceUuid,
83
+ CHARACTERISTIC_CONFIRM_CODE_UUID
84
+ );
85
+ return base64.decode(response.value);
86
+ }, [serviceUuid]);
87
+
88
+ const realConnect = useCallback(async () => {
89
+ // return await new Promise((resolve) => {
90
+ if (!serviceUuid || !password) {
91
+ console.log('Bluetooth is not enabled for this device');
92
+ return false;
93
+ }
94
+ console.log('start real connect');
95
+ try {
96
+ bleManager.stopDeviceScan();
97
+ } catch (e) {
98
+ /* istanbul ignore next */
99
+ console.log('Failed to stop scan');
100
+ }
101
+ bleManager.startDeviceScan(
102
+ [serviceUuid],
103
+ { scanMode: ScanMode?.LowLatency },
104
+ // eslint-disable-next-line promise/prefer-await-to-callbacks
105
+ async (error, bleDevice) => {
106
+ if (error) {
107
+ console.log(error);
108
+ return false;
109
+ }
110
+ console.log(bleDevice?.name, bleDevice?.localName);
111
+
112
+ console.log('bleManager.stopDeviceScan');
113
+ bleManager.stopDeviceScan();
114
+ console.log('device.connect');
115
+ const connectedDevice = await bleDevice.connect({ timeout: 5000 });
116
+
117
+ console.log('device.discoverAllServicesAndCharacteristics');
118
+ const fullInfoDevice =
119
+ await connectedDevice.discoverAllServicesAndCharacteristics();
120
+ console.log('device.publicCodeCharacteristic');
121
+ deviceRef.current = fullInfoDevice;
122
+
123
+ const instanceCode = await askInstanceCode();
124
+ return await sendConfirmCode(instanceCode);
125
+ }
126
+ );
127
+ // });
128
+ }, [askInstanceCode, password, sendConfirmCode, serviceUuid]);
129
+
130
+ useEffect(() => {
131
+ realConnect();
132
+ }, [realConnect]);
133
+
134
+ return { control, isConnected };
135
+ };