diff --git a/libguh/interfaces/interfaces.qrc b/libguh/interfaces/interfaces.qrc index 8ad817b9..7bae56df 100644 --- a/libguh/interfaces/interfaces.qrc +++ b/libguh/interfaces/interfaces.qrc @@ -1,5 +1,6 @@ + media.json mediacontroller.json light.json dimmablelight.json @@ -7,5 +8,6 @@ garagegate.json gateway.json notifications.json + weather.json diff --git a/libguh/interfaces/media.json b/libguh/interfaces/media.json new file mode 100644 index 00000000..0db3279e --- /dev/null +++ b/libguh/interfaces/media.json @@ -0,0 +1,3 @@ +{ + +} diff --git a/libguh/interfaces/mediacontroller.json b/libguh/interfaces/mediacontroller.json index 83a95843..ed9b3839 100644 --- a/libguh/interfaces/mediacontroller.json +++ b/libguh/interfaces/mediacontroller.json @@ -1,4 +1,5 @@ { + "extends": "media", "states": [ { "name": "mute", diff --git a/libguh/interfaces/weather.json b/libguh/interfaces/weather.json new file mode 100644 index 00000000..136754e8 --- /dev/null +++ b/libguh/interfaces/weather.json @@ -0,0 +1,8 @@ +{ + "states": [ + { + "name": "temperature", + "type": "double" + } + ] +} diff --git a/libguh/plugin/deviceplugin.cpp b/libguh/plugin/deviceplugin.cpp index 111ebdcf..19847554 100644 --- a/libguh/plugin/deviceplugin.cpp +++ b/libguh/plugin/deviceplugin.cpp @@ -584,7 +584,7 @@ QList DevicePlugin::supportedDevices() const } if (valid) { - interfaces.append(value.toString()); + interfaces.append(generateInterfaceParentList(value.toString())); } } deviceClass.setInterfaces(interfaces); @@ -1186,3 +1186,24 @@ QVariantMap DevicePlugin::loadInterface(const QString &name) } return content; } + +QStringList DevicePlugin::generateInterfaceParentList(const QString &interface) +{ + QFile f(QString(":/interfaces/%1.json").arg(interface)); + if (!f.open(QFile::ReadOnly)) { + qCWarning(dcDeviceManager()) << "Failed to load interface" << interface; + return QStringList(); + } + QJsonParseError error; + QJsonDocument jsonDoc = QJsonDocument::fromJson(f.readAll(), &error); + if (error.error != QJsonParseError::NoError) { + qCWarning(dcDeviceManager) << "Cannot load interface definition for interface" << interface << ":" << error.errorString(); + return QStringList(); + } + QStringList ret = {interface}; + QVariantMap content = jsonDoc.toVariant().toMap(); + if (content.contains("extends")) { + ret << generateInterfaceParentList(content.value("extends").toString()); + } + return ret; +} diff --git a/libguh/plugin/deviceplugin.h b/libguh/plugin/deviceplugin.h index 7472fc09..c2023bc9 100644 --- a/libguh/plugin/deviceplugin.h +++ b/libguh/plugin/deviceplugin.h @@ -148,6 +148,7 @@ private: QPair loadAndVerifyDeviceIcon(const QString &deviceIcon) const; static QVariantMap loadInterface(const QString &name); + static QStringList generateInterfaceParentList(const QString &interface); QTranslator *m_translator; DeviceManager *m_deviceManager;