From 89eb3523c67a05e96221ad3421456eecad2b650b Mon Sep 17 00:00:00 2001 From: LordGrey <48840279+Lord-Grey@users.noreply.github.com> Date: Sun, 3 Sep 2023 18:15:49 +0200 Subject: [PATCH] Hue API v2 - Migrate database --- libsrc/hyperion/SettingsManager.cpp | 55 +++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/libsrc/hyperion/SettingsManager.cpp b/libsrc/hyperion/SettingsManager.cpp index b9d78edc..af610bd1 100644 --- a/libsrc/hyperion/SettingsManager.cpp +++ b/libsrc/hyperion/SettingsManager.cpp @@ -715,6 +715,7 @@ bool SettingsManager::handleConfigUpgrade(QJsonObject& config) } //Migration steps for versions <= 2.0.13 + _previousVersion = targetVersion; targetVersion.setVersion("2.0.13"); if (_previousVersion <= targetVersion) { @@ -766,6 +767,60 @@ bool SettingsManager::handleConfigUpgrade(QJsonObject& config) } } } + + //Migration steps for versions <= 2.0.16 + _previousVersion = targetVersion; + targetVersion.setVersion("2.0.16"); + if (_previousVersion <= targetVersion) + { + Info(_log, "Instance [%u]: Migrate from version [%s] to version [%s] or later", _instance, _previousVersion.getVersion().c_str(), targetVersion.getVersion().c_str()); + + // Have Hostname/IP-address separate from port for LED-Devices + if (config.contains("device")) + { + QJsonObject newDeviceConfig = config["device"].toObject(); + + if (newDeviceConfig.contains("type")) + { + QString type = newDeviceConfig["type"].toString(); + if ( type == "philipshue") + { + if (newDeviceConfig.contains("groupId")) + { + if (newDeviceConfig["groupId"].isDouble()) + { + int groupID = newDeviceConfig["groupId"].toInt(); + newDeviceConfig["groupId"] = QString::number(groupID); + migrated = true; + } + } + + if (newDeviceConfig.contains("lightIds")) + { + QJsonArray lightIds = newDeviceConfig.value( "lightIds").toArray(); + // Iterate through the JSON array and update integer values to strings + for (int i = 0; i < lightIds.size(); ++i) { + QJsonValue value = lightIds.at(i); + if (value.isDouble()) + { + int lightId = value.toInt(); + lightIds.replace(i, QString::number(lightId)); + migrated = true; + } + } + newDeviceConfig["lightIds"] = lightIds; + + } + } + } + + if (migrated) + { + config["device"] = newDeviceConfig; + Debug(_log, "LED-Device records migrated"); + } + } + } } } return migrated;