@eohjsc/react-native-smart-city 0.4.83 → 0.4.84

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.4.83",
4
+ "version": "0.4.84",
5
5
  "description": "TODO",
6
6
  "main": "index.js",
7
7
  "files": [
@@ -36,7 +36,10 @@ export const useFetchConfigHistory = (configs, setChartData) => {
36
36
  'date_from',
37
37
  startDate.subtract(7, 'hours').format('YYYY-MM-DDTHH:mm:ss')
38
38
  );
39
- params.append('date_to', endDate.format('YYYY-MM-DDTHH:mm:ss'));
39
+ params.append(
40
+ 'date_to',
41
+ endDate.subtract(7, 'hours').format('YYYY-MM-DDTHH:mm:ss')
42
+ );
40
43
 
41
44
  const { success, data } = await axiosGet(
42
45
  API.CONFIG.DISPLAY_HISTORY_V3(),
@@ -7,10 +7,8 @@ const useBluetoothDeviceConnected = (device) => {
7
7
  const isBluetoothEnabled = useSCContextSelector((state) => {
8
8
  return state.bluetooth.isEnabled;
9
9
  });
10
-
11
- const isConnected =
12
- isBluetoothEnabled &&
13
- !!connectedDevices[device?.remote_control_options?.bluetooth?.address];
10
+ const address = device?.remote_control_options?.bluetooth?.address;
11
+ const isConnected = isBluetoothEnabled && !!connectedDevices[address];
14
12
 
15
13
  return { isConnected };
16
14
  };
@@ -30,7 +30,7 @@ export const clearFoundDevices = () => {
30
30
 
31
31
  export const scanBluetoothDevices = async (names, onDeviceFound) => {
32
32
  names.map((name) => {
33
- if (bluetoothDevices[name]) {
33
+ if (needToScanDevices.includes(name)) {
34
34
  return;
35
35
  }
36
36
  needToScanDevices.push(name);
@@ -163,20 +163,26 @@ export const sendDataOverBluetooth = async (
163
163
  let fullDataDevice = null;
164
164
  let result = true;
165
165
  let hasResponse = false;
166
-
167
166
  try {
168
- connectedDevice = await device.connect();
167
+ connectedDevice = await device.connect({ timeout: 5000 });
169
168
  } catch (e) {
170
169
  const BLE_ERROR = {
171
170
  DEVICE_IS_NOT_ALREADY_CONNECTED: 201,
172
171
  DEVICE_WAS_DISCONNECTED: 203,
172
+ DEVICE_CONNECTION_TIMEOUT: 3,
173
+ PHONE_HAS_BLUETOOTH_TURNED_OFF: 102,
173
174
  };
174
- if (
175
- e?.errorCode === BLE_ERROR.DEVICE_IS_NOT_ALREADY_CONNECTED ||
176
- BLE_ERROR.DEVICE_WAS_DISCONNECTED
177
- ) {
178
- await bleManager.cancelDeviceConnection(device.id);
179
- return BLUETOOOH_DEVICE_UNSTABLE;
175
+ switch (e?.errorCode) {
176
+ case BLE_ERROR.DEVICE_IS_NOT_ALREADY_CONNECTED:
177
+ case BLE_ERROR.DEVICE_WAS_DISCONNECTED:
178
+ await bleManager.cancelDeviceConnection(device.id);
179
+ return BLUETOOOH_DEVICE_UNSTABLE;
180
+ case BLE_ERROR.DEVICE_CONNECTION_TIMEOUT:
181
+ case BLE_ERROR.PHONE_HAS_BLUETOOTH_TURNED_OFF:
182
+ delete bluetoothDevices[device.address];
183
+ return SEND_COMMAND_OVER_BLUETOOTH_FAIL;
184
+ default:
185
+ return SEND_COMMAND_OVER_BLUETOOTH_FAIL;
180
186
  }
181
187
  }
182
188
  try {
@@ -39,22 +39,22 @@ export const SensorConnectStatusViewHeader = ({
39
39
  </>
40
40
  );
41
41
  }
42
- if (connectedViaNetwork) {
42
+ if (connectedViaBle) {
43
43
  return (
44
44
  <>
45
45
  <ConnectedViewHeader
46
46
  lastUpdated={lastUpdated}
47
+ type={'Bluetooth'}
47
48
  isDisplayTime={isDisplayTime}
48
49
  showWindDirection={showWindDirection}
49
50
  />
50
51
  </>
51
52
  );
52
- } else if (connectedViaBle) {
53
+ } else if (connectedViaNetwork) {
53
54
  return (
54
55
  <>
55
56
  <ConnectedViewHeader
56
57
  lastUpdated={lastUpdated}
57
- type={'Bluetooth'}
58
58
  isDisplayTime={isDisplayTime}
59
59
  showWindDirection={showWindDirection}
60
60
  />
@@ -292,7 +292,7 @@ const VisualChart = ({ item, isDemo = false, isWidgetOrder }) => {
292
292
  return (
293
293
  <View style={styles.container}>
294
294
  <View style={styles.titleHistory}>
295
- <Text size={20} semibold color={Colors.Gray9}>
295
+ <Text type="H3" semibold color={Colors.Gray9}>
296
296
  {item.label}
297
297
  </Text>
298
298
  </View>
@@ -190,6 +190,13 @@ const DeviceDetail = ({ route }) => {
190
190
  }
191
191
  }, [unitId]);
192
192
 
193
+ const checkScanDevicesBLE = useCallback(async () => {
194
+ const bluetooth = controlOptions?.bluetooth;
195
+ if (isBluetoothEnabled && bluetooth) {
196
+ bluetoothScanDevices([bluetooth.address]);
197
+ }
198
+ }, [bluetoothScanDevices, controlOptions?.bluetooth, isBluetoothEnabled]);
199
+
193
200
  useEffect(() => {
194
201
  if (unitId && !unitData) {
195
202
  fetchUnitDetail();
@@ -222,10 +229,7 @@ const DeviceDetail = ({ route }) => {
222
229
  }, [unit, isNetworkConnected]);
223
230
 
224
231
  useEffect(() => {
225
- if (isBluetoothEnabled && controlOptions?.bluetooth) {
226
- const bluetooth = controlOptions.bluetooth;
227
- bluetoothScanDevices([bluetooth.address]);
228
- }
232
+ checkScanDevicesBLE();
229
233
  // eslint-disable-next-line react-hooks/exhaustive-deps
230
234
  }, [isBluetoothEnabled, bluetoothPermGranted, controlOptions, unit]);
231
235
 
@@ -296,7 +300,9 @@ const DeviceDetail = ({ route }) => {
296
300
 
297
301
  success &&
298
302
  data.items.length &&
299
- data.items.some((item) => (item?.template || item?.type) === 'action') &&
303
+ data.items.some(
304
+ (item) => item.template.toLowerCase().search('action') !== -1
305
+ ) &&
300
306
  (await fetchRemoteControlOptions());
301
307
  }, [token, sensor, setDeviceId, fetchRemoteControlOptions]);
302
308
 
@@ -489,6 +495,7 @@ const DeviceDetail = ({ route }) => {
489
495
  await connectHomeAssistant(unit.remote_control_options.googlehome);
490
496
  })();
491
497
  }
498
+ checkScanDevicesBLE();
492
499
  // eslint-disable-next-line react-hooks/exhaustive-deps
493
500
  }, [sensor, unit, isNetworkConnected, fetchDataDeviceDetail]);
494
501