@eohjsc/react-native-smart-city 0.2.99 → 0.3.2
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/README.md +1 -1
- package/package.json +6 -4
- package/react-native-smart-city.podspec +1 -0
- package/src/commons/Action/ItemQuickAction.js +11 -2
- package/src/commons/Action/__test__/ItemQuickAction.test.js +11 -6
- package/src/commons/ActionGroup/CurtainButtonTemplate.js +10 -5
- package/src/commons/ActionGroup/NumberUpDownActionTemplate.js +31 -20
- package/src/commons/ActionGroup/OnOffSmartLock/AutoLock/__test__/index.test.js +4 -0
- package/src/commons/ActionGroup/OnOffSmartLock/PasscodeList/ItemPasscode.js +1 -1
- package/src/commons/ActionGroup/OnOffSmartLock/PasscodeList/__test__/ItemPasscode.test.js +24 -0
- package/src/commons/ActionGroup/OnOffSmartLock/SetupGeneratePasscode/__test__/index.test.js +14 -0
- package/src/commons/ActionGroup/OptionsDropdownActionTemplate.js +1 -1
- package/src/commons/ActionGroup/SmartTiviActionTemplate/SmartTiviActionTemplate.js +3 -2
- package/src/commons/ActionGroup/StatesGridActionTemplate.js +8 -4
- package/src/commons/ActionGroup/TimerActionTemplate.js +2 -2
- package/src/commons/ActionGroup/TwoButtonTemplate/index.js +0 -1
- package/src/commons/ActionGroup/__test__/CurtainButtonTemplate.test.js +53 -4
- package/src/commons/ActionGroup/__test__/NumberUpDownTemplate.test.js +45 -48
- package/src/commons/ActionGroup/__test__/StatesGridActionTemplate.test.js +77 -0
- package/src/commons/ActionGroup/__test__/TimerActionTemplate.test.js +58 -6
- package/src/commons/ActionGroup/__test__/TwoButtonTemplate.test.js +49 -1
- package/src/commons/ActionGroup/__test__/index.test.js +137 -2
- package/src/commons/Automate/ItemAutomate.js +1 -3
- package/src/commons/Calendar/__test__/Calendar.test.js +33 -0
- package/src/commons/Connecting/__test__/Connecting.test.js +19 -2
- package/src/commons/ConnectingProcess/DeviceItem/DeviceItem.js +7 -3
- package/src/commons/ConnectingProcess/DeviceItem/DeviceItemStyles.js +8 -11
- package/src/commons/ConnectingProcess/__test__/Connecting.test.js +136 -3
- package/src/commons/ConnectingProcess/__test__/DeviceItem.test.js +3 -2
- package/src/commons/ConnectingProcess/index.js +72 -25
- package/src/commons/Dashboard/MyPinnedSharedUnit/__test__/MyPinnedSharedUnit.test.js +16 -13
- package/src/commons/Dashboard/MyPinnedSharedUnit/index.js +1 -1
- package/src/commons/Dashboard/MyUnit/__test__/MyUnit.test.js +0 -5
- package/src/commons/Device/ConnectedViewHeader.js +1 -1
- package/src/commons/Device/Hanet/ItemHanetDevice.test.js +58 -0
- package/src/commons/Device/HistoryChart.js +3 -3
- package/src/commons/Device/ItemDevice.js +15 -11
- package/src/commons/Device/LinearChart.js +15 -0
- package/src/commons/Device/SonosSpeaker/index.js +1 -1
- package/src/commons/Explore/__test__/CityItem.test.js +33 -54
- package/src/commons/FieldTemplate/ChooseUserField/__test__/index.test.js +19 -14
- package/src/commons/FieldTemplate/PasscodeField/__test__/index.test.js +0 -3
- package/src/commons/FieldTemplate/ScheduleField/__test__/index.test.js +0 -3
- package/src/commons/FieldTemplate/ScheduleField/index.js +2 -2
- package/src/commons/Header/HeaderCustom.js +2 -1
- package/src/commons/HorizontalPicker/index.js +2 -2
- package/src/commons/MediaPlayerDetail/Styles/MediaPlayerDetailStyles.js +0 -6
- package/src/commons/MediaPlayerDetail/index.js +24 -55
- package/src/commons/Sharing/__test__/DevicePermissionsCheckbox.test.js +0 -1
- package/src/commons/SubUnit/Favorites/index.js +2 -3
- package/src/commons/SubUnit/OneTap/__test__/SubUnitAutomate.test.js +8 -35
- package/src/commons/SubUnit/OneTap/index.js +1 -2
- package/src/commons/SubUnit/ShortDetail.js +25 -9
- package/src/commons/SubUnit/__test__/Item.test.js +0 -1
- package/src/commons/SubUnit/__test__/ShortDetail.test.js +8 -1
- package/src/commons/Unit/SharedUnit.js +1 -0
- package/src/commons/Unit/__test__/SharedUnit.test.js +38 -183
- package/src/commons/UnitSummary/ConfigHistoryChart/index.js +2 -13
- package/src/commons/UnitSummary/ConfigHistoryChart.js +22 -13
- package/src/commons/WheelDateTimePicker/index.js +2 -2
- package/src/configs/API.js +85 -144
- package/src/configs/Constants.js +24 -0
- package/src/configs/SCConfig.js +2 -0
- package/src/context/actionType.ts +8 -0
- package/src/context/mockStore.ts +10 -0
- package/src/context/reducer.ts +38 -2
- package/src/hooks/Common/index.js +2 -0
- package/src/hooks/Common/useGGHomeDeviceConnected.js +16 -0
- package/src/hooks/Common/useGetIdUser.js +1 -5
- package/src/hooks/Common/useSensorsStatus.js +4 -4
- package/src/hooks/IoT/__test__/useGGHomeConnection.test.js +198 -0
- package/src/hooks/IoT/__test__/useRemoteControl.test.js +198 -0
- package/src/hooks/IoT/index.js +4 -0
- package/src/hooks/IoT/useGGHomeConnection.js +91 -0
- package/src/hooks/IoT/useRemoteControl.js +79 -0
- package/src/hooks/index.js +4 -0
- package/src/hooks/useReceiveNotifications.js +9 -5
- package/src/iot/Monitor.js +3 -2
- package/src/iot/RemoteControl/Bluetooth.js +1 -1
- package/src/iot/RemoteControl/GoogleHome.js +75 -49
- package/src/iot/RemoteControl/Internet.js +1 -1
- package/src/iot/RemoteControl/__test__/GoogleHome.test.js +95 -48
- package/src/iot/RemoteControl/__test__/Internet.test.js +18 -7
- package/src/iot/RemoteControl/__test__/LgThinq.test.js +36 -177
- package/src/iot/RemoteControl/index.js +52 -52
- package/src/screens/ActivityLog/__test__/index.test.js +38 -23
- package/src/screens/ActivityLog/hooks/__test__/index.test.js +51 -90
- package/src/screens/ActivityLog/hooks/index.js +1 -1
- package/src/screens/ActivityLog/index.js +2 -2
- package/src/screens/AddCommon/__test__/SelectSubUnit.test.js +13 -24
- package/src/screens/AddCommon/__test__/SelectUnit.test.js +9 -33
- package/src/screens/AddLocationMaps/index.js +5 -4
- package/src/screens/AddNewAction/SelectAction.js +8 -8
- package/src/screens/AddNewAction/SetupSensor.js +7 -7
- package/src/screens/AddNewAction/__test__/SelectAction.test.js +10 -91
- package/src/screens/AddNewAction/__test__/SelectSensorDevices.test.js +40 -26
- package/src/screens/AddNewDevice/ConnectingDevices.js +3 -3
- package/src/screens/AddNewDevice/__test__/AddNewDevice.test.js +34 -33
- package/src/screens/AddNewDevice/__test__/ConnectDevices.test.js +0 -4
- package/src/screens/AddNewDevice/__test__/ConnectingDevices.test.js +21 -21
- package/src/screens/AddNewDevice/hooks/ConnectDevices.js +1 -1
- package/src/screens/AddNewGateway/PlugAndPlay/ConnectWifiWarning.js +23 -17
- package/src/screens/AddNewGateway/PlugAndPlay/GatewayWifiList.js +3 -3
- package/src/screens/AddNewGateway/SetupGatewayWifi.js +1 -0
- package/src/screens/AddNewGateway/__test__/AddNewGateway.test.js +4 -6
- package/src/screens/AddNewGateway/__test__/ConnectedGateway.test.js +0 -4
- package/src/screens/AddNewGateway/__test__/ConnectingGateway.test.js +5 -29
- package/src/screens/AddNewGateway/__test__/SelectGateway.test.js +0 -4
- package/src/screens/AddNewGateway/__test__/SetupGateway.test.js +0 -4
- package/src/screens/AddNewOneTap/__test__/AddNewOneTap.test.js +9 -23
- package/src/screens/AllCamera/index.js +4 -4
- package/src/screens/Automate/MultiUnits.js +8 -8
- package/src/screens/Automate/__test__/MultiUnits.test.js +6 -9
- package/src/screens/Automate/__test__/index.test.js +7 -12
- package/src/screens/Automate/index.js +3 -3
- package/src/screens/ConfirmUnitDeletion/__test__/ConfirmUnitDeletion.test.js +36 -8
- package/src/screens/ConfirmUnitDeletion/index.js +7 -1
- package/src/screens/Device/EditDevice/__test__/EditDevice.test.js +71 -22
- package/src/screens/Device/EditDevice/index.js +2 -2
- package/src/screens/Device/__test__/detail.test.js +32 -85
- package/src/screens/Device/components/DetailHistoryChart.js +1 -1
- package/src/screens/Device/components/SensorConnectStatusViewHeader.js +1 -0
- package/src/screens/Device/components/SensorDisplayItem.js +5 -2
- package/src/screens/Device/detail.js +53 -22
- package/src/screens/Device/hooks/useDisconnectedDevice.js +4 -4
- package/src/screens/Device/hooks/useFavoriteDevice.js +5 -9
- package/src/screens/DeviceInfo/__test__/index.test.js +0 -2
- package/src/screens/EditActionsList/index.js +1 -1
- package/src/screens/EmergencyContacts/EmergencyContactsSelectContacts.js +1 -1
- package/src/screens/EmergencyContacts/__test__/EmergencyContactAddNew.test.js +7 -19
- package/src/screens/EmergencyContacts/__test__/EmergencyContactList.test.js +18 -14
- package/src/screens/EmergencyContacts/__test__/EmergencyContactsSelectContacts.test.js +30 -31
- package/src/screens/EmergencySetting/components/DropDownItem.js +2 -2
- package/src/screens/EnterPassword/__test__/EnterPassword.test.js +41 -25
- package/src/screens/GuestInfo/__test__/index.test.js +13 -40
- package/src/screens/HanetCamera/Detail.js +1 -1
- package/src/screens/HanetCamera/__test__/CaptureFaceID.test.js +8 -12
- package/src/screens/HanetCamera/__test__/Detail.test.js +27 -42
- package/src/screens/HanetCamera/__test__/ManageAccess.test.js +8 -5
- package/src/screens/HanetCamera/__test__/MemberInfo.test.js +10 -32
- package/src/screens/HanetCamera/components/RequestFaceIDPopup.js +3 -2
- package/src/screens/HanetCamera/hooks/__test__/useHanetCheckinData.test.js +43 -35
- package/src/screens/HanetCamera/hooks/__test__/useHanetPlaceMembers.test.js +10 -21
- package/src/screens/HanetCamera/hooks/useHanetCheckinData.js +11 -11
- package/src/screens/HanetCamera/hooks/useHanetPlaceMembers.js +11 -11
- package/src/screens/ManageAccess/__test__/ManageAccess.test.js +33 -22
- package/src/screens/ManageAccess/hooks/__test__/useManageAccess.test.js +44 -45
- package/src/screens/ManageAccess/hooks/index.js +7 -4
- package/src/screens/ManageAccess/index.js +1 -1
- package/src/screens/MoveToAnotherSubUnit/__test__/index.test.js +35 -12
- package/src/screens/MoveToAnotherSubUnit/index.js +5 -5
- package/src/screens/Notification/__test__/Notification.test.js +14 -25
- package/src/screens/Notification/__test__/NotificationItem.test.js +8 -7
- package/src/screens/Notification/components/NotificationItem.js +17 -20
- package/src/screens/Notification/index.js +9 -2
- package/src/screens/PlayBackCamera/Timer.js +2 -2
- package/src/screens/PlayBackCamera/__test__/index.test.js +87 -2
- package/src/screens/PlayBackCamera/index.js +22 -6
- package/src/screens/ScanChipQR/__test__/ScanChipQR.test.js +7 -20
- package/src/screens/ScanChipQR/hooks/index.js +15 -16
- package/src/screens/ScanSensorQR/__test__/ScanSensorQR.test.js +8 -24
- package/src/screens/ScriptDetail/__test__/index.test.js +17 -86
- package/src/screens/ScriptDetail/index.js +16 -11
- package/src/screens/SelectUnit/__test__/index.test.js +11 -54
- package/src/screens/SelectUnit/index.js +4 -2
- package/src/screens/SetSchedule/index.js +9 -9
- package/src/screens/SharedUnit/__test__/TabHeader.test.js +0 -2
- package/src/screens/Sharing/Components/SensorItem.js +10 -12
- package/src/screens/Sharing/InfoMemberUnit.js +1 -1
- package/src/screens/Sharing/SelectPermission.js +121 -76
- package/src/screens/Sharing/__test__/InfoMemberUnit.test.js +47 -29
- package/src/screens/Sharing/__test__/MemberList.test.js +13 -127
- package/src/screens/Sharing/__test__/MemberList2.test.js +80 -0
- package/src/screens/Sharing/__test__/SelectPermission.test.js +28 -38
- package/src/screens/Sharing/__test__/SelectUser.test.js +17 -38
- package/src/screens/SideMenuDetail/__test__/index.test.js +12 -23
- package/src/screens/SideMenuDetail/index.js +2 -3
- package/src/screens/SmartIr/components/GroupButtonByType/GroupButtonByType.js +3 -2
- package/src/screens/SubUnit/Detail.js +1 -2
- package/src/screens/SubUnit/ManageSubUnit.js +12 -7
- package/src/screens/SubUnit/__test__/AddSubUnit.test.js +21 -67
- package/src/screens/SubUnit/__test__/Detail.test.js +31 -8
- package/src/screens/SubUnit/__test__/EditSubUnit.test.js +21 -89
- package/src/screens/SubUnit/__test__/ManageSubUnit.test.js +27 -1
- package/src/screens/SubUnit/hooks/__test__/useManageSubUnit.test.js +48 -45
- package/src/screens/SubUnit/hooks/useManageSubUnit.js +7 -7
- package/src/screens/SyncLGDevice/__test__/AddLGDevice.test.js +14 -90
- package/src/screens/Unit/ChooseLocation.js +7 -14
- package/src/screens/Unit/Detail.js +30 -75
- package/src/screens/Unit/ManageUnit.js +1 -0
- package/src/screens/Unit/SelectAddress.js +34 -21
- package/src/screens/Unit/SmartAccount.js +4 -4
- package/src/screens/Unit/Summaries.js +17 -1
- package/src/screens/Unit/__test__/CheckSendEmail.test.js +24 -29
- package/src/screens/Unit/__test__/ChooseLocation.test.js +27 -14
- package/src/screens/Unit/__test__/Detail.test.js +99 -200
- package/src/screens/Unit/__test__/ManageUnit.test.js +18 -42
- package/src/screens/Unit/__test__/SelectAddress.test.js +84 -51
- package/src/screens/Unit/__test__/SmartAccount.test.js +17 -9
- package/src/screens/Unit/__test__/SmartAccountItem.test.js +0 -1
- package/src/screens/Unit/__test__/Summaries.test.js +100 -0
- package/src/screens/Unit/components/MyAllUnit/__test__/MyAllUnit.test.js +36 -0
- package/src/screens/Unit/components/MyAllUnit/__test__/index.test.js +54 -0
- package/src/screens/Unit/components/SharedUnit/index.js +1 -0
- package/src/screens/Unit/components/__test__/SharedUnit.test.js +31 -34
- package/src/screens/Unit/hook/useUnitConnectRemoteDevices.js +50 -0
- package/src/screens/Unit/styles.js +4 -0
- package/src/screens/UnitSummary/__test__/index.test.js +70 -41
- package/src/screens/UnitSummary/components/3PPowerConsumption/__test__/3PPowerConsumption.test.js +31 -2
- package/src/screens/UnitSummary/components/PowerConsumeHistoryChart/__test__/index.test.js +7 -4
- package/src/screens/UnitSummary/components/PowerConsumeHistoryChart/index.js +2 -13
- package/src/screens/UnitSummary/components/PowerConsumption/__test__/ItemPower.test.js +0 -1
- package/src/screens/UnitSummary/components/PowerConsumption/__test__/PowerConsumption.test.js +14 -16
- package/src/screens/UnitSummary/components/RunningDevices/__test__/index.test.js +11 -2
- package/src/screens/UnitSummary/components/RunningDevices/index.js +7 -10
- package/src/screens/UnitSummary/components/Temperature/index.js +4 -4
- package/src/screens/UnitSummary/components/WaterQuality/Item/index.js +10 -2
- package/src/screens/UnitSummary/index.js +15 -1
- package/src/utils/Apis/axios.js +46 -31
- package/src/utils/Converter/time.js +0 -18
- package/src/utils/I18n/translations/en.json +4 -1
- package/src/utils/I18n/translations/vi.json +5 -1
- package/src/utils/Permission/common.js +67 -0
- package/src/utils/Utils.js +11 -7
|
@@ -0,0 +1,198 @@
|
|
|
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(2);
|
|
171
|
+
expect(mockedSetAction).toBeCalledWith(
|
|
172
|
+
Action.SET_GOOGLE_HOME_CONNECTIONS,
|
|
173
|
+
conns
|
|
174
|
+
);
|
|
175
|
+
expect(mockedSetAction).toBeCalledWith(Action.LIST_DEVICE_TYPES, {
|
|
176
|
+
chipId: options[0].chip_id,
|
|
177
|
+
sentEmail: true,
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it('test disconnectGoogleHome', async () => {
|
|
182
|
+
let conns = {};
|
|
183
|
+
conns[options[0].chip_id] = connection;
|
|
184
|
+
conns[options[1].chip_id] = 0;
|
|
185
|
+
|
|
186
|
+
const { result } = renderHook(() => useGGHomeConnection(), {
|
|
187
|
+
wrapper,
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
await act(async () => {
|
|
191
|
+
await result.current.disconnectGoogleHome(conns, options);
|
|
192
|
+
});
|
|
193
|
+
expect(mockedSetAction).toBeCalledWith(
|
|
194
|
+
Action.SET_GOOGLE_HOME_CONNECTIONS,
|
|
195
|
+
{}
|
|
196
|
+
);
|
|
197
|
+
});
|
|
198
|
+
});
|
|
@@ -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,91 @@
|
|
|
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
|
+
await googleHomeConnect(
|
|
67
|
+
connections,
|
|
68
|
+
options,
|
|
69
|
+
onEstablished,
|
|
70
|
+
onDisconnected,
|
|
71
|
+
onReconnected
|
|
72
|
+
);
|
|
73
|
+
},
|
|
74
|
+
[connections, onEstablished, onDisconnected, onReconnected]
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
const disconnectGoogleHome = useCallback(
|
|
78
|
+
async (options) => {
|
|
79
|
+
await googleHomeDisconnect(connections, options);
|
|
80
|
+
setAction(Action.SET_GOOGLE_HOME_CONNECTIONS, {});
|
|
81
|
+
},
|
|
82
|
+
[setAction, connections]
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
return {
|
|
86
|
+
connectGoogleHome,
|
|
87
|
+
disconnectGoogleHome,
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
export default useGGHomeConnection;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
import { useSCContextSelector } from '../../context';
|
|
3
|
+
import { sendCommandOverGoogleHome } from '../../iot/RemoteControl/GoogleHome';
|
|
4
|
+
import { sendCommandOverInternet } from '../../iot/RemoteControl/Internet';
|
|
5
|
+
import { sendCommandOverLGThinq } from '../../iot/RemoteControl/LG';
|
|
6
|
+
import {
|
|
7
|
+
sendCommandOverBluetooth,
|
|
8
|
+
SEND_COMMAND_OVER_BLUETOOTH_FAIL,
|
|
9
|
+
} from '../../iot/RemoteControl/Bluetooth';
|
|
10
|
+
import { ToastBottomHelper } from '../../utils/Utils';
|
|
11
|
+
import { t } from 'i18n-js';
|
|
12
|
+
|
|
13
|
+
const useRemoteControl = () => {
|
|
14
|
+
const ggHomeConnections = useSCContextSelector(
|
|
15
|
+
(state) => state.iot.googlehome.connections
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
const sendRemoteCommand = useCallback(
|
|
19
|
+
async (sensor, action, data, userId, actionName) => {
|
|
20
|
+
// No action, raise not authorized
|
|
21
|
+
let result = false;
|
|
22
|
+
if (!action) {
|
|
23
|
+
ToastBottomHelper.error(
|
|
24
|
+
t('your_account_has_not_been_authorized_to_control')
|
|
25
|
+
);
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (action.command_prefer_over_bluetooth) {
|
|
30
|
+
try {
|
|
31
|
+
result = await sendCommandOverBluetooth(sensor, action, data, userId);
|
|
32
|
+
} catch (err) {
|
|
33
|
+
if (err === SEND_COMMAND_OVER_BLUETOOTH_FAIL) {
|
|
34
|
+
result = await sendCommandOverInternet(
|
|
35
|
+
sensor,
|
|
36
|
+
action,
|
|
37
|
+
data,
|
|
38
|
+
'bluetooth',
|
|
39
|
+
actionName
|
|
40
|
+
);
|
|
41
|
+
} else {
|
|
42
|
+
throw err;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (
|
|
48
|
+
action.command_prefer_over_internet ||
|
|
49
|
+
action.command_prefer_over_bluetooth
|
|
50
|
+
) {
|
|
51
|
+
result = await sendCommandOverInternet(
|
|
52
|
+
sensor,
|
|
53
|
+
action,
|
|
54
|
+
data,
|
|
55
|
+
'internet'
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (action.command_prefer_over_googlehome) {
|
|
60
|
+
result = await sendCommandOverGoogleHome(
|
|
61
|
+
ggHomeConnections,
|
|
62
|
+
sensor,
|
|
63
|
+
action,
|
|
64
|
+
data
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (action.command_prefer_over_lg) {
|
|
69
|
+
result = await sendCommandOverLGThinq(sensor, action, data);
|
|
70
|
+
}
|
|
71
|
+
return result;
|
|
72
|
+
},
|
|
73
|
+
[ggHomeConnections]
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
return sendRemoteCommand;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export default useRemoteControl;
|
|
@@ -3,19 +3,23 @@ import OneSignal from 'react-native-onesignal';
|
|
|
3
3
|
|
|
4
4
|
const useReceiveNotifications = () => {
|
|
5
5
|
const [dataNofitication, setDataNofitication] = useState(null);
|
|
6
|
-
const [showEmergencyPopup, setShowEmergencyPopup] = useState(false);
|
|
7
6
|
|
|
8
7
|
const onReceived = useCallback((data) => {
|
|
9
|
-
const { additionalData } = data
|
|
8
|
+
const { additionalData } = data;
|
|
10
9
|
setDataNofitication(additionalData);
|
|
11
|
-
setShowEmergencyPopup(!!additionalData);
|
|
12
10
|
}, []);
|
|
13
11
|
|
|
14
12
|
useEffect(() => {
|
|
15
|
-
OneSignal.
|
|
13
|
+
OneSignal.setNotificationWillShowInForegroundHandler(
|
|
14
|
+
(notifReceivedEvent) => {
|
|
15
|
+
let notif = notifReceivedEvent.getNotification();
|
|
16
|
+
setTimeout(() => notifReceivedEvent.complete(notif), 0);
|
|
17
|
+
onReceived(notif);
|
|
18
|
+
}
|
|
19
|
+
);
|
|
16
20
|
}, [onReceived]);
|
|
17
21
|
|
|
18
|
-
return { dataNofitication
|
|
22
|
+
return { dataNofitication };
|
|
19
23
|
};
|
|
20
24
|
|
|
21
25
|
export default useReceiveNotifications;
|
package/src/iot/Monitor.js
CHANGED
|
@@ -99,8 +99,9 @@ export const realWatchMultiConfigs = async (configIds) => {
|
|
|
99
99
|
const configValues = getConfigGlobalState('configValues');
|
|
100
100
|
const newConfigValues = { ...configValues, ...data };
|
|
101
101
|
setConfigGlobalState('configValues', newConfigValues);
|
|
102
|
-
|
|
103
|
-
|
|
102
|
+
for (const configId in data) {
|
|
103
|
+
watchConfig(configId);
|
|
104
|
+
}
|
|
104
105
|
}
|
|
105
106
|
};
|
|
106
107
|
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/* eslint-disable promise/prefer-await-to-then */
|
|
2
1
|
/* eslint-disable promise/prefer-await-to-callbacks */
|
|
3
2
|
import { BLE } from '../../configs';
|
|
4
3
|
import t from '../../hooks/Common/useTranslations';
|
|
@@ -82,6 +81,7 @@ const realScanBluetoothDevices = () => {
|
|
|
82
81
|
setTimeout(() => {
|
|
83
82
|
try {
|
|
84
83
|
bleManager.stopDeviceScan();
|
|
84
|
+
// eslint-disable-next-line no-empty
|
|
85
85
|
} catch {}
|
|
86
86
|
}, 15000);
|
|
87
87
|
};
|