@eohjsc/react-native-smart-city 0.3.52 → 0.3.53
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 +2 -2
- package/src/commons/Device/ItemDevice.js +1 -1
- package/src/hooks/IoT/useBluetoothConnection.js +3 -1
- package/src/screens/Device/__test__/detail.test.js +13 -2
- package/src/screens/Device/detail.js +65 -63
- package/src/screens/Device/hooks/useDisconnectedDevice.js +1 -1
- package/src/screens/PlayBackCamera/index.js +4 -1
- package/src/screens/Sharing/SelectPermission.js +2 -2
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.
|
|
4
|
+
"version": "0.3.53",
|
|
5
5
|
"description": "TODO",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"files": [
|
|
@@ -116,7 +116,7 @@
|
|
|
116
116
|
"@react-native-community/datetimepicker": "https://github.com/hinh-eoh/datepicker",
|
|
117
117
|
"@react-native-community/geolocation": "^2.0.2",
|
|
118
118
|
"@react-native-community/masked-view": "^0.1.10",
|
|
119
|
-
"@react-native-community/netinfo": "^
|
|
119
|
+
"@react-native-community/netinfo": "^9.3.4",
|
|
120
120
|
"@react-native-community/segmented-control": "^2.1.1",
|
|
121
121
|
"@react-native-community/slider": "^3.0.3",
|
|
122
122
|
"@react-native-community/toolbar-android": "^0.1.0-rc.2",
|
|
@@ -13,7 +13,8 @@ const permissions = [
|
|
|
13
13
|
'android.permission.BLUETOOTH_ADVERTISE',
|
|
14
14
|
];
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
// NOTE: fnCallback is used for Lavida when found device
|
|
17
|
+
const useBluetoothConnection = (fnCallback) => {
|
|
17
18
|
const t = useTranslations();
|
|
18
19
|
const appState = useRef(AppState.currentState);
|
|
19
20
|
|
|
@@ -29,6 +30,7 @@ const useBluetoothConnection = () => {
|
|
|
29
30
|
useSCContextSelector((state) => state.bluetooth.permissionsGranted);
|
|
30
31
|
|
|
31
32
|
const onDeviceFound = useCallback(async (name, device) => {
|
|
33
|
+
fnCallback && fnCallback({ name, device });
|
|
32
34
|
setAction(Action.SET_BLUETOOTH_CONNECTED_DEVICE, { name, device });
|
|
33
35
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
34
36
|
}, []);
|
|
@@ -2,6 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import { Alert, ScrollView } from 'react-native';
|
|
3
3
|
import { act, create } from 'react-test-renderer';
|
|
4
4
|
import MockAdapter from 'axios-mock-adapter';
|
|
5
|
+
import { NavigationContext } from '@react-navigation/native';
|
|
5
6
|
|
|
6
7
|
import DeviceDetail from '../detail';
|
|
7
8
|
import { API } from '../../../configs';
|
|
@@ -29,7 +30,6 @@ jest.mock('@react-navigation/native', () => {
|
|
|
29
30
|
useNavigation: () => ({
|
|
30
31
|
navigate: mockedNavigate,
|
|
31
32
|
}),
|
|
32
|
-
useFocusEffect: jest.fn(),
|
|
33
33
|
};
|
|
34
34
|
});
|
|
35
35
|
|
|
@@ -73,9 +73,20 @@ const mockAxios = (
|
|
|
73
73
|
|
|
74
74
|
let store = mockSCStore({});
|
|
75
75
|
|
|
76
|
+
const navContextValue = {
|
|
77
|
+
isFocused: () => false,
|
|
78
|
+
addListener: jest.fn(() => jest.fn()),
|
|
79
|
+
};
|
|
76
80
|
const wrapComponent = (state, account, route) => (
|
|
77
81
|
<SCProvider initState={state}>
|
|
78
|
-
<
|
|
82
|
+
<NavigationContext.Provider
|
|
83
|
+
value={{
|
|
84
|
+
...navContextValue,
|
|
85
|
+
isFocused: () => true,
|
|
86
|
+
}}
|
|
87
|
+
>
|
|
88
|
+
<DeviceDetail account={account} route={route} />
|
|
89
|
+
</NavigationContext.Provider>
|
|
79
90
|
</SCProvider>
|
|
80
91
|
);
|
|
81
92
|
|
|
@@ -7,7 +7,7 @@ import React, {
|
|
|
7
7
|
useContext,
|
|
8
8
|
} from 'react';
|
|
9
9
|
import { View, TouchableOpacity, Platform } from 'react-native';
|
|
10
|
-
import { useNavigation } from '@react-navigation/native';
|
|
10
|
+
import { useNavigation, useFocusEffect } from '@react-navigation/native';
|
|
11
11
|
import { useSelector } from 'react-redux';
|
|
12
12
|
import { IconFill, IconOutline } from '@ant-design/icons-react-native';
|
|
13
13
|
import { Icon } from '@ant-design/react-native';
|
|
@@ -118,7 +118,7 @@ const DeviceDetail = ({ route }) => {
|
|
|
118
118
|
|
|
119
119
|
const isDeviceHasBle = useMemo(() => {
|
|
120
120
|
if (display.items.length === 0) {
|
|
121
|
-
return
|
|
121
|
+
return false;
|
|
122
122
|
}
|
|
123
123
|
const action = display.items.filter((item) => item.type === 'action');
|
|
124
124
|
if (action.length === 0) {
|
|
@@ -501,77 +501,79 @@ const DeviceDetail = ({ route }) => {
|
|
|
501
501
|
[configValues, displayValuesData, evaluateValue]
|
|
502
502
|
);
|
|
503
503
|
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
504
|
+
useFocusEffect(
|
|
505
|
+
useCallback(() => {
|
|
506
|
+
let params = new URLSearchParams();
|
|
507
|
+
const configIds = [];
|
|
507
508
|
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
if (!item.configuration) {
|
|
514
|
-
return;
|
|
515
|
-
}
|
|
509
|
+
display.items.map((item) => {
|
|
510
|
+
if (item.type !== 'value') {
|
|
511
|
+
return;
|
|
512
|
+
}
|
|
516
513
|
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
configIds.push(config.id);
|
|
514
|
+
if (!item.configuration) {
|
|
515
|
+
return;
|
|
520
516
|
}
|
|
517
|
+
|
|
518
|
+
item.configuration.configs.map((config) => {
|
|
519
|
+
if (!configIds.includes(config.id)) {
|
|
520
|
+
configIds.push(config.id);
|
|
521
|
+
}
|
|
522
|
+
});
|
|
521
523
|
});
|
|
522
|
-
});
|
|
523
524
|
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
525
|
+
configIds.map((id) => {
|
|
526
|
+
params.append('config', id);
|
|
527
|
+
});
|
|
527
528
|
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
529
|
+
const fetchValues = async () => {
|
|
530
|
+
const { success, data, resp_status } = await axiosGet(
|
|
531
|
+
API.DEVICE.DISPLAY_VALUES_V2(sensor?.id),
|
|
532
|
+
{
|
|
533
|
+
params: params,
|
|
534
|
+
}
|
|
535
|
+
);
|
|
536
|
+
if (success) {
|
|
537
|
+
data.isConnected = data.is_connected;
|
|
538
|
+
data.lastUpdated = data.last_updated
|
|
539
|
+
? moment(data.last_updated)
|
|
540
|
+
: data.last_updated;
|
|
541
|
+
setDisplayValuesData((prevState) => {
|
|
542
|
+
if (prevState.isConnected !== data.isConnected) {
|
|
543
|
+
setAction(Action.SET_DEVICES_STATUS, [
|
|
544
|
+
{ id: sensor?.id, is_connected: data.is_connected },
|
|
545
|
+
]);
|
|
546
|
+
}
|
|
547
|
+
return data;
|
|
548
|
+
});
|
|
549
|
+
} else if (resp_status >= 500) {
|
|
550
|
+
setServerDown(true);
|
|
533
551
|
}
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
setDisplayValuesData((prevState) => {
|
|
541
|
-
if (prevState.isConnected !== data.isConnected) {
|
|
542
|
-
setAction(Action.SET_DEVICES_STATUS, [
|
|
543
|
-
{ id: sensor?.id, is_connected: data.is_connected },
|
|
544
|
-
]);
|
|
552
|
+
setLoading((preState) => {
|
|
553
|
+
if (preState.isConnected) {
|
|
554
|
+
return {
|
|
555
|
+
...preState,
|
|
556
|
+
isConnected: false,
|
|
557
|
+
};
|
|
545
558
|
}
|
|
546
|
-
return
|
|
559
|
+
return preState;
|
|
547
560
|
});
|
|
548
|
-
}
|
|
549
|
-
|
|
561
|
+
};
|
|
562
|
+
if (
|
|
563
|
+
isNetworkConnected &&
|
|
564
|
+
sensor?.is_managed_by_backend &&
|
|
565
|
+
sensor?.device_type !== DEVICE_TYPE.LG_THINQ
|
|
566
|
+
) {
|
|
567
|
+
const updateInterval = setInterval(() => fetchValues(), 5000);
|
|
568
|
+
fetchValues();
|
|
569
|
+
return () => clearInterval(updateInterval);
|
|
570
|
+
} else {
|
|
571
|
+
Object.keys(sensor).length > 1 &&
|
|
572
|
+
setLoading((preState) => ({ ...preState, isConnected: false }));
|
|
550
573
|
}
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
...preState,
|
|
555
|
-
isConnected: false,
|
|
556
|
-
};
|
|
557
|
-
}
|
|
558
|
-
return preState;
|
|
559
|
-
});
|
|
560
|
-
};
|
|
561
|
-
if (
|
|
562
|
-
isNetworkConnected &&
|
|
563
|
-
sensor?.is_managed_by_backend &&
|
|
564
|
-
sensor?.device_type !== DEVICE_TYPE.LG_THINQ
|
|
565
|
-
) {
|
|
566
|
-
const updateInterval = setInterval(() => fetchValues(), 5000);
|
|
567
|
-
fetchValues();
|
|
568
|
-
return () => clearInterval(updateInterval);
|
|
569
|
-
} else {
|
|
570
|
-
Object.keys(sensor).length > 1 &&
|
|
571
|
-
setLoading((preState) => ({ ...preState, isConnected: false }));
|
|
572
|
-
}
|
|
573
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
574
|
-
}, [sensor, display, isNetworkConnected]);
|
|
574
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
575
|
+
}, [sensor, display, isNetworkConnected])
|
|
576
|
+
);
|
|
575
577
|
|
|
576
578
|
const isShowEmergencyResolve =
|
|
577
579
|
display.items.filter(
|
|
@@ -72,7 +72,10 @@ const PlayBackCamera = () => {
|
|
|
72
72
|
(hour) => {
|
|
73
73
|
const hourWithTimezone =
|
|
74
74
|
parseInt(hour, 10) + parseInt(item?.configuration?.time_zone || 0, 10);
|
|
75
|
-
|
|
75
|
+
if (hourWithTimezone < 0 || hourWithTimezone > 9) {
|
|
76
|
+
return hourWithTimezone;
|
|
77
|
+
}
|
|
78
|
+
return '0' + hourWithTimezone;
|
|
76
79
|
},
|
|
77
80
|
[item?.configuration?.time_zone]
|
|
78
81
|
);
|
|
@@ -267,8 +267,8 @@ const SelectPermission = ({ route }) => {
|
|
|
267
267
|
arrIdReadTemp.length &&
|
|
268
268
|
read_permissions.push({ id: item.id, values: arrIdReadTemp });
|
|
269
269
|
|
|
270
|
-
!arrIdControlTemp &&
|
|
271
|
-
!arrIdReadTemp &&
|
|
270
|
+
!arrIdControlTemp.length &&
|
|
271
|
+
!arrIdReadTemp.length &&
|
|
272
272
|
item.isChecked &&
|
|
273
273
|
read_permissions.push({ id: item.id, values: [] });
|
|
274
274
|
}
|