@eohjsc/react-native-smart-city 0.3.7 → 0.3.10

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 (292) hide show
  1. package/README.md +36 -15
  2. package/package.json +10 -6
  3. package/react-native-smart-city.podspec +1 -0
  4. package/src/commons/Action/ItemQuickAction.js +16 -4
  5. package/src/commons/Action/__test__/ItemQuickAction.test.js +11 -6
  6. package/src/commons/ActionGroup/ColorPickerTemplate.js +37 -24
  7. package/src/commons/ActionGroup/CurtainButtonTemplate.js +10 -5
  8. package/src/commons/ActionGroup/OnOffSmartLock/AutoLock/__test__/index.test.js +4 -0
  9. package/src/commons/ActionGroup/OnOffSmartLock/PasscodeList/ItemPasscode.js +1 -1
  10. package/src/commons/ActionGroup/OnOffSmartLock/PasscodeList/__test__/ItemPasscode.test.js +24 -0
  11. package/src/commons/ActionGroup/OnOffSmartLock/SetupGeneratePasscode/__test__/index.test.js +14 -0
  12. package/src/commons/ActionGroup/OnOffSmartLock/SetupGeneratePasscode/index.js +1 -0
  13. package/src/commons/ActionGroup/OnOffTemplate/OnOffButtonTemplate.js +8 -2
  14. package/src/commons/ActionGroup/OnOffTemplate/OnOffSimpleTemplate.js +10 -10
  15. package/src/commons/ActionGroup/OnOffTemplate/index.js +3 -2
  16. package/src/commons/ActionGroup/SliderRangeTemplate.js +6 -2
  17. package/src/commons/ActionGroup/SmartTiviActionTemplate/SmartTiviActionTemplate.js +7 -3
  18. package/src/commons/ActionGroup/StatesGridActionTemplate.js +22 -8
  19. package/src/commons/ActionGroup/TimerActionTemplate.js +11 -3
  20. package/src/commons/ActionGroup/TwoButtonTemplate/index.js +1 -5
  21. package/src/commons/ActionGroup/__test__/CurtainButtonTemplate.test.js +53 -4
  22. package/src/commons/ActionGroup/__test__/OnOffButtonTemplate.test.js +14 -14
  23. package/src/commons/ActionGroup/__test__/OnOffTemplate.test.js +53 -78
  24. package/src/commons/ActionGroup/__test__/OneBigButtonTemplate.test.js +36 -20
  25. package/src/commons/ActionGroup/__test__/StatesGridActionTemplate.test.js +77 -0
  26. package/src/commons/ActionGroup/__test__/TimerActionTemplate.test.js +58 -6
  27. package/src/commons/ActionGroup/__test__/TwoButtonTemplate.test.js +49 -1
  28. package/src/commons/ActionGroup/__test__/index.test.js +135 -0
  29. package/src/commons/Auth/AccountList.js +1 -1
  30. package/src/commons/Automate/ItemAutomate.js +1 -3
  31. package/src/commons/Calendar/__test__/Calendar.test.js +33 -0
  32. package/src/commons/Connecting/__test__/Connecting.test.js +19 -2
  33. package/src/commons/ConnectingProcess/DeviceItem/DeviceItem.js +7 -3
  34. package/src/commons/ConnectingProcess/DeviceItem/DeviceItemStyles.js +8 -11
  35. package/src/commons/ConnectingProcess/__test__/Connecting.test.js +136 -3
  36. package/src/commons/ConnectingProcess/__test__/DeviceItem.test.js +3 -2
  37. package/src/commons/ConnectingProcess/index.js +76 -26
  38. package/src/commons/Dashboard/MyPinnedSharedUnit/__test__/MyPinnedSharedUnit.test.js +16 -13
  39. package/src/commons/Dashboard/MyPinnedSharedUnit/index.js +1 -1
  40. package/src/commons/Dashboard/MyUnit/__test__/MyUnit.test.js +0 -5
  41. package/src/commons/Device/ConnectedViewHeader.js +1 -1
  42. package/src/commons/Device/Hanet/ItemHanetDevice.test.js +58 -0
  43. package/src/commons/Device/HistoryChart.js +7 -3
  44. package/src/commons/Device/ItemDevice.js +34 -13
  45. package/src/commons/Device/LinearChart.js +15 -0
  46. package/src/commons/Device/PMSensor/PMSensorIndicatior.js +16 -12
  47. package/src/commons/Device/PMSensor/PMSensorIndicatorStyles.js +3 -0
  48. package/src/commons/Device/SonosSpeaker/index.js +1 -1
  49. package/src/commons/Device/WaterQualitySensor/ListQualityIndicator.js +1 -0
  50. package/src/commons/Device/WaterQualitySensor/QualityIndicatorsItem.js +7 -2
  51. package/src/commons/Explore/__test__/CityItem.test.js +33 -54
  52. package/src/commons/FieldTemplate/ChooseUserField/ChooseFieldStyles.js +25 -0
  53. package/src/commons/FieldTemplate/ChooseUserField/ChoosePopup.js +96 -0
  54. package/src/commons/FieldTemplate/ChooseUserField/ChoosePopupStyles.js +39 -0
  55. package/src/commons/FieldTemplate/ChooseUserField/__test__/index.test.js +118 -0
  56. package/src/commons/FieldTemplate/ChooseUserField/index.js +62 -0
  57. package/src/commons/FieldTemplate/PasscodeField/PasscodeFieldStyles.js +30 -0
  58. package/src/commons/FieldTemplate/PasscodeField/__test__/index.test.js +90 -0
  59. package/src/commons/FieldTemplate/PasscodeField/index.js +43 -0
  60. package/src/commons/FieldTemplate/ScheduleField/ScheduleFieldStyles.js +13 -0
  61. package/src/commons/FieldTemplate/ScheduleField/__test__/index.test.js +179 -0
  62. package/src/commons/FieldTemplate/ScheduleField/index.js +176 -0
  63. package/src/commons/Form/CurrencyInput.js +15 -1
  64. package/src/commons/Form/TextInputPassword.js +1 -1
  65. package/src/commons/FullLoading/index.js +2 -1
  66. package/src/commons/Header/HeaderCustom.js +2 -1
  67. package/src/commons/HeaderAni/index.js +6 -1
  68. package/src/commons/HorizontalPicker/index.js +2 -2
  69. package/src/commons/MediaPlayerDetail/Styles/MediaPlayerDetailStyles.js +0 -6
  70. package/src/commons/MediaPlayerDetail/index.js +29 -47
  71. package/src/commons/MenuActionAddnew/index.js +1 -0
  72. package/src/commons/MenuActionList/index.js +1 -0
  73. package/src/commons/MenuActionMore/index.js +1 -1
  74. package/src/commons/PreventAccess/__test__/PreventAccess.test.js +62 -0
  75. package/src/commons/PreventAccess/index.js +9 -1
  76. package/src/commons/Sharing/MemberList.js +10 -2
  77. package/src/commons/Sharing/WrapHeaderScrollable.js +2 -0
  78. package/src/commons/Sharing/__test__/DevicePermissionsCheckbox.test.js +0 -1
  79. package/src/commons/SubUnit/Favorites/index.js +2 -3
  80. package/src/commons/SubUnit/OneTap/__test__/SubUnitAutomate.test.js +8 -35
  81. package/src/commons/SubUnit/OneTap/index.js +1 -2
  82. package/src/commons/SubUnit/ShortDetail.js +25 -9
  83. package/src/commons/SubUnit/__test__/Item.test.js +0 -1
  84. package/src/commons/SubUnit/__test__/ShortDetail.test.js +9 -2
  85. package/src/commons/Unit/SharedUnit.js +1 -0
  86. package/src/commons/Unit/__test__/SharedUnit.test.js +38 -183
  87. package/src/commons/UnitSummary/ConfigHistoryChart/__test__/ConfigHistoryChart.test.js +28 -1
  88. package/src/commons/UnitSummary/ConfigHistoryChart/index.js +2 -13
  89. package/src/commons/UnitSummary/ConfigHistoryChart.js +55 -13
  90. package/src/commons/WheelDateTimePicker/index.js +4 -3
  91. package/src/configs/API.js +87 -143
  92. package/src/configs/Constants.js +80 -1
  93. package/src/configs/SCConfig.js +4 -0
  94. package/src/context/actionType.ts +11 -0
  95. package/src/context/mockStore.ts +12 -0
  96. package/src/context/reducer.ts +57 -2
  97. package/src/hooks/Common/index.js +2 -0
  98. package/src/hooks/Common/useGGHomeDeviceConnected.js +16 -0
  99. package/src/hooks/Common/useGetIdUser.js +1 -5
  100. package/src/hooks/Common/useSensorsStatus.js +4 -4
  101. package/src/hooks/IoT/__test__/useGGHomeConnection.test.js +199 -0
  102. package/src/hooks/IoT/__test__/useRemoteControl.test.js +198 -0
  103. package/src/hooks/IoT/index.js +4 -0
  104. package/src/hooks/IoT/useGGHomeConnection.js +93 -0
  105. package/src/hooks/IoT/useRemoteControl.js +79 -0
  106. package/src/hooks/index.js +4 -0
  107. package/src/hooks/useReceiveNotifications.js +12 -7
  108. package/src/iot/Monitor.js +3 -2
  109. package/src/iot/RemoteControl/Bluetooth.js +1 -1
  110. package/src/iot/RemoteControl/GoogleHome.js +75 -49
  111. package/src/iot/RemoteControl/Internet.js +1 -1
  112. package/src/iot/RemoteControl/__test__/GoogleHome.test.js +95 -48
  113. package/src/iot/RemoteControl/__test__/Internet.test.js +18 -7
  114. package/src/iot/RemoteControl/__test__/LgThinq.test.js +36 -177
  115. package/src/iot/RemoteControl/index.js +52 -52
  116. package/src/navigations/UnitStack.js +11 -20
  117. package/src/navigations/UnitStackStyles.js +21 -0
  118. package/src/screens/AQIGuide/index.js +1 -1
  119. package/src/screens/ActivityLog/FilterPopup.js +2 -0
  120. package/src/screens/ActivityLog/__test__/index.test.js +38 -23
  121. package/src/screens/ActivityLog/hooks/__test__/index.test.js +51 -90
  122. package/src/screens/ActivityLog/hooks/index.js +1 -1
  123. package/src/screens/ActivityLog/index.js +2 -2
  124. package/src/screens/AddCommon/SelectSubUnit.js +1 -0
  125. package/src/screens/AddCommon/SelectUnit.js +1 -0
  126. package/src/screens/AddCommon/__test__/SelectSubUnit.test.js +13 -24
  127. package/src/screens/AddCommon/__test__/SelectUnit.test.js +9 -33
  128. package/src/screens/AddLocationMaps/__test__/index.test.js +265 -0
  129. package/src/screens/AddLocationMaps/index.js +48 -21
  130. package/src/screens/AddNewAction/SelectAction.js +32 -13
  131. package/src/screens/AddNewAction/SelectSensorDevices.js +8 -2
  132. package/src/screens/AddNewAction/SetupSensor.js +67 -32
  133. package/src/screens/AddNewAction/__test__/SelectAction.test.js +10 -91
  134. package/src/screens/AddNewAction/__test__/SelectSensorDevices.test.js +40 -26
  135. package/src/screens/AddNewAction/__test__/SetupSensor.test.js +2 -0
  136. package/src/screens/AddNewAutoSmart/__test__/AddNewAutoSmart.test.js +3 -1
  137. package/src/screens/AddNewAutoSmart/index.js +5 -2
  138. package/src/screens/AddNewDevice/ConnectingDevices.js +3 -3
  139. package/src/screens/AddNewDevice/__test__/AddNewDevice.test.js +42 -34
  140. package/src/screens/AddNewDevice/__test__/ConnectDevices.test.js +0 -4
  141. package/src/screens/AddNewDevice/__test__/ConnectingDevices.test.js +22 -22
  142. package/src/screens/AddNewDevice/hooks/ConnectDevices.js +1 -1
  143. package/src/screens/AddNewDevice/index.js +1 -0
  144. package/src/screens/AddNewGateway/PlugAndPlay/ConnectWifiWarning.js +23 -17
  145. package/src/screens/AddNewGateway/PlugAndPlay/GatewayWifiList.js +46 -40
  146. package/src/screens/AddNewGateway/PlugAndPlay/__test__/GatewayWifiList.test.js +64 -10
  147. package/src/screens/AddNewGateway/SelectGateway.js +1 -0
  148. package/src/screens/AddNewGateway/SetupGatewayWifi.js +2 -0
  149. package/src/screens/AddNewGateway/__test__/AddNewGateway.test.js +4 -6
  150. package/src/screens/AddNewGateway/__test__/ConnectedGateway.test.js +0 -4
  151. package/src/screens/AddNewGateway/__test__/ConnectingGateway.test.js +5 -29
  152. package/src/screens/AddNewGateway/__test__/SelectGateway.test.js +0 -4
  153. package/src/screens/AddNewGateway/__test__/SetupGateway.test.js +0 -4
  154. package/src/screens/AddNewGateway/index.js +1 -0
  155. package/src/screens/AddNewOneTap/__test__/AddNewOneTap.test.js +10 -24
  156. package/src/screens/AddNewOneTap/index.js +3 -2
  157. package/src/screens/AllCamera/index.js +4 -4
  158. package/src/screens/Automate/MultiUnits.js +8 -8
  159. package/src/screens/Automate/__test__/MultiUnits.test.js +6 -9
  160. package/src/screens/Automate/__test__/index.test.js +7 -12
  161. package/src/screens/Automate/index.js +5 -3
  162. package/src/screens/ConfirmUnitDeletion/__test__/ConfirmUnitDeletion.test.js +36 -8
  163. package/src/screens/ConfirmUnitDeletion/index.js +7 -1
  164. package/src/screens/Device/EditDevice/__test__/EditDevice.test.js +71 -22
  165. package/src/screens/Device/EditDevice/index.js +17 -15
  166. package/src/screens/Device/__test__/detail.test.js +33 -86
  167. package/src/screens/Device/components/DetailHistoryChart.js +1 -1
  168. package/src/screens/Device/components/SensorConnectStatusViewHeader.js +44 -24
  169. package/src/screens/Device/components/SensorDisplayItem.js +5 -2
  170. package/src/screens/Device/detail.js +85 -26
  171. package/src/screens/Device/hooks/useDisconnectedDevice.js +4 -4
  172. package/src/screens/Device/hooks/useFavoriteDevice.js +5 -9
  173. package/src/screens/DeviceInfo/__test__/index.test.js +0 -2
  174. package/src/screens/EditActionsList/index.js +1 -1
  175. package/src/screens/EmergencyContacts/EmergencyContactsSelectContacts.js +6 -3
  176. package/src/screens/EmergencyContacts/__test__/EmergencyContactAddNew.test.js +7 -19
  177. package/src/screens/EmergencyContacts/__test__/EmergencyContactList.test.js +20 -2
  178. package/src/screens/EmergencyContacts/__test__/EmergencyContactsSelectContacts.test.js +40 -23
  179. package/src/screens/EmergencySetting/components/DropDownItem.js +2 -2
  180. package/src/screens/EmergencySetting/index.js +4 -1
  181. package/src/screens/EnterPassword/__test__/EnterPassword.test.js +41 -25
  182. package/src/screens/Explore/index.js +2 -0
  183. package/src/screens/GuestInfo/__test__/index.test.js +14 -41
  184. package/src/screens/GuestInfo/components/RecurringDetail.js +1 -0
  185. package/src/screens/GuestInfo/components/TemporaryDetail.js +2 -2
  186. package/src/screens/HanetCamera/Detail.js +1 -1
  187. package/src/screens/HanetCamera/__test__/CaptureFaceID.test.js +8 -12
  188. package/src/screens/HanetCamera/__test__/Detail.test.js +27 -42
  189. package/src/screens/HanetCamera/__test__/ManageAccess.test.js +8 -5
  190. package/src/screens/HanetCamera/__test__/MemberInfo.test.js +10 -32
  191. package/src/screens/HanetCamera/components/RequestFaceIDPopup.js +3 -2
  192. package/src/screens/HanetCamera/hooks/__test__/useHanetCheckinData.test.js +43 -35
  193. package/src/screens/HanetCamera/hooks/__test__/useHanetPlaceMembers.test.js +10 -21
  194. package/src/screens/HanetCamera/hooks/useHanetCheckinData.js +11 -11
  195. package/src/screens/HanetCamera/hooks/useHanetPlaceMembers.js +11 -11
  196. package/src/screens/ManageAccess/__test__/ManageAccess.test.js +33 -22
  197. package/src/screens/ManageAccess/hooks/__test__/useManageAccess.test.js +44 -45
  198. package/src/screens/ManageAccess/hooks/index.js +7 -4
  199. package/src/screens/ManageAccess/index.js +2 -1
  200. package/src/screens/MoveToAnotherSubUnit/__test__/index.test.js +35 -12
  201. package/src/screens/MoveToAnotherSubUnit/index.js +6 -6
  202. package/src/screens/Notification/__test__/Notification.test.js +31 -25
  203. package/src/screens/Notification/__test__/NotificationItem.test.js +8 -7
  204. package/src/screens/Notification/components/NotificationItem.js +17 -20
  205. package/src/screens/Notification/index.js +13 -2
  206. package/src/screens/PlayBackCamera/Timer.js +2 -2
  207. package/src/screens/PlayBackCamera/__test__/index.test.js +87 -2
  208. package/src/screens/PlayBackCamera/index.js +54 -35
  209. package/src/screens/ScanChipQR/__test__/ScanChipQR.test.js +7 -20
  210. package/src/screens/ScanChipQR/components/QRScan/index.js +1 -0
  211. package/src/screens/ScanChipQR/hooks/index.js +15 -16
  212. package/src/screens/ScanSensorQR/__test__/ScanSensorQR.test.js +8 -24
  213. package/src/screens/ScriptDetail/__test__/index.test.js +17 -86
  214. package/src/screens/ScriptDetail/index.js +19 -14
  215. package/src/screens/SelectUnit/__test__/index.test.js +12 -55
  216. package/src/screens/SelectUnit/index.js +9 -4
  217. package/src/screens/SetSchedule/index.js +15 -11
  218. package/src/screens/SharedUnit/__test__/TabHeader.test.js +0 -2
  219. package/src/screens/SharedUnit/index.js +2 -0
  220. package/src/screens/Sharing/Components/SensorItem.js +10 -12
  221. package/src/screens/Sharing/InfoMemberUnit.js +1 -1
  222. package/src/screens/Sharing/MemberList.js +12 -11
  223. package/src/screens/Sharing/SelectPermission.js +136 -83
  224. package/src/screens/Sharing/__test__/InfoMemberUnit.test.js +47 -29
  225. package/src/screens/Sharing/__test__/MemberList.test.js +13 -127
  226. package/src/screens/Sharing/__test__/MemberList2.test.js +80 -0
  227. package/src/screens/Sharing/__test__/SelectPermission.test.js +28 -38
  228. package/src/screens/Sharing/__test__/SelectUser.test.js +17 -38
  229. package/src/screens/Sharing/hooks/index.js +3 -0
  230. package/src/screens/SideMenuDetail/SideMenuDetailStyles.js +28 -0
  231. package/src/screens/SideMenuDetail/__test__/index.test.js +154 -0
  232. package/src/screens/SideMenuDetail/index.js +148 -0
  233. package/src/screens/SmartIr/components/GroupButtonByType/GroupButtonByType.js +3 -2
  234. package/src/screens/SmartIr/components/SelectBrand.js +1 -1
  235. package/src/screens/SubUnit/AddSubUnit.js +23 -17
  236. package/src/screens/SubUnit/Detail.js +1 -2
  237. package/src/screens/SubUnit/EditSubUnit.js +15 -13
  238. package/src/screens/SubUnit/ManageSubUnit.js +13 -7
  239. package/src/screens/SubUnit/__test__/AddSubUnit.test.js +29 -89
  240. package/src/screens/SubUnit/__test__/Detail.test.js +31 -8
  241. package/src/screens/SubUnit/__test__/EditSubUnit.test.js +21 -89
  242. package/src/screens/SubUnit/__test__/ManageSubUnit.test.js +27 -1
  243. package/src/screens/SubUnit/hooks/__test__/useManageSubUnit.test.js +48 -45
  244. package/src/screens/SubUnit/hooks/useManageSubUnit.js +7 -7
  245. package/src/screens/SyncLGDevice/AddLGDevice.js +1 -0
  246. package/src/screens/SyncLGDevice/__test__/AddLGDevice.test.js +22 -91
  247. package/src/screens/TDSGuide/index.js +4 -1
  248. package/src/screens/UVIndexGuide/index.js +1 -1
  249. package/src/screens/Unit/ChooseLocation.js +7 -14
  250. package/src/screens/Unit/Detail.js +32 -75
  251. package/src/screens/Unit/ManageUnit.js +1 -0
  252. package/src/screens/Unit/SelectAddress.js +45 -23
  253. package/src/screens/Unit/SmartAccount.js +4 -4
  254. package/src/screens/Unit/Station/index.js +4 -0
  255. package/src/screens/Unit/Summaries.js +18 -2
  256. package/src/screens/Unit/__test__/CheckSendEmail.test.js +24 -29
  257. package/src/screens/Unit/__test__/ChooseLocation.test.js +27 -14
  258. package/src/screens/Unit/__test__/Detail.test.js +98 -199
  259. package/src/screens/Unit/__test__/ManageUnit.test.js +18 -42
  260. package/src/screens/Unit/__test__/SelectAddress.test.js +159 -49
  261. package/src/screens/Unit/__test__/SmartAccount.test.js +17 -9
  262. package/src/screens/Unit/__test__/SmartAccountItem.test.js +0 -1
  263. package/src/screens/Unit/__test__/Summaries.test.js +100 -0
  264. package/src/screens/Unit/components/MyAllUnit/__test__/MyAllUnit.test.js +36 -0
  265. package/src/screens/Unit/components/MyAllUnit/__test__/index.test.js +54 -0
  266. package/src/screens/Unit/components/MyUnitDevice/index.js +4 -4
  267. package/src/screens/Unit/components/SharedUnit/index.js +1 -0
  268. package/src/screens/Unit/components/__test__/MyUnitDevice.test.js +2 -2
  269. package/src/screens/Unit/components/__test__/SharedUnit.test.js +31 -34
  270. package/src/screens/Unit/hook/useUnitConnectRemoteDevices.js +50 -0
  271. package/src/screens/Unit/styles.js +8 -0
  272. package/src/screens/UnitSummary/__test__/index.test.js +91 -30
  273. package/src/screens/UnitSummary/components/3PPowerConsumption/__test__/3PPowerConsumption.test.js +31 -2
  274. package/src/screens/UnitSummary/components/PowerConsumeHistoryChart/__test__/index.test.js +7 -4
  275. package/src/screens/UnitSummary/components/PowerConsumeHistoryChart/index.js +2 -13
  276. package/src/screens/UnitSummary/components/PowerConsumption/__test__/ItemPower.test.js +0 -1
  277. package/src/screens/UnitSummary/components/PowerConsumption/__test__/PowerConsumption.test.js +14 -16
  278. package/src/screens/UnitSummary/components/RunningDevices/__test__/index.test.js +11 -2
  279. package/src/screens/UnitSummary/components/RunningDevices/index.js +7 -10
  280. package/src/screens/UnitSummary/components/Temperature/index.js +4 -4
  281. package/src/screens/UnitSummary/components/WaterQuality/Item/index.js +10 -2
  282. package/src/screens/UnitSummary/index.js +15 -1
  283. package/src/screens/WaterQualityGuide/index.js +1 -1
  284. package/src/utils/Apis/axios.js +54 -31
  285. package/src/utils/Converter/time.js +0 -18
  286. package/src/utils/I18n/translations/en.json +11 -1
  287. package/src/utils/I18n/translations/vi.json +12 -1
  288. package/src/utils/Permission/common.js +67 -0
  289. package/src/utils/Route/index.js +1 -0
  290. package/src/utils/Setting/Location.js +30 -0
  291. package/src/utils/Utils.js +12 -7
  292. package/src/utils/__test__/Utils.test.js +12 -0
@@ -10,6 +10,7 @@ import {
10
10
  UnitType,
11
11
  AutomateType,
12
12
  AppType,
13
+ IoTType,
13
14
  } from './actionType';
14
15
  import { uniq } from 'lodash';
15
16
 
@@ -22,6 +23,7 @@ export type ContextData = {
22
23
  unit: UnitType;
23
24
  automate: AutomateType;
24
25
  app: AppType;
26
+ iot: IoTType;
25
27
  };
26
28
 
27
29
  export type Action = {
@@ -56,6 +58,13 @@ export const initialState = {
56
58
  isNetworkConnected: false,
57
59
  camera_opened: [],
58
60
  },
61
+ iot: {
62
+ googlehome: {
63
+ isFirstTimeConnect: true,
64
+ isConnecting: false,
65
+ connections: {},
66
+ },
67
+ },
59
68
  };
60
69
 
61
70
  export const reducer = (currentState: ContextData, action: Action) => {
@@ -88,6 +97,7 @@ export const reducer = (currentState: ContextData, action: Action) => {
88
97
  }
89
98
 
90
99
  case Action.LIST_ACTION:
100
+ // eslint-disable-next-line no-case-declarations
91
101
  let newListAction = [...currentState.listAction];
92
102
 
93
103
  if (Object.keys(payload).length === 0) {
@@ -151,7 +161,9 @@ export const reducer = (currentState: ContextData, action: Action) => {
151
161
  }
152
162
 
153
163
  case Action.CAMERA_STATUS_CHANGE:
164
+ // eslint-disable-next-line no-case-declarations
154
165
  const { id, status } = payload;
166
+ // eslint-disable-next-line no-case-declarations
155
167
  const arrCameraTemp = currentState.app.camera_opened || [];
156
168
  if (status) {
157
169
  if (arrCameraTemp.length >= 4) {
@@ -205,7 +217,7 @@ export const reducer = (currentState: ContextData, action: Action) => {
205
217
  unit: {
206
218
  ...currentState.unit,
207
219
  favoriteDeviceIds: currentState.unit.favoriteDeviceIds.filter(
208
- (id) => id !== payload
220
+ (deviceId) => deviceId !== payload
209
221
  ),
210
222
  },
211
223
  };
@@ -234,11 +246,54 @@ export const reducer = (currentState: ContextData, action: Action) => {
234
246
  automate: {
235
247
  ...currentState.automate,
236
248
  starredScriptIds: currentState.automate.starredScriptIds.filter(
237
- (id) => id !== payload
249
+ (scriptId) => scriptId !== payload
238
250
  ),
239
251
  },
240
252
  };
241
253
 
254
+ case Action.SET_GOOGLE_HOME_CONNECTIONS:
255
+ return {
256
+ ...currentState,
257
+ iot: {
258
+ ...currentState.iot,
259
+ googlehome: {
260
+ ...currentState.iot.googlehome,
261
+ isFirstTimeConnect: false,
262
+ isConnecting: false,
263
+ connections: payload,
264
+ },
265
+ },
266
+ };
267
+ case Action.CHANGE_GOOGLE_HOME_CONN_STATE:
268
+ return {
269
+ ...currentState,
270
+ iot: {
271
+ ...currentState.iot,
272
+ googlehome: {
273
+ ...currentState.iot.googlehome,
274
+ isFirstTimeConnect: false,
275
+ isConnecting: false,
276
+ connections: {
277
+ ...currentState.iot.googlehome.connections,
278
+ [payload.option.chip_id]: payload.data,
279
+ },
280
+ },
281
+ },
282
+ };
283
+ case Action.CONNECTING_GOOGLE_HOME:
284
+ return {
285
+ ...currentState,
286
+ iot: {
287
+ ...currentState.iot,
288
+ googlehome: {
289
+ ...currentState.iot.googlehome,
290
+ isConnecting: currentState.iot.googlehome.isFirstTimeConnect
291
+ ? true
292
+ : false,
293
+ },
294
+ },
295
+ };
296
+
242
297
  default:
243
298
  return currentState;
244
299
  }
@@ -5,6 +5,7 @@ import useKeyboardShow from './useKeyboardShow';
5
5
  import usePopover from './usePopover';
6
6
  import useTitleHeader from './useTitleHeader';
7
7
  import useSensorsStatus from './useSensorsStatus';
8
+ import useGGHomeDeviceConnected from './useGGHomeDeviceConnected';
8
9
  import { useBlockBackAndroid } from './useBlockBackAndroid';
9
10
  import { useIsOwnerOfUnit } from './useIsOwnerOfUnit';
10
11
  import { useStatusBar } from './useStatusBar';
@@ -22,4 +23,5 @@ export {
22
23
  useStatusBar,
23
24
  useGetIdUser,
24
25
  useSensorsStatus,
26
+ useGGHomeDeviceConnected,
25
27
  };
@@ -0,0 +1,16 @@
1
+ import { useSCContextSelector } from '../../context';
2
+
3
+ const useGGHomeDeviceConnected = (device) => {
4
+ const { connections, isConnecting } = useSCContextSelector(
5
+ (state) => state.iot.googlehome
6
+ );
7
+
8
+ const isConnected =
9
+ !!device?.chip_id &&
10
+ device.chip_id in connections &&
11
+ !!connections[device.chip_id];
12
+
13
+ return { isConnected, isConnecting };
14
+ };
15
+
16
+ export default useGGHomeDeviceConnected;
@@ -1,9 +1,5 @@
1
1
  import { useSCContextSelector } from '../../context';
2
2
 
3
3
  export const useGetIdUser = () => {
4
- // eslint-disable-next-line react-hooks/rules-of-hooks
5
- const idUser = useSCContextSelector(
6
- (state) => state?.auth?.account?.user?.id
7
- );
8
- return idUser;
4
+ return useSCContextSelector((state) => state?.auth?.account?.user?.id);
9
5
  };
@@ -12,14 +12,14 @@ const useSensorsStatus = (unit, sensors) => {
12
12
 
13
13
  // eslint-disable-next-line react-hooks/exhaustive-deps
14
14
  const getSensorsStatus = useCallback(
15
- throttle(async (unit, sensors) => {
15
+ throttle(async (_unit, _sensors) => {
16
16
  const params = new URLSearchParams();
17
- if (sensors?.length > 0) {
18
- sensors.forEach((sensor) => {
17
+ if (_sensors?.length > 0) {
18
+ _sensors.forEach((sensor) => {
19
19
  params.append('sensors', sensor.id);
20
20
  });
21
21
  const { success, data, resp_status } = await axiosGet(
22
- API.UNIT.SENSORS_STATUS(unit.id),
22
+ API.UNIT.SENSORS_STATUS(_unit.id),
23
23
  {
24
24
  params: params,
25
25
  }
@@ -0,0 +1,199 @@
1
+ import React from 'react';
2
+ import { act, renderHook } from '@testing-library/react-hooks';
3
+ import { createConnection, getStates } from 'home-assistant-js-websocket';
4
+ import MockAdapter from 'axios-mock-adapter';
5
+ import api from '../../../utils/Apis/axios';
6
+ import { useGGHomeConnection } from '../index';
7
+ import { SCProvider } from '../../../context';
8
+ import { mockSCStore } from '../../../context/mockStore';
9
+ import { Action } from '../../../context/actionType';
10
+ import { API } from '../../../configs';
11
+
12
+ const mock = new MockAdapter(api.axiosInstance);
13
+
14
+ jest.mock('home-assistant-js-websocket', () => {
15
+ return {
16
+ Auth: jest.fn(),
17
+ createConnection: jest.fn(),
18
+ getStates: jest.fn(),
19
+ };
20
+ });
21
+
22
+ getStates.mockImplementation(() => []);
23
+
24
+ const connection = {
25
+ subscribeEvents: jest.fn(),
26
+ addEventListener: jest.fn(),
27
+ sendMessagePromise: jest.fn(),
28
+ close: jest.fn(),
29
+ };
30
+
31
+ const mockedSetAction = jest.fn();
32
+
33
+ const wrapper = ({ children }) => <SCProvider>{children}</SCProvider>;
34
+
35
+ const mockUseContext = jest.fn().mockImplementation(() => ({
36
+ stateData: mockSCStore({}),
37
+ setAction: mockedSetAction,
38
+ }));
39
+
40
+ React.useContext = mockUseContext;
41
+
42
+ describe('Test useGGHomeConnection', () => {
43
+ let options;
44
+
45
+ beforeEach(() => {
46
+ createConnection.mockClear();
47
+ mockedSetAction.mockClear();
48
+ options = [
49
+ {
50
+ auth: {},
51
+ chip_id: 1,
52
+ text_maps: {
53
+ here: 10,
54
+ },
55
+ config_maps: [
56
+ {
57
+ entity_id: 'group.sensor',
58
+ config_id: 1,
59
+ value_type: 'boolean',
60
+ attribute_maps: [
61
+ {
62
+ config_id: 2,
63
+ attribute_name: 'battery',
64
+ value_type: 'int',
65
+ },
66
+ {
67
+ config_id: 3,
68
+ attribute_name: 'name',
69
+ value_type: 'text',
70
+ },
71
+ {
72
+ config_id: 4,
73
+ attribute_name: 'height',
74
+ value_type: 'number',
75
+ },
76
+ ],
77
+ },
78
+ ],
79
+ },
80
+ {
81
+ auth: {},
82
+ chip_id: 2,
83
+ text_maps: {
84
+ here: 10,
85
+ },
86
+ config_maps: [
87
+ {
88
+ entity_id: 'group.sensor',
89
+ config_id: 1,
90
+ value_type: 'boolean',
91
+ attribute_maps: [
92
+ {
93
+ config_id: 2,
94
+ attribute_name: 'battery',
95
+ value_type: 'int',
96
+ },
97
+ {
98
+ config_id: 3,
99
+ attribute_name: 'name',
100
+ value_type: 'text',
101
+ },
102
+ {
103
+ config_id: 4,
104
+ attribute_name: 'height',
105
+ value_type: 'number',
106
+ },
107
+ ],
108
+ },
109
+ ],
110
+ },
111
+ ];
112
+ });
113
+
114
+ it('test connectGoogleHome all connected', async () => {
115
+ let conns = {};
116
+ options.forEach((option) => {
117
+ conns[option.chip_id] = connection;
118
+ createConnection.mockImplementationOnce(() => connection);
119
+ });
120
+ const { result } = renderHook(() => useGGHomeConnection(), {
121
+ wrapper,
122
+ });
123
+
124
+ await act(async () => {
125
+ await result.current.connectGoogleHome(options);
126
+ });
127
+ expect(mockedSetAction).toBeCalledWith(
128
+ Action.SET_GOOGLE_HOME_CONNECTIONS,
129
+ conns
130
+ );
131
+ });
132
+
133
+ it('test connectGoogleHome have chip disconnected', async () => {
134
+ let conns = {};
135
+ conns[options[0].chip_id] = connection;
136
+ conns[options[1].chip_id] = 0;
137
+ createConnection.mockImplementationOnce(() => connection);
138
+ createConnection.mockImplementationOnce(async () => {
139
+ throw new Error();
140
+ });
141
+ const { result } = renderHook(() => useGGHomeConnection(), {
142
+ wrapper,
143
+ });
144
+
145
+ await act(async () => {
146
+ await result.current.connectGoogleHome(options);
147
+ });
148
+ expect(mockedSetAction).toBeCalledWith(
149
+ Action.SET_GOOGLE_HOME_CONNECTIONS,
150
+ conns
151
+ );
152
+ });
153
+
154
+ it('test connectGooleHome all chip disconnected', async () => {
155
+ let conns = {};
156
+ options.forEach((option) => {
157
+ conns[option.chip_id] = 0;
158
+ createConnection.mockImplementationOnce(async () => {
159
+ throw new Error();
160
+ });
161
+ });
162
+ const { result } = renderHook(() => useGGHomeConnection(), {
163
+ wrapper,
164
+ });
165
+
166
+ mock.onPost(API.GOOGLE_HOME.CHECK_SEND_EMAIL()).reply(200);
167
+ await act(async () => {
168
+ await result.current.connectGoogleHome(options);
169
+ });
170
+ expect(mockedSetAction).toBeCalledTimes(3);
171
+ expect(mockedSetAction).toBeCalledWith(Action.CONNECTING_GOOGLE_HOME);
172
+ expect(mockedSetAction).toBeCalledWith(
173
+ Action.SET_GOOGLE_HOME_CONNECTIONS,
174
+ conns
175
+ );
176
+ expect(mockedSetAction).toBeCalledWith(Action.LIST_DEVICE_TYPES, {
177
+ chipId: options[0].chip_id,
178
+ sentEmail: true,
179
+ });
180
+ });
181
+
182
+ it('test disconnectGoogleHome', async () => {
183
+ let conns = {};
184
+ conns[options[0].chip_id] = connection;
185
+ conns[options[1].chip_id] = 0;
186
+
187
+ const { result } = renderHook(() => useGGHomeConnection(), {
188
+ wrapper,
189
+ });
190
+
191
+ await act(async () => {
192
+ await result.current.disconnectGoogleHome(conns, options);
193
+ });
194
+ expect(mockedSetAction).toBeCalledWith(
195
+ Action.SET_GOOGLE_HOME_CONNECTIONS,
196
+ {}
197
+ );
198
+ });
199
+ });
@@ -0,0 +1,198 @@
1
+ import React from 'react';
2
+ import { act, renderHook } from '@testing-library/react-hooks';
3
+ import { useRemoteControl } from '../index';
4
+ import {
5
+ sendCommandOverBluetooth,
6
+ SEND_COMMAND_OVER_BLUETOOTH_FAIL,
7
+ } from '../../../iot/RemoteControl/Bluetooth';
8
+ import { sendCommandOverGoogleHome } from '../../../iot/RemoteControl/GoogleHome';
9
+ import { sendCommandOverInternet } from '../../../iot/RemoteControl/Internet';
10
+ import { sendCommandOverLGThinq } from '../../../iot/RemoteControl/LG';
11
+ import { SCProvider } from '../../../context';
12
+ import { mockSCStore } from '../../../context/mockStore';
13
+
14
+ jest.mock('../../../iot/RemoteControl/Bluetooth');
15
+ jest.mock('../../../iot/RemoteControl/GoogleHome');
16
+ jest.mock('../../../iot/RemoteControl/Internet');
17
+ jest.mock('../../../iot/RemoteControl/LG');
18
+
19
+ const mockedSetAction = jest.fn();
20
+
21
+ const wrapper = ({ children }) => <SCProvider>{children}</SCProvider>;
22
+
23
+ const mockUseContext = jest.fn().mockImplementation(() => ({
24
+ stateData: mockSCStore({}),
25
+ setAction: mockedSetAction,
26
+ }));
27
+
28
+ React.useContext = mockUseContext;
29
+
30
+ describe('Test useRemoteControl', () => {
31
+ let sensor, action, data, userId, actionName;
32
+
33
+ beforeEach(() => {
34
+ sendCommandOverBluetooth.mockClear();
35
+ sendCommandOverGoogleHome.mockClear();
36
+ sendCommandOverInternet.mockClear();
37
+ sendCommandOverLGThinq.mockClear();
38
+
39
+ sensor = {
40
+ id: 1,
41
+ };
42
+ action = {
43
+ color: '#00979D',
44
+ command_prefer_over_bluetooth: true,
45
+ command_prefer_over_googlehome: false,
46
+ command_prefer_over_internet: false,
47
+ googlehome_actions: [],
48
+ icon: 'caret-up',
49
+ id: 1,
50
+ key: '2b949045-8e03-4c07-a855-7794ade2e69c',
51
+ };
52
+ data = null;
53
+ userId = 1;
54
+ actionName = 'action name';
55
+ });
56
+
57
+ it('test send remote command action null', async () => {
58
+ action = null;
59
+ const { result: sendRemoteCommand } = renderHook(() => useRemoteControl(), {
60
+ wrapper,
61
+ });
62
+ act(() => {
63
+ sendRemoteCommand.current(sensor, action, data, userId, actionName);
64
+ });
65
+ expect(sendCommandOverInternet).not.toBeCalled();
66
+ expect(sendCommandOverGoogleHome).not.toBeCalled();
67
+ expect(sendCommandOverLGThinq).not.toBeCalled();
68
+ expect(sendCommandOverBluetooth).not.toBeCalled();
69
+ });
70
+
71
+ it('test send remote command via bluetooth success', async () => {
72
+ const { result: sendRemoteCommand } = renderHook(() => useRemoteControl(), {
73
+ wrapper,
74
+ });
75
+
76
+ sendCommandOverBluetooth.mockImplementation(async () => true);
77
+ act(() => {
78
+ sendRemoteCommand.current(sensor, action, data, userId, actionName);
79
+ });
80
+ expect(sendCommandOverBluetooth).toBeCalledWith(
81
+ sensor,
82
+ action,
83
+ data,
84
+ userId
85
+ );
86
+ expect(sendCommandOverInternet).not.toBeCalled();
87
+ expect(sendCommandOverGoogleHome).not.toBeCalled();
88
+ expect(sendCommandOverLGThinq).not.toBeCalled();
89
+ });
90
+
91
+ it('test send remote command via bluetooth failed then send via internet', async () => {
92
+ const { result: sendRemoteCommand } = renderHook(() => useRemoteControl(), {
93
+ wrapper,
94
+ });
95
+
96
+ sendCommandOverBluetooth.mockImplementation(() => {
97
+ throw SEND_COMMAND_OVER_BLUETOOTH_FAIL;
98
+ });
99
+ sendCommandOverInternet.mockImplementation(async () => true);
100
+ act(() => {
101
+ sendRemoteCommand.current(sensor, action, data, userId, actionName);
102
+ });
103
+ expect(sendCommandOverBluetooth).toBeCalledWith(
104
+ sensor,
105
+ action,
106
+ data,
107
+ userId
108
+ );
109
+ expect(sendCommandOverInternet).toBeCalledWith(
110
+ sensor,
111
+ action,
112
+ data,
113
+ 'bluetooth',
114
+ actionName
115
+ );
116
+ expect(sendCommandOverGoogleHome).not.toBeCalled();
117
+ expect(sendCommandOverLGThinq).not.toBeCalled();
118
+ });
119
+
120
+ it('test send remote command via bluetooth failed throw unhandled error', async () => {
121
+ const { result: sendRemoteCommand } = renderHook(() => useRemoteControl(), {
122
+ wrapper,
123
+ });
124
+
125
+ sendCommandOverBluetooth.mockImplementation(() => {
126
+ throw 'ANOTHER_ERROR';
127
+ });
128
+ sendCommandOverInternet.mockImplementation(async () => true);
129
+ act(() => {
130
+ sendRemoteCommand.current(sensor, action, data, userId, actionName);
131
+ });
132
+ expect(sendCommandOverBluetooth).toBeCalledWith(
133
+ sensor,
134
+ action,
135
+ data,
136
+ userId
137
+ );
138
+ expect(sendCommandOverInternet).not.toBeCalled();
139
+ expect(sendCommandOverGoogleHome).not.toBeCalled();
140
+ expect(sendCommandOverLGThinq).not.toBeCalled();
141
+ });
142
+
143
+ it('test send remote command via internet', async () => {
144
+ action.command_prefer_over_bluetooth = false;
145
+ action.command_prefer_over_internet = true;
146
+ const { result: sendRemoteCommand } = renderHook(() => useRemoteControl(), {
147
+ wrapper,
148
+ });
149
+
150
+ sendCommandOverInternet.mockImplementation(async () => true);
151
+ act(() => {
152
+ sendRemoteCommand.current(sensor, action, data, userId, actionName);
153
+ });
154
+ expect(sendCommandOverInternet).toBeCalledWith(
155
+ sensor,
156
+ action,
157
+ data,
158
+ 'internet'
159
+ );
160
+ expect(sendCommandOverBluetooth).not.toBeCalled();
161
+ expect(sendCommandOverGoogleHome).not.toBeCalled();
162
+ expect(sendCommandOverLGThinq).not.toBeCalled();
163
+ });
164
+
165
+ it('test send remote command via googlehome', async () => {
166
+ action.command_prefer_over_bluetooth = false;
167
+ action.command_prefer_over_googlehome = true;
168
+ const { result: sendRemoteCommand } = renderHook(() => useRemoteControl(), {
169
+ wrapper,
170
+ });
171
+
172
+ sendCommandOverGoogleHome.mockImplementation(async () => true);
173
+ act(() => {
174
+ sendRemoteCommand.current(sensor, action, data, userId, actionName);
175
+ });
176
+ expect(sendCommandOverGoogleHome).toBeCalledWith({}, sensor, action, data);
177
+ expect(sendCommandOverBluetooth).not.toBeCalled();
178
+ expect(sendCommandOverInternet).not.toBeCalled();
179
+ expect(sendCommandOverLGThinq).not.toBeCalled();
180
+ });
181
+
182
+ it('test send remote command via lg', async () => {
183
+ action.command_prefer_over_bluetooth = false;
184
+ action.command_prefer_over_lg = true;
185
+ const { result: sendRemoteCommand } = renderHook(() => useRemoteControl(), {
186
+ wrapper,
187
+ });
188
+
189
+ sendCommandOverLGThinq.mockImplementation(async () => true);
190
+ act(() => {
191
+ sendRemoteCommand.current(sensor, action, data, userId, actionName);
192
+ });
193
+ expect(sendCommandOverLGThinq).toBeCalledWith(sensor, action, data);
194
+ expect(sendCommandOverBluetooth).not.toBeCalled();
195
+ expect(sendCommandOverGoogleHome).not.toBeCalled();
196
+ expect(sendCommandOverInternet).not.toBeCalled();
197
+ });
198
+ });
@@ -0,0 +1,4 @@
1
+ import useGGHomeConnection from './useGGHomeConnection';
2
+ import useRemoteControl from './useRemoteControl';
3
+
4
+ export { useGGHomeConnection, useRemoteControl };
@@ -0,0 +1,93 @@
1
+ import { useContext, useCallback } from 'react';
2
+ import { SCContext, useSCContextSelector } from '../../context';
3
+ import { Action } from '../../context/actionType';
4
+ import {
5
+ googleHomeConnect,
6
+ googleHomeDisconnect,
7
+ } from '../../iot/RemoteControl/GoogleHome';
8
+ import { axiosPost } from '../../utils/Apis/axios';
9
+ import { API } from '../../configs';
10
+
11
+ const useGGHomeConnection = () => {
12
+ const { setAction } = useContext(SCContext);
13
+ const { connections } = useSCContextSelector((state) => state.iot.googlehome);
14
+ const { listDevice } = useSCContextSelector((state) => state);
15
+
16
+ const onEstablished = useCallback(
17
+ async (newConnections, options) => {
18
+ setAction(Action.SET_GOOGLE_HOME_CONNECTIONS, newConnections);
19
+
20
+ const isConnected = options.some(
21
+ (option) => !!newConnections[option.chip_id]
22
+ );
23
+ let chipId = options[0].chip_id;
24
+ if (!isConnected) {
25
+ setAction(Action.LIST_DEVICE_TYPES, {
26
+ chipId: chipId,
27
+ sentEmail: true,
28
+ });
29
+ await axiosPost(API.GOOGLE_HOME.CHECK_SEND_EMAIL(), {
30
+ chip_id: chipId,
31
+ is_connected: false,
32
+ });
33
+ } else if (isConnected && listDevice[chipId]?.sentEmail) {
34
+ setAction(Action.LIST_DEVICE_TYPES, {
35
+ chipId: chipId,
36
+ sentEmail: false,
37
+ });
38
+ await axiosPost(API.GOOGLE_HOME.CHECK_SEND_EMAIL(), {
39
+ chip_id: chipId,
40
+ is_connected: true,
41
+ });
42
+ }
43
+ },
44
+ [setAction, listDevice]
45
+ );
46
+
47
+ const onDisconnected = useCallback(
48
+ async (option) => {
49
+ setAction(Action.CHANGE_GOOGLE_HOME_CONN_STATE, { option, data: 0 });
50
+ },
51
+ [setAction]
52
+ );
53
+
54
+ const onReconnected = useCallback(
55
+ async (option, connection) => {
56
+ setAction(Action.CHANGE_GOOGLE_HOME_CONN_STATE, {
57
+ option,
58
+ data: connection,
59
+ });
60
+ },
61
+ [setAction]
62
+ );
63
+
64
+ const connectGoogleHome = useCallback(
65
+ async (options) => {
66
+ setAction(Action.CONNECTING_GOOGLE_HOME);
67
+ await googleHomeConnect(
68
+ connections,
69
+ options,
70
+ onEstablished,
71
+ onDisconnected,
72
+ onReconnected
73
+ );
74
+ },
75
+ // eslint-disable-next-line react-hooks/exhaustive-deps
76
+ [connections, onEstablished, onDisconnected, onReconnected]
77
+ );
78
+
79
+ const disconnectGoogleHome = useCallback(
80
+ async (options) => {
81
+ await googleHomeDisconnect(connections, options);
82
+ setAction(Action.SET_GOOGLE_HOME_CONNECTIONS, {});
83
+ },
84
+ [setAction, connections]
85
+ );
86
+
87
+ return {
88
+ connectGoogleHome,
89
+ disconnectGoogleHome,
90
+ };
91
+ };
92
+
93
+ export default useGGHomeConnection;