@eohjsc/react-native-smart-city 0.2.98 → 0.3.1

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 (238) hide show
  1. package/README.md +36 -15
  2. package/package.json +5 -3
  3. package/src/commons/Action/ItemQuickAction.js +11 -2
  4. package/src/commons/Action/__test__/ItemQuickAction.test.js +11 -6
  5. package/src/commons/ActionGroup/CurtainButtonTemplate.js +10 -5
  6. package/src/commons/ActionGroup/NumberUpDownActionTemplate.js +32 -21
  7. package/src/commons/ActionGroup/OnOffSmartLock/AutoLock/__test__/index.test.js +4 -0
  8. package/src/commons/ActionGroup/OnOffSmartLock/OnOffSmartLock.js +3 -3
  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/OnOffTemplate/OnOffSimpleTemplate.js +1 -3
  13. package/src/commons/ActionGroup/OnOffTemplate/index.js +15 -45
  14. package/src/commons/ActionGroup/OptionsDropdownActionTemplate.js +1 -1
  15. package/src/commons/ActionGroup/SmartTiviActionTemplate/SmartTiviActionTemplate.js +3 -2
  16. package/src/commons/ActionGroup/StatesGridActionTemplate.js +8 -4
  17. package/src/commons/ActionGroup/TimerActionTemplate.js +2 -2
  18. package/src/commons/ActionGroup/TwoButtonTemplate/index.js +6 -7
  19. package/src/commons/ActionGroup/__test__/CurtainButtonTemplate.test.js +53 -4
  20. package/src/commons/ActionGroup/__test__/NumberUpDownTemplate.test.js +45 -48
  21. package/src/commons/ActionGroup/__test__/StatesGridActionTemplate.test.js +77 -0
  22. package/src/commons/ActionGroup/__test__/TimerActionTemplate.test.js +58 -6
  23. package/src/commons/ActionGroup/__test__/TwoButtonTemplate.test.js +49 -1
  24. package/src/commons/ActionGroup/__test__/index.test.js +137 -2
  25. package/src/commons/Automate/ItemAutomate.js +1 -3
  26. package/src/commons/Calendar/__test__/Calendar.test.js +33 -0
  27. package/src/commons/Connecting/__test__/Connecting.test.js +19 -2
  28. package/src/commons/ConnectingProcess/__test__/Connecting.test.js +136 -3
  29. package/src/commons/ConnectingProcess/index.js +12 -8
  30. package/src/commons/Dashboard/MyPinnedSharedUnit/__test__/MyPinnedSharedUnit.test.js +16 -13
  31. package/src/commons/Dashboard/MyPinnedSharedUnit/index.js +1 -1
  32. package/src/commons/Dashboard/MyUnit/__test__/MyUnit.test.js +0 -5
  33. package/src/commons/Device/ConnectedViewHeader.js +1 -1
  34. package/src/commons/Device/Hanet/ItemHanetDevice.test.js +58 -0
  35. package/src/commons/Device/HistoryChart.js +3 -3
  36. package/src/commons/Device/ItemDevice.js +15 -11
  37. package/src/commons/Device/LinearChart.js +15 -0
  38. package/src/commons/Device/SonosSpeaker/index.js +1 -1
  39. package/src/commons/Explore/__test__/CityItem.test.js +33 -54
  40. package/src/commons/FieldTemplate/ChooseUserField/ChooseFieldStyles.js +25 -0
  41. package/src/commons/FieldTemplate/ChooseUserField/ChoosePopup.js +96 -0
  42. package/src/commons/FieldTemplate/ChooseUserField/ChoosePopupStyles.js +39 -0
  43. package/src/commons/FieldTemplate/ChooseUserField/__test__/index.test.js +118 -0
  44. package/src/commons/FieldTemplate/ChooseUserField/index.js +62 -0
  45. package/src/commons/FieldTemplate/PasscodeField/PasscodeFieldStyles.js +30 -0
  46. package/src/commons/FieldTemplate/PasscodeField/__test__/index.test.js +90 -0
  47. package/src/commons/FieldTemplate/PasscodeField/index.js +43 -0
  48. package/src/commons/FieldTemplate/ScheduleField/ScheduleFieldStyles.js +13 -0
  49. package/src/commons/FieldTemplate/ScheduleField/__test__/index.test.js +179 -0
  50. package/src/commons/FieldTemplate/ScheduleField/index.js +176 -0
  51. package/src/commons/Header/HeaderCustom.js +2 -1
  52. package/src/commons/HorizontalPicker/index.js +2 -2
  53. package/src/commons/MediaPlayerDetail/Styles/MediaPlayerDetailStyles.js +0 -6
  54. package/src/commons/MediaPlayerDetail/index.js +19 -50
  55. package/src/commons/Sharing/__test__/DevicePermissionsCheckbox.test.js +0 -1
  56. package/src/commons/SubUnit/Favorites/index.js +2 -3
  57. package/src/commons/SubUnit/OneTap/__test__/SubUnitAutomate.test.js +8 -35
  58. package/src/commons/SubUnit/OneTap/index.js +1 -2
  59. package/src/commons/SubUnit/ShortDetail.js +1 -2
  60. package/src/commons/SubUnit/__test__/Item.test.js +0 -1
  61. package/src/commons/Unit/SharedUnit.js +1 -0
  62. package/src/commons/Unit/__test__/SharedUnit.test.js +38 -183
  63. package/src/commons/UnitSummary/ConfigHistoryChart/index.js +2 -13
  64. package/src/commons/UnitSummary/ConfigHistoryChart.js +22 -13
  65. package/src/commons/WheelDateTimePicker/index.js +4 -3
  66. package/src/configs/API.js +85 -145
  67. package/src/configs/Constants.js +36 -1
  68. package/src/configs/SCConfig.js +2 -0
  69. package/src/context/actionType.ts +8 -1
  70. package/src/context/mockStore.ts +10 -0
  71. package/src/context/reducer.ts +38 -5
  72. package/src/hooks/Common/index.js +2 -0
  73. package/src/hooks/Common/useGGHomeDeviceConnected.js +16 -0
  74. package/src/hooks/Common/useGetIdUser.js +1 -5
  75. package/src/hooks/Common/useSensorsStatus.js +5 -8
  76. package/src/hooks/IoT/__test__/useGGHomeConnection.test.js +198 -0
  77. package/src/hooks/IoT/__test__/useRemoteControl.test.js +198 -0
  78. package/src/hooks/IoT/index.js +4 -0
  79. package/src/hooks/IoT/useGGHomeConnection.js +91 -0
  80. package/src/hooks/IoT/useRemoteControl.js +79 -0
  81. package/src/hooks/index.js +4 -0
  82. package/src/hooks/useReceiveNotifications.js +8 -4
  83. package/src/iot/Monitor.js +3 -2
  84. package/src/iot/RemoteControl/Bluetooth.js +1 -1
  85. package/src/iot/RemoteControl/GoogleHome.js +75 -49
  86. package/src/iot/RemoteControl/Internet.js +1 -1
  87. package/src/iot/RemoteControl/__test__/GoogleHome.test.js +95 -48
  88. package/src/iot/RemoteControl/__test__/Internet.test.js +18 -7
  89. package/src/iot/RemoteControl/__test__/LgThinq.test.js +36 -177
  90. package/src/iot/RemoteControl/index.js +52 -52
  91. package/src/navigations/UnitStack.js +8 -0
  92. package/src/screens/ActivityLog/__test__/index.test.js +38 -23
  93. package/src/screens/ActivityLog/hooks/__test__/index.test.js +51 -90
  94. package/src/screens/ActivityLog/hooks/index.js +1 -1
  95. package/src/screens/ActivityLog/index.js +2 -2
  96. package/src/screens/AddCommon/__test__/SelectSubUnit.test.js +13 -24
  97. package/src/screens/AddCommon/__test__/SelectUnit.test.js +9 -33
  98. package/src/screens/AddLocationMaps/index.js +5 -4
  99. package/src/screens/AddNewAction/SelectAction.js +8 -8
  100. package/src/screens/AddNewAction/SelectSensorDevices.js +2 -1
  101. package/src/screens/AddNewAction/SetupSensor.js +7 -7
  102. package/src/screens/AddNewAction/__test__/SelectAction.test.js +10 -91
  103. package/src/screens/AddNewAction/__test__/SelectSensorDevices.test.js +40 -26
  104. package/src/screens/AddNewAutoSmart/__test__/AddNewAutoSmart.test.js +3 -1
  105. package/src/screens/AddNewAutoSmart/index.js +5 -2
  106. package/src/screens/AddNewDevice/ConnectingDevices.js +3 -3
  107. package/src/screens/AddNewDevice/__test__/AddNewDevice.test.js +34 -33
  108. package/src/screens/AddNewDevice/__test__/ConnectDevices.test.js +0 -4
  109. package/src/screens/AddNewDevice/__test__/ConnectingDevices.test.js +21 -21
  110. package/src/screens/AddNewDevice/hooks/ConnectDevices.js +1 -1
  111. package/src/screens/AddNewGateway/PlugAndPlay/ConnectWifiWarning.js +23 -17
  112. package/src/screens/AddNewGateway/PlugAndPlay/GatewayWifiList.js +3 -3
  113. package/src/screens/AddNewGateway/SetupGatewayWifi.js +1 -0
  114. package/src/screens/AddNewGateway/__test__/AddNewGateway.test.js +4 -6
  115. package/src/screens/AddNewGateway/__test__/ConnectedGateway.test.js +0 -4
  116. package/src/screens/AddNewGateway/__test__/ConnectingGateway.test.js +5 -29
  117. package/src/screens/AddNewGateway/__test__/SelectGateway.test.js +0 -4
  118. package/src/screens/AddNewGateway/__test__/SetupGateway.test.js +0 -4
  119. package/src/screens/AddNewOneTap/__test__/AddNewOneTap.test.js +10 -24
  120. package/src/screens/AddNewOneTap/index.js +2 -1
  121. package/src/screens/AllCamera/index.js +4 -4
  122. package/src/screens/Automate/MultiUnits.js +8 -8
  123. package/src/screens/Automate/__test__/MultiUnits.test.js +6 -9
  124. package/src/screens/Automate/__test__/index.test.js +7 -12
  125. package/src/screens/Automate/index.js +3 -3
  126. package/src/screens/ConfirmUnitDeletion/__test__/ConfirmUnitDeletion.test.js +36 -8
  127. package/src/screens/ConfirmUnitDeletion/index.js +7 -1
  128. package/src/screens/Device/EditDevice/__test__/EditDevice.test.js +71 -22
  129. package/src/screens/Device/EditDevice/index.js +2 -2
  130. package/src/screens/Device/__test__/detail.test.js +33 -86
  131. package/src/screens/Device/components/DetailHistoryChart.js +1 -1
  132. package/src/screens/Device/components/SensorConnectStatusViewHeader.js +1 -0
  133. package/src/screens/Device/components/SensorDisplayItem.js +5 -2
  134. package/src/screens/Device/detail.js +81 -33
  135. package/src/screens/Device/hooks/useDisconnectedDevice.js +4 -4
  136. package/src/screens/Device/hooks/useFavoriteDevice.js +5 -9
  137. package/src/screens/DeviceInfo/__test__/index.test.js +0 -2
  138. package/src/screens/EditActionsList/index.js +1 -1
  139. package/src/screens/EmergencyContacts/EmergencyContactsSelectContacts.js +6 -3
  140. package/src/screens/EmergencyContacts/__test__/EmergencyContactAddNew.test.js +7 -19
  141. package/src/screens/EmergencyContacts/__test__/EmergencyContactList.test.js +18 -14
  142. package/src/screens/EmergencyContacts/__test__/EmergencyContactsSelectContacts.test.js +30 -31
  143. package/src/screens/EmergencySetting/components/DropDownItem.js +2 -2
  144. package/src/screens/EnterPassword/__test__/EnterPassword.test.js +41 -25
  145. package/src/screens/GuestInfo/__test__/index.test.js +14 -41
  146. package/src/screens/GuestInfo/components/RecurringDetail.js +1 -0
  147. package/src/screens/GuestInfo/components/TemporaryDetail.js +2 -2
  148. package/src/screens/HanetCamera/Detail.js +1 -1
  149. package/src/screens/HanetCamera/__test__/CaptureFaceID.test.js +8 -12
  150. package/src/screens/HanetCamera/__test__/Detail.test.js +27 -42
  151. package/src/screens/HanetCamera/__test__/ManageAccess.test.js +8 -5
  152. package/src/screens/HanetCamera/__test__/MemberInfo.test.js +10 -32
  153. package/src/screens/HanetCamera/components/RequestFaceIDPopup.js +3 -2
  154. package/src/screens/HanetCamera/hooks/__test__/useHanetCheckinData.test.js +43 -35
  155. package/src/screens/HanetCamera/hooks/__test__/useHanetPlaceMembers.test.js +10 -21
  156. package/src/screens/HanetCamera/hooks/useHanetCheckinData.js +11 -11
  157. package/src/screens/HanetCamera/hooks/useHanetPlaceMembers.js +11 -11
  158. package/src/screens/ManageAccess/__test__/ManageAccess.test.js +33 -22
  159. package/src/screens/ManageAccess/hooks/__test__/useManageAccess.test.js +44 -45
  160. package/src/screens/ManageAccess/hooks/index.js +7 -4
  161. package/src/screens/ManageAccess/index.js +1 -1
  162. package/src/screens/MoveToAnotherSubUnit/__test__/index.test.js +35 -12
  163. package/src/screens/MoveToAnotherSubUnit/index.js +5 -5
  164. package/src/screens/Notification/__test__/Notification.test.js +14 -25
  165. package/src/screens/Notification/__test__/NotificationItem.test.js +8 -7
  166. package/src/screens/Notification/components/NotificationItem.js +17 -20
  167. package/src/screens/Notification/index.js +9 -2
  168. package/src/screens/PlayBackCamera/Timer.js +2 -2
  169. package/src/screens/PlayBackCamera/__test__/index.test.js +87 -2
  170. package/src/screens/PlayBackCamera/index.js +22 -6
  171. package/src/screens/ScanChipQR/__test__/ScanChipQR.test.js +7 -20
  172. package/src/screens/ScanChipQR/components/QRScan/index.js +1 -0
  173. package/src/screens/ScanChipQR/hooks/index.js +15 -16
  174. package/src/screens/ScanSensorQR/__test__/ScanSensorQR.test.js +8 -24
  175. package/src/screens/ScriptDetail/__test__/index.test.js +17 -86
  176. package/src/screens/ScriptDetail/index.js +17 -12
  177. package/src/screens/SelectUnit/__test__/index.test.js +12 -55
  178. package/src/screens/SelectUnit/index.js +8 -4
  179. package/src/screens/SetSchedule/index.js +11 -10
  180. package/src/screens/SharedUnit/__test__/TabHeader.test.js +0 -2
  181. package/src/screens/Sharing/Components/SensorItem.js +10 -12
  182. package/src/screens/Sharing/InfoMemberUnit.js +1 -1
  183. package/src/screens/Sharing/SelectPermission.js +121 -77
  184. package/src/screens/Sharing/__test__/InfoMemberUnit.test.js +47 -29
  185. package/src/screens/Sharing/__test__/MemberList.test.js +13 -127
  186. package/src/screens/Sharing/__test__/MemberList2.test.js +80 -0
  187. package/src/screens/Sharing/__test__/SelectPermission.test.js +28 -38
  188. package/src/screens/Sharing/__test__/SelectUser.test.js +17 -38
  189. package/src/screens/SideMenuDetail/SideMenuDetailStyles.js +28 -0
  190. package/src/screens/SideMenuDetail/__test__/index.test.js +154 -0
  191. package/src/screens/SideMenuDetail/index.js +148 -0
  192. package/src/screens/SmartIr/components/GroupButtonByType/GroupButtonByType.js +3 -2
  193. package/src/screens/SubUnit/Detail.js +1 -2
  194. package/src/screens/SubUnit/ManageSubUnit.js +12 -7
  195. package/src/screens/SubUnit/__test__/AddSubUnit.test.js +21 -67
  196. package/src/screens/SubUnit/__test__/Detail.test.js +31 -8
  197. package/src/screens/SubUnit/__test__/EditSubUnit.test.js +21 -89
  198. package/src/screens/SubUnit/__test__/ManageSubUnit.test.js +27 -1
  199. package/src/screens/SubUnit/hooks/__test__/useManageSubUnit.test.js +48 -45
  200. package/src/screens/SubUnit/hooks/useManageSubUnit.js +7 -7
  201. package/src/screens/SyncLGDevice/__test__/AddLGDevice.test.js +14 -90
  202. package/src/screens/Unit/ChooseLocation.js +7 -14
  203. package/src/screens/Unit/Detail.js +30 -75
  204. package/src/screens/Unit/ManageUnit.js +1 -0
  205. package/src/screens/Unit/SelectAddress.js +34 -21
  206. package/src/screens/Unit/SmartAccount.js +4 -4
  207. package/src/screens/Unit/Summaries.js +17 -1
  208. package/src/screens/Unit/__test__/CheckSendEmail.test.js +24 -29
  209. package/src/screens/Unit/__test__/ChooseLocation.test.js +27 -14
  210. package/src/screens/Unit/__test__/Detail.test.js +99 -200
  211. package/src/screens/Unit/__test__/ManageUnit.test.js +18 -42
  212. package/src/screens/Unit/__test__/SelectAddress.test.js +84 -51
  213. package/src/screens/Unit/__test__/SmartAccount.test.js +17 -9
  214. package/src/screens/Unit/__test__/SmartAccountItem.test.js +0 -1
  215. package/src/screens/Unit/__test__/Summaries.test.js +100 -0
  216. package/src/screens/Unit/components/MyAllUnit/__test__/MyAllUnit.test.js +36 -0
  217. package/src/screens/Unit/components/MyAllUnit/__test__/index.test.js +54 -0
  218. package/src/screens/Unit/components/SharedUnit/index.js +1 -0
  219. package/src/screens/Unit/components/__test__/SharedUnit.test.js +31 -34
  220. package/src/screens/Unit/hook/useUnitConnectRemoteDevices.js +50 -0
  221. package/src/screens/Unit/styles.js +4 -0
  222. package/src/screens/UnitSummary/__test__/index.test.js +70 -41
  223. package/src/screens/UnitSummary/components/3PPowerConsumption/__test__/3PPowerConsumption.test.js +31 -2
  224. package/src/screens/UnitSummary/components/PowerConsumeHistoryChart/__test__/index.test.js +7 -4
  225. package/src/screens/UnitSummary/components/PowerConsumeHistoryChart/index.js +2 -13
  226. package/src/screens/UnitSummary/components/PowerConsumption/__test__/ItemPower.test.js +0 -1
  227. package/src/screens/UnitSummary/components/PowerConsumption/__test__/PowerConsumption.test.js +14 -16
  228. package/src/screens/UnitSummary/components/RunningDevices/__test__/index.test.js +11 -2
  229. package/src/screens/UnitSummary/components/RunningDevices/index.js +7 -10
  230. package/src/screens/UnitSummary/components/Temperature/index.js +4 -4
  231. package/src/screens/UnitSummary/index.js +15 -1
  232. package/src/utils/Apis/axios.js +46 -31
  233. package/src/utils/Converter/time.js +0 -18
  234. package/src/utils/I18n/translations/en.json +3 -1
  235. package/src/utils/I18n/translations/vi.json +4 -1
  236. package/src/utils/Permission/common.js +39 -0
  237. package/src/utils/Route/index.js +1 -0
  238. package/src/utils/Utils.js +11 -7
package/README.md CHANGED
@@ -1,19 +1,26 @@
1
1
  ## react-native-smart-city
2
2
 
3
3
  ## Getting started
4
+
4
5
  1. Install package dependencies:
5
- - Using [Yarn](https://yarnpkg.com/): `yarn add react-native-reanimated@^1.10.1`
6
+
7
+ - Using [Yarn](https://yarnpkg.com/): `yarn add react-native-reanimated@^1.10.1`
6
8
 
7
9
  2. Install:
8
- - Using [npm](https://www.npmjs.com/#getting-started): `npm install @eohjsc/react-native-smart-city --save`
9
- - Using [Yarn](https://yarnpkg.com/): `yarn add @eohjsc/react-native-smart-city`
10
+
11
+ - Using [npm](https://www.npmjs.com/#getting-started): `npm install @eohjsc/react-native-smart-city --save`
12
+ - Using [Yarn](https://yarnpkg.com/): `yarn add @eohjsc/react-native-smart-city`
10
13
 
11
14
  3. Compile application using react-native run-android
15
+
12
16
  ### Mostly automatic installation
17
+
13
18
  `$ react-native link @eohjsc/react-native-smart-city`
14
19
 
15
20
  ## Usage
21
+
16
22
  1. StackNavigator
23
+
17
24
  ```javascript
18
25
  import {
19
26
  UnitStack,
@@ -30,7 +37,7 @@ import {
30
37
  } from '@eohjsc/react-native-smart-city';
31
38
  import { createStackNavigator } from '@react-navigation/stack';
32
39
 
33
- // TODO: What to do with the module?
40
+ // TODO: What to do with the module?
34
41
  const Stack = createStackNavigator();
35
42
 
36
43
  const YourStack = () => {
@@ -84,7 +91,9 @@ const MainTab = () => {
84
91
  );
85
92
  };
86
93
  ```
94
+
87
95
  2. Use components
96
+
88
97
  ```javascript
89
98
  import React from 'react';
90
99
  import { View } from 'react-native';
@@ -93,13 +102,15 @@ import { MyPinnedSharedUnit, MyUnit } from '@eohjsc/react-native-smart-city';
93
102
  const MyScreen = () => {
94
103
  return (
95
104
  <View>
96
- <MyUnit />
97
- <MyPinnedSharedUnit />
105
+ <MyUnit />
106
+ <MyPinnedSharedUnit />
98
107
  </View>
99
108
  );
100
109
  };
101
110
  ```
111
+
102
112
  3. Trigger quick action
113
+
103
114
  ```javascript
104
115
  import React from 'react';
105
116
  import { View, Button } from 'react-native';
@@ -126,23 +137,33 @@ export const MyFunctionalComponent = () => {
126
137
  lg_actions: [],
127
138
  name: 'Garage Up',
128
139
  };
129
- const handleQuickAction = async() => {
140
+ const handleQuickAction = async () => {
130
141
  const result = await sendRemoteCommand(sensor, action); // Action Garage Up
131
- if (result){
132
- console.log('Successful control')
133
- }else {
134
- console.log('Control failed')
142
+ if (result) {
143
+ console.log('Successful control');
144
+ } else {
145
+ console.log('Control failed');
135
146
  }
136
147
  };
137
148
  return (
138
149
  <View>
139
- <Button onPress={handleQuickAction} title="Example trigger quick action control Garage Up" />
150
+ <Button
151
+ onPress={handleQuickAction}
152
+ title="Example trigger quick action control Garage Up"
153
+ />
140
154
  </View>
141
155
  );
142
156
  };
143
157
  ```
144
- - sendRemoteCommand user needs to `have permission to control the device`, you pass in the `sensor and action` to it and it will run after calling render.
145
- - `sensor` is a device in your Unit and action is the `action` key of the device..
158
+
159
+ - sendRemoteCommand user needs to `have permission to control the device`, you pass in the `sensor and action` to it and it will run after calling render.
160
+ - `sensor` is a device in your Unit and action is the `action` key of the device..
146
161
  - You can take out the sensor and action from your Unit when calling the `API.UNIT.UNIT_DETAIL(unitId)` it will return all devices in 1 unit.
147
- - Or get sensor from `API.SENSOR.DISPLAY(sensor.id)` returns all actions of 1 device.
162
+ - Or get sensor from `API.DEVICE.DISPLAY(sensor.id)` returns all actions of 1 device.
148
163
  - Refer YourProjectPath /node_modules/@eohjsc/react-native-smart-city/src/screens/Unit/Detail.js
164
+
165
+ ## Sync file to EoH source
166
+
167
+ ```
168
+ yarn install && yarn watch
169
+ ```
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@eohjsc/react-native-smart-city",
3
3
  "title": "React Native Smart Home",
4
- "version": "0.2.98",
4
+ "version": "0.3.01",
5
5
  "description": "TODO",
6
6
  "main": "index.js",
7
7
  "files": [
@@ -18,7 +18,7 @@
18
18
  "ios": "react-native run-ios",
19
19
  "start": "react-native start",
20
20
  "test": "yarn run lint && yarn run jest",
21
- "lint": "eslint . --ext js --ext ts --ext tsx",
21
+ "lint": "eslint . --ext js --ext ts --ext tsx --max-warnings 5",
22
22
  "lint-fix": "eslint . --fix",
23
23
  "type-check": "npx tsc",
24
24
  "pod": "cd ios && pod install",
@@ -74,6 +74,7 @@
74
74
  "@types/react": "^17.0.0",
75
75
  "@types/react-native": "^0.63.43",
76
76
  "@types/react-test-renderer": "^17.0.0",
77
+ "axios-mock-adapter": "^1.21.1",
77
78
  "babel-jest": "^26.6.3",
78
79
  "detox": "^18.3.1",
79
80
  "eslint": "7.14.0",
@@ -124,6 +125,7 @@
124
125
  "@react-navigation/stack": "^5.7.0",
125
126
  "@sentry/react-native": "^1.7.1",
126
127
  "@testing-library/react-hooks": "^6.0.0",
128
+ "apisauce": "^2.1.5",
127
129
  "axios": "^0.19.2",
128
130
  "dotenv": "^8.2.0",
129
131
  "google-libphonenumber": "^3.2.10",
@@ -174,7 +176,7 @@
174
176
  "react-native-pager-view": "^5.4.1",
175
177
  "react-native-parallax-scroll-view": "^0.21.3",
176
178
  "react-native-parsed-text": "^0.0.22",
177
- "react-native-permissions": "^2.1.5",
179
+ "react-native-permissions": "3.0.3",
178
180
  "react-native-popover-view": "^4.0.3",
179
181
  "react-native-progress": "^5.0.0",
180
182
  "react-native-reanimated": "1.10.1",
@@ -3,7 +3,7 @@ import { TouchableOpacity, View } from 'react-native';
3
3
  import { TESTID } from '../../configs/Constants';
4
4
  import { useSCContextSelector } from '../../context';
5
5
  import { watchMultiConfigs } from '../../iot/Monitor';
6
- import { sendRemoteCommand } from '../../iot/RemoteControl';
6
+ import { useRemoteControl } from '../../hooks/IoT';
7
7
  import { useConfigGlobalState } from '../../iot/states';
8
8
  import IconComponent from '../IconComponent';
9
9
 
@@ -13,6 +13,8 @@ const ItemQuickAction = memo(({ sensor, wrapperStyle, setStatus, unit }) => {
13
13
  // eslint-disable-next-line no-unused-vars
14
14
  const [configValues, _] = useConfigGlobalState('configValues');
15
15
 
16
+ const sendRemoteCommand = useRemoteControl();
17
+
16
18
  const revertActionUpdate = useCallback(
17
19
  (value, on_action, on_status, off_action, off_status) => {
18
20
  setIsSendingCommand(false);
@@ -81,7 +83,14 @@ const ItemQuickAction = memo(({ sensor, wrapperStyle, setStatus, unit }) => {
81
83
  statusCallback(action.id === sensor.quick_action.on_action.id);
82
84
  }, sensor.quick_action.interval);
83
85
  }
84
- }, [sensor, action, userId, revertActionUpdate, statusCallback]);
86
+ }, [
87
+ sensor,
88
+ action,
89
+ userId,
90
+ revertActionUpdate,
91
+ statusCallback,
92
+ sendRemoteCommand,
93
+ ]);
85
94
 
86
95
  if (!action) {
87
96
  return <View />;
@@ -5,7 +5,6 @@ import ItemQuickAction from '../ItemQuickAction';
5
5
  import { Colors } from '../../../configs';
6
6
  import { TESTID } from '../../../configs/Constants';
7
7
  import { factory } from 'factory-girl';
8
- import { sendRemoteCommand } from '../../../iot/RemoteControl';
9
8
 
10
9
  class Sensor {}
11
10
 
@@ -21,7 +20,13 @@ jest.mock('react', () => {
21
20
 
22
21
  useState.mockImplementation((init) => [init, mockSetState]);
23
22
 
24
- jest.mock('../../../iot/RemoteControl');
23
+ const mockSendRemoteControl = jest.fn();
24
+ jest.mock('../../../hooks/IoT', () => {
25
+ return {
26
+ ...jest.requireActual('../../../hooks/IoT'),
27
+ useRemoteControl: () => mockSendRemoteControl,
28
+ };
29
+ });
25
30
 
26
31
  jest.mock('../../../iot/states', () => ({
27
32
  useConfigGlobalState: () => [{}, null],
@@ -83,9 +88,9 @@ describe('Test ItemQuickAction', () => {
83
88
  };
84
89
 
85
90
  test('render with no action', async () => {
86
- const sensor = await factory.build('Sensor');
91
+ const newSensor = await factory.build('Sensor');
87
92
  act(() => {
88
- tree = create(<ItemQuickAction sensor={sensor} />);
93
+ tree = create(<ItemQuickAction sensor={newSensor} />);
89
94
  });
90
95
  const instance = tree.root;
91
96
  const buttonOnActionPress = instance.findAll(
@@ -121,7 +126,7 @@ describe('Test ItemQuickAction', () => {
121
126
  act(() => {
122
127
  buttonOnActionPress.props.onPress();
123
128
  });
124
- expect(sendRemoteCommand).toBeCalled();
129
+ expect(mockSendRemoteControl).toBeCalled();
125
130
  expect(mockSetState).toBeCalledTimes(1);
126
131
 
127
132
  jest.runAllTimers();
@@ -154,7 +159,7 @@ describe('Test ItemQuickAction', () => {
154
159
  act(() => {
155
160
  buttonOnActionPress.props.onPress();
156
161
  });
157
- expect(sendRemoteCommand).toBeCalled();
162
+ expect(mockSendRemoteControl).toBeCalled();
158
163
  expect(mockSetState).toBeCalledTimes(1);
159
164
 
160
165
  jest.runAllTimers();
@@ -17,6 +17,11 @@ const CurtainButtonTemplate = memo(({ actionGroup, doAction, sensor }) => {
17
17
  close_action_data,
18
18
  action_off_data,
19
19
  action_on_data,
20
+ is_display_lock,
21
+ text1,
22
+ text2,
23
+ text3,
24
+ text_door_lock,
20
25
  } = configuration || {};
21
26
  const [lock, setLock] = useState(false);
22
27
 
@@ -52,21 +57,21 @@ const CurtainButtonTemplate = memo(({ actionGroup, doAction, sensor }) => {
52
57
  {
53
58
  style: styles.buttonActionCurtain,
54
59
  icon: Images.buttonLeftCurtain,
55
- text: configuration.text1,
60
+ text: text1,
56
61
  onPress: onButtonOpenPress,
57
62
  testID: TESTID.BUTTON_TEMPLATE_1,
58
63
  },
59
64
  {
60
65
  style: styles.buttonActionCurtainCenter,
61
66
  icon: Images.buttonPauseCurtain,
62
- text: configuration.text2,
67
+ text: text2,
63
68
  onPress: onButtonStopPress,
64
69
  testID: TESTID.BUTTON_TEMPLATE_2,
65
70
  },
66
71
  {
67
72
  style: styles.buttonActionCurtain,
68
73
  icon: Images.buttonRightCurtain,
69
- text: configuration.text3,
74
+ text: text3,
70
75
  onPress: onButtonClosePress,
71
76
  testID: TESTID.BUTTON_TEMPLATE_3,
72
77
  },
@@ -96,7 +101,7 @@ const CurtainButtonTemplate = memo(({ actionGroup, doAction, sensor }) => {
96
101
  style={styles.textLockDoor}
97
102
  testID={TESTID.TEXT_DOOR_LOOK_ON_OFF}
98
103
  >
99
- {configuration.text_door_lock}{' '}
104
+ {text_door_lock}{' '}
100
105
  </Text>
101
106
  </View>
102
107
  <Switch
@@ -115,7 +120,7 @@ const CurtainButtonTemplate = memo(({ actionGroup, doAction, sensor }) => {
115
120
  <RenderThreeButtonActions />
116
121
  </View>
117
122
  <View style={styles.lockSwitch}>
118
- {configuration.is_display_lock &&
123
+ {is_display_lock &&
119
124
  itemLock(
120
125
  lock ? 'lock' : 'unlock',
121
126
  lock ? Colors.Primary : Colors.Gray6
@@ -7,6 +7,7 @@ import Text from '../Text';
7
7
  import { useConfigGlobalState } from '../../iot/states';
8
8
  import styles from './NumberUpDownActionTemplateStyle';
9
9
  import { watchMultiConfigs } from '../../iot/Monitor';
10
+ import { TESTID } from '../../configs/Constants';
10
11
 
11
12
  const NumberUpDownActionTemplate = ({ actionGroup, doAction, sensor }) => {
12
13
  const { configuration, title } = actionGroup;
@@ -15,39 +16,39 @@ const NumberUpDownActionTemplate = ({ actionGroup, doAction, sensor }) => {
15
16
  max_value,
16
17
  min_value,
17
18
  text_format,
18
- keep_track_config,
19
19
  config,
20
+ allow_config_store_value,
20
21
  } = configuration;
21
22
 
22
23
  // eslint-disable-next-line no-unused-vars
23
24
  const [configValues, setConfigValues] = useConfigGlobalState('configValues');
24
- const [value, setValue] = useState((config && configValues[config]) || 28);
25
+ const [value, setValue] = useState();
26
+ const valueDefault = 28;
25
27
 
26
28
  useEffect(() => {
27
- if (!keep_track_config) {
28
- return;
29
- }
30
29
  if (!config) {
30
+ setValue(valueDefault);
31
31
  return;
32
32
  }
33
33
 
34
34
  const configValue = configValues[config];
35
35
  if (configValue !== null && configValue !== undefined) {
36
36
  setValue(configValue);
37
+ } else {
38
+ setValue(valueDefault);
37
39
  }
38
- }, [configValues, config, keep_track_config]);
40
+ // eslint-disable-next-line react-hooks/exhaustive-deps
41
+ }, []);
39
42
 
40
43
  const doActionAndWatchConfig = useCallback(
41
- (actionData, actionValue, actionName) => {
42
- doAction(
43
- actionData,
44
- JSON.stringify({ temperature: actionValue }),
45
- actionName
46
- );
47
- if (!sensor?.is_managed_by_backend) {
48
- return;
44
+ async (actionData, actionValue, actionName) => {
45
+ const data = { temperature: actionValue };
46
+ if (allow_config_store_value && config) {
47
+ data.config_id = config;
48
+ data.value = actionValue;
49
49
  }
50
- if (!keep_track_config) {
50
+ await doAction(actionData, JSON.stringify(data), actionName);
51
+ if (!sensor?.is_managed_by_backend) {
51
52
  return;
52
53
  }
53
54
  if (!config) {
@@ -59,11 +60,11 @@ const NumberUpDownActionTemplate = ({ actionGroup, doAction, sensor }) => {
59
60
  watchMultiConfigs([config]);
60
61
  },
61
62
  [
62
- config,
63
63
  doAction,
64
- keep_track_config,
65
- sensor.is_managed_by_backend,
64
+ sensor?.is_managed_by_backend,
66
65
  sensor.device_type,
66
+ allow_config_store_value,
67
+ config,
67
68
  ]
68
69
  );
69
70
 
@@ -103,13 +104,23 @@ const NumberUpDownActionTemplate = ({ actionGroup, doAction, sensor }) => {
103
104
  )}
104
105
 
105
106
  <View style={styles.controlPannel}>
106
- <TouchableOpacity style={styles.downButton} onPress={doActionDown}>
107
+ <TouchableOpacity
108
+ style={styles.downButton}
109
+ onPress={doActionDown}
110
+ testID={TESTID.NUMBER_ACTION_DOWN}
111
+ >
107
112
  <IconOutline name="down" size={32} color={Colors.Primary} />
108
113
  </TouchableOpacity>
109
114
 
110
- <Text type="H2">{text_format.replace('{number}', value)}</Text>
115
+ <Text testID={'abcd'} type="H2">
116
+ {text_format.replace('{number}', value)}
117
+ </Text>
111
118
 
112
- <TouchableOpacity style={styles.upButton} onPress={doActionUp}>
119
+ <TouchableOpacity
120
+ style={styles.upButton}
121
+ onPress={doActionUp}
122
+ testID={TESTID.NUMBER_ACTION_UP}
123
+ >
113
124
  <IconOutline name="up" size={32} color={Colors.Primary} />
114
125
  </TouchableOpacity>
115
126
  </View>
@@ -1,5 +1,6 @@
1
1
  import React from 'react';
2
2
  import { act, create } from 'react-test-renderer';
3
+ import { Switch } from 'react-native';
3
4
 
4
5
  import AutoLock from '../index';
5
6
  import { mockSCStore } from '../../../../../context/mockStore';
@@ -38,6 +39,9 @@ describe('Test AutoLock', () => {
38
39
  });
39
40
 
40
41
  const instance = tree.root;
42
+ const switchs = instance.findByType(Switch);
43
+ await switchs.props.onValueChange();
44
+
41
45
  const { buttonEnable, buttonInstant, buttonRelockTiming } =
42
46
  getElement(instance);
43
47
 
@@ -17,7 +17,7 @@ const OnOffSmartLock = memo(({ actionGroup, doAction, sensor }) => {
17
17
  const [isUnlock, setisUnlock] = useState(true);
18
18
  const [configValues] = useConfigGlobalState('configValues');
19
19
 
20
- const handleActionSmartLock = useCallback(() => {
20
+ const handleActionSmartLock = useCallback(async () => {
21
21
  if (action_on_data && action_off_data) {
22
22
  if (isUnlock) {
23
23
  let actionName = `${
@@ -25,14 +25,14 @@ const OnOffSmartLock = memo(({ actionGroup, doAction, sensor }) => {
25
25
  } ${actionGroup?.title?.toLowerCase()} lock`;
26
26
  actionName = actionName.replace(/\s+/g, ' ').trim();
27
27
  const dataLock = { door_lock: 0 };
28
- doAction(action_on_data, JSON.stringify(dataLock), actionName);
28
+ await doAction(action_on_data, JSON.stringify(dataLock), actionName);
29
29
  } else {
30
30
  let actionName = `${
31
31
  sensor?.name
32
32
  } ${actionGroup?.title?.toLowerCase()} unlock`;
33
33
  actionName = actionName.replace(/\s+/g, ' ').trim();
34
34
  const dataUnlock = { door_lock: 1 };
35
- doAction(action_off_data, JSON.stringify(dataUnlock), actionName);
35
+ await doAction(action_off_data, JSON.stringify(dataUnlock), actionName);
36
36
  }
37
37
  if (sensor?.is_managed_by_backend) {
38
38
  configuration.config &&
@@ -19,7 +19,7 @@ const ButtonWrapper = ({ item, textHeadline }) => {
19
19
  };
20
20
 
21
21
  const ItemPasscode = memo(({ route }) => {
22
- const { item } = route.params;
22
+ const { item = {} } = route.params || {};
23
23
 
24
24
  return (
25
25
  <SafeAreaView style={styles.container}>
@@ -0,0 +1,24 @@
1
+ import React from 'react';
2
+ import { TouchableOpacity } from 'react-native';
3
+ import { act, create } from 'react-test-renderer';
4
+ import { SCProvider } from '../../../../../context';
5
+ import { mockSCStore } from '../../../../../context/mockStore';
6
+ import ItemPasscode from '../ItemPasscode';
7
+
8
+ const wrapComponent = (route = {}) => (
9
+ <SCProvider initState={mockSCStore({})}>
10
+ <ItemPasscode route={route} />
11
+ </SCProvider>
12
+ );
13
+
14
+ describe('Test ItemPasscode', () => {
15
+ let tree;
16
+ test('test render without params', async () => {
17
+ await act(async () => {
18
+ tree = await create(wrapComponent());
19
+ });
20
+ const instance = tree.root;
21
+ const TouchableOpacities = instance.findAllByType(TouchableOpacity);
22
+ expect(TouchableOpacities).toHaveLength(2);
23
+ });
24
+ });
@@ -40,6 +40,7 @@ describe('Test SetupGeneratePasscode', () => {
40
40
  const changeDuration = instance.findAll(
41
41
  (item) => item.props.testID === TESTID.GENERATE_PASSCODE_SET_DURATION
42
42
  );
43
+
43
44
  return {
44
45
  changeName,
45
46
  changeTime,
@@ -58,5 +59,18 @@ describe('Test SetupGeneratePasscode', () => {
58
59
  expect(changeName[0]).toBeDefined();
59
60
  expect(changeTime[0]).toBeDefined();
60
61
  expect(changeDuration[0]).toBeDefined();
62
+
63
+ await changeDuration[0].props.onPressSetMinute();
64
+ await changeDuration[0].props.onPressSelectCircle();
65
+ await changeTime[0].props.onPressSetTime();
66
+
67
+ const wheelDateTimePicker = instance.findAll(
68
+ (item) =>
69
+ item.props.testID ===
70
+ `${TESTID.WHEEL_DATE_TIME_PICKER_BUTTON}${TESTID.VIEW_BUTTON_BOTTOM_RIGHT_BUTTON}`
71
+ );
72
+ await wheelDateTimePicker[5].props.onClick();
73
+ await wheelDateTimePicker[11].props.onClick();
74
+ await wheelDateTimePicker[17].props.onClick();
61
75
  });
62
76
  });
@@ -11,8 +11,6 @@ const OnOffSimpleTemplate = ({
11
11
  triggerAction,
12
12
  actionGroup,
13
13
  disabled,
14
- valueOfSwitch,
15
- checkValueOfSwitch,
16
14
  }) => {
17
15
  return (
18
16
  <View style={styles.wrap}>
@@ -26,7 +24,7 @@ const OnOffSimpleTemplate = ({
26
24
  thumbColor={isOn ? Colors.White : Colors.Gray6}
27
25
  ios_backgroundColor={Colors.Gray4}
28
26
  onValueChange={triggerAction}
29
- value={checkValueOfSwitch ? !!isOn : valueOfSwitch}
27
+ value={!!isOn}
30
28
  disabled={disabled}
31
29
  />
32
30
  )}
@@ -1,19 +1,10 @@
1
- import React, {
2
- memo,
3
- useCallback,
4
- useContext,
5
- useEffect,
6
- useMemo,
7
- useState,
8
- } from 'react';
1
+ import React, { memo, useCallback, useEffect, useMemo, useState } from 'react';
9
2
  import { DEVICE_TYPE } from '../../../configs/Constants';
10
3
 
11
4
  import { watchMultiConfigs } from '../../../iot/Monitor';
12
5
  import { useConfigGlobalState } from '../../../iot/states';
13
6
  import OnOffButtonTemplate from './OnOffButtonTemplate';
14
7
  import OnOffSimpleTemplate from './OnOffSimpleTemplate';
15
- import { SCContext } from '../../../context';
16
- import { Action } from '../../../context/actionType';
17
8
 
18
9
  const getComponent = (template) => {
19
10
  switch (template) {
@@ -30,13 +21,9 @@ const OnOffTemplate = memo(({ actionGroup, doAction, sensor }) => {
30
21
  const { configuration } = actionGroup;
31
22
  const { action_data, action_on_data, action_off_data } = configuration;
32
23
  const [isOn, setIsOn] = useState(null);
33
- const [valueOfSwitch, setValueOfSwitch] = useState(false);
34
- const [checkValueOfSwitch, setCheckValueOfSwitch] = useState(true);
35
- //checkValueOfSwitch to check the value real-time of Switch when re-entering the screen
36
24
 
37
25
  // eslint-disable-next-line no-unused-vars
38
26
  const [configValues, _] = useConfigGlobalState('configValues');
39
- const { setAction } = useContext(SCContext);
40
27
 
41
28
  const actionName = useCallback(
42
29
  (text) => {
@@ -47,62 +34,48 @@ const OnOffTemplate = memo(({ actionGroup, doAction, sensor }) => {
47
34
  },
48
35
  [actionGroup?.title, sensor?.name]
49
36
  );
50
- const triggerAction = useCallback(() => {
51
- if (actionGroup?.template === 'OnOffSimpleActionTemplate') {
52
- setAction(Action.IS_FULL_LOADING, true);
53
- }
54
- setCheckValueOfSwitch(false);
37
+ const triggerAction = useCallback(async () => {
55
38
  switch (sensor?.device_type) {
56
39
  case DEVICE_TYPE.ZIGBEE:
57
40
  if (action_on_data && action_off_data) {
58
41
  if (isOn) {
59
- doAction(
42
+ await doAction(
60
43
  action_off_data,
61
44
  JSON.stringify({ state: 0 }),
62
45
  actionName('off')
63
46
  );
64
47
  } else {
65
- doAction(
48
+ await doAction(
66
49
  action_on_data,
67
50
  JSON.stringify({ state: 1 }),
68
51
  actionName('on')
69
52
  );
70
53
  }
71
54
  }
72
- return;
55
+ break;
73
56
  default:
74
57
  if (action_data) {
75
58
  if (isOn) {
76
- doAction(action_data, false);
59
+ await doAction(action_data, false);
77
60
  } else {
78
- doAction(action_data, true);
61
+ await doAction(action_data, true);
79
62
  }
80
63
  }
81
64
  if (action_on_data && action_off_data) {
82
- setValueOfSwitch(!isOn);
83
65
  if (isOn) {
84
- doAction(action_off_data, null, actionName('off'));
66
+ await doAction(action_off_data, null, actionName('off'));
85
67
  } else {
86
- doAction(action_on_data, null, actionName('on'));
87
- }
88
- }
89
- if (sensor?.is_managed_by_backend) {
90
- configuration?.config &&
91
- sensor?.device_type !== 'GOOGLE_HOME' &&
92
- watchMultiConfigs([configuration?.config]);
93
- if (actionGroup?.template === 'OnOffSimpleActionTemplate') {
94
- const cleanTimeout = setTimeout(() => {
95
- setAction(Action.IS_FULL_LOADING, false);
96
- clearTimeout(cleanTimeout);
97
- }, 2000);
68
+ await doAction(action_on_data, null, actionName('on'));
98
69
  }
99
- } else {
100
- setValueOfSwitch(isOn);
101
70
  }
102
- return;
71
+ break;
72
+ }
73
+ if (sensor?.is_managed_by_backend) {
74
+ configuration?.config &&
75
+ sensor?.device_type !== 'GOOGLE_HOME' &&
76
+ watchMultiConfigs([configuration?.config]);
103
77
  }
104
78
  }, [
105
- actionGroup.template,
106
79
  actionName,
107
80
  action_data,
108
81
  action_off_data,
@@ -112,7 +85,6 @@ const OnOffTemplate = memo(({ actionGroup, doAction, sensor }) => {
112
85
  isOn,
113
86
  sensor?.device_type,
114
87
  sensor?.is_managed_by_backend,
115
- setAction,
116
88
  ]);
117
89
 
118
90
  useEffect(() => {
@@ -150,8 +122,6 @@ const OnOffTemplate = memo(({ actionGroup, doAction, sensor }) => {
150
122
  triggerAction={triggerAction}
151
123
  actionGroup={actionGroup}
152
124
  disabled={!action_data && !action_on_data && !action_off_data}
153
- valueOfSwitch={valueOfSwitch}
154
- checkValueOfSwitch={checkValueOfSwitch}
155
125
  />
156
126
  </>
157
127
  );
@@ -92,7 +92,7 @@ const OptionsDropdownActionTemplate = ({ actionGroup, doAction, sensor }) => {
92
92
  return t('not_available');
93
93
  }
94
94
  return selectedOption.text;
95
- }, [configuration.config, selectedOption.text, t]);
95
+ }, [configuration?.config, selectedOption?.text, t]);
96
96
 
97
97
  const iconSvg = useMemo(() => {
98
98
  switch (icon) {