diff --git a/libnymea/devicemanager.cpp b/libnymea/devicemanager.cpp index c2738282..085b57c9 100644 --- a/libnymea/devicemanager.cpp +++ b/libnymea/devicemanager.cpp @@ -334,9 +334,14 @@ DeviceManager::DeviceError DeviceManager::setPluginConfig(const PluginId &plugin NymeaSettings settings(NymeaSettings::SettingsRolePlugins); settings.beginGroup("PluginConfig"); settings.beginGroup(plugin->pluginId().toString()); - foreach (const Param ¶m, params) { - settings.setValue(param.paramTypeId().toString(), param.value()); + + foreach (const Param ¶m, pluginConfig) { + settings.beginGroup(param.paramTypeId().toString()); + settings.setValue("type", static_cast(param.value().type())); + settings.setValue("value", param.value()); + settings.endGroup(); } + settings.endGroup(); settings.endGroup(); emit pluginConfigChanged(plugin->pluginId(), pluginConfig); @@ -1085,10 +1090,31 @@ void DeviceManager::loadPlugin(DevicePlugin *pluginIface) ParamList params; if (settings.childGroups().contains(pluginIface->pluginId().toString())) { settings.beginGroup(pluginIface->pluginId().toString()); - foreach (const QString ¶mTypeIdString, settings.allKeys()) { - Param param(ParamTypeId(paramTypeIdString), settings.value(paramTypeIdString)); - params.append(param); + + if (!settings.childGroups().isEmpty()) { + // Note: since nymea 0.12.2 the param type gets saved too for better data converting + foreach (const QString ¶mTypeIdString, settings.childGroups()) { + ParamTypeId paramTypeId(paramTypeIdString); + ParamType paramType = pluginIface->configurationDescription().findById(paramTypeId); + if (!paramType.isValid()) { + qCWarning(dcDeviceManager()) << "Skip loading Param for plugin" << pluginIface->pluginName() << "because could not find ParamType for saved Param" << ParamTypeId(paramTypeIdString).toString(); + continue; + } + + QVariant paramValue; + settings.beginGroup(paramTypeIdString); + paramValue = settings.value("value", paramType.defaultValue()); + paramValue.convert(settings.value("type").toInt()); + params.append(Param(paramTypeId, paramValue)); + settings.endGroup(); + } + } else { + // Note: < nymea 0.12.2 + foreach (const QString ¶mTypeIdString, settings.allKeys()) { + params.append(Param(ParamTypeId(paramTypeIdString), settings.value(paramTypeIdString))); + } } + settings.endGroup(); } else if (!pluginIface->configurationDescription().isEmpty()){ // plugin requires config but none stored. Init with defaults @@ -1121,6 +1147,7 @@ void DeviceManager::loadPlugin(DevicePlugin *pluginIface) } + void DeviceManager::loadConfiguredDevices() { NymeaSettings settings(NymeaSettings::SettingsRoleDevices); @@ -1133,11 +1160,38 @@ void DeviceManager::loadConfiguredDevices() device->setName(settings.value("devicename").toString()); device->setParentId(DeviceId(settings.value("parentid", QUuid()).toString())); + DeviceClass deviceClass = findDeviceClass(device->deviceClassId()); + if (!deviceClass.isValid()) { + qCWarning(dcDeviceManager()) << "Skip loading device" << device << " because could not find device class for this device."; + continue; + } + ParamList params; settings.beginGroup("Params"); - foreach (const QString ¶mTypeIdString, settings.allKeys()) { - params.append(Param(ParamTypeId(paramTypeIdString), settings.value(paramTypeIdString))); + + if (!settings.childGroups().isEmpty()) { + foreach (const QString ¶mTypeIdString, settings.childGroups()) { + ParamTypeId paramTypeId(paramTypeIdString); + ParamType paramType = deviceClass.paramTypes().findById(paramTypeId); + if (!paramType.isValid()) { + qCWarning(dcDeviceManager()) << "Skip loading Param for device" << device << "because could not find ParamType for saved Param" << ParamTypeId(paramTypeIdString).toString(); + continue; + } + + // Note: since nymea 0.12.2 + QVariant paramValue; + settings.beginGroup(paramTypeIdString); + paramValue = settings.value("value", paramType.defaultValue()); + paramValue.convert(settings.value("type").toInt()); + params.append(Param(paramTypeId, paramValue)); + settings.endGroup(); + } + } else { + foreach (const QString ¶mTypeIdString, settings.allKeys()) { + params.append(Param(ParamTypeId(paramTypeIdString), settings.value(paramTypeIdString))); + } } + device->setParams(params); settings.endGroup(); settings.endGroup(); @@ -1174,6 +1228,8 @@ void DeviceManager::storeConfiguredDevices() settings.beginGroup("DeviceConfig"); foreach (Device *device, m_configuredDevices) { settings.beginGroup(device->id().toString()); + // Note: clean device settings before storing it for clean up + settings.remove(""); settings.setValue("autoCreated", device->autoCreated()); settings.setValue("devicename", device->name()); settings.setValue("deviceClassId", device->deviceClassId().toString()); @@ -1183,7 +1239,10 @@ void DeviceManager::storeConfiguredDevices() settings.beginGroup("Params"); foreach (const Param ¶m, device->params()) { - settings.setValue(param.paramTypeId().toString(), param.value()); + settings.beginGroup(param.paramTypeId().toString()); + settings.setValue("type", static_cast(param.value().type())); + settings.setValue("value", param.value()); + settings.endGroup(); } settings.endGroup(); settings.endGroup(); @@ -1351,8 +1410,8 @@ void DeviceManager::slotPairingFinished(const PairingTransactionId &pairingTrans device->setName(deviceName); } } else { - qCDebug(dcDeviceManager()) << "Reconfiguring device" << device; device = m_configuredDevices.value(deviceId); + qCDebug(dcDeviceManager()) << "Reconfiguring device" << device; } emit pairingFinished(pairingTransactionId, DeviceErrorNoError, deviceId); diff --git a/libnymea/devicemanager.h b/libnymea/devicemanager.h index 503fade1..db1998fa 100644 --- a/libnymea/devicemanager.h +++ b/libnymea/devicemanager.h @@ -181,7 +181,6 @@ private: void storeDeviceStates(Device *device); void loadDeviceStates(Device *device); - private: HardwareManager *m_hardwareManager; diff --git a/libnymea/interfaces/extendednavigationpad.json b/libnymea/interfaces/extendednavigationpad.json new file mode 100644 index 00000000..c6576edd --- /dev/null +++ b/libnymea/interfaces/extendednavigationpad.json @@ -0,0 +1,12 @@ +{ + "description": "The extended media interface offers also the info and menu button of media devices.", + "extends": "navigationpad", + "actions": [ + { + "name": "navigateMenu" + }, + { + "name": "navigateInfo" + } + ] +} diff --git a/libnymea/interfaces/interfaces.qrc b/libnymea/interfaces/interfaces.qrc index cd838815..c6656a9b 100644 --- a/libnymea/interfaces/interfaces.qrc +++ b/libnymea/interfaces/interfaces.qrc @@ -65,6 +65,8 @@ co2sensor.json presencesensor.json wirelessconnectable.json + navigationpad.json + extendednavigationpad.json diff --git a/libnymea/interfaces/navigationpad.json b/libnymea/interfaces/navigationpad.json new file mode 100644 index 00000000..a7056bdf --- /dev/null +++ b/libnymea/interfaces/navigationpad.json @@ -0,0 +1,24 @@ +{ + "description": "Many media devices have a navigation pad for browsing a library or a menu. This interface represents a basic navigation pad.", + "extends": "media", + "actions": [ + { + "name": "navigateUp" + }, + { + "name": "navigateDown" + }, + { + "name": "navigateLeft" + }, + { + "name": "navigateRight" + }, + { + "name": "navigateOk" + }, + { + "name": "navigateBack" + } + ] +} diff --git a/libnymea/plugin/deviceplugin.cpp b/libnymea/plugin/deviceplugin.cpp index 8a767b4f..2f8a449d 100644 --- a/libnymea/plugin/deviceplugin.cpp +++ b/libnymea/plugin/deviceplugin.cpp @@ -254,7 +254,7 @@ DeviceManager::DeviceError DevicePlugin::executeAction(Device *device, const Act } /*! Returns the configuration description of this DevicePlugin as a list of \l{ParamType}{ParamTypes}. */ -QList DevicePlugin::configurationDescription() const +ParamTypes DevicePlugin::configurationDescription() const { return m_configurationDescription; } diff --git a/libnymea/plugin/deviceplugin.h b/libnymea/plugin/deviceplugin.h index 1d5c7845..587568ea 100644 --- a/libnymea/plugin/deviceplugin.h +++ b/libnymea/plugin/deviceplugin.h @@ -76,7 +76,7 @@ public: virtual DeviceManager::DeviceError executeAction(Device *device, const Action &action); // Configuration - QList configurationDescription() const; + ParamTypes configurationDescription() const; DeviceManager::DeviceError setConfiguration(const ParamList &configuration); ParamList configuration() const; QVariant configValue(const ParamTypeId ¶mTypeId) const; diff --git a/libnymea/types/deviceclass.cpp b/libnymea/types/deviceclass.cpp index 5c17e3f4..52230010 100644 --- a/libnymea/types/deviceclass.cpp +++ b/libnymea/types/deviceclass.cpp @@ -215,27 +215,27 @@ bool DeviceClass::hasActionType(const ActionTypeId &actionTypeId) /*! Returns the params description of this DeviceClass. \{Device}{Devices} created from this \l{DeviceClass} must have their params matching to this template. */ -QList DeviceClass::paramTypes() const +ParamTypes DeviceClass::paramTypes() const { return m_paramTypes; } /*! Set the \a params of this DeviceClass. \{Device}{Devices} created from this \l{DeviceClass} must have their actions matching to this template. */ -void DeviceClass::setParamTypes(const QList ¶ms) +void DeviceClass::setParamTypes(const ParamTypes ¶ms) { m_paramTypes = params; } /*! Returns the discovery params description of this DeviceClass. \{Device}{Devices} created from this \l{DeviceClass} must have their params matching to this template. */ -QList DeviceClass::discoveryParamTypes() const +ParamTypes DeviceClass::discoveryParamTypes() const { return m_discoveryParamTypes; } /*! Set the \a params of this DeviceClass for the discovery. \{Device}{Devices} created from this \l{DeviceClass} must have their actions matching to this template. */ -void DeviceClass::setDiscoveryParamTypes(const QList ¶ms) +void DeviceClass::setDiscoveryParamTypes(const ParamTypes ¶ms) { m_discoveryParamTypes = params; } diff --git a/libnymea/types/deviceclass.h b/libnymea/types/deviceclass.h index 1c95ca33..a5231f29 100644 --- a/libnymea/types/deviceclass.h +++ b/libnymea/types/deviceclass.h @@ -84,11 +84,11 @@ public: void setActionTypes(const QList &actionTypes); bool hasActionType(const ActionTypeId &actionTypeId); - QList paramTypes() const; - void setParamTypes(const QList ¶mTypes); + ParamTypes paramTypes() const; + void setParamTypes(const ParamTypes ¶mTypes); - QList discoveryParamTypes() const; - void setDiscoveryParamTypes(const QList ¶mTypes); + ParamTypes discoveryParamTypes() const; + void setDiscoveryParamTypes(const ParamTypes ¶mTypes); CreateMethods createMethods() const; void setCreateMethods(CreateMethods createMethods); @@ -113,11 +113,11 @@ private: PluginId m_pluginId; QString m_name; QString m_displayName; - QList m_stateTypes; - QList m_eventTypes; - QList m_actionTypes; - QList m_paramTypes; - QList m_discoveryParamTypes; + StateTypes m_stateTypes; + EventTypes m_eventTypes; + ActionTypes m_actionTypes; + ParamTypes m_paramTypes; + ParamTypes m_discoveryParamTypes; CreateMethods m_createMethods; SetupMethod m_setupMethod; QString m_pairingInfo;