@@ -183,6 +183,11 @@ void DeRestPluginPrivate::internetDiscoveryTimerFired()
183183 return ;
184184 }
185185
186+ if (gwSwUpdateState == swUpdateState.transferring || gwSwUpdateState == swUpdateState.installing )
187+ {
188+ return ; // don't interfere with running operations
189+ }
190+
186191 int i = 0 ;
187192 const deCONZ::Node *node;
188193 deCONZ::ApsController *ctrl = deCONZ::ApsController::instance ();
@@ -268,6 +273,38 @@ void DeRestPluginPrivate::internetDiscoveryFinishedRequest(QNetworkReply *reply)
268273 reply->deleteLater ();
269274}
270275
276+ /* ! Fills major.minor.patch versions as int in the array \p ls.
277+ \returns true if \p version is a valid version string and \p ls could be filled.
278+ */
279+ bool versionToIntList (const QString &version, std::array<int , 3 > &ls)
280+ {
281+ bool result = false ;
282+ const auto versionList = version.split (' .' );
283+
284+ if (versionList.size () >= 3 )
285+ {
286+ for (size_t i = 0 ; i < ls.size (); i++)
287+ {
288+ ls[i] = versionList[i].toInt (&result);
289+ if (!result)
290+ {
291+ break ;
292+ }
293+ }
294+ }
295+
296+ return result;
297+ }
298+
299+ /* ! Returns true if the \p remote version is newer than \p current version.
300+ */
301+ bool remoteVersionIsNewer (const std::array<int , 3 > ¤t, const std::array<int , 3 > &remote)
302+ {
303+ return current[0 ] < remote[0 ] ||
304+ (current[0 ] == remote[0 ] && current[1 ] < remote[1 ]) ||
305+ (current[0 ] == remote[0 ] && current[1 ] == remote[1 ] && current[2 ] < remote[2 ]);
306+ }
307+
271308/* ! Extracts the update channels version info about the deCONZ/WebApp.
272309
273310 \param reply which holds the version info in JSON format
@@ -350,21 +387,20 @@ void DeRestPluginPrivate::internetDiscoveryExtractVersionInfo(QNetworkReply *rep
350387#ifdef ARCH_ARM
351388 if (map.contains (" versions" ) && (map[" versions" ].type () == QVariant::Map))
352389 {
353- QString version;
354- QVariantMap versions = map[" versions" ].toMap ();
390+ const auto versions = map[" versions" ].toMap ();
355391
356392 if (versions.contains (gwUpdateChannel) && (versions[gwUpdateChannel].type () == QVariant::String))
357393 {
358- version = versions[gwUpdateChannel].toString ();
394+ const auto version = versions[gwUpdateChannel].toString ();
359395
360396 if (!version.isEmpty ())
361397 {
362- QStringList gwUpdateVersionList = gwUpdateVersion. split ( ' . ' ) ;
363- QStringList versionList = version. split ( ' . ' ) ;
364- if (gwUpdateVersionList. size () >= 3 && versionList. size () >= 3 &&
365- (((gwUpdateVersionList[ 0 ]. toInt () < versionList[ 0 ]. toInt ())) ||
366- ((gwUpdateVersionList[ 0 ]. toInt () == versionList[ 0 ]. toInt ()) && (gwUpdateVersionList[ 1 ]. toInt () < versionList[ 1 ]. toInt ())) ||
367- ((gwUpdateVersionList[ 0 ]. toInt () == versionList[ 0 ]. toInt ()) && (gwUpdateVersionList[ 1 ]. toInt () == versionList[ 1 ]. toInt ()) && (gwUpdateVersionList[ 2 ]. toInt () < versionList[ 2 ]. toInt ())) ))
398+ std::array< int , 3 > current = { } ;
399+ std::array< int , 3 > remote = { } ;
400+
401+ if ( versionToIntList (gwUpdateVersion, current) &&
402+ versionToIntList (version, remote) &&
403+ remoteVersionIsNewer (current, remote ))
368404 {
369405 DBG_Printf (DBG_INFO, " discovery found version %s for update channel %s\n " , qPrintable (version), qPrintable (gwUpdateChannel));
370406 gwUpdateVersion = version;
0 commit comments