@eohjsc/react-native-smart-city 0.3.4 → 0.3.7
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 +15 -36
- package/package.json +5 -9
- package/react-native-smart-city.podspec +0 -1
- package/src/commons/Action/ItemQuickAction.js +4 -16
- package/src/commons/Action/__test__/ItemQuickAction.test.js +6 -11
- package/src/commons/ActionGroup/ColorPickerTemplate.js +24 -37
- package/src/commons/ActionGroup/CurtainButtonTemplate.js +5 -10
- package/src/commons/ActionGroup/NumberUpDownActionTemplate.js +31 -12
- package/src/commons/ActionGroup/OnOffSmartLock/AutoLock/__test__/index.test.js +0 -4
- package/src/commons/ActionGroup/OnOffSmartLock/PasscodeList/ItemPasscode.js +1 -1
- package/src/commons/ActionGroup/OnOffSmartLock/SetupGeneratePasscode/__test__/index.test.js +0 -14
- package/src/commons/ActionGroup/OnOffSmartLock/SetupGeneratePasscode/index.js +0 -1
- package/src/commons/ActionGroup/OnOffTemplate/OnOffButtonTemplate.js +2 -8
- package/src/commons/ActionGroup/OnOffTemplate/OnOffSimpleTemplate.js +10 -10
- package/src/commons/ActionGroup/OnOffTemplate/index.js +2 -3
- package/src/commons/ActionGroup/OptionsDropdownActionTemplate.js +9 -7
- package/src/commons/ActionGroup/SliderRangeTemplate.js +2 -6
- package/src/commons/ActionGroup/SmartTiviActionTemplate/SmartTiviActionTemplate.js +3 -7
- package/src/commons/ActionGroup/StatesGridActionTemplate.js +8 -22
- package/src/commons/ActionGroup/TimerActionTemplate.js +3 -11
- package/src/commons/ActionGroup/TwoButtonTemplate/index.js +5 -1
- package/src/commons/ActionGroup/__test__/CurtainButtonTemplate.test.js +4 -53
- package/src/commons/ActionGroup/__test__/NumberUpDownTemplate.test.js +83 -3
- package/src/commons/ActionGroup/__test__/OnOffButtonTemplate.test.js +14 -14
- package/src/commons/ActionGroup/__test__/OnOffTemplate.test.js +78 -53
- package/src/commons/ActionGroup/__test__/OneBigButtonTemplate.test.js +20 -36
- package/src/commons/ActionGroup/__test__/OptionsDropdownTemplate.test.js +57 -1
- package/src/commons/ActionGroup/__test__/TimerActionTemplate.test.js +6 -58
- package/src/commons/ActionGroup/__test__/TwoButtonTemplate.test.js +1 -49
- package/src/commons/ActionGroup/__test__/index.test.js +4 -142
- package/src/commons/Auth/AccountList.js +1 -1
- package/src/commons/Automate/ItemAutomate.js +3 -1
- package/src/commons/Connecting/__test__/Connecting.test.js +2 -19
- package/src/commons/ConnectingProcess/DeviceItem/DeviceItem.js +3 -7
- package/src/commons/ConnectingProcess/DeviceItem/DeviceItemStyles.js +11 -8
- package/src/commons/ConnectingProcess/__test__/Connecting.test.js +3 -136
- package/src/commons/ConnectingProcess/__test__/DeviceItem.test.js +2 -3
- package/src/commons/ConnectingProcess/index.js +25 -75
- package/src/commons/Dashboard/MyPinnedSharedUnit/__test__/MyPinnedSharedUnit.test.js +13 -16
- package/src/commons/Dashboard/MyPinnedSharedUnit/index.js +1 -1
- package/src/commons/Dashboard/MyUnit/__test__/MyUnit.test.js +5 -0
- package/src/commons/Device/ConnectedViewHeader.js +1 -1
- package/src/commons/Device/HistoryChart.js +3 -7
- package/src/commons/Device/ItemDevice.js +12 -19
- package/src/commons/Device/LinearChart.js +0 -15
- package/src/commons/Device/PMSensor/PMSensorIndicatior.js +12 -16
- package/src/commons/Device/PMSensor/PMSensorIndicatorStyles.js +0 -3
- package/src/commons/Device/SonosSpeaker/index.js +1 -1
- package/src/commons/Device/WaterQualitySensor/ListQualityIndicator.js +0 -1
- package/src/commons/Device/WaterQualitySensor/QualityIndicatorsItem.js +2 -7
- package/src/commons/Explore/__test__/CityItem.test.js +54 -33
- package/src/commons/Form/CurrencyInput.js +1 -15
- package/src/commons/Form/TextInputPassword.js +1 -1
- package/src/commons/FullLoading/index.js +1 -2
- package/src/commons/Header/HeaderCustom.js +1 -2
- package/src/commons/HeaderAni/index.js +1 -6
- package/src/commons/HorizontalPicker/index.js +2 -2
- package/src/commons/MediaPlayerDetail/Styles/MediaPlayerDetailStyles.js +6 -0
- package/src/commons/MediaPlayerDetail/index.js +47 -25
- package/src/commons/MenuActionAddnew/index.js +0 -1
- package/src/commons/MenuActionList/index.js +0 -1
- package/src/commons/MenuActionMore/index.js +1 -1
- package/src/commons/PreventAccess/index.js +1 -9
- package/src/commons/Sharing/MemberList.js +2 -10
- package/src/commons/Sharing/WrapHeaderScrollable.js +0 -2
- package/src/commons/Sharing/__test__/DevicePermissionsCheckbox.test.js +1 -0
- package/src/commons/SubUnit/Favorites/index.js +3 -2
- package/src/commons/SubUnit/OneTap/__test__/SubUnitAutomate.test.js +35 -8
- package/src/commons/SubUnit/OneTap/index.js +2 -1
- package/src/commons/SubUnit/ShortDetail.js +9 -25
- package/src/commons/SubUnit/__test__/Item.test.js +1 -0
- package/src/commons/SubUnit/__test__/ShortDetail.test.js +2 -9
- package/src/commons/Unit/SharedUnit.js +0 -1
- package/src/commons/Unit/__test__/SharedUnit.test.js +183 -38
- package/src/commons/UnitSummary/ConfigHistoryChart/index.js +13 -2
- package/src/commons/UnitSummary/ConfigHistoryChart.js +13 -22
- package/src/commons/WheelDateTimePicker/index.js +3 -4
- package/src/configs/API.js +143 -87
- package/src/configs/Constants.js +2 -57
- package/src/configs/SCConfig.js +0 -4
- package/src/context/actionType.ts +0 -8
- package/src/context/mockStore.ts +0 -10
- package/src/context/reducer.ts +2 -38
- package/src/hooks/Common/index.js +0 -2
- package/src/hooks/Common/useGetIdUser.js +5 -1
- package/src/hooks/Common/useSensorsStatus.js +4 -4
- package/src/hooks/useReceiveNotifications.js +5 -9
- package/src/iot/Monitor.js +2 -3
- package/src/iot/RemoteControl/Bluetooth.js +1 -1
- package/src/iot/RemoteControl/GoogleHome.js +49 -75
- package/src/iot/RemoteControl/Internet.js +1 -1
- package/src/iot/RemoteControl/__test__/GoogleHome.test.js +48 -95
- package/src/iot/RemoteControl/__test__/Internet.test.js +7 -18
- package/src/iot/RemoteControl/__test__/LgThinq.test.js +177 -36
- package/src/iot/RemoteControl/index.js +52 -52
- package/src/navigations/UnitStack.js +20 -11
- package/src/screens/AQIGuide/index.js +1 -1
- package/src/screens/ActivityLog/FilterPopup.js +0 -2
- package/src/screens/ActivityLog/__test__/index.test.js +23 -38
- package/src/screens/ActivityLog/hooks/__test__/index.test.js +90 -51
- package/src/screens/ActivityLog/hooks/index.js +1 -1
- package/src/screens/ActivityLog/index.js +2 -2
- package/src/screens/AddCommon/SelectSubUnit.js +0 -1
- package/src/screens/AddCommon/SelectUnit.js +0 -1
- package/src/screens/AddCommon/__test__/SelectSubUnit.test.js +24 -13
- package/src/screens/AddCommon/__test__/SelectUnit.test.js +33 -9
- package/src/screens/AddLocationMaps/index.js +5 -9
- package/src/screens/AddNewAction/SelectAction.js +8 -8
- package/src/screens/AddNewAction/SelectSensorDevices.js +2 -8
- package/src/screens/AddNewAction/SetupSensor.js +7 -7
- package/src/screens/AddNewAction/__test__/SelectAction.test.js +91 -10
- package/src/screens/AddNewAction/__test__/SelectSensorDevices.test.js +26 -40
- package/src/screens/AddNewAutoSmart/__test__/AddNewAutoSmart.test.js +1 -3
- package/src/screens/AddNewAutoSmart/index.js +2 -5
- package/src/screens/AddNewDevice/ConnectingDevices.js +3 -3
- package/src/screens/AddNewDevice/__test__/AddNewDevice.test.js +34 -42
- package/src/screens/AddNewDevice/__test__/ConnectDevices.test.js +4 -0
- package/src/screens/AddNewDevice/__test__/ConnectingDevices.test.js +22 -22
- package/src/screens/AddNewDevice/hooks/ConnectDevices.js +1 -1
- package/src/screens/AddNewDevice/index.js +0 -1
- package/src/screens/AddNewGateway/PlugAndPlay/ConnectWifiWarning.js +17 -23
- package/src/screens/AddNewGateway/PlugAndPlay/GatewayWifiList.js +4 -7
- package/src/screens/AddNewGateway/SelectGateway.js +0 -1
- package/src/screens/AddNewGateway/SetupGatewayWifi.js +0 -2
- package/src/screens/AddNewGateway/__test__/AddNewGateway.test.js +6 -4
- package/src/screens/AddNewGateway/__test__/ConnectedGateway.test.js +4 -0
- package/src/screens/AddNewGateway/__test__/ConnectingGateway.test.js +29 -5
- package/src/screens/AddNewGateway/__test__/SelectGateway.test.js +4 -0
- package/src/screens/AddNewGateway/__test__/SetupGateway.test.js +4 -0
- package/src/screens/AddNewGateway/index.js +0 -1
- package/src/screens/AddNewOneTap/__test__/AddNewOneTap.test.js +24 -10
- package/src/screens/AddNewOneTap/index.js +2 -3
- package/src/screens/AllCamera/index.js +4 -4
- package/src/screens/Automate/MultiUnits.js +8 -8
- package/src/screens/Automate/__test__/MultiUnits.test.js +9 -6
- package/src/screens/Automate/__test__/index.test.js +12 -7
- package/src/screens/Automate/index.js +3 -5
- package/src/screens/ConfirmUnitDeletion/__test__/ConfirmUnitDeletion.test.js +8 -36
- package/src/screens/ConfirmUnitDeletion/index.js +1 -7
- package/src/screens/Device/EditDevice/__test__/EditDevice.test.js +22 -71
- package/src/screens/Device/EditDevice/index.js +15 -17
- package/src/screens/Device/__test__/detail.test.js +86 -33
- package/src/screens/Device/components/DetailHistoryChart.js +1 -1
- package/src/screens/Device/components/SensorConnectStatusViewHeader.js +0 -1
- package/src/screens/Device/components/SensorDisplayItem.js +2 -5
- package/src/screens/Device/detail.js +24 -80
- package/src/screens/Device/hooks/useDisconnectedDevice.js +4 -4
- package/src/screens/Device/hooks/useFavoriteDevice.js +9 -5
- package/src/screens/DeviceInfo/__test__/index.test.js +2 -0
- package/src/screens/EditActionsList/index.js +1 -1
- package/src/screens/EmergencyContacts/EmergencyContactsSelectContacts.js +3 -6
- package/src/screens/EmergencyContacts/__test__/EmergencyContactAddNew.test.js +19 -7
- package/src/screens/EmergencyContacts/__test__/EmergencyContactList.test.js +2 -20
- package/src/screens/EmergencyContacts/__test__/EmergencyContactsSelectContacts.test.js +23 -40
- package/src/screens/EmergencySetting/components/DropDownItem.js +2 -2
- package/src/screens/EmergencySetting/index.js +1 -4
- package/src/screens/EnterPassword/__test__/EnterPassword.test.js +25 -41
- package/src/screens/Explore/index.js +0 -2
- package/src/screens/GuestInfo/__test__/index.test.js +41 -14
- package/src/screens/GuestInfo/components/RecurringDetail.js +0 -1
- package/src/screens/GuestInfo/components/TemporaryDetail.js +2 -2
- package/src/screens/HanetCamera/Detail.js +1 -1
- package/src/screens/HanetCamera/__test__/CaptureFaceID.test.js +12 -8
- package/src/screens/HanetCamera/__test__/Detail.test.js +42 -27
- package/src/screens/HanetCamera/__test__/ManageAccess.test.js +5 -8
- package/src/screens/HanetCamera/__test__/MemberInfo.test.js +32 -10
- package/src/screens/HanetCamera/components/RequestFaceIDPopup.js +2 -3
- package/src/screens/HanetCamera/hooks/__test__/useHanetCheckinData.test.js +35 -43
- package/src/screens/HanetCamera/hooks/__test__/useHanetPlaceMembers.test.js +21 -10
- 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 +22 -33
- package/src/screens/ManageAccess/hooks/__test__/useManageAccess.test.js +45 -44
- package/src/screens/ManageAccess/hooks/index.js +4 -7
- package/src/screens/ManageAccess/index.js +1 -2
- package/src/screens/MoveToAnotherSubUnit/__test__/index.test.js +12 -35
- package/src/screens/MoveToAnotherSubUnit/index.js +6 -6
- package/src/screens/Notification/__test__/Notification.test.js +25 -14
- package/src/screens/Notification/__test__/NotificationItem.test.js +7 -8
- package/src/screens/Notification/components/NotificationItem.js +20 -17
- package/src/screens/Notification/index.js +2 -9
- package/src/screens/PlayBackCamera/Timer.js +2 -2
- package/src/screens/PlayBackCamera/__test__/index.test.js +2 -87
- package/src/screens/PlayBackCamera/index.js +6 -22
- package/src/screens/ScanChipQR/__test__/ScanChipQR.test.js +20 -7
- package/src/screens/ScanChipQR/components/QRScan/index.js +0 -1
- package/src/screens/ScanChipQR/hooks/index.js +16 -15
- package/src/screens/ScanSensorQR/__test__/ScanSensorQR.test.js +24 -8
- package/src/screens/ScriptDetail/__test__/index.test.js +86 -17
- package/src/screens/ScriptDetail/index.js +14 -19
- package/src/screens/SelectUnit/__test__/index.test.js +55 -12
- package/src/screens/SelectUnit/index.js +4 -9
- package/src/screens/SetSchedule/index.js +11 -15
- package/src/screens/SharedUnit/__test__/TabHeader.test.js +2 -0
- package/src/screens/SharedUnit/index.js +0 -2
- package/src/screens/Sharing/Components/SensorItem.js +12 -10
- package/src/screens/Sharing/InfoMemberUnit.js +1 -1
- package/src/screens/Sharing/MemberList.js +11 -12
- package/src/screens/Sharing/SelectPermission.js +76 -121
- package/src/screens/Sharing/__test__/InfoMemberUnit.test.js +29 -47
- package/src/screens/Sharing/__test__/MemberList.test.js +127 -13
- package/src/screens/Sharing/__test__/SelectPermission.test.js +38 -28
- package/src/screens/Sharing/__test__/SelectUser.test.js +38 -17
- package/src/screens/Sharing/hooks/index.js +0 -3
- package/src/screens/SmartIr/components/GroupButtonByType/GroupButtonByType.js +2 -3
- package/src/screens/SmartIr/components/SelectBrand.js +1 -1
- package/src/screens/SubUnit/AddSubUnit.js +17 -23
- package/src/screens/SubUnit/Detail.js +2 -1
- package/src/screens/SubUnit/EditSubUnit.js +13 -15
- package/src/screens/SubUnit/ManageSubUnit.js +7 -13
- package/src/screens/SubUnit/__test__/AddSubUnit.test.js +89 -29
- package/src/screens/SubUnit/__test__/Detail.test.js +8 -31
- package/src/screens/SubUnit/__test__/EditSubUnit.test.js +89 -21
- package/src/screens/SubUnit/__test__/ManageSubUnit.test.js +1 -27
- package/src/screens/SubUnit/hooks/__test__/useManageSubUnit.test.js +45 -48
- package/src/screens/SubUnit/hooks/useManageSubUnit.js +7 -7
- package/src/screens/SyncLGDevice/AddLGDevice.js +0 -1
- package/src/screens/SyncLGDevice/__test__/AddLGDevice.test.js +91 -22
- package/src/screens/TDSGuide/index.js +1 -4
- package/src/screens/UVIndexGuide/index.js +1 -1
- package/src/screens/Unit/ChooseLocation.js +14 -7
- package/src/screens/Unit/Detail.js +75 -30
- package/src/screens/Unit/ManageUnit.js +0 -1
- package/src/screens/Unit/SelectAddress.js +23 -45
- package/src/screens/Unit/SmartAccount.js +4 -4
- package/src/screens/Unit/Station/index.js +0 -4
- package/src/screens/Unit/Summaries.js +2 -18
- package/src/screens/Unit/__test__/CheckSendEmail.test.js +29 -24
- package/src/screens/Unit/__test__/ChooseLocation.test.js +14 -27
- package/src/screens/Unit/__test__/Detail.test.js +200 -99
- package/src/screens/Unit/__test__/ManageUnit.test.js +42 -18
- package/src/screens/Unit/__test__/SelectAddress.test.js +49 -159
- package/src/screens/Unit/__test__/SmartAccount.test.js +9 -17
- package/src/screens/Unit/__test__/SmartAccountItem.test.js +1 -0
- package/src/screens/Unit/components/MyUnitDevice/index.js +4 -4
- package/src/screens/Unit/components/SharedUnit/index.js +0 -1
- package/src/screens/Unit/components/__test__/MyUnitDevice.test.js +2 -2
- package/src/screens/Unit/components/__test__/SharedUnit.test.js +34 -31
- package/src/screens/Unit/styles.js +0 -4
- package/src/screens/UnitSummary/__test__/index.test.js +30 -91
- package/src/screens/UnitSummary/components/3PPowerConsumption/__test__/3PPowerConsumption.test.js +2 -31
- package/src/screens/UnitSummary/components/PowerConsumeHistoryChart/__test__/index.test.js +4 -7
- package/src/screens/UnitSummary/components/PowerConsumeHistoryChart/index.js +13 -2
- package/src/screens/UnitSummary/components/PowerConsumption/__test__/ItemPower.test.js +1 -0
- package/src/screens/UnitSummary/components/PowerConsumption/__test__/PowerConsumption.test.js +16 -14
- package/src/screens/UnitSummary/components/RunningDevices/__test__/index.test.js +2 -11
- package/src/screens/UnitSummary/components/RunningDevices/index.js +10 -7
- package/src/screens/UnitSummary/components/Temperature/index.js +4 -4
- package/src/screens/UnitSummary/components/WaterQuality/Item/index.js +2 -10
- package/src/screens/UnitSummary/index.js +1 -15
- package/src/screens/WaterQualityGuide/index.js +1 -1
- package/src/utils/Apis/axios.js +31 -54
- package/src/utils/Converter/time.js +18 -0
- package/src/utils/I18n/translations/en.json +1 -7
- package/src/utils/I18n/translations/vi.json +1 -8
- package/src/utils/Route/index.js +0 -1
- package/src/utils/Utils.js +7 -11
- package/src/commons/ActionGroup/OnOffSmartLock/PasscodeList/__test__/ItemPasscode.test.js +0 -24
- package/src/commons/ActionGroup/__test__/NumberUpDownTemplateWithNullConfigValue.test.js +0 -60
- package/src/commons/ActionGroup/__test__/StatesGridActionTemplate.test.js +0 -77
- package/src/commons/Calendar/__test__/Calendar.test.js +0 -33
- package/src/commons/Device/Hanet/ItemHanetDevice.test.js +0 -58
- package/src/commons/FieldTemplate/ChooseUserField/ChooseFieldStyles.js +0 -25
- package/src/commons/FieldTemplate/ChooseUserField/ChoosePopup.js +0 -96
- package/src/commons/FieldTemplate/ChooseUserField/ChoosePopupStyles.js +0 -39
- package/src/commons/FieldTemplate/ChooseUserField/__test__/index.test.js +0 -118
- package/src/commons/FieldTemplate/ChooseUserField/index.js +0 -62
- package/src/commons/FieldTemplate/PasscodeField/PasscodeFieldStyles.js +0 -30
- package/src/commons/FieldTemplate/PasscodeField/__test__/index.test.js +0 -90
- package/src/commons/FieldTemplate/PasscodeField/index.js +0 -43
- package/src/commons/FieldTemplate/ScheduleField/ScheduleFieldStyles.js +0 -13
- package/src/commons/FieldTemplate/ScheduleField/__test__/index.test.js +0 -179
- package/src/commons/FieldTemplate/ScheduleField/index.js +0 -176
- package/src/commons/PreventAccess/__test__/PreventAccess.test.js +0 -62
- package/src/hooks/Common/useGGHomeDeviceConnected.js +0 -16
- package/src/hooks/IoT/__test__/useGGHomeConnection.test.js +0 -198
- package/src/hooks/IoT/__test__/useRemoteControl.test.js +0 -198
- package/src/hooks/IoT/index.js +0 -4
- package/src/hooks/IoT/useGGHomeConnection.js +0 -91
- package/src/hooks/IoT/useRemoteControl.js +0 -79
- package/src/hooks/index.js +0 -4
- package/src/navigations/UnitStackStyles.js +0 -21
- package/src/screens/Sharing/__test__/MemberList2.test.js +0 -80
- package/src/screens/SideMenuDetail/SideMenuDetailStyles.js +0 -28
- package/src/screens/SideMenuDetail/__test__/index.test.js +0 -154
- package/src/screens/SideMenuDetail/index.js +0 -148
- package/src/screens/Unit/__test__/Summaries.test.js +0 -100
- package/src/screens/Unit/components/MyAllUnit/__test__/MyAllUnit.test.js +0 -36
- package/src/screens/Unit/components/MyAllUnit/__test__/index.test.js +0 -54
- package/src/screens/Unit/hook/useUnitConnectRemoteDevices.js +0 -50
- package/src/utils/Permission/common.js +0 -67
- package/src/utils/Setting/Location.js +0 -30
- package/src/utils/__test__/Utils.test.js +0 -12
|
@@ -3,23 +3,19 @@ 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);
|
|
6
7
|
|
|
7
8
|
const onReceived = useCallback((data) => {
|
|
8
|
-
const { additionalData } = data;
|
|
9
|
+
const { additionalData } = data.payload;
|
|
9
10
|
setDataNofitication(additionalData);
|
|
11
|
+
setShowEmergencyPopup(!!additionalData);
|
|
10
12
|
}, []);
|
|
11
13
|
|
|
12
14
|
useEffect(() => {
|
|
13
|
-
OneSignal.
|
|
14
|
-
(notifReceivedEvent) => {
|
|
15
|
-
let notif = notifReceivedEvent.getNotification();
|
|
16
|
-
setTimeout(() => notifReceivedEvent.complete(notif), 0);
|
|
17
|
-
onReceived(notif);
|
|
18
|
-
}
|
|
19
|
-
);
|
|
15
|
+
OneSignal.addEventListener('received', onReceived);
|
|
20
16
|
}, [onReceived]);
|
|
21
17
|
|
|
22
|
-
return { dataNofitication };
|
|
18
|
+
return { dataNofitication, showEmergencyPopup, setShowEmergencyPopup };
|
|
23
19
|
};
|
|
24
20
|
|
|
25
21
|
export default useReceiveNotifications;
|
package/src/iot/Monitor.js
CHANGED
|
@@ -99,9 +99,8 @@ export const realWatchMultiConfigs = async (configIds) => {
|
|
|
99
99
|
const configValues = getConfigGlobalState('configValues');
|
|
100
100
|
const newConfigValues = { ...configValues, ...data };
|
|
101
101
|
setConfigGlobalState('configValues', newConfigValues);
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
102
|
+
|
|
103
|
+
configIds.map((id) => watchConfig(id));
|
|
105
104
|
}
|
|
106
105
|
};
|
|
107
106
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable promise/prefer-await-to-then */
|
|
1
2
|
/* eslint-disable promise/prefer-await-to-callbacks */
|
|
2
3
|
import { BLE } from '../../configs';
|
|
3
4
|
import t from '../../hooks/Common/useTranslations';
|
|
@@ -81,7 +82,6 @@ const realScanBluetoothDevices = () => {
|
|
|
81
82
|
setTimeout(() => {
|
|
82
83
|
try {
|
|
83
84
|
bleManager.stopDeviceScan();
|
|
84
|
-
// eslint-disable-next-line no-empty
|
|
85
85
|
} catch {}
|
|
86
86
|
}, 15000);
|
|
87
87
|
};
|
|
@@ -5,6 +5,8 @@ import { ToastBottomHelper } from '../../utils/Utils';
|
|
|
5
5
|
import { API } from '../../configs';
|
|
6
6
|
import { axiosPost } from '../../utils/Apis/axios';
|
|
7
7
|
|
|
8
|
+
let connections = {};
|
|
9
|
+
|
|
8
10
|
let configMaps = {};
|
|
9
11
|
|
|
10
12
|
let attributeMaps = {};
|
|
@@ -87,14 +89,14 @@ async function fetchConnectionEntities(connection) {
|
|
|
87
89
|
const entity = states[i];
|
|
88
90
|
const entityId = entity.entity_id;
|
|
89
91
|
|
|
90
|
-
if (
|
|
92
|
+
if (configMaps.hasOwnProperty(entityId)) {
|
|
91
93
|
const [configId, type] = configMaps[entityId];
|
|
92
94
|
const typeConverter = valueTypes[type] || keepValue;
|
|
93
95
|
|
|
94
96
|
configValues[configId] = typeConverter(entity.state, entityId);
|
|
95
97
|
}
|
|
96
98
|
|
|
97
|
-
if (
|
|
99
|
+
if (attributeMaps.hasOwnProperty(entityId)) {
|
|
98
100
|
const entityAttributeMaps = attributeMaps[entityId];
|
|
99
101
|
for (const [attributeName, attributeMap] of Object.entries(
|
|
100
102
|
entityAttributeMaps
|
|
@@ -116,21 +118,14 @@ async function fetchConnectionEntities(connection) {
|
|
|
116
118
|
setConfigGlobalState('configValues', { ...configValues });
|
|
117
119
|
}
|
|
118
120
|
|
|
119
|
-
export const googleHomeConnect = async (
|
|
120
|
-
|
|
121
|
-
options,
|
|
122
|
-
onEstablished,
|
|
123
|
-
onDisconnected,
|
|
124
|
-
onReconnected
|
|
125
|
-
) => {
|
|
126
|
-
let connections = {};
|
|
127
|
-
|
|
121
|
+
export const googleHomeConnect = async (options) => {
|
|
122
|
+
let isConnected = true;
|
|
128
123
|
for (let i = 0; i < options.length; i++) {
|
|
129
124
|
const option = options[i];
|
|
130
125
|
|
|
131
|
-
if (option.chip_id in
|
|
132
|
-
|
|
133
|
-
|
|
126
|
+
if (option.chip_id in connections) {
|
|
127
|
+
// skip connected
|
|
128
|
+
return isConnected;
|
|
134
129
|
}
|
|
135
130
|
connections[option.chip_id] = 0; // connecting
|
|
136
131
|
|
|
@@ -157,45 +152,43 @@ export const googleHomeConnect = async (
|
|
|
157
152
|
}
|
|
158
153
|
});
|
|
159
154
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
} catch (err) {
|
|
179
|
-
connections[option.chip_id] = 0;
|
|
180
|
-
}
|
|
155
|
+
let auth = new Auth(option.auth);
|
|
156
|
+
const connection = await createConnection({ auth });
|
|
157
|
+
await connection.subscribeEvents(stateChangeCallback, 'state_changed');
|
|
158
|
+
|
|
159
|
+
connection.addEventListener('disconnected', () => {
|
|
160
|
+
ToastBottomHelper.error(t('command_googlehome_lost'));
|
|
161
|
+
isConnected = false;
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
connection.addEventListener('ready', async (conn, eventData) => {
|
|
165
|
+
await fetchConnectionEntities(conn);
|
|
166
|
+
ToastBottomHelper.success(t('command_googlehome_ready'));
|
|
167
|
+
isConnected = true;
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
connections[option.chip_id] = connection;
|
|
171
|
+
await fetchConnectionEntities(connection);
|
|
172
|
+
isConnected = true;
|
|
181
173
|
}
|
|
182
|
-
|
|
183
|
-
return connections;
|
|
174
|
+
return isConnected;
|
|
184
175
|
};
|
|
185
176
|
|
|
186
|
-
export const googleHomeDisconnect = async (
|
|
177
|
+
export const googleHomeDisconnect = async (options) => {
|
|
187
178
|
for (let i = 0; i < options.length; i++) {
|
|
188
179
|
const option = options[i];
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
}
|
|
180
|
+
|
|
181
|
+
if (!(option.chip_id in connections)) {
|
|
182
|
+
return;
|
|
193
183
|
}
|
|
184
|
+
|
|
185
|
+
await connections[option.chip_id].close();
|
|
186
|
+
delete connections[option.chip_id];
|
|
194
187
|
}
|
|
195
188
|
};
|
|
196
189
|
|
|
197
|
-
function
|
|
198
|
-
return connections[
|
|
190
|
+
function getSensorConnection(sensor) {
|
|
191
|
+
return connections[sensor.chip_id];
|
|
199
192
|
}
|
|
200
193
|
|
|
201
194
|
function getServiceName(message) {
|
|
@@ -216,20 +209,10 @@ async function sendCommandSingleAction(connection, ghAction, data) {
|
|
|
216
209
|
message.service_data[name] = data;
|
|
217
210
|
}
|
|
218
211
|
|
|
219
|
-
|
|
220
|
-
await connection.sendMessagePromise(message);
|
|
221
|
-
return true;
|
|
222
|
-
} catch (err) {
|
|
223
|
-
ToastBottomHelper.error(t('command_send_fail_googlehome'));
|
|
224
|
-
}
|
|
212
|
+
await connection.sendMessagePromise(message);
|
|
225
213
|
}
|
|
226
214
|
|
|
227
|
-
export async function sendCommandOverGoogleHome(
|
|
228
|
-
connections,
|
|
229
|
-
device,
|
|
230
|
-
action,
|
|
231
|
-
data
|
|
232
|
-
) {
|
|
215
|
+
export async function sendCommandOverGoogleHome(sensor, action, data) {
|
|
233
216
|
if (
|
|
234
217
|
!(action.googlehome_actions && action.googlehome_actions.length) &&
|
|
235
218
|
!action.googlehome_action
|
|
@@ -237,39 +220,30 @@ export async function sendCommandOverGoogleHome(
|
|
|
237
220
|
return;
|
|
238
221
|
}
|
|
239
222
|
|
|
240
|
-
const connection =
|
|
223
|
+
const connection = getSensorConnection(sensor);
|
|
241
224
|
if (!connection) {
|
|
242
225
|
ToastBottomHelper.error(t('command_send_fail_googlehome'));
|
|
243
226
|
return;
|
|
244
227
|
}
|
|
245
228
|
|
|
246
|
-
let triggerSuccess;
|
|
247
|
-
|
|
248
229
|
if (action.googlehome_actions) {
|
|
249
230
|
for (let i = 0; i < action.googlehome_actions.length; i++) {
|
|
250
|
-
|
|
231
|
+
await sendCommandSingleAction(
|
|
251
232
|
connection,
|
|
252
233
|
action.googlehome_actions[i],
|
|
253
234
|
data
|
|
254
235
|
);
|
|
255
236
|
}
|
|
256
237
|
} else if (action.googlehome_action) {
|
|
257
|
-
|
|
258
|
-
connection,
|
|
259
|
-
action.googlehome_action,
|
|
260
|
-
data
|
|
261
|
-
);
|
|
238
|
+
await sendCommandSingleAction(connection, action.googlehome_action, data);
|
|
262
239
|
}
|
|
263
240
|
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
ToastBottomHelper.success(t('command_send_success_googlehome'));
|
|
271
|
-
}
|
|
272
|
-
return success;
|
|
241
|
+
const { success } = await axiosPost(API.SENSOR.ACTIVITY_LOG(), {
|
|
242
|
+
action_id: action.id,
|
|
243
|
+
message: 'Trigger by user action with google home',
|
|
244
|
+
});
|
|
245
|
+
if (success) {
|
|
246
|
+
ToastBottomHelper.success(t('command_send_success_googlehome'));
|
|
273
247
|
}
|
|
274
|
-
return
|
|
248
|
+
return success;
|
|
275
249
|
}
|
|
@@ -17,7 +17,7 @@ export const sendCommandOverInternet = async (
|
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
ToastBottomHelper.success(t('Sending command via internet'));
|
|
20
|
-
const { success } = await axiosPost(API.
|
|
20
|
+
const { success } = await axiosPost(API.SENSOR.QUICK_ACTION(sensor.id), {
|
|
21
21
|
key: action.key,
|
|
22
22
|
data,
|
|
23
23
|
source,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createConnection, getStates } from 'home-assistant-js-websocket';
|
|
2
2
|
import Toast from 'react-native-toast-message';
|
|
3
|
-
import
|
|
3
|
+
import axios from 'axios';
|
|
4
4
|
import {
|
|
5
5
|
googleHomeConnect,
|
|
6
6
|
googleHomeDisconnect,
|
|
@@ -9,9 +9,8 @@ import {
|
|
|
9
9
|
import { getConfigGlobalState, setConfigGlobalState } from '../../states';
|
|
10
10
|
import { API } from '../../../configs';
|
|
11
11
|
import { getTranslate } from '../../../utils/I18n';
|
|
12
|
-
import api from '../../../utils/Apis/axios';
|
|
13
12
|
|
|
14
|
-
|
|
13
|
+
jest.mock('axios');
|
|
15
14
|
jest.mock('home-assistant-js-websocket', () => {
|
|
16
15
|
return {
|
|
17
16
|
Auth: jest.fn(),
|
|
@@ -27,10 +26,6 @@ const connection = {
|
|
|
27
26
|
close: jest.fn(),
|
|
28
27
|
};
|
|
29
28
|
|
|
30
|
-
const mockEstablished = jest.fn();
|
|
31
|
-
const mockDisconnected = jest.fn();
|
|
32
|
-
const mockReconnected = jest.fn();
|
|
33
|
-
|
|
34
29
|
getStates.mockImplementation(() => []);
|
|
35
30
|
createConnection.mockImplementation(() => connection);
|
|
36
31
|
|
|
@@ -85,7 +80,13 @@ describe('Remote Control Google Home', () => {
|
|
|
85
80
|
},
|
|
86
81
|
};
|
|
87
82
|
|
|
83
|
+
const response = {
|
|
84
|
+
status: 200,
|
|
85
|
+
};
|
|
86
|
+
|
|
88
87
|
beforeEach(async () => {
|
|
88
|
+
axios.post.mockClear();
|
|
89
|
+
await googleHomeDisconnect(options);
|
|
89
90
|
connection.sendMessagePromise.mockClear();
|
|
90
91
|
createConnection.mockClear();
|
|
91
92
|
getStates.mockClear();
|
|
@@ -111,13 +112,7 @@ describe('Remote Control Google Home', () => {
|
|
|
111
112
|
let configValues = getConfigGlobalState('configValues');
|
|
112
113
|
expect(configValues).toEqual({});
|
|
113
114
|
|
|
114
|
-
await googleHomeConnect(
|
|
115
|
-
{},
|
|
116
|
-
options,
|
|
117
|
-
mockEstablished,
|
|
118
|
-
mockDisconnected,
|
|
119
|
-
mockReconnected
|
|
120
|
-
);
|
|
115
|
+
await googleHomeConnect(options);
|
|
121
116
|
expect(createConnection).toBeCalledTimes(1);
|
|
122
117
|
expect(getStates).toBeCalledTimes(1);
|
|
123
118
|
|
|
@@ -153,33 +148,15 @@ describe('Remote Control Google Home', () => {
|
|
|
153
148
|
}
|
|
154
149
|
});
|
|
155
150
|
|
|
156
|
-
await googleHomeConnect(
|
|
157
|
-
{},
|
|
158
|
-
options,
|
|
159
|
-
mockEstablished,
|
|
160
|
-
mockDisconnected,
|
|
161
|
-
mockReconnected
|
|
162
|
-
);
|
|
151
|
+
await googleHomeConnect(options);
|
|
163
152
|
|
|
164
153
|
configValues = getConfigGlobalState('configValues');
|
|
165
154
|
expect(configValues).toEqual({ 1: true });
|
|
166
155
|
});
|
|
167
156
|
|
|
168
157
|
it('Connect to same google home will be skipped', async () => {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
options,
|
|
172
|
-
mockEstablished,
|
|
173
|
-
mockDisconnected,
|
|
174
|
-
mockReconnected
|
|
175
|
-
);
|
|
176
|
-
await googleHomeConnect(
|
|
177
|
-
connections,
|
|
178
|
-
options,
|
|
179
|
-
mockEstablished,
|
|
180
|
-
mockDisconnected,
|
|
181
|
-
mockReconnected
|
|
182
|
-
);
|
|
158
|
+
await googleHomeConnect(options);
|
|
159
|
+
await googleHomeConnect(options);
|
|
183
160
|
expect(createConnection).toBeCalledTimes(1);
|
|
184
161
|
expect(getStates).toBeCalledTimes(1);
|
|
185
162
|
});
|
|
@@ -190,13 +167,7 @@ describe('Remote Control Google Home', () => {
|
|
|
190
167
|
listener();
|
|
191
168
|
}
|
|
192
169
|
});
|
|
193
|
-
await googleHomeConnect(
|
|
194
|
-
{},
|
|
195
|
-
options,
|
|
196
|
-
mockEstablished,
|
|
197
|
-
mockDisconnected,
|
|
198
|
-
mockReconnected
|
|
199
|
-
);
|
|
170
|
+
await googleHomeConnect(options);
|
|
200
171
|
expect(createConnection).toBeCalledTimes(1);
|
|
201
172
|
expect(getStates).toBeCalledTimes(2);
|
|
202
173
|
});
|
|
@@ -207,31 +178,21 @@ describe('Remote Control Google Home', () => {
|
|
|
207
178
|
listener();
|
|
208
179
|
}
|
|
209
180
|
});
|
|
210
|
-
await googleHomeConnect(
|
|
211
|
-
{},
|
|
212
|
-
options,
|
|
213
|
-
mockEstablished,
|
|
214
|
-
mockDisconnected,
|
|
215
|
-
mockReconnected
|
|
216
|
-
);
|
|
181
|
+
await googleHomeConnect(options);
|
|
217
182
|
expect(Toast.show).toBeCalledWith({
|
|
218
|
-
type: '
|
|
183
|
+
type: 'success',
|
|
219
184
|
position: 'bottom',
|
|
220
|
-
text1: getTranslate('en', '
|
|
185
|
+
text1: getTranslate('en', 'command_googlehome_ready'),
|
|
221
186
|
visibilityTime: 1000,
|
|
222
187
|
});
|
|
223
188
|
});
|
|
224
189
|
|
|
225
190
|
it('Send command over google home will send message to chip', async () => {
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
mockDisconnected,
|
|
232
|
-
mockReconnected
|
|
233
|
-
);
|
|
234
|
-
await sendCommandOverGoogleHome(connections, sensor, action);
|
|
191
|
+
axios.post.mockImplementation(async () => {
|
|
192
|
+
return response;
|
|
193
|
+
});
|
|
194
|
+
await googleHomeConnect(options);
|
|
195
|
+
await sendCommandOverGoogleHome(sensor, action);
|
|
235
196
|
expect(connection.sendMessagePromise).toBeCalledWith(
|
|
236
197
|
action.googlehome_actions[0].message
|
|
237
198
|
);
|
|
@@ -248,19 +209,21 @@ describe('Remote Control Google Home', () => {
|
|
|
248
209
|
},
|
|
249
210
|
id: 20,
|
|
250
211
|
};
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
);
|
|
259
|
-
await sendCommandOverGoogleHome(connections, sensor, action, 19);
|
|
212
|
+
|
|
213
|
+
axios.post.mockImplementation(async () => {
|
|
214
|
+
return response;
|
|
215
|
+
});
|
|
216
|
+
await googleHomeConnect(options);
|
|
217
|
+
await sendCommandOverGoogleHome(sensor, action, 19);
|
|
218
|
+
|
|
260
219
|
action.googlehome_actions[0].message.service_data.temperature = 19;
|
|
261
220
|
expect(connection.sendMessagePromise).toBeCalledWith(
|
|
262
221
|
action.googlehome_actions[0].message
|
|
263
222
|
);
|
|
223
|
+
expect(axios.post).toHaveBeenCalledWith(API.SENSOR.ACTIVITY_LOG(), {
|
|
224
|
+
action_id: 1,
|
|
225
|
+
message: 'Trigger by user action with google home',
|
|
226
|
+
});
|
|
264
227
|
});
|
|
265
228
|
|
|
266
229
|
it('Send command over google home action googlehome_action one to one', async () => {
|
|
@@ -275,48 +238,38 @@ describe('Remote Control Google Home', () => {
|
|
|
275
238
|
},
|
|
276
239
|
id: 20,
|
|
277
240
|
};
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
);
|
|
286
|
-
await sendCommandOverGoogleHome(connections, sensor, action, 19);
|
|
241
|
+
|
|
242
|
+
axios.post.mockImplementation(async () => {
|
|
243
|
+
return response;
|
|
244
|
+
});
|
|
245
|
+
await googleHomeConnect(options);
|
|
246
|
+
await sendCommandOverGoogleHome(sensor, action, 19);
|
|
247
|
+
|
|
287
248
|
action.googlehome_action.message.service_data.temperature = 19;
|
|
288
249
|
expect(connection.sendMessagePromise).toBeCalledWith(
|
|
289
250
|
action.googlehome_action.message
|
|
290
251
|
);
|
|
252
|
+
expect(axios.post).toHaveBeenCalledWith(API.SENSOR.ACTIVITY_LOG(), {
|
|
253
|
+
action_id: 1,
|
|
254
|
+
message: 'Trigger by user action with google home',
|
|
255
|
+
});
|
|
291
256
|
});
|
|
292
257
|
|
|
293
258
|
it('Send command over google home that not connected', async () => {
|
|
294
|
-
await googleHomeConnect(
|
|
295
|
-
|
|
296
|
-
options,
|
|
297
|
-
mockEstablished,
|
|
298
|
-
mockDisconnected,
|
|
299
|
-
mockReconnected
|
|
300
|
-
);
|
|
301
|
-
await sendCommandOverGoogleHome({}, { chip_id: 2 }, action);
|
|
259
|
+
await googleHomeConnect(options);
|
|
260
|
+
await sendCommandOverGoogleHome({ chip_id: 2 }, action);
|
|
302
261
|
expect(connection.sendMessagePromise).not.toBeCalled();
|
|
303
262
|
});
|
|
304
263
|
|
|
305
264
|
it('Send command over google home that not a google home', async () => {
|
|
306
|
-
await googleHomeConnect(
|
|
307
|
-
|
|
308
|
-
options,
|
|
309
|
-
mockEstablished,
|
|
310
|
-
mockDisconnected,
|
|
311
|
-
mockReconnected
|
|
312
|
-
);
|
|
313
|
-
await sendCommandOverGoogleHome({}, sensor, {});
|
|
265
|
+
await googleHomeConnect(options);
|
|
266
|
+
await sendCommandOverGoogleHome(sensor, {});
|
|
314
267
|
expect(connection.sendMessagePromise).not.toBeCalled();
|
|
315
268
|
});
|
|
316
269
|
|
|
317
270
|
it('Disconnect a not connected gateway', async () => {
|
|
318
271
|
connection.close.mockClear();
|
|
319
|
-
await googleHomeDisconnect(
|
|
272
|
+
await googleHomeDisconnect(options);
|
|
320
273
|
expect(connection.close).not.toBeCalled();
|
|
321
274
|
});
|
|
322
275
|
});
|
|
@@ -1,37 +1,26 @@
|
|
|
1
1
|
import Toast from 'react-native-toast-message';
|
|
2
|
-
import
|
|
2
|
+
import axios from 'axios';
|
|
3
3
|
import { sendCommandOverInternet } from '../Internet';
|
|
4
|
-
import api from '../../../utils/Apis/axios';
|
|
5
|
-
import { API } from '../../../configs';
|
|
6
4
|
|
|
7
|
-
|
|
5
|
+
jest.mock('axios');
|
|
8
6
|
|
|
9
7
|
describe('Test IOT Remote Control Internet', () => {
|
|
10
8
|
beforeEach(() => {
|
|
11
9
|
Toast.show.mockClear();
|
|
10
|
+
axios.post.mockClear();
|
|
12
11
|
});
|
|
13
12
|
|
|
14
13
|
test('Trigger action via request POST', async () => {
|
|
15
|
-
|
|
14
|
+
axios.post.mockImplementation(() => ({ status: 200 }));
|
|
16
15
|
await sendCommandOverInternet({}, {}, 'internet');
|
|
17
|
-
expect(
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
test('Trigger action via request POST with data isInteger', async () => {
|
|
21
|
-
mock.onPost(API.DEVICE.TRIGGER_ACTION()).reply(200);
|
|
22
|
-
await sendCommandOverInternet({}, {}, 1);
|
|
23
|
-
expect(Toast.show).toBeCalledTimes(2);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
test('Trigger action via request POST with data is null', async () => {
|
|
27
|
-
mock.onPost(API.DEVICE.TRIGGER_ACTION()).reply(200);
|
|
28
|
-
await sendCommandOverInternet({}, {}, null);
|
|
16
|
+
expect(axios.post).toBeCalled();
|
|
29
17
|
expect(Toast.show).toBeCalledTimes(2);
|
|
30
18
|
});
|
|
31
19
|
|
|
32
20
|
test('Trigger action fail show error', async () => {
|
|
33
|
-
|
|
21
|
+
axios.post.mockImplementation(() => ({ success: false }));
|
|
34
22
|
await sendCommandOverInternet({}, {}, 'internet');
|
|
23
|
+
expect(axios.post).toBeCalled();
|
|
35
24
|
expect(Toast.show).toBeCalled();
|
|
36
25
|
});
|
|
37
26
|
});
|