some more work on interfaces
This commit is contained in:
parent
7aa6ab2795
commit
d0231d5cdd
@ -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>
|
||||
|
||||
3
libguh/interfaces/media.json
Normal file
3
libguh/interfaces/media.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
|
||||
}
|
||||
@ -1,4 +1,5 @@
|
||||
{
|
||||
"extends": "media",
|
||||
"states": [
|
||||
{
|
||||
"name": "mute",
|
||||
|
||||
8
libguh/interfaces/weather.json
Normal file
8
libguh/interfaces/weather.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"states": [
|
||||
{
|
||||
"name": "temperature",
|
||||
"type": "double"
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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;
|
||||
|
||||
Reference in New Issue
Block a user