some more work on interfaces

This commit is contained in:
Michael Zanetti 2017-09-16 18:42:58 +02:00
parent 7aa6ab2795
commit d0231d5cdd
6 changed files with 37 additions and 1 deletions

View File

@ -1,5 +1,6 @@
<RCC>
<qresource prefix="/interfaces">
<file>media.json</file>
<file>mediacontroller.json</file>
<file>light.json</file>
<file>dimmablelight.json</file>
@ -7,5 +8,6 @@
<file>garagegate.json</file>
<file>gateway.json</file>
<file>notifications.json</file>
<file>weather.json</file>
</qresource>
</RCC>

View File

@ -0,0 +1,3 @@
{
}

View File

@ -1,4 +1,5 @@
{
"extends": "media",
"states": [
{
"name": "mute",

View File

@ -0,0 +1,8 @@
{
"states": [
{
"name": "temperature",
"type": "double"
}
]
}

View File

@ -584,7 +584,7 @@ QList<DeviceClass> 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;
}

View File

@ -148,6 +148,7 @@ private:
QPair<bool, DeviceClass::DeviceIcon> loadAndVerifyDeviceIcon(const QString &deviceIcon) const;
static QVariantMap loadInterface(const QString &name);
static QStringList generateInterfaceParentList(const QString &interface);
QTranslator *m_translator;
DeviceManager *m_deviceManager;