@eohjsc/react-native-smart-city 0.3.15 → 0.3.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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.3.15",
4
+ "version": "0.3.18",
5
5
  "description": "TODO",
6
6
  "main": "index.js",
7
7
  "files": [
@@ -22,8 +22,8 @@ const NumberUpDownActionTemplate = ({ actionGroup, doAction, sensor }) => {
22
22
 
23
23
  // eslint-disable-next-line no-unused-vars
24
24
  const [configValues, setConfigValues] = useConfigGlobalState('configValues');
25
- const [value, setValue] = useState();
26
25
  const valueDefault = 28;
26
+ const [value, setValue] = useState(valueDefault);
27
27
 
28
28
  useEffect(() => {
29
29
  if (sensor?.device_type === DEVICE_TYPE.LG_THINQ) {
@@ -40,15 +40,12 @@ const NumberUpDownActionTemplate = ({ actionGroup, doAction, sensor }) => {
40
40
 
41
41
  useEffect(() => {
42
42
  if (!config) {
43
- setValue(valueDefault);
44
43
  return;
45
44
  }
46
45
 
47
46
  const configValue = configValues[config];
48
47
  if (configValue !== null && configValue !== undefined) {
49
48
  setValue(configValue);
50
- } else {
51
- setValue(valueDefault);
52
49
  }
53
50
  // eslint-disable-next-line react-hooks/exhaustive-deps
54
51
  }, [JSON.stringify(configValues)]);
@@ -14,6 +14,35 @@ import Connecting from '../Connecting';
14
14
  import { useSCContextSelector } from '../../context';
15
15
  import { ToastBottomHelper } from '../../utils/Utils';
16
16
 
17
+ const ConnectingSuccess = ({
18
+ unit,
19
+ sensor,
20
+ station,
21
+ unit_name,
22
+ newName,
23
+ setNewName,
24
+ }) => {
25
+ const t = useTranslations();
26
+ return (
27
+ <View style={styles.ConnectingSuccess}>
28
+ <ImageSuccessfully />
29
+ <Text bold style={styles.connectingText}>
30
+ {t('successfully_connected')}
31
+ </Text>
32
+ <Text size={14} style={styles.textHome}>
33
+ {`${unit?.name || unit_name} ${
34
+ station?.name !== undefined ? '- ' + station?.name : ''
35
+ }`}
36
+ </Text>
37
+ <DeviceItem
38
+ icon={sensor?.icon_kit}
39
+ name={newName}
40
+ setNewName={setNewName}
41
+ />
42
+ </View>
43
+ );
44
+ };
45
+
17
46
  const ConnectingProcess = ({ route }) => {
18
47
  const { navigate, goBack } = useNavigation();
19
48
  const t = useTranslations();
@@ -34,7 +63,7 @@ const ConnectingProcess = ({ route }) => {
34
63
  const user = useSCContextSelector((state) => state?.auth?.account?.user);
35
64
  const [newName, setNewName] = useState('');
36
65
 
37
- const ConnectingDevice = useCallback(async () => {
66
+ const connectingDevice = useCallback(async () => {
38
67
  setIsLoading(true);
39
68
  switch (devicePrefixName) {
40
69
  case 'SENSOR': {
@@ -106,27 +135,6 @@ const ConnectingProcess = ({ route }) => {
106
135
  unit_id,
107
136
  ]);
108
137
 
109
- const ConnectingSuccess = useCallback(() => {
110
- return (
111
- <View style={styles.ConnectingSuccess}>
112
- <ImageSuccessfully />
113
- <Text bold style={styles.connectingText}>
114
- {t('successfully_connected')}
115
- </Text>
116
- <Text size={14} style={styles.textHome}>
117
- {`${unit?.name || unit_name} ${
118
- station?.name !== undefined ? '- ' + station?.name : ''
119
- }`}
120
- </Text>
121
- <DeviceItem
122
- icon={sensor?.icon_kit}
123
- name={newName}
124
- setNewName={setNewName}
125
- />
126
- </View>
127
- );
128
- }, [newName, sensor?.icon_kit, station?.name, t, unit?.name, unit_name]);
129
-
130
138
  const handleDone = useCallback(async () => {
131
139
  let result, message;
132
140
  switch (devicePrefixName) {
@@ -178,8 +186,8 @@ const ConnectingProcess = ({ route }) => {
178
186
  ]);
179
187
 
180
188
  useEffect(() => {
181
- ConnectingDevice();
182
- }, [ConnectingDevice]);
189
+ connectingDevice();
190
+ }, [connectingDevice]);
183
191
 
184
192
  return (
185
193
  <SafeAreaView style={styles.wrap}>
@@ -188,7 +196,16 @@ const ConnectingProcess = ({ route }) => {
188
196
  {t('connect_device')}
189
197
  </Text>
190
198
  {!!isLoading && <Connecting isLoading={isLoading} />}
191
- {!isLoading && <ConnectingSuccess />}
199
+ {!isLoading && (
200
+ <ConnectingSuccess
201
+ unit={unit}
202
+ sensor={sensor}
203
+ station={station}
204
+ unit_name={unit_name}
205
+ newName={newName}
206
+ setNewName={setNewName}
207
+ />
208
+ )}
192
209
  </View>
193
210
  {!isLoading && (
194
211
  <TouchableOpacity style={styles.buttonDone} onPress={handleDone}>
@@ -24,7 +24,7 @@ const SubUnitFavorites = ({
24
24
  const { getStatus, serverDown } = useSensorsStatus(unit, favoriteDevices);
25
25
 
26
26
  const handleOnAddNew = () => {
27
- navigate(Routes.SelectDevices, {
27
+ navigate(Routes.SelectFavoritesDevices, {
28
28
  unitId: unit.id,
29
29
  });
30
30
  };
@@ -113,6 +113,7 @@ describe('Test useRemoteControl', () => {
113
113
  'bluetooth',
114
114
  actionName
115
115
  );
116
+ expect(sendCommandOverInternet).toBeCalledTimes(1);
116
117
  expect(sendCommandOverGoogleHome).not.toBeCalled();
117
118
  expect(sendCommandOverLGThinq).not.toBeCalled();
118
119
  });
@@ -18,6 +18,7 @@ const useRemoteControl = () => {
18
18
  async (sensor, action, data, userId, actionName) => {
19
19
  // No action, raise not authorized
20
20
  let result = false;
21
+
21
22
  if (!action) {
22
23
  ToastBottomHelper.error(
23
24
  t('your_account_has_not_been_authorized_to_control')
@@ -29,6 +30,7 @@ const useRemoteControl = () => {
29
30
  try {
30
31
  result = await sendCommandOverBluetooth(sensor, action, data, userId);
31
32
  } catch (err) {
33
+ result = false;
32
34
  if (err === SEND_COMMAND_OVER_BLUETOOTH_FAIL) {
33
35
  result = await sendCommandOverInternet(
34
36
  sensor,
@@ -44,8 +46,9 @@ const useRemoteControl = () => {
44
46
  }
45
47
 
46
48
  if (
47
- action.command_prefer_over_internet ||
48
- action.command_prefer_over_bluetooth
49
+ (action.command_prefer_over_internet ||
50
+ action.command_prefer_over_bluetooth) &&
51
+ !result
49
52
  ) {
50
53
  result = await sendCommandOverInternet(
51
54
  sensor,
@@ -55,7 +58,7 @@ const useRemoteControl = () => {
55
58
  );
56
59
  }
57
60
 
58
- if (action.command_prefer_over_googlehome) {
61
+ if (action.command_prefer_over_googlehome && !result) {
59
62
  result = await sendCommandOverGoogleHome(
60
63
  ggHomeConnections,
61
64
  sensor,
@@ -51,7 +51,7 @@ import EmergencySetting from '../screens/EmergencySetting';
51
51
  import ConfirmUnitDeletion from '../screens/ConfirmUnitDeletion';
52
52
  import InfoMemberUnit from '../screens/Sharing/InfoMemberUnit';
53
53
  import EnterPassword from '../screens/EnterPassword';
54
- import SelectDevices from '../screens/Unit/SelectDevices';
54
+ import SelectFavoritesDevices from '../screens/Unit/SelectFavoritesDevices';
55
55
  import { HanetCameraStack } from './HanetCameraStack';
56
56
  import { axiosGet } from '../utils/Apis/axios';
57
57
  import { API } from '../configs';
@@ -402,8 +402,8 @@ export const UnitStack = memo((props) => {
402
402
  }}
403
403
  />
404
404
  <Stack.Screen
405
- name={Route.SelectDevices}
406
- component={SelectDevices}
405
+ name={Route.SelectFavoritesDevices}
406
+ component={SelectFavoritesDevices}
407
407
  options={{
408
408
  headerShown: false,
409
409
  }}
@@ -64,7 +64,7 @@ const AddCommonSelectSubUnit = ({ route }) => {
64
64
  const fetchDetails = useCallback(async () => {
65
65
  const { success, data } = await axiosGet(
66
66
  API.UNIT.UNIT_DETAIL(unit_id),
67
- {},
67
+ { headers: { 'Cache-Control': 'no-cache' } },
68
68
  true
69
69
  );
70
70
  if (success) {
@@ -41,6 +41,7 @@ const SelectAction = memo(({ route }) => {
41
41
  isAutomateTab,
42
42
  isCreateNewAction,
43
43
  isMultiUnits,
44
+ oldType,
44
45
  } = route.params;
45
46
  const [data, setData] = useState([]);
46
47
  const [actions, setActions] = useState([]);
@@ -257,7 +258,7 @@ const SelectAction = memo(({ route }) => {
257
258
  navigate(Routes.ScriptDetail, {
258
259
  id: automateId,
259
260
  name: scriptName,
260
- type: type,
261
+ type: oldType,
261
262
  havePermission: true,
262
263
  unit,
263
264
  isMultiUnits,
@@ -116,6 +116,7 @@ const SelectSensorDevices = memo(({ route }) => {
116
116
  isAutomateTab,
117
117
  isCreateNewAction,
118
118
  isMultiUnits,
119
+ oldType,
119
120
  });
120
121
  }, [
121
122
  navigate,
@@ -131,6 +132,7 @@ const SelectSensorDevices = memo(({ route }) => {
131
132
  isAutomateTab,
132
133
  isCreateNewAction,
133
134
  isMultiUnits,
135
+ oldType,
134
136
  ]);
135
137
 
136
138
  const onPressClose = useCallback(() => {
@@ -13,7 +13,7 @@ const useConnectDevices = (new_sensor, station_id, unit_id) => {
13
13
  const fetchDetails = useCallback(async () => {
14
14
  const { success: fetchSuccess, data: unit } = await axiosGet(
15
15
  API.UNIT.UNIT_DETAIL(unit_id),
16
- {},
16
+ { headers: { 'Cache-Control': 'no-cache' } },
17
17
  true
18
18
  );
19
19
  const station = unit.stations.find((item) => item.id === station_id);
@@ -27,7 +27,7 @@ const AddNewDevice = memo(({ route }) => {
27
27
  const fetchDetails = useCallback(async () => {
28
28
  const { success, data } = await axiosGet(
29
29
  API.UNIT.UNIT_DETAIL(unit_id),
30
- {},
30
+ { headers: { 'Cache-Control': 'no-cache' } },
31
31
  true
32
32
  );
33
33
  if (success) {
@@ -9,7 +9,7 @@ const useConnectGateway = (unit_id) => {
9
9
  const fetchDetails = useCallback(async () => {
10
10
  const { success: fetchSuccess, data: unit } = await axiosGet(
11
11
  API.UNIT.UNIT_DETAIL(unit_id),
12
- {},
12
+ { headers: { 'Cache-Control': 'no-cache' } },
13
13
  true
14
14
  );
15
15
  return { fetchSuccess, unit };
@@ -11,7 +11,7 @@ export default (unit) => {
11
11
  setIsLoading(true);
12
12
  const { success, data } = await axiosGet(
13
13
  API.UNIT.UNIT_DETAIL(unit?.id),
14
- {},
14
+ { headers: { 'Cache-Control': 'no-cache' } },
15
15
  true
16
16
  );
17
17
  if (success) {
@@ -24,7 +24,7 @@ const AddLGDevice = memo(({ route }) => {
24
24
  const fetchDetails = useCallback(async () => {
25
25
  const { success, data } = await axiosGet(
26
26
  API.UNIT.UNIT_DETAIL(unit_id),
27
- {},
27
+ { headers: { 'Cache-Control': 'no-cache' } },
28
28
  true
29
29
  );
30
30
  if (success) {
@@ -20,9 +20,9 @@ import { SCContext } from '../../context';
20
20
  import { Action } from '../../context/actionType';
21
21
  import { axiosGet, axiosPost } from '../../utils/Apis/axios';
22
22
  import { API, Colors } from '../../configs';
23
- import styles from './SelectDevicesStyles';
23
+ import styles from './SelectFavoritesDevicesStyles';
24
24
 
25
- const SelectDevices = memo(({ route }) => {
25
+ const SelectFavoritesDevices = memo(({ route }) => {
26
26
  const t = useTranslations();
27
27
  const { goBack } = useNavigation();
28
28
  const { unitId } = route.params;
@@ -32,7 +32,7 @@ const SelectDevices = memo(({ route }) => {
32
32
  const [indexStation, setIndexStation] = useState(0);
33
33
  const [stations, setStations] = useState([]);
34
34
  const [selectedIds, setSelectedIds] = useState([]);
35
- const [loading, setLoading] = useState(false);
35
+ const [loading, setLoading] = useState(true);
36
36
 
37
37
  const fetchData = useCallback(async () => {
38
38
  setLoading(true);
@@ -116,7 +116,7 @@ const SelectDevices = memo(({ route }) => {
116
116
  {t('select_device')}
117
117
  </Text>
118
118
 
119
- {listStation.length ? (
119
+ {!!listStation.length && (
120
120
  <NavBar
121
121
  listStation={listStation}
122
122
  listMenuItem={listMenuItem}
@@ -124,7 +124,8 @@ const SelectDevices = memo(({ route }) => {
124
124
  indexStation={indexStation}
125
125
  style={styles.navbar}
126
126
  />
127
- ) : (
127
+ )}
128
+ {!listStation.length && !loading && (
128
129
  <View style={styles.noneData}>
129
130
  <Text center>{t('text_unit_add_to_favorites_no_devices')}</Text>
130
131
  </View>
@@ -155,4 +156,4 @@ const SelectDevices = memo(({ route }) => {
155
156
  );
156
157
  });
157
158
 
158
- export default SelectDevices;
159
+ export default SelectFavoritesDevices;
@@ -4,7 +4,7 @@ import MockAdapter from 'axios-mock-adapter';
4
4
 
5
5
  import { SCProvider } from '../../../context';
6
6
  import { mockSCStore } from '../../../context/mockStore';
7
- import SelectDevices from '../SelectDevices';
7
+ import SelectFavoritesDevices from '../SelectFavoritesDevices';
8
8
  import Device from '../../AddNewAction/Device';
9
9
  import BottomButtonView from '../../../commons/BottomButtonView';
10
10
  import { API } from '../../../configs';
@@ -12,7 +12,7 @@ import api from '../../../utils/Apis/axios';
12
12
 
13
13
  const wrapComponent = (route) => (
14
14
  <SCProvider initState={mockSCStore({})}>
15
- <SelectDevices route={route} />
15
+ <SelectFavoritesDevices route={route} />
16
16
  </SCProvider>
17
17
  );
18
18
 
@@ -35,7 +35,7 @@ jest.mock('react', () => {
35
35
  };
36
36
  });
37
37
 
38
- describe('Test SelectDevices', () => {
38
+ describe('Test SelectFavoritesDevices', () => {
39
39
  let tree, route;
40
40
 
41
41
  beforeAll(() => {
@@ -93,7 +93,7 @@ const UnitSummary = memo(({ route }) => {
93
93
  const fetchUnitDetail = useCallback(async () => {
94
94
  const { success, data } = await axiosGet(
95
95
  API.UNIT.UNIT_DETAIL(unit?.id),
96
- {},
96
+ { headers: { 'Cache-Control': 'no-cache' } },
97
97
  true
98
98
  );
99
99
  if (success) {
@@ -146,7 +146,7 @@ const Routes = {
146
146
  ItemPasscode: 'ItemPasscode',
147
147
  UnitMemberInformation: 'UnitMemberInformation',
148
148
  EnterPassword: 'EnterPassword',
149
- SelectDevices: 'SelectDevices',
149
+ SelectFavoritesDevices: 'SelectFavoritesDevices',
150
150
  };
151
151
 
152
152
  export default Routes;