diff --git a/lib/Backend/Bluetooth/bluetooth_manager_plus.dart b/lib/Backend/Bluetooth/bluetooth_manager_plus.dart index 85af217e..7ed1063b 100644 --- a/lib/Backend/Bluetooth/bluetooth_manager_plus.dart +++ b/lib/Backend/Bluetooth/bluetooth_manager_plus.dart @@ -361,7 +361,10 @@ class _OnCharacteristicReceived extends _$OnCharacteristicReceived { ), ); } - await ref.read(hasOtaUpdateProvider(statefulDevice).future); + // Don't check for updates unless both values are set + if (statefulDevice.hwVersion.value.isNotEmpty && statefulDevice.fwVersion.value != Version()) { + await ref.read(hasOtaUpdateProvider(statefulDevice).future).catchError((error, stackTrace) => true); + } // Sent after VER message } else if (value.startsWith("GLOWTIP")) { String substring = value.substring(value.indexOf(" ")).trim(); @@ -381,7 +384,11 @@ class _OnCharacteristicReceived extends _$OnCharacteristicReceived { } else if (value.contains("HWVER") || value.contains("MITAIL") || value.contains("MINITAIL") || value.contains("FLUTTERWINGS")) { // Hardware Version statefulDevice.hwVersion.value = value.substring(value.indexOf(" ")); - await ref.read(hasOtaUpdateProvider(statefulDevice).future); + // Don't check for updates unless both values are set + if (statefulDevice.hwVersion.value.isNotEmpty && statefulDevice.fwVersion.value != Version()) { + await ref.read(hasOtaUpdateProvider(statefulDevice).future).catchError((error, stackTrace) => true); + } + ; } else if (int.tryParse(value) != null) { // Battery Level statefulDevice.batteryLevel.value = int.parse(value).toDouble(); diff --git a/lib/Backend/firmware_update.dart b/lib/Backend/firmware_update.dart index b14fa03e..eeb1242a 100644 --- a/lib/Backend/firmware_update.dart +++ b/lib/Backend/firmware_update.dart @@ -98,8 +98,7 @@ Future checkForFWUpdate(Ref ref, BaseStatefulDevice baseStatefulDevice) } String hwVer = baseStatefulDevice.hwVersion.value; if (hwVer.isEmpty) { - ref.invalidateSelf(); - return null; + throw Exception("Hardware Version from gear is unknown"); } FWInfo? fwInfo = await ref.read(getFirmwareInfoProvider(url, hwVer).future); baseStatefulDevice.fwInfo.value = fwInfo; @@ -113,16 +112,22 @@ Future hasOtaUpdate(Ref ref, BaseStatefulDevice baseStatefulDevice) async // Check if fw version is not set (0.0.0) if (baseStatefulDevice.fwVersion.value == const Version()) { - return false; + throw Exception("Version from gear is unknown"); } // check if firmware info from firmware is set and is greater than (0.0.0) if (fwInfo == null || fwVersion.compareTo(const Version()) <= 0) { - return false; + throw Exception("Version from gear or server is unavailable"); } // Check that the firmware from the server is greater than the firmware on device if (fwVersion.compareTo(getVersionSemVer(fwInfo.version)) < 0) { baseStatefulDevice.hasUpdate.value = true; + // handle if the update is mandatory for app functionality + if (baseStatefulDevice.baseDeviceDefinition.minVersion != null) { + if (fwVersion.compareTo(baseStatefulDevice.baseDeviceDefinition.minVersion!) < 0) { + baseStatefulDevice.mandatoryOtaRequired.value = true; + } + } return true; } return false;