Merge PR #547: Cleanup legacy
This commit is contained in:
commit
d86159900c
@ -47,7 +47,7 @@ ApplicationWindow {
|
|||||||
ThingsProxy {
|
ThingsProxy {
|
||||||
id: thingProxy
|
id: thingProxy
|
||||||
engine: _engine
|
engine: _engine
|
||||||
filterDeviceId: controlledThingId
|
filterThingId: controlledThingId
|
||||||
}
|
}
|
||||||
|
|
||||||
property Thing controlledThing: engine.thingManager.fetchingData ? null : engine.thingManager.things.getThing(controlledThingId)
|
property Thing controlledThing: engine.thingManager.fetchingData ? null : engine.thingManager.things.getThing(controlledThingId)
|
||||||
|
|||||||
@ -120,7 +120,7 @@ void DeviceControlApplication::handleNdefMessage(QNdefMessage message, QNearFiel
|
|||||||
connectToNymea(nymeaId);
|
connectToNymea(nymeaId);
|
||||||
m_qmlEngine->rootContext()->setContextProperty("controlledThingId", thingId);
|
m_qmlEngine->rootContext()->setContextProperty("controlledThingId", thingId);
|
||||||
|
|
||||||
connect(m_engine->thingManager(), &DeviceManager::fetchingDataChanged, [this](){
|
connect(m_engine->thingManager(), &ThingManager::fetchingDataChanged, [this](){
|
||||||
if (m_engine->jsonRpcClient()->connected() && !m_engine->thingManager()->fetchingData()) {
|
if (m_engine->jsonRpcClient()->connected() && !m_engine->thingManager()->fetchingData()) {
|
||||||
qDebug() << "Ready to process commands";
|
qDebug() << "Ready to process commands";
|
||||||
runNfcAction();
|
runNfcAction();
|
||||||
@ -160,7 +160,7 @@ void DeviceControlApplication::runNfcAction()
|
|||||||
}
|
}
|
||||||
|
|
||||||
QUuid thingId = QUuid(QUrlQuery(url).queryItemValue("t"));
|
QUuid thingId = QUuid(QUrlQuery(url).queryItemValue("t"));
|
||||||
Device *thing = m_engine->thingManager()->things()->getThing(thingId);
|
Thing *thing = m_engine->thingManager()->things()->getThing(thingId);
|
||||||
if (!thing) {
|
if (!thing) {
|
||||||
qDebug() << "Thing" << thingId.toString() << "from" << url.toString() << "doesn't exist on nymea host" << nymeaId.toString();
|
qDebug() << "Thing" << thingId.toString() << "from" << url.toString() << "doesn't exist on nymea host" << nymeaId.toString();
|
||||||
return;
|
return;
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
#include "androidbinder.h"
|
#include "androidbinder.h"
|
||||||
#include "engine.h"
|
#include "engine.h"
|
||||||
#include "types/device.h"
|
#include "types/thing.h"
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QAndroidParcel>
|
#include <QAndroidParcel>
|
||||||
@ -54,7 +54,7 @@ bool AndroidBinder::onTransact(int code, const QAndroidParcel &data, const QAndr
|
|||||||
}
|
}
|
||||||
QVariantList thingsList;
|
QVariantList thingsList;
|
||||||
for (int i = 0; i < engine->thingManager()->things()->rowCount(); i++) {
|
for (int i = 0; i < engine->thingManager()->things()->rowCount(); i++) {
|
||||||
Device *thing = engine->thingManager()->things()->get(i);
|
Thing *thing = engine->thingManager()->things()->get(i);
|
||||||
QVariantMap thingMap;
|
QVariantMap thingMap;
|
||||||
thingMap.insert("id", thing->id());
|
thingMap.insert("id", thing->id());
|
||||||
thingMap.insert("name", thing->name());
|
thingMap.insert("name", thing->name());
|
||||||
|
|||||||
@ -42,7 +42,7 @@ NymeaAppService::NymeaAppService(int argc, char **argv):
|
|||||||
m_engines.insert(host->uuid(), engine);
|
m_engines.insert(host->uuid(), engine);
|
||||||
|
|
||||||
|
|
||||||
QObject::connect(engine->thingManager(), &DeviceManager::thingStateChanged, [=](const QUuid &thingId, const QUuid &stateTypeId, const QVariant &value){
|
QObject::connect(engine->thingManager(), &ThingManager::thingStateChanged, [=](const QUuid &thingId, const QUuid &stateTypeId, const QVariant &value){
|
||||||
QVariantMap params;
|
QVariantMap params;
|
||||||
params.insert("nymeaId", engine->jsonRpcClient()->currentHost()->uuid());
|
params.insert("nymeaId", engine->jsonRpcClient()->currentHost()->uuid());
|
||||||
params.insert("thingId", thingId);
|
params.insert("thingId", thingId);
|
||||||
@ -51,7 +51,7 @@ NymeaAppService::NymeaAppService(int argc, char **argv):
|
|||||||
sendNotification("ThingStateChanged", params);
|
sendNotification("ThingStateChanged", params);
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(engine->thingManager(), &DeviceManager::fetchingDataChanged, [=]() {
|
connect(engine->thingManager(), &ThingManager::fetchingDataChanged, [=]() {
|
||||||
qDebug() << "Fetching data changed";
|
qDebug() << "Fetching data changed";
|
||||||
QVariantMap params;
|
QVariantMap params;
|
||||||
params.insert("nymeaId", engine->jsonRpcClient()->currentHost()->uuid());
|
params.insert("nymeaId", engine->jsonRpcClient()->currentHost()->uuid());
|
||||||
|
|||||||
@ -1,786 +0,0 @@
|
|||||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
||||||
*
|
|
||||||
* Copyright 2013 - 2020, nymea GmbH
|
|
||||||
* Contact: contact@nymea.io
|
|
||||||
*
|
|
||||||
* This file is part of nymea.
|
|
||||||
* This project including source code and documentation is protected by
|
|
||||||
* copyright law, and remains the property of nymea GmbH. All rights, including
|
|
||||||
* reproduction, publication, editing and translation, are reserved. The use of
|
|
||||||
* this project is subject to the terms of a license agreement to be concluded
|
|
||||||
* with nymea GmbH in accordance with the terms of use of nymea GmbH, available
|
|
||||||
* under https://nymea.io/license
|
|
||||||
*
|
|
||||||
* GNU General Public License Usage
|
|
||||||
* Alternatively, this project may be redistributed and/or modified under the
|
|
||||||
* terms of the GNU General Public License as published by the Free Software
|
|
||||||
* Foundation, GNU version 3. This project is distributed in the hope that it
|
|
||||||
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
|
|
||||||
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
|
||||||
* Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along with
|
|
||||||
* this project. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
* For any further details and any questions please contact us under
|
|
||||||
* contact@nymea.io or see our FAQ/Licensing Information on
|
|
||||||
* https://nymea.io/license/faq
|
|
||||||
*
|
|
||||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
||||||
|
|
||||||
#include "devicemanager.h"
|
|
||||||
#include "engine.h"
|
|
||||||
#include "jsonrpc/jsontypes.h"
|
|
||||||
#include "types/browseritems.h"
|
|
||||||
#include "types/browseritem.h"
|
|
||||||
#include "thinggroup.h"
|
|
||||||
#include "types/interface.h"
|
|
||||||
#include "types/ioconnections.h"
|
|
||||||
|
|
||||||
#include <QMetaEnum>
|
|
||||||
#include <QFile>
|
|
||||||
#include <QStandardPaths>
|
|
||||||
|
|
||||||
DeviceManager::DeviceManager(JsonRpcClient* jsonclient, QObject *parent) :
|
|
||||||
JsonHandler(parent),
|
|
||||||
m_vendors(new Vendors(this)),
|
|
||||||
m_plugins(new Plugins(this)),
|
|
||||||
m_devices(new Devices(this)),
|
|
||||||
m_thingClasses(new DeviceClasses(this)),
|
|
||||||
m_ioConnections(new IOConnections(this)),
|
|
||||||
m_jsonClient(jsonclient)
|
|
||||||
{
|
|
||||||
m_jsonClient->registerNotificationHandler(this, "notificationReceived");
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeviceManager::clear()
|
|
||||||
{
|
|
||||||
m_devices->clearModel();
|
|
||||||
m_thingClasses->clearModel();
|
|
||||||
m_vendors->clearModel();
|
|
||||||
m_plugins->clearModel();
|
|
||||||
m_ioConnections->clearModel();
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeviceManager::init()
|
|
||||||
{
|
|
||||||
m_connectionBenchmark = QDateTime::currentDateTime();
|
|
||||||
|
|
||||||
// For old nymea setups we need to register to Events.Notifications.
|
|
||||||
// Deprecated since JSONRPC 4.0/nymea 0.17
|
|
||||||
if (!m_jsonClient->ensureServerVersion("4.0")) {
|
|
||||||
if (!m_eventHandler) {
|
|
||||||
m_eventHandler = new EventHandler(this);
|
|
||||||
m_jsonClient->registerNotificationHandler(m_eventHandler, "notificationReceived");
|
|
||||||
connect(m_eventHandler, &EventHandler::eventReceived, this, [this](const QVariantMap event) {
|
|
||||||
QUuid deviceId = event.value("deviceId").toUuid();
|
|
||||||
QUuid eventTypeId = event.value("eventTypeId").toUuid();
|
|
||||||
|
|
||||||
Device *dev = m_devices->getDevice(deviceId);
|
|
||||||
if (!dev) {
|
|
||||||
qWarning() << "received an event from a device we don't know..." << deviceId << event;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// qDebug() << "Event received" << deviceId.toString() << eventTypeId.toString() << qUtf8Printable(QJsonDocument::fromVariant(event).toJson());
|
|
||||||
dev->eventTriggered(eventTypeId.toString(), event.value("params").toMap());
|
|
||||||
emit eventTriggered(deviceId.toString(), eventTypeId.toString(), event.value("params").toMap());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (m_eventHandler) {
|
|
||||||
m_jsonClient->unregisterNotificationHandler(m_eventHandler);
|
|
||||||
m_eventHandler->deleteLater();
|
|
||||||
m_eventHandler = nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Register a custom notification handler for the Integrations namespace for now.
|
|
||||||
if (m_jsonClient->ensureServerVersion("5.1")) {
|
|
||||||
if (!m_integrationsHandler) {
|
|
||||||
m_integrationsHandler = new IntegrationsHandler(this);
|
|
||||||
m_jsonClient->registerNotificationHandler(m_integrationsHandler, "notificationReceived");
|
|
||||||
connect(m_integrationsHandler, &IntegrationsHandler::onNotificationReceived, this, [this](const QVariantMap ¶ms){
|
|
||||||
notificationReceived(params);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
m_fetchingData = true;
|
|
||||||
emit fetchingDataChanged();
|
|
||||||
|
|
||||||
m_jsonClient->sendCommand("Devices.GetSupportedDevices", this, "getSupportedDevicesResponse");
|
|
||||||
}
|
|
||||||
|
|
||||||
QString DeviceManager::nameSpace() const
|
|
||||||
{
|
|
||||||
return "Devices";
|
|
||||||
}
|
|
||||||
|
|
||||||
Vendors *DeviceManager::vendors() const
|
|
||||||
{
|
|
||||||
return m_vendors;
|
|
||||||
}
|
|
||||||
|
|
||||||
Plugins *DeviceManager::plugins() const
|
|
||||||
{
|
|
||||||
return m_plugins;
|
|
||||||
}
|
|
||||||
|
|
||||||
Devices *DeviceManager::devices() const
|
|
||||||
{
|
|
||||||
return m_devices;
|
|
||||||
}
|
|
||||||
|
|
||||||
Devices *DeviceManager::things() const
|
|
||||||
{
|
|
||||||
return m_devices;
|
|
||||||
}
|
|
||||||
|
|
||||||
DeviceClasses *DeviceManager::deviceClasses() const
|
|
||||||
{
|
|
||||||
return m_thingClasses;
|
|
||||||
}
|
|
||||||
|
|
||||||
DeviceClasses *DeviceManager::thingClasses() const
|
|
||||||
{
|
|
||||||
return m_thingClasses;
|
|
||||||
}
|
|
||||||
|
|
||||||
IOConnections *DeviceManager::ioConnections() const
|
|
||||||
{
|
|
||||||
return m_ioConnections;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DeviceManager::fetchingData() const
|
|
||||||
{
|
|
||||||
return m_fetchingData;
|
|
||||||
}
|
|
||||||
|
|
||||||
int DeviceManager::addDevice(const QUuid &deviceClassId, const QString &name, const QVariantList &deviceParams)
|
|
||||||
{
|
|
||||||
qDebug() << "add device " << deviceClassId.toString();
|
|
||||||
QVariantMap params;
|
|
||||||
params.insert("deviceClassId", deviceClassId.toString());
|
|
||||||
params.insert("name", name);
|
|
||||||
params.insert("deviceParams", deviceParams);
|
|
||||||
return m_jsonClient->sendCommand("Devices.AddConfiguredDevice", params, this, "addDeviceResponse");
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeviceManager::notificationReceived(const QVariantMap &data)
|
|
||||||
{
|
|
||||||
QString notification = data.value("notification").toString();
|
|
||||||
if (notification == "Devices.StateChanged") {
|
|
||||||
Device *dev = m_devices->getDevice(data.value("params").toMap().value("deviceId").toUuid());
|
|
||||||
if (!dev) {
|
|
||||||
qWarning() << "Device state change notification received for an unknown device";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
QUuid stateTypeId = data.value("params").toMap().value("stateTypeId").toUuid();
|
|
||||||
QVariant value = data.value("params").toMap().value("value");
|
|
||||||
// qDebug() << "Device state changed for:" << dev->name() << "State name:" << dev->thingClass()->stateTypes()->getStateType(stateTypeId) << "value:" << value;
|
|
||||||
dev->setStateValue(stateTypeId, value);
|
|
||||||
emit thingStateChanged(dev->id(), stateTypeId, value);
|
|
||||||
} else if (notification == "Devices.DeviceAdded") {
|
|
||||||
Device *dev = JsonTypes::unpackDevice(this, data.value("params").toMap().value("device").toMap(), m_thingClasses);
|
|
||||||
if (!dev) {
|
|
||||||
qWarning() << "Cannot parse json device:" << data;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
DeviceClass *dc = deviceClasses()->getDeviceClass(dev->deviceClassId());
|
|
||||||
if (!dc) {
|
|
||||||
qWarning() << "Skipping invalid device. Don't have a device class for it";
|
|
||||||
delete dev;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
m_devices->addDevice(dev);
|
|
||||||
} else if (notification == "Devices.DeviceRemoved") {
|
|
||||||
QUuid deviceId = data.value("params").toMap().value("deviceId").toUuid();
|
|
||||||
// qDebug() << "JsonRpc: Notification: Device removed" << deviceId.toString();
|
|
||||||
Device *thing = m_devices->getDevice(deviceId);
|
|
||||||
if (!thing) {
|
|
||||||
qWarning() << "Received a DeviceRemoved notification for a device we don't know!";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
m_devices->removeThing(thing);
|
|
||||||
thing->deleteLater();
|
|
||||||
} else if (notification == "Devices.DeviceChanged") {
|
|
||||||
QUuid deviceId = data.value("params").toMap().value("device").toMap().value("id").toUuid();
|
|
||||||
// qDebug() << "Device changed notification" << deviceId << data.value("params").toMap();
|
|
||||||
Device *oldDevice = m_devices->getDevice(deviceId);
|
|
||||||
if (!oldDevice) {
|
|
||||||
qWarning() << "Received a device changed notification for a device we don't know";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!JsonTypes::unpackDevice(this, data.value("params").toMap().value("device").toMap(), m_thingClasses, oldDevice)) {
|
|
||||||
qWarning() << "Error parsing device changed notification";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else if (notification == "Devices.DeviceSettingChanged") {
|
|
||||||
QUuid deviceId = data.value("params").toMap().value("deviceId").toUuid();
|
|
||||||
QString paramTypeId = data.value("params").toMap().value("paramTypeId").toString();
|
|
||||||
QVariant value = data.value("params").toMap().value("value");
|
|
||||||
// qDebug() << "Device settings changed notification for device" << deviceId << data.value("params").toMap().value("settings").toList();
|
|
||||||
Device *dev = m_devices->getDevice(deviceId);
|
|
||||||
if (!dev) {
|
|
||||||
qWarning() << "Device settings changed notification for a device we don't know" << deviceId.toString();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Param *p = dev->settings()->getParam(paramTypeId);
|
|
||||||
if (!p) {
|
|
||||||
qWarning() << "Device" << dev->name() << dev->id().toString() << "does not have a setting of id" << paramTypeId;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
p->setValue(value);
|
|
||||||
} else if (notification == "Devices.EventTriggered") {
|
|
||||||
QVariantMap event = data.value("params").toMap().value("event").toMap();
|
|
||||||
QUuid deviceId = event.value("deviceId").toUuid();
|
|
||||||
QUuid eventTypeId = event.value("eventTypeId").toUuid();
|
|
||||||
|
|
||||||
Device *dev = m_devices->getDevice(deviceId);
|
|
||||||
if (!dev) {
|
|
||||||
qWarning() << "received an event from a device we don't know..." << deviceId << qUtf8Printable(QJsonDocument::fromVariant(data).toJson());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// qDebug() << "Event received" << deviceId.toString() << eventTypeId.toString() << qUtf8Printable(QJsonDocument::fromVariant(event).toJson());
|
|
||||||
dev->eventTriggered(eventTypeId.toString(), event.value("params").toMap());
|
|
||||||
} else if (notification == "Integrations.IOConnectionAdded") {
|
|
||||||
QVariantMap connectionMap = data.value("params").toMap().value("ioConnection").toMap();
|
|
||||||
QUuid id = connectionMap.value("id").toUuid();
|
|
||||||
QUuid inputThingId = connectionMap.value("inputThingId").toUuid();
|
|
||||||
QUuid inputStateTypeId = connectionMap.value("inputStateTypeId").toUuid();
|
|
||||||
QUuid outputThingId = connectionMap.value("outputThingId").toUuid();
|
|
||||||
QUuid outputStateTypeId = connectionMap.value("outputStateTypeId").toUuid();
|
|
||||||
bool inverted = connectionMap.value("inverted").toBool();
|
|
||||||
IOConnection *ioConnection = new IOConnection(id, inputThingId, inputStateTypeId, outputThingId, outputStateTypeId, inverted);
|
|
||||||
m_ioConnections->addIOConnection(ioConnection);
|
|
||||||
} else if (notification == "Integrations.IOConnectionRemoved") {
|
|
||||||
QUuid connectionId = data.value("params").toMap().value("ioConnectionId").toUuid();
|
|
||||||
if (!m_ioConnections->getIOConnection(connectionId)) {
|
|
||||||
qWarning() << "Received an IO connection removed event for an IO connection we don't know.";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
m_ioConnections->removeIOConnection(connectionId);
|
|
||||||
} else if (notification == "Integrations.EventTriggered") {
|
|
||||||
// Still using Devices.EventTriggered
|
|
||||||
} else if (notification == "Integrations.StateChanged") {
|
|
||||||
// Still using Devies.StateChanged
|
|
||||||
} else {
|
|
||||||
qWarning() << "DeviceManager unhandled device notification received" << notification;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeviceManager::getVendorsResponse(int /*commandId*/, const QVariantMap ¶ms)
|
|
||||||
{
|
|
||||||
// qDebug() << "Got GetSupportedVendors response" << params;
|
|
||||||
if (params.keys().contains("vendors")) {
|
|
||||||
QVariantList vendorList = params.value("vendors").toList();
|
|
||||||
foreach (QVariant vendorVariant, vendorList) {
|
|
||||||
Vendor *vendor = JsonTypes::unpackVendor(vendorVariant.toMap());
|
|
||||||
m_vendors->addVendor(vendor);
|
|
||||||
// qDebug() << "Added Vendor:" << vendor->name();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeviceManager::getSupportedDevicesResponse(int /*commandId*/, const QVariantMap ¶ms)
|
|
||||||
{
|
|
||||||
// qDebug() << "DeviceClasses received:" << qUtf8Printable(QJsonDocument::fromVariant(params).toJson(QJsonDocument::Indented));
|
|
||||||
if (params.keys().contains("deviceClasses")) {
|
|
||||||
QVariantList deviceClassList = params.value("deviceClasses").toList();
|
|
||||||
foreach (QVariant deviceClassVariant, deviceClassList) {
|
|
||||||
DeviceClass *deviceClass = JsonTypes::unpackDeviceClass(deviceClassVariant.toMap(), deviceClasses());
|
|
||||||
m_thingClasses->addDeviceClass(deviceClass);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
m_jsonClient->sendCommand("Devices.GetConfiguredDevices", this, "getConfiguredDevicesResponse");
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeviceManager::getPluginsResponse(int /*commandId*/, const QVariantMap ¶ms)
|
|
||||||
{
|
|
||||||
// qDebug() << "received plugins";
|
|
||||||
if (params.keys().contains("plugins")) {
|
|
||||||
QVariantList pluginList = params.value("plugins").toList();
|
|
||||||
foreach (QVariant pluginVariant, pluginList) {
|
|
||||||
Plugin *plugin = JsonTypes::unpackPlugin(pluginVariant.toMap(), plugins());
|
|
||||||
m_plugins->addPlugin(plugin);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
m_jsonClient->sendCommand("Devices.GetSupportedVendors", this, "getVendorsResponse");
|
|
||||||
|
|
||||||
if (m_plugins->count() > 0) {
|
|
||||||
m_currentGetConfigIndex = 0;
|
|
||||||
QVariantMap configRequestParams;
|
|
||||||
configRequestParams.insert("pluginId", m_plugins->get(m_currentGetConfigIndex)->pluginId());
|
|
||||||
m_jsonClient->sendCommand("Devices.GetPluginConfiguration", configRequestParams, this, "getPluginConfigResponse");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeviceManager::getPluginConfigResponse(int /*commandId*/, const QVariantMap ¶ms)
|
|
||||||
{
|
|
||||||
// qDebug() << "plugin config response" << params;
|
|
||||||
Plugin *p = m_plugins->get(m_currentGetConfigIndex);
|
|
||||||
if (!p) {
|
|
||||||
qDebug() << "Received a plugin config for a plugin we don't know";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
QVariantList pluginParams = params.value("configuration").toList();
|
|
||||||
foreach (const QVariant ¶mVariant, pluginParams) {
|
|
||||||
Param* param = new Param();
|
|
||||||
JsonTypes::unpackParam(paramVariant.toMap(), param);
|
|
||||||
p->params()->addParam(param);
|
|
||||||
}
|
|
||||||
|
|
||||||
m_currentGetConfigIndex++;
|
|
||||||
if (m_plugins->count() > m_currentGetConfigIndex) {
|
|
||||||
QVariantMap configRequestParams;
|
|
||||||
configRequestParams.insert("pluginId", m_plugins->get(m_currentGetConfigIndex)->pluginId());
|
|
||||||
m_jsonClient->sendCommand("Devices.GetPluginConfiguration", configRequestParams, this, "getPluginConfigResponse");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeviceManager::getConfiguredDevicesResponse(int /*commandId*/, const QVariantMap ¶ms)
|
|
||||||
{
|
|
||||||
if (params.keys().contains("devices")) {
|
|
||||||
QVariantList deviceList = params.value("devices").toList();
|
|
||||||
foreach (QVariant deviceVariant, deviceList) {
|
|
||||||
Device *device = JsonTypes::unpackDevice(this, deviceVariant.toMap(), m_thingClasses);
|
|
||||||
if (!device) {
|
|
||||||
qWarning() << "Error unpacking device" << deviceVariant.toMap().value("name").toString();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// set initial state values
|
|
||||||
QVariantList stateVariantList = deviceVariant.toMap().value("states").toList();
|
|
||||||
foreach (const QVariant &stateMap, stateVariantList) {
|
|
||||||
QString stateTypeId = stateMap.toMap().value("stateTypeId").toString();
|
|
||||||
StateType *st = device->thingClass()->stateTypes()->getStateType(stateTypeId);
|
|
||||||
if (!st) {
|
|
||||||
qWarning() << "Can't find a statetype for this state";
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
QVariant value = stateMap.toMap().value("value");
|
|
||||||
if (st->type() == "Bool") {
|
|
||||||
value.convert(QVariant::Bool);
|
|
||||||
} else if (st->type() == "Double") {
|
|
||||||
value.convert(QVariant::Double);
|
|
||||||
} else if (st->type() == "Int") {
|
|
||||||
value.convert(QVariant::Int);
|
|
||||||
}
|
|
||||||
device->setStateValue(stateTypeId, value);
|
|
||||||
// qDebug() << "Set device state value:" << device->stateValue(stateTypeId) << value;
|
|
||||||
}
|
|
||||||
// qDebug() << "Configured Device JSON:" << qUtf8Printable(QJsonDocument::fromVariant(deviceVariant).toJson(QJsonDocument::Indented));
|
|
||||||
devices()->addDevice(device);
|
|
||||||
// qDebug() << "*** Added device:" << endl << device;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
qDebug() << "Initializing thing manager took" << m_connectionBenchmark.msecsTo(QDateTime::currentDateTime()) << "ms";
|
|
||||||
m_fetchingData = false;
|
|
||||||
emit fetchingDataChanged();
|
|
||||||
|
|
||||||
m_jsonClient->sendCommand("Integrations.GetIOConnections", this, "getIOConnectionsResponse");
|
|
||||||
|
|
||||||
m_jsonClient->sendCommand("Devices.GetPlugins", this, "getPluginsResponse");
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeviceManager::addDeviceResponse(int commandId, const QVariantMap ¶ms)
|
|
||||||
{
|
|
||||||
if (params.value("deviceError").toString() != "DeviceErrorNoError") {
|
|
||||||
qWarning() << "Failed to add the device:" << params.value("deviceError").toString();
|
|
||||||
} else if (params.keys().contains("device")) {
|
|
||||||
QVariantMap deviceVariant = params.value("device").toMap();
|
|
||||||
Device *device = JsonTypes::unpackDevice(this, deviceVariant, m_thingClasses);
|
|
||||||
if (!device) {
|
|
||||||
qWarning() << "Couldn't parse json in addDeviceResponse";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
qDebug() << "Device added" << device->id().toString();
|
|
||||||
m_devices->addDevice(device);
|
|
||||||
}
|
|
||||||
emit addDeviceReply(commandId, params);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeviceManager::removeThingResponse(int commandId, const QVariantMap ¶ms)
|
|
||||||
{
|
|
||||||
qDebug() << "Thing removed response" << params;
|
|
||||||
emit removeThingReply(commandId, params);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeviceManager::pairDeviceResponse(int commandId, const QVariantMap ¶ms)
|
|
||||||
{
|
|
||||||
qDebug() << "Pair device response:" << params;
|
|
||||||
emit pairDeviceReply(commandId, params);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeviceManager::confirmPairingResponse(int commandId, const QVariantMap ¶ms)
|
|
||||||
{
|
|
||||||
qDebug() << "ConfirmPairingResponse" << params;
|
|
||||||
emit confirmPairingReply(commandId, params);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeviceManager::setPluginConfigResponse(int commandId, const QVariantMap ¶ms)
|
|
||||||
{
|
|
||||||
qDebug() << "set plugin config response" << params;
|
|
||||||
emit savePluginConfigReply(commandId, params);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeviceManager::editThingResponse(int commandId, const QVariantMap ¶ms)
|
|
||||||
{
|
|
||||||
qDebug() << "Edit thing response" << params;
|
|
||||||
emit editThingReply(commandId, params);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeviceManager::executeActionResponse(int commandId, const QVariantMap ¶ms)
|
|
||||||
{
|
|
||||||
qDebug() << "Execute Action response" << params;
|
|
||||||
emit executeActionReply(commandId, params);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeviceManager::reconfigureDeviceResponse(int commandId, const QVariantMap ¶ms)
|
|
||||||
{
|
|
||||||
qDebug() << "Reconfigure device response" << params;
|
|
||||||
emit reconfigureDeviceReply(commandId, params);
|
|
||||||
}
|
|
||||||
|
|
||||||
int DeviceManager::savePluginConfig(const QUuid &pluginId)
|
|
||||||
{
|
|
||||||
Plugin *p = m_plugins->getPlugin(pluginId);
|
|
||||||
if (!p) {
|
|
||||||
qWarning()<< "Error: can't find plugin with id" << pluginId;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
QVariantMap params;
|
|
||||||
params.insert("pluginId", pluginId);
|
|
||||||
QVariantList pluginParams;
|
|
||||||
for (int i = 0; i < p->params()->rowCount(); i++) {
|
|
||||||
pluginParams.append(JsonTypes::packParam(p->params()->get(i)));
|
|
||||||
}
|
|
||||||
params.insert("configuration", pluginParams);
|
|
||||||
return m_jsonClient->sendCommand("Devices.SetPluginConfiguration", params, this, "setPluginConfigResponse");
|
|
||||||
}
|
|
||||||
|
|
||||||
ThingGroup *DeviceManager::createGroup(Interface *interface, DevicesProxy *things)
|
|
||||||
{
|
|
||||||
ThingGroup* group = new ThingGroup(this, interface->createDeviceClass(), things, this);
|
|
||||||
group->setSetupStatus(Device::ThingSetupStatusComplete, QString());
|
|
||||||
return group;
|
|
||||||
}
|
|
||||||
|
|
||||||
int DeviceManager::addDiscoveredDevice(const QUuid &deviceClassId, const QUuid &deviceDescriptorId, const QString &name, const QVariantList &deviceParams)
|
|
||||||
{
|
|
||||||
qDebug() << "JsonRpc: add discovered device " << deviceClassId.toString();
|
|
||||||
QVariantMap params;
|
|
||||||
params.insert("deviceClassId", deviceClassId.toString());
|
|
||||||
params.insert("name", name);
|
|
||||||
params.insert("deviceDescriptorId", deviceDescriptorId.toString());
|
|
||||||
params.insert("deviceParams", deviceParams);
|
|
||||||
return m_jsonClient->sendCommand("Devices.AddConfiguredDevice", params, this, "addDeviceResponse");
|
|
||||||
}
|
|
||||||
|
|
||||||
int DeviceManager::pairDiscoveredDevice(const QUuid &deviceClassId, const QUuid &deviceDescriptorId, const QVariantList &deviceParams, const QString &name)
|
|
||||||
{
|
|
||||||
qDebug() << "JsonRpc: pair discovered device " << deviceDescriptorId.toString();
|
|
||||||
QVariantMap params;
|
|
||||||
params.insert("deviceDescriptorId", deviceDescriptorId.toString());
|
|
||||||
params.insert("deviceParams", deviceParams);
|
|
||||||
params.insert("name", name);
|
|
||||||
|
|
||||||
if (!m_jsonClient->ensureServerVersion("3.2")) {
|
|
||||||
params.insert("deviceClassId", deviceClassId);
|
|
||||||
}
|
|
||||||
|
|
||||||
return m_jsonClient->sendCommand("Devices.PairDevice", params, this, "pairDeviceResponse");
|
|
||||||
}
|
|
||||||
|
|
||||||
int DeviceManager::pairDevice(const QUuid &deviceClassId, const QVariantList &deviceParams, const QString &name)
|
|
||||||
{
|
|
||||||
qDebug() << "JsonRpc: pair device " << deviceClassId.toString();
|
|
||||||
QVariantMap params;
|
|
||||||
params.insert("deviceClassId", deviceClassId.toString());
|
|
||||||
params.insert("deviceParams", deviceParams);
|
|
||||||
params.insert("name", name);
|
|
||||||
return m_jsonClient->sendCommand("Devices.PairDevice", params, this, "pairDeviceResponse");
|
|
||||||
}
|
|
||||||
|
|
||||||
int DeviceManager::rePairDevice(const QUuid &deviceId, const QVariantList &deviceParams, const QString &name)
|
|
||||||
{
|
|
||||||
qDebug() << "JsonRpc: pair device (reconfigure)" << deviceId;
|
|
||||||
QVariantMap params;
|
|
||||||
params.insert("deviceId", deviceId.toString());
|
|
||||||
params.insert("deviceParams", deviceParams);
|
|
||||||
if (!name.isEmpty()) {
|
|
||||||
params.insert("name", name);
|
|
||||||
}
|
|
||||||
return m_jsonClient->sendCommand("Devices.PairDevice", params, this, "pairDeviceResponse");
|
|
||||||
}
|
|
||||||
|
|
||||||
int DeviceManager::confirmPairing(const QUuid &pairingTransactionId, const QString &secret, const QString &username)
|
|
||||||
{
|
|
||||||
qDebug() << "JsonRpc: confirm pairing" << pairingTransactionId.toString();
|
|
||||||
QVariantMap params;
|
|
||||||
params.insert("pairingTransactionId", pairingTransactionId.toString());
|
|
||||||
params.insert("secret", secret);
|
|
||||||
if (!username.isEmpty()) {
|
|
||||||
params.insert("username", username);
|
|
||||||
}
|
|
||||||
return m_jsonClient->sendCommand("Devices.ConfirmPairing", params, this, "confirmPairingResponse");
|
|
||||||
}
|
|
||||||
|
|
||||||
int DeviceManager::removeThing(const QUuid &thingId, DeviceManager::RemovePolicy policy)
|
|
||||||
{
|
|
||||||
qDebug() << "JsonRpc: delete device" << thingId.toString();
|
|
||||||
QVariantMap params;
|
|
||||||
params.insert("deviceId", thingId.toString());
|
|
||||||
if (policy != RemovePolicyNone) {
|
|
||||||
QMetaEnum policyEnum = QMetaEnum::fromType<DeviceManager::RemovePolicy>();
|
|
||||||
params.insert("removePolicy", policyEnum.valueToKey(policy));
|
|
||||||
}
|
|
||||||
return m_jsonClient->sendCommand("Devices.RemoveConfiguredDevice", params, this, "removeThingResponse");
|
|
||||||
}
|
|
||||||
|
|
||||||
int DeviceManager::editThing(const QUuid &thingId, const QString &name)
|
|
||||||
{
|
|
||||||
QVariantMap params;
|
|
||||||
params.insert("deviceId", thingId.toString());
|
|
||||||
params.insert("name", name);
|
|
||||||
return m_jsonClient->sendCommand("Devices.EditDevice", params, this, "editThingResponse");
|
|
||||||
}
|
|
||||||
|
|
||||||
int DeviceManager::setDeviceSettings(const QUuid &deviceId, const QVariantList &settings)
|
|
||||||
{
|
|
||||||
QVariantMap params;
|
|
||||||
params.insert("deviceId", deviceId);
|
|
||||||
params.insert("settings", settings);
|
|
||||||
return m_jsonClient->sendCommand("Devices.SetDeviceSettings", params);
|
|
||||||
}
|
|
||||||
|
|
||||||
int DeviceManager::reconfigureDevice(const QUuid &deviceId, const QVariantList &deviceParams)
|
|
||||||
{
|
|
||||||
QVariantMap params;
|
|
||||||
params.insert("deviceId", deviceId.toString());
|
|
||||||
params.insert("deviceParams", deviceParams);
|
|
||||||
return m_jsonClient->sendCommand("Devices.ReconfigureDevice", params, this, "reconfigureDeviceResponse");
|
|
||||||
}
|
|
||||||
|
|
||||||
int DeviceManager::reconfigureDiscoveredDevice(const QUuid &deviceId, const QUuid &deviceDescriptorId, const QVariantList ¶mOverride)
|
|
||||||
{
|
|
||||||
QVariantMap params;
|
|
||||||
params.insert("deviceId", deviceId.toString());
|
|
||||||
params.insert("deviceDescriptorId", deviceDescriptorId);
|
|
||||||
if (!paramOverride.isEmpty()) {
|
|
||||||
params.insert("deviceParams", paramOverride);
|
|
||||||
}
|
|
||||||
qDebug() << "Calling ReconfigureDevice" << qUtf8Printable(QJsonDocument::fromVariant(params).toJson());
|
|
||||||
return m_jsonClient->sendCommand("Devices.ReconfigureDevice", params, this, "reconfigureDeviceResponse");
|
|
||||||
}
|
|
||||||
|
|
||||||
int DeviceManager::executeAction(const QUuid &deviceId, const QUuid &actionTypeId, const QVariantList ¶ms)
|
|
||||||
{
|
|
||||||
// qDebug() << "JsonRpc: execute action " << deviceId.toString() << actionTypeId.toString() << params;
|
|
||||||
QVariantMap p;
|
|
||||||
p.insert("deviceId", deviceId.toString());
|
|
||||||
p.insert("actionTypeId", actionTypeId.toString());
|
|
||||||
if (!params.isEmpty()) {
|
|
||||||
p.insert("params", params);
|
|
||||||
}
|
|
||||||
QString method = m_jsonClient->ensureServerVersion("4.0") ? "Devices.ExecuteAction" : "Actions.ExecuteAction";
|
|
||||||
|
|
||||||
return m_jsonClient->sendCommand(method, p, this, "executeActionResponse");
|
|
||||||
}
|
|
||||||
|
|
||||||
BrowserItems *DeviceManager::browseDevice(const QUuid &deviceId, const QString &itemId)
|
|
||||||
{
|
|
||||||
QVariantMap params;
|
|
||||||
params.insert("deviceId", deviceId.toString());
|
|
||||||
params.insert("itemId", itemId);
|
|
||||||
int id = m_jsonClient->sendCommand("Devices.BrowseDevice", params, this, "browseDeviceResponse");
|
|
||||||
|
|
||||||
// Intentionally not parented. The caller takes ownership and needs to destroy when not needed any more.
|
|
||||||
BrowserItems *itemModel = new BrowserItems(deviceId, itemId);
|
|
||||||
itemModel->setBusy(true);
|
|
||||||
QPointer<BrowserItems> itemModelPtr(itemModel);
|
|
||||||
m_browsingRequests.insert(id, itemModelPtr);
|
|
||||||
|
|
||||||
return itemModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeviceManager::refreshBrowserItems(BrowserItems *browserItems)
|
|
||||||
{
|
|
||||||
QVariantMap params;
|
|
||||||
params.insert("deviceId", browserItems->deviceId().toString());
|
|
||||||
params.insert("itemId", browserItems->itemId());
|
|
||||||
int id = m_jsonClient->sendCommand("Devices.BrowseDevice", params, this, "browseDeviceResponse");
|
|
||||||
|
|
||||||
// Intentionally not parented. The caller takes ownership and needs to destroy when not needed any more.
|
|
||||||
browserItems->setBusy(true);
|
|
||||||
QPointer<BrowserItems> itemModelPtr(browserItems);
|
|
||||||
m_browsingRequests.insert(id, browserItems);
|
|
||||||
}
|
|
||||||
|
|
||||||
BrowserItem *DeviceManager::browserItem(const QUuid &deviceId, const QString &itemId)
|
|
||||||
{
|
|
||||||
QVariantMap params;
|
|
||||||
params.insert("deviceId", deviceId.toString());
|
|
||||||
params.insert("itemId", itemId);
|
|
||||||
int id = m_jsonClient->sendCommand("Devices.GetBrowserItem", params, this, "browserItemResponse");
|
|
||||||
|
|
||||||
// Intentionally not parented. The caller takes ownership and needs to destroy when not needed any more.
|
|
||||||
BrowserItem *item = new BrowserItem(itemId);
|
|
||||||
QPointer<BrowserItem> itemPtr(item);
|
|
||||||
m_browserDetailsRequests.insert(id, itemPtr);
|
|
||||||
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeviceManager::browseDeviceResponse(int commandId, const QVariantMap ¶ms)
|
|
||||||
{
|
|
||||||
// qDebug() << "Browsing response:" << qUtf8Printable(QJsonDocument::fromVariant(params).toJson(QJsonDocument::Indented));
|
|
||||||
if (!m_browsingRequests.contains(commandId)) {
|
|
||||||
qWarning() << "Received a browsing reply for an id we don't know.";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QPointer<BrowserItems> itemModel = m_browsingRequests.take(commandId);
|
|
||||||
if (!itemModel) {
|
|
||||||
qDebug() << "BrowserItems model seems to have disappeared. Discarding browsing result.";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QList<BrowserItem*> itemsToRemove = itemModel->list();
|
|
||||||
|
|
||||||
foreach (const QVariant &itemVariant, params.value("items").toList()) {
|
|
||||||
QVariantMap itemMap = itemVariant.toMap();
|
|
||||||
QString itemId = itemMap.value("id").toString();
|
|
||||||
BrowserItem *item = itemModel->getBrowserItem(itemId);
|
|
||||||
if (!item) {
|
|
||||||
item = new BrowserItem(itemId, this);
|
|
||||||
itemModel->addBrowserItem(item);
|
|
||||||
}
|
|
||||||
item->setDisplayName(itemMap.value("displayName").toString());
|
|
||||||
item->setDescription(itemMap.value("description").toString());
|
|
||||||
item->setIcon(itemMap.value("icon").toString());
|
|
||||||
item->setThumbnail(itemMap.value("thumbnail").toString());
|
|
||||||
item->setExecutable(itemMap.value("executable").toBool());
|
|
||||||
item->setBrowsable(itemMap.value("browsable").toBool());
|
|
||||||
item->setDisabled(itemMap.value("disabled").toBool());
|
|
||||||
item->setActionTypeIds(itemMap.value("actionTypeIds").toStringList());
|
|
||||||
|
|
||||||
item->setMediaIcon(itemMap.value("mediaIcon").toString());
|
|
||||||
|
|
||||||
if (itemsToRemove.contains(item)) {
|
|
||||||
itemsToRemove.removeAll(item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
while (!itemsToRemove.isEmpty()) {
|
|
||||||
BrowserItem *item = itemsToRemove.takeFirst();
|
|
||||||
itemModel->removeItem(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
itemModel->setBusy(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeviceManager::browserItemResponse(int commandId, const QVariantMap ¶ms)
|
|
||||||
{
|
|
||||||
qDebug() << "Browser item details response:" << qUtf8Printable(QJsonDocument::fromVariant(params).toJson(QJsonDocument::Indented));
|
|
||||||
if (!m_browserDetailsRequests.contains(commandId)) {
|
|
||||||
qWarning() << "Received a browser item details reply for an id we don't know.";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QPointer<BrowserItem> item = m_browserDetailsRequests.take(commandId);
|
|
||||||
if (!item) {
|
|
||||||
qDebug() << "BrowserItem seems to have disappeared. Discarding browser item details result.";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QVariantMap itemMap = params.value("item").toMap();
|
|
||||||
item->setDisplayName(itemMap.value("displayName").toString());
|
|
||||||
item->setDescription(itemMap.value("description").toString());
|
|
||||||
item->setIcon(itemMap.value("icon").toString());
|
|
||||||
item->setThumbnail(itemMap.value("thumbnail").toString());
|
|
||||||
item->setExecutable(itemMap.value("executable").toBool());
|
|
||||||
item->setBrowsable(itemMap.value("browsable").toBool());
|
|
||||||
item->setDisabled(itemMap.value("disabled").toBool());
|
|
||||||
item->setActionTypeIds(itemMap.value("actionTypeIds").toStringList());
|
|
||||||
|
|
||||||
item->setMediaIcon(itemMap.value("mediaIcon").toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
int DeviceManager::executeBrowserItem(const QUuid &deviceId, const QString &itemId)
|
|
||||||
{
|
|
||||||
QVariantMap params;
|
|
||||||
params.insert("thingId", deviceId);
|
|
||||||
params.insert("itemId", itemId);
|
|
||||||
return m_jsonClient->sendCommand("Integrations.ExecuteBrowserItem", params, this, "executeBrowserItemResponse");
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeviceManager::executeBrowserItemResponse(int commandId, const QVariantMap ¶ms)
|
|
||||||
{
|
|
||||||
qDebug() << "Execute Browser Item finished" << params;
|
|
||||||
emit executeBrowserItemReply(commandId, params);
|
|
||||||
}
|
|
||||||
|
|
||||||
int DeviceManager::executeBrowserItemAction(const QUuid &deviceId, const QString &itemId, const QUuid &actionTypeId, const QVariantList ¶ms)
|
|
||||||
{
|
|
||||||
QVariantMap data;
|
|
||||||
data.insert("thingId", deviceId);
|
|
||||||
data.insert("itemId", itemId);
|
|
||||||
data.insert("actionTypeId", actionTypeId);
|
|
||||||
data.insert("params", params);
|
|
||||||
qDebug() << "params:" << params;
|
|
||||||
return m_jsonClient->sendCommand("Integrations.ExecuteBrowserItemAction", data, this, "executeBrowserItemActionResponse");
|
|
||||||
}
|
|
||||||
|
|
||||||
int DeviceManager::connectIO(const QUuid &inputThingId, const QUuid &inputStateTypeId, const QUuid &outputThingId, const QUuid &outputStateTypeId, bool inverted)
|
|
||||||
{
|
|
||||||
QVariantMap data;
|
|
||||||
data.insert("inputThingId", inputThingId);
|
|
||||||
data.insert("inputStateTypeId", inputStateTypeId);
|
|
||||||
data.insert("outputThingId", outputThingId);
|
|
||||||
data.insert("outputStateTypeId", outputStateTypeId);
|
|
||||||
data.insert("inverted", inverted);
|
|
||||||
return m_jsonClient->sendCommand("Integrations.ConnectIO", data, this, "connectIOResponse");
|
|
||||||
}
|
|
||||||
|
|
||||||
int DeviceManager::disconnectIO(const QUuid &ioConnectionId)
|
|
||||||
{
|
|
||||||
QVariantMap data;
|
|
||||||
data.insert("ioConnectionId", ioConnectionId);
|
|
||||||
return m_jsonClient->sendCommand("Integrations.DisconnectIO", data, this, "disconnectIOResponse");
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeviceManager::executeBrowserItemActionResponse(int commandId, const QVariantMap ¶ms)
|
|
||||||
{
|
|
||||||
qDebug() << "Execute Browser Item Action finished" << params;
|
|
||||||
emit executeBrowserItemActionReply(commandId, params);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeviceManager::getIOConnectionsResponse(int /*commandId*/, const QVariantMap ¶ms)
|
|
||||||
{
|
|
||||||
// qDebug() << "Get IO connections response" << qUtf8Printable(QJsonDocument::fromVariant(params).toJson());
|
|
||||||
|
|
||||||
foreach (const QVariant &connectionVariant, params.value("ioConnections").toList()) {
|
|
||||||
QVariantMap connectionMap = connectionVariant.toMap();
|
|
||||||
QUuid id = connectionMap.value("id").toUuid();
|
|
||||||
QUuid inputThingId = connectionMap.value("inputThingId").toUuid();
|
|
||||||
QUuid inputStateTypeId = connectionMap.value("inputStateTypeId").toUuid();
|
|
||||||
QUuid outputThingId = connectionMap.value("outputThingId").toUuid();
|
|
||||||
QUuid outputStateTypeId = connectionMap.value("outputStateTypeId").toUuid();
|
|
||||||
bool inverted = connectionMap.value("inverted").toBool();
|
|
||||||
IOConnection *ioConnection = new IOConnection(id, inputThingId, inputStateTypeId, outputThingId, outputStateTypeId, inverted);
|
|
||||||
m_ioConnections->addIOConnection(ioConnection);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeviceManager::connectIOResponse(int commandId, const QVariantMap ¶ms)
|
|
||||||
{
|
|
||||||
qDebug() << "ConnectIO response" << commandId << qUtf8Printable(QJsonDocument::fromVariant(params).toJson());
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeviceManager::disconnectIOResponse(int commandId, const QVariantMap ¶ms)
|
|
||||||
{
|
|
||||||
qDebug() << "DisconnectIO response" << commandId << qUtf8Printable(QJsonDocument::fromVariant(params).toJson());
|
|
||||||
}
|
|
||||||
|
|
||||||
@ -42,7 +42,7 @@
|
|||||||
Engine::Engine(QObject *parent) :
|
Engine::Engine(QObject *parent) :
|
||||||
QObject(parent),
|
QObject(parent),
|
||||||
m_jsonRpcClient(new JsonRpcClient(this)),
|
m_jsonRpcClient(new JsonRpcClient(this)),
|
||||||
m_thingManager(new DeviceManager(m_jsonRpcClient, this)),
|
m_thingManager(new ThingManager(m_jsonRpcClient, this)),
|
||||||
m_ruleManager(new RuleManager(m_jsonRpcClient, this)),
|
m_ruleManager(new RuleManager(m_jsonRpcClient, this)),
|
||||||
m_scriptManager(new ScriptManager(m_jsonRpcClient, this)),
|
m_scriptManager(new ScriptManager(m_jsonRpcClient, this)),
|
||||||
m_logManager(new LogManager(m_jsonRpcClient, this)),
|
m_logManager(new LogManager(m_jsonRpcClient, this)),
|
||||||
@ -53,7 +53,7 @@ Engine::Engine(QObject *parent) :
|
|||||||
|
|
||||||
connect(m_jsonRpcClient, &JsonRpcClient::connectedChanged, this, &Engine::onConnectedChanged);
|
connect(m_jsonRpcClient, &JsonRpcClient::connectedChanged, this, &Engine::onConnectedChanged);
|
||||||
|
|
||||||
connect(m_thingManager, &DeviceManager::fetchingDataChanged, this, &Engine::onDeviceManagerFetchingChanged);
|
connect(m_thingManager, &ThingManager::fetchingDataChanged, this, &Engine::onThingManagerFetchingChanged);
|
||||||
|
|
||||||
connect(m_jsonRpcClient, &JsonRpcClient::connectedChanged, this, [this]() {
|
connect(m_jsonRpcClient, &JsonRpcClient::connectedChanged, this, [this]() {
|
||||||
qDebug() << "JSONRpc connected changed:" << m_jsonRpcClient->connected() << "AWS status:" << AWSClient::instance()->awsDevices()->rowCount();
|
qDebug() << "JSONRpc connected changed:" << m_jsonRpcClient->connected() << "AWS status:" << AWSClient::instance()->awsDevices()->rowCount();
|
||||||
@ -72,12 +72,7 @@ Engine::Engine(QObject *parent) :
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceManager *Engine::deviceManager() const
|
ThingManager *Engine::thingManager() const
|
||||||
{
|
|
||||||
return m_thingManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
DeviceManager *Engine::thingManager() const
|
|
||||||
{
|
{
|
||||||
return m_thingManager;
|
return m_thingManager;
|
||||||
}
|
}
|
||||||
@ -147,16 +142,13 @@ void Engine::onConnectedChanged()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Engine::onDeviceManagerFetchingChanged()
|
void Engine::onThingManagerFetchingChanged()
|
||||||
{
|
{
|
||||||
if (!m_thingManager->fetchingData()) {
|
if (!m_thingManager->fetchingData()) {
|
||||||
|
m_tagsManager->init();
|
||||||
m_ruleManager->init();
|
m_ruleManager->init();
|
||||||
m_scriptManager->init();
|
m_scriptManager->init();
|
||||||
m_nymeaConfiguration->init();
|
m_nymeaConfiguration->init();
|
||||||
m_systemController->init();
|
m_systemController->init();
|
||||||
|
|
||||||
if (m_jsonRpcClient->ensureServerVersion("1.7")) {
|
|
||||||
m_tagsManager->init();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -33,7 +33,7 @@
|
|||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
#include "devicemanager.h"
|
#include "thingmanager.h"
|
||||||
#include "connection/nymeatransportinterface.h"
|
#include "connection/nymeatransportinterface.h"
|
||||||
#include "jsonrpc/jsonrpcclient.h"
|
#include "jsonrpc/jsonrpcclient.h"
|
||||||
#include "wifisetup/bluetoothdiscovery.h"
|
#include "wifisetup/bluetoothdiscovery.h"
|
||||||
@ -49,8 +49,7 @@ class NetworkManager;
|
|||||||
class Engine : public QObject
|
class Engine : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(DeviceManager* deviceManager READ deviceManager CONSTANT)
|
Q_PROPERTY(ThingManager* thingManager READ thingManager CONSTANT)
|
||||||
Q_PROPERTY(DeviceManager* thingManager READ thingManager CONSTANT)
|
|
||||||
Q_PROPERTY(RuleManager* ruleManager READ ruleManager CONSTANT)
|
Q_PROPERTY(RuleManager* ruleManager READ ruleManager CONSTANT)
|
||||||
Q_PROPERTY(ScriptManager* scriptManager READ scriptManager CONSTANT)
|
Q_PROPERTY(ScriptManager* scriptManager READ scriptManager CONSTANT)
|
||||||
Q_PROPERTY(TagsManager* tagsManager READ tagsManager CONSTANT)
|
Q_PROPERTY(TagsManager* tagsManager READ tagsManager CONSTANT)
|
||||||
@ -61,8 +60,7 @@ class Engine : public QObject
|
|||||||
public:
|
public:
|
||||||
explicit Engine(QObject *parent = nullptr);
|
explicit Engine(QObject *parent = nullptr);
|
||||||
|
|
||||||
DeviceManager *deviceManager() const;
|
ThingManager *thingManager() const;
|
||||||
DeviceManager *thingManager() const;
|
|
||||||
RuleManager *ruleManager() const;
|
RuleManager *ruleManager() const;
|
||||||
ScriptManager *scriptManager() const;
|
ScriptManager *scriptManager() const;
|
||||||
TagsManager *tagsManager() const;
|
TagsManager *tagsManager() const;
|
||||||
@ -75,7 +73,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
JsonRpcClient *m_jsonRpcClient;
|
JsonRpcClient *m_jsonRpcClient;
|
||||||
DeviceManager *m_thingManager;
|
ThingManager *m_thingManager;
|
||||||
RuleManager *m_ruleManager;
|
RuleManager *m_ruleManager;
|
||||||
ScriptManager *m_scriptManager;
|
ScriptManager *m_scriptManager;
|
||||||
LogManager *m_logManager;
|
LogManager *m_logManager;
|
||||||
@ -85,7 +83,7 @@ private:
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onConnectedChanged();
|
void onConnectedChanged();
|
||||||
void onDeviceManagerFetchingChanged();
|
void onThingManagerFetchingChanged();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -31,7 +31,7 @@
|
|||||||
#include "interfacesmodel.h"
|
#include "interfacesmodel.h"
|
||||||
|
|
||||||
#include "engine.h"
|
#include "engine.h"
|
||||||
#include "devicesproxy.h"
|
#include "thingsproxy.h"
|
||||||
|
|
||||||
InterfacesModel::InterfacesModel(QObject *parent):
|
InterfacesModel::InterfacesModel(QObject *parent):
|
||||||
QAbstractListModel(parent)
|
QAbstractListModel(parent)
|
||||||
@ -77,7 +77,7 @@ void InterfacesModel::setEngine(Engine *engine)
|
|||||||
m_engine = engine;
|
m_engine = engine;
|
||||||
emit engineChanged();
|
emit engineChanged();
|
||||||
|
|
||||||
m_thingClassesCountChangedConnection = connect(engine->deviceManager()->deviceClasses(), &DeviceClasses::countChanged, this, [this]() {
|
m_thingClassesCountChangedConnection = connect(engine->thingManager()->thingClasses(), &ThingClasses::countChanged, this, [this]() {
|
||||||
syncInterfaces();
|
syncInterfaces();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -85,12 +85,12 @@ void InterfacesModel::setEngine(Engine *engine)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DevicesProxy *InterfacesModel::things() const
|
ThingsProxy *InterfacesModel::things() const
|
||||||
{
|
{
|
||||||
return m_thingsProxy;
|
return m_thingsProxy;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InterfacesModel::setThings(DevicesProxy *things)
|
void InterfacesModel::setThings(ThingsProxy *things)
|
||||||
{
|
{
|
||||||
if (m_thingsProxy != things) {
|
if (m_thingsProxy != things) {
|
||||||
if (m_thingsProxy) {
|
if (m_thingsProxy) {
|
||||||
@ -100,7 +100,7 @@ void InterfacesModel::setThings(DevicesProxy *things)
|
|||||||
m_thingsProxy = things;
|
m_thingsProxy = things;
|
||||||
emit thingsChanged();
|
emit thingsChanged();
|
||||||
|
|
||||||
m_thingsCountChangedConnection = connect(things, &DevicesProxy::countChanged, this, [this]() {
|
m_thingsCountChangedConnection = connect(things, &ThingsProxy::countChanged, this, [this]() {
|
||||||
syncInterfaces();
|
syncInterfaces();
|
||||||
});
|
});
|
||||||
syncInterfaces();
|
syncInterfaces();
|
||||||
@ -149,20 +149,20 @@ void InterfacesModel::syncInterfaces()
|
|||||||
if (!m_engine) {
|
if (!m_engine) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
QList<DeviceClass*> deviceClasses;
|
QList<ThingClass*> thingClasses;
|
||||||
if (m_thingsProxy) {
|
if (m_thingsProxy) {
|
||||||
for (int i = 0; i < m_thingsProxy->rowCount(); i++) {
|
for (int i = 0; i < m_thingsProxy->rowCount(); i++) {
|
||||||
deviceClasses << m_engine->deviceManager()->deviceClasses()->getDeviceClass(m_thingsProxy->get(i)->deviceClassId());
|
thingClasses << m_engine->thingManager()->thingClasses()->getThingClass(m_thingsProxy->get(i)->thingClassId());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (int i = 0; i < m_engine->deviceManager()->deviceClasses()->rowCount(); i++) {
|
for (int i = 0; i < m_engine->thingManager()->thingClasses()->rowCount(); i++) {
|
||||||
deviceClasses << m_engine->deviceManager()->deviceClasses()->get(i);
|
thingClasses << m_engine->thingManager()->thingClasses()->get(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList interfacesInSource;
|
QStringList interfacesInSource;
|
||||||
foreach (DeviceClass *dc, deviceClasses) {
|
foreach (ThingClass *dc, thingClasses) {
|
||||||
// qDebug() << "device" <<dc->name() << "has interfaces" << dc->interfaces();
|
// qDebug() << "thing" <<dc->name() << "has interfaces" << dc->interfaces();
|
||||||
|
|
||||||
bool isInShownIfaces = false;
|
bool isInShownIfaces = false;
|
||||||
foreach (const QString &interface, dc->interfaces()) {
|
foreach (const QString &interface, dc->interfaces()) {
|
||||||
@ -227,7 +227,7 @@ void InterfacesSortModel::setInterfacesModel(InterfacesModel *interfacesModel)
|
|||||||
m_interfacesModel = interfacesModel;
|
m_interfacesModel = interfacesModel;
|
||||||
setSourceModel(interfacesModel);
|
setSourceModel(interfacesModel);
|
||||||
connect(interfacesModel, &InterfacesModel::countChanged, this, &InterfacesSortModel::countChanged);
|
connect(interfacesModel, &InterfacesModel::countChanged, this, &InterfacesSortModel::countChanged);
|
||||||
setSortRole(Devices::RoleName);
|
setSortRole(Things::RoleName);
|
||||||
sort(0);
|
sort(0);
|
||||||
emit interfacesModelChanged();
|
emit interfacesModelChanged();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -34,10 +34,10 @@
|
|||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QAbstractListModel>
|
#include <QAbstractListModel>
|
||||||
|
|
||||||
#include "devices.h"
|
#include "things.h"
|
||||||
|
|
||||||
class Engine;
|
class Engine;
|
||||||
class DevicesProxy;
|
class ThingsProxy;
|
||||||
|
|
||||||
class InterfacesModel : public QAbstractListModel
|
class InterfacesModel : public QAbstractListModel
|
||||||
{
|
{
|
||||||
@ -48,7 +48,7 @@ class InterfacesModel : public QAbstractListModel
|
|||||||
Q_PROPERTY(Engine* engine READ engine WRITE setEngine NOTIFY engineChanged)
|
Q_PROPERTY(Engine* engine READ engine WRITE setEngine NOTIFY engineChanged)
|
||||||
|
|
||||||
// Optional filters
|
// Optional filters
|
||||||
Q_PROPERTY(DevicesProxy* things READ things WRITE setThings NOTIFY thingsChanged)
|
Q_PROPERTY(ThingsProxy* things READ things WRITE setThings NOTIFY thingsChanged)
|
||||||
Q_PROPERTY(QStringList shownInterfaces READ shownInterfaces WRITE setShownInterfaces NOTIFY shownInterfacesChanged)
|
Q_PROPERTY(QStringList shownInterfaces READ shownInterfaces WRITE setShownInterfaces NOTIFY shownInterfacesChanged)
|
||||||
Q_PROPERTY(bool showUncategorized READ showUncategorized WRITE setShowUncategorized NOTIFY showUncategorizedChanged)
|
Q_PROPERTY(bool showUncategorized READ showUncategorized WRITE setShowUncategorized NOTIFY showUncategorizedChanged)
|
||||||
|
|
||||||
@ -67,15 +67,12 @@ public:
|
|||||||
Engine* engine() const;
|
Engine* engine() const;
|
||||||
void setEngine(Engine *engine);
|
void setEngine(Engine *engine);
|
||||||
|
|
||||||
DevicesProxy* things() const;
|
ThingsProxy* things() const;
|
||||||
void setThings(DevicesProxy *things);
|
void setThings(ThingsProxy *things);
|
||||||
|
|
||||||
QStringList shownInterfaces() const;
|
QStringList shownInterfaces() const;
|
||||||
void setShownInterfaces(const QStringList &shownInterfaces);
|
void setShownInterfaces(const QStringList &shownInterfaces);
|
||||||
|
|
||||||
bool onlyConfiguredDevices() const;
|
|
||||||
void setOnlyConfiguredDevices(bool onlyConfigured);
|
|
||||||
|
|
||||||
bool showUncategorized() const;
|
bool showUncategorized() const;
|
||||||
void setShowUncategorized(bool showUncategorized);
|
void setShowUncategorized(bool showUncategorized);
|
||||||
|
|
||||||
@ -86,7 +83,6 @@ signals:
|
|||||||
void engineChanged();
|
void engineChanged();
|
||||||
void thingsChanged();
|
void thingsChanged();
|
||||||
void shownInterfacesChanged();
|
void shownInterfacesChanged();
|
||||||
bool onlyConfiguredDevicesChanged();
|
|
||||||
void showUncategorizedChanged();
|
void showUncategorizedChanged();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
@ -99,7 +95,7 @@ private:
|
|||||||
|
|
||||||
QStringList m_interfaces;
|
QStringList m_interfaces;
|
||||||
|
|
||||||
DevicesProxy *m_thingsProxy = nullptr;
|
ThingsProxy *m_thingsProxy = nullptr;
|
||||||
QMetaObject::Connection m_thingsCountChangedConnection;
|
QMetaObject::Connection m_thingsCountChangedConnection;
|
||||||
|
|
||||||
QStringList m_shownInterfaces;
|
QStringList m_shownInterfaces;
|
||||||
|
|||||||
@ -644,13 +644,19 @@ void JsonRpcClient::helloReply(int /*commandId*/, const QVariantMap ¶ms)
|
|||||||
|
|
||||||
qDebug() << "Handshake reply:" << "Protocol version:" << protoVersionString << "InitRequired:" << m_initialSetupRequired << "AuthRequired:" << m_authenticationRequired << "PushButtonAvailable:" << m_pushButtonAuthAvailable;;
|
qDebug() << "Handshake reply:" << "Protocol version:" << protoVersionString << "InitRequired:" << m_initialSetupRequired << "AuthRequired:" << m_authenticationRequired << "PushButtonAvailable:" << m_pushButtonAuthAvailable;;
|
||||||
|
|
||||||
QVersionNumber minimumRequiredVersion = QVersionNumber(1, 10);
|
QVersionNumber minimumRequiredVersion = QVersionNumber(5, 0);
|
||||||
|
QVersionNumber maximumMajorVersion = QVersionNumber(5);
|
||||||
if (m_jsonRpcVersion < minimumRequiredVersion) {
|
if (m_jsonRpcVersion < minimumRequiredVersion) {
|
||||||
qWarning() << "Nymea core doesn't support minimum required version. Required:" << minimumRequiredVersion << "Found:" << m_jsonRpcVersion;
|
qWarning() << "Nymea core doesn't support minimum required version. Required:" << minimumRequiredVersion << "Found:" << m_jsonRpcVersion;
|
||||||
m_connection->disconnect();
|
emit invalidMinimumVersion(m_jsonRpcVersion.toString(), minimumRequiredVersion.toString());
|
||||||
emit invalidProtocolVersion(m_jsonRpcVersion.toString(), minimumRequiredVersion.toString());
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (m_jsonRpcVersion.majorVersion() > maximumMajorVersion.majorVersion()) {
|
||||||
|
qWarning() << "Nymea core has breaking API changes not supported by this app version. Core major version:" << m_jsonRpcVersion.majorVersion() << "Maximum supported major version:" << maximumMajorVersion.majorVersion();
|
||||||
|
emit invalidMaximumVersion(m_jsonRpcVersion.toString(), QString("%1.x").arg(maximumMajorVersion.majorVersion()));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Verify SSL certificate
|
// Verify SSL certificate
|
||||||
if (m_connection->isEncrypted()) {
|
if (m_connection->isEncrypted()) {
|
||||||
|
|||||||
@ -129,7 +129,8 @@ signals:
|
|||||||
void pushButtonAuthAvailableChanged();
|
void pushButtonAuthAvailableChanged();
|
||||||
void authenticatedChanged();
|
void authenticatedChanged();
|
||||||
void tokenChanged();
|
void tokenChanged();
|
||||||
void invalidProtocolVersion(const QString &actualVersion, const QString &minimumVersion);
|
void invalidMinimumVersion(const QString &actualVersion, const QString &minVersion);
|
||||||
|
void invalidMaximumVersion(const QString &actualVersion, const QString &maxVersion);
|
||||||
void authenticationFailed();
|
void authenticationFailed();
|
||||||
void pushButtonAuthFailed();
|
void pushButtonAuthFailed();
|
||||||
void createUserSucceeded();
|
void createUserSucceeded();
|
||||||
|
|||||||
@ -1,477 +0,0 @@
|
|||||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
||||||
*
|
|
||||||
* Copyright 2013 - 2020, nymea GmbH
|
|
||||||
* Contact: contact@nymea.io
|
|
||||||
*
|
|
||||||
* This file is part of nymea.
|
|
||||||
* This project including source code and documentation is protected by
|
|
||||||
* copyright law, and remains the property of nymea GmbH. All rights, including
|
|
||||||
* reproduction, publication, editing and translation, are reserved. The use of
|
|
||||||
* this project is subject to the terms of a license agreement to be concluded
|
|
||||||
* with nymea GmbH in accordance with the terms of use of nymea GmbH, available
|
|
||||||
* under https://nymea.io/license
|
|
||||||
*
|
|
||||||
* GNU General Public License Usage
|
|
||||||
* Alternatively, this project may be redistributed and/or modified under the
|
|
||||||
* terms of the GNU General Public License as published by the Free Software
|
|
||||||
* Foundation, GNU version 3. This project is distributed in the hope that it
|
|
||||||
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
|
|
||||||
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
|
||||||
* Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along with
|
|
||||||
* this project. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
* For any further details and any questions please contact us under
|
|
||||||
* contact@nymea.io or see our FAQ/Licensing Information on
|
|
||||||
* https://nymea.io/license/faq
|
|
||||||
*
|
|
||||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
||||||
|
|
||||||
#include "jsontypes.h"
|
|
||||||
#include "engine.h"
|
|
||||||
#include "types/vendors.h"
|
|
||||||
#include "deviceclasses.h"
|
|
||||||
#include "types/params.h"
|
|
||||||
#include "types/paramtypes.h"
|
|
||||||
#include "types/rule.h"
|
|
||||||
#include "types/ruleaction.h"
|
|
||||||
#include "types/ruleactions.h"
|
|
||||||
#include "types/eventdescriptor.h"
|
|
||||||
#include "types/eventdescriptors.h"
|
|
||||||
#include "types/ruleactionparam.h"
|
|
||||||
#include "types/ruleactionparams.h"
|
|
||||||
#include "types/stateevaluator.h"
|
|
||||||
#include "types/stateevaluators.h"
|
|
||||||
#include "types/statedescriptor.h"
|
|
||||||
#include "types/timeeventitem.h"
|
|
||||||
#include "types/timeeventitems.h"
|
|
||||||
#include "types/timedescriptor.h"
|
|
||||||
#include "types/repeatingoption.h"
|
|
||||||
#include "types/calendaritems.h"
|
|
||||||
#include "types/calendaritem.h"
|
|
||||||
|
|
||||||
#include <QMetaEnum>
|
|
||||||
|
|
||||||
JsonTypes::JsonTypes(QObject *parent) :
|
|
||||||
QObject(parent)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
Vendor *JsonTypes::unpackVendor(const QVariantMap &vendorMap)
|
|
||||||
{
|
|
||||||
Vendor *v = new Vendor(vendorMap.value("id").toString(), vendorMap.value("name").toString());
|
|
||||||
v->setDisplayName(vendorMap.value("displayName").toString());
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
|
|
||||||
Plugin *JsonTypes::unpackPlugin(const QVariantMap &pluginMap, QObject *parent)
|
|
||||||
{
|
|
||||||
Plugin *plugin = new Plugin(parent);
|
|
||||||
plugin->setName(pluginMap.value("name").toString());
|
|
||||||
plugin->setPluginId(pluginMap.value("id").toUuid());
|
|
||||||
ParamTypes *paramTypes = new ParamTypes(plugin);
|
|
||||||
foreach (QVariant paramType, pluginMap.value("paramTypes").toList()) {
|
|
||||||
paramTypes->addParamType(JsonTypes::unpackParamType(paramType.toMap(), paramTypes));
|
|
||||||
}
|
|
||||||
plugin->setParamTypes(paramTypes);
|
|
||||||
return plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
DeviceClass *JsonTypes::unpackDeviceClass(const QVariantMap &deviceClassMap, QObject *parent)
|
|
||||||
{
|
|
||||||
DeviceClass *deviceClass = new DeviceClass(parent);
|
|
||||||
deviceClass->setName(deviceClassMap.value("name").toString());
|
|
||||||
deviceClass->setDisplayName(deviceClassMap.value("displayName").toString());
|
|
||||||
deviceClass->setId(deviceClassMap.value("id").toUuid());
|
|
||||||
deviceClass->setVendorId(deviceClassMap.value("vendorId").toUuid());
|
|
||||||
deviceClass->setBrowsable(deviceClassMap.value("browsable").toBool());
|
|
||||||
QVariantList createMethodsList = deviceClassMap.value("createMethods").toList();
|
|
||||||
QStringList createMethods;
|
|
||||||
foreach (QVariant method, createMethodsList) {
|
|
||||||
createMethods.append(method.toString());
|
|
||||||
}
|
|
||||||
deviceClass->setCreateMethods(createMethods);
|
|
||||||
deviceClass->setSetupMethod(stringToSetupMethod(deviceClassMap.value("setupMethod").toString()));
|
|
||||||
deviceClass->setInterfaces(deviceClassMap.value("interfaces").toStringList());
|
|
||||||
|
|
||||||
// ParamTypes
|
|
||||||
ParamTypes *paramTypes = new ParamTypes(deviceClass);
|
|
||||||
foreach (QVariant paramType, deviceClassMap.value("paramTypes").toList()) {
|
|
||||||
paramTypes->addParamType(JsonTypes::unpackParamType(paramType.toMap(), paramTypes));
|
|
||||||
}
|
|
||||||
deviceClass->setParamTypes(paramTypes);
|
|
||||||
|
|
||||||
// SettingsTypes
|
|
||||||
ParamTypes *settingsTypes = new ParamTypes(deviceClass);
|
|
||||||
foreach (QVariant settingsType, deviceClassMap.value("settingsTypes").toList()) {
|
|
||||||
settingsTypes->addParamType(JsonTypes::unpackParamType(settingsType.toMap(), settingsTypes));
|
|
||||||
}
|
|
||||||
deviceClass->setSettingsTypes(settingsTypes);
|
|
||||||
|
|
||||||
// discovery ParamTypes
|
|
||||||
ParamTypes *discoveryParamTypes = new ParamTypes(deviceClass);
|
|
||||||
foreach (QVariant paramType, deviceClassMap.value("discoveryParamTypes").toList()) {
|
|
||||||
discoveryParamTypes->addParamType(JsonTypes::unpackParamType(paramType.toMap(), discoveryParamTypes));
|
|
||||||
}
|
|
||||||
deviceClass->setDiscoveryParamTypes(discoveryParamTypes);
|
|
||||||
|
|
||||||
// StateTypes
|
|
||||||
StateTypes *stateTypes = new StateTypes(deviceClass);
|
|
||||||
foreach (QVariant stateType, deviceClassMap.value("stateTypes").toList()) {
|
|
||||||
stateTypes->addStateType(JsonTypes::unpackStateType(stateType.toMap(), stateTypes));
|
|
||||||
}
|
|
||||||
deviceClass->setStateTypes(stateTypes);
|
|
||||||
|
|
||||||
// EventTypes
|
|
||||||
EventTypes *eventTypes = new EventTypes(deviceClass);
|
|
||||||
foreach (QVariant eventType, deviceClassMap.value("eventTypes").toList()) {
|
|
||||||
eventTypes->addEventType(JsonTypes::unpackEventType(eventType.toMap(), eventTypes));
|
|
||||||
}
|
|
||||||
deviceClass->setEventTypes(eventTypes);
|
|
||||||
|
|
||||||
// ActionTypes
|
|
||||||
ActionTypes *actionTypes = new ActionTypes(deviceClass);
|
|
||||||
foreach (QVariant actionType, deviceClassMap.value("actionTypes").toList()) {
|
|
||||||
actionTypes->addActionType(JsonTypes::unpackActionType(actionType.toMap(), actionTypes));
|
|
||||||
}
|
|
||||||
deviceClass->setActionTypes(actionTypes);
|
|
||||||
|
|
||||||
// BrowserItemActionTypes
|
|
||||||
ActionTypes *browserItemActionTypes = new ActionTypes(deviceClass);
|
|
||||||
foreach (QVariant actionType, deviceClassMap.value("browserItemActionTypes").toList()) {
|
|
||||||
browserItemActionTypes->addActionType(JsonTypes::unpackActionType(actionType.toMap(), actionTypes));
|
|
||||||
}
|
|
||||||
deviceClass->setBrowserItemActionTypes(browserItemActionTypes);
|
|
||||||
|
|
||||||
return deviceClass;
|
|
||||||
}
|
|
||||||
|
|
||||||
void JsonTypes::unpackParam(const QVariantMap ¶mMap, Param *param)
|
|
||||||
{
|
|
||||||
param->setParamTypeId(paramMap.value("paramTypeId").toString());
|
|
||||||
param->setValue(paramMap.value("value"));
|
|
||||||
}
|
|
||||||
|
|
||||||
ParamType *JsonTypes::unpackParamType(const QVariantMap ¶mTypeMap, QObject *parent)
|
|
||||||
{
|
|
||||||
ParamType *paramType = new ParamType(parent);
|
|
||||||
paramType->setId(paramTypeMap.value("id").toString());
|
|
||||||
paramType->setName(paramTypeMap.value("name").toString());
|
|
||||||
paramType->setDisplayName(paramTypeMap.value("displayName").toString());
|
|
||||||
paramType->setType(paramTypeMap.value("type").toString());
|
|
||||||
paramType->setIndex(paramTypeMap.value("index").toInt());
|
|
||||||
paramType->setDefaultValue(paramTypeMap.value("defaultValue"));
|
|
||||||
paramType->setMinValue(paramTypeMap.value("minValue"));
|
|
||||||
paramType->setMaxValue(paramTypeMap.value("maxValue"));
|
|
||||||
paramType->setAllowedValues(paramTypeMap.value("allowedValues").toList());
|
|
||||||
paramType->setInputType(stringToInputType(paramTypeMap.value("inputType").toString()));
|
|
||||||
paramType->setReadOnly(paramTypeMap.value("readOnly").toBool());
|
|
||||||
QPair<Types::Unit, QString> unit = stringToUnit(paramTypeMap.value("unit").toString());
|
|
||||||
paramType->setUnit(unit.first);
|
|
||||||
paramType->setUnitString(unit.second);
|
|
||||||
return paramType;
|
|
||||||
}
|
|
||||||
|
|
||||||
StateType *JsonTypes::unpackStateType(const QVariantMap &stateTypeMap, QObject *parent)
|
|
||||||
{
|
|
||||||
StateType *stateType = new StateType(parent);
|
|
||||||
stateType->setId(stateTypeMap.value("id").toString());
|
|
||||||
stateType->setName(stateTypeMap.value("name").toString());
|
|
||||||
stateType->setDisplayName(stateTypeMap.value("displayName").toString());
|
|
||||||
stateType->setIndex(stateTypeMap.value("index").toInt());
|
|
||||||
stateType->setDefaultValue(stateTypeMap.value("defaultValue"));
|
|
||||||
stateType->setAllowedValues(stateTypeMap.value("possibleValues").toList());
|
|
||||||
stateType->setType(stateTypeMap.value("type").toString());
|
|
||||||
stateType->setMinValue(stateTypeMap.value("minValue"));
|
|
||||||
stateType->setMaxValue(stateTypeMap.value("maxValue"));
|
|
||||||
|
|
||||||
QPair<Types::Unit, QString> unit = stringToUnit(stateTypeMap.value("unit").toString());
|
|
||||||
stateType->setUnit(unit.first);
|
|
||||||
stateType->setUnitString(unit.second);
|
|
||||||
|
|
||||||
QMetaEnum metaEnum = QMetaEnum::fromType<Types::IOType>();
|
|
||||||
Types::IOType ioType = static_cast<Types::IOType>(metaEnum.keyToValue(stateTypeMap.value("ioType").toByteArray()));
|
|
||||||
stateType->setIOType(ioType);
|
|
||||||
|
|
||||||
return stateType;
|
|
||||||
}
|
|
||||||
|
|
||||||
EventType *JsonTypes::unpackEventType(const QVariantMap &eventTypeMap, QObject *parent)
|
|
||||||
{
|
|
||||||
EventType *eventType = new EventType(parent);
|
|
||||||
eventType->setId(eventTypeMap.value("id").toString());
|
|
||||||
eventType->setName(eventTypeMap.value("name").toString());
|
|
||||||
eventType->setDisplayName(eventTypeMap.value("displayName").toString());
|
|
||||||
eventType->setIndex(eventTypeMap.value("index").toInt());
|
|
||||||
ParamTypes *paramTypes = new ParamTypes(eventType);
|
|
||||||
foreach (QVariant paramType, eventTypeMap.value("paramTypes").toList()) {
|
|
||||||
paramTypes->addParamType(JsonTypes::unpackParamType(paramType.toMap(), paramTypes));
|
|
||||||
}
|
|
||||||
eventType->setParamTypes(paramTypes);
|
|
||||||
return eventType;
|
|
||||||
}
|
|
||||||
|
|
||||||
ActionType *JsonTypes::unpackActionType(const QVariantMap &actionTypeMap, QObject *parent)
|
|
||||||
{
|
|
||||||
ActionType *actionType = new ActionType(parent);
|
|
||||||
actionType->setId(actionTypeMap.value("id").toString());
|
|
||||||
actionType->setName(actionTypeMap.value("name").toString());
|
|
||||||
actionType->setDisplayName(actionTypeMap.value("displayName").toString());
|
|
||||||
actionType->setIndex(actionTypeMap.value("index").toInt());
|
|
||||||
ParamTypes *paramTypes = new ParamTypes(actionType);
|
|
||||||
foreach (QVariant paramType, actionTypeMap.value("paramTypes").toList()) {
|
|
||||||
paramTypes->addParamType(JsonTypes::unpackParamType(paramType.toMap(), paramTypes));
|
|
||||||
}
|
|
||||||
actionType->setParamTypes(paramTypes);
|
|
||||||
return actionType;
|
|
||||||
}
|
|
||||||
|
|
||||||
Device* JsonTypes::unpackDevice(DeviceManager *deviceManager, const QVariantMap &deviceMap, DeviceClasses *deviceClasses, Device *oldDevice)
|
|
||||||
{
|
|
||||||
QUuid deviceClassId = deviceMap.value("deviceClassId").toUuid();
|
|
||||||
DeviceClass *deviceClass = deviceClasses->getDeviceClass(deviceClassId);
|
|
||||||
if (!deviceClass) {
|
|
||||||
qWarning() << "Cannot find a device class for this device";
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
QUuid parentDeviceId = deviceMap.value("parentId").toUuid();
|
|
||||||
Device *device = nullptr;
|
|
||||||
if (oldDevice) {
|
|
||||||
device = oldDevice;
|
|
||||||
} else {
|
|
||||||
device = new Device(deviceManager, deviceClass, parentDeviceId);
|
|
||||||
}
|
|
||||||
device->setName(deviceMap.value("name").toString());
|
|
||||||
device->setId(deviceMap.value("id").toUuid());
|
|
||||||
// As of JSONRPC 4.2 setupComplete is deprecated and setupStatus is new
|
|
||||||
if (deviceMap.contains("setupStatus")) {
|
|
||||||
QString setupStatus = deviceMap.value("setupStatus").toString();
|
|
||||||
QString setupDisplayMessage = deviceMap.value("setupDisplayMessage").toString();
|
|
||||||
if (setupStatus == "DeviceSetupStatusNone" || setupStatus == "ThingSetupStatusNone") {
|
|
||||||
device->setSetupStatus(Device::ThingSetupStatusNone, setupDisplayMessage);
|
|
||||||
} else if (setupStatus == "DeviceSetupStatusInProgress" || setupStatus == "ThingSetupStatusInProgress") {
|
|
||||||
device->setSetupStatus(Device::ThingSetupStatusInProgress, setupDisplayMessage);
|
|
||||||
} else if (setupStatus == "DeviceSetupStatusComplete" || setupStatus == "ThingSetupStatusComplete") {
|
|
||||||
device->setSetupStatus(Device::ThingSetupStatusComplete, setupDisplayMessage);
|
|
||||||
} else if (setupStatus == "DeviceSetupStatusFailed" || setupStatus == "ThingSetupStatusFailed") {
|
|
||||||
device->setSetupStatus(Device::ThingSetupStatusFailed, setupDisplayMessage);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
device->setSetupStatus(deviceMap.value("setupComplete").toBool() ? Device::ThingSetupStatusComplete : Device::ThingSetupStatusNone, QString());
|
|
||||||
}
|
|
||||||
|
|
||||||
Params *params = device->params();
|
|
||||||
if (!params) {
|
|
||||||
params = new Params(device);
|
|
||||||
}
|
|
||||||
foreach (QVariant param, deviceMap.value("params").toList()) {
|
|
||||||
Param *p = params->getParam(param.toMap().value("paramTypeId").toString());
|
|
||||||
if (!p) {
|
|
||||||
p = new Param();
|
|
||||||
params->addParam(p);
|
|
||||||
}
|
|
||||||
JsonTypes::unpackParam(param.toMap(), p);
|
|
||||||
}
|
|
||||||
device->setParams(params);
|
|
||||||
|
|
||||||
Params *settings = device->settings();
|
|
||||||
if (!settings) {
|
|
||||||
settings = new Params(device);
|
|
||||||
}
|
|
||||||
foreach (QVariant setting, deviceMap.value("settings").toList()) {
|
|
||||||
Param *p = settings->getParam(setting.toMap().value("paramTypeId").toString());
|
|
||||||
if (!p) {
|
|
||||||
p = new Param();
|
|
||||||
settings->addParam(p);
|
|
||||||
}
|
|
||||||
JsonTypes::unpackParam(setting.toMap(), p);
|
|
||||||
}
|
|
||||||
device->setSettings(settings);
|
|
||||||
|
|
||||||
States *states = device->states();
|
|
||||||
if (!states) {
|
|
||||||
states = new States(device);
|
|
||||||
}
|
|
||||||
foreach (const QVariant &stateVariant, deviceMap.value("states").toList()) {
|
|
||||||
State *state = states->getState(stateVariant.toMap().value("stateTypeId").toUuid());
|
|
||||||
if (!state) {
|
|
||||||
state = new State(device->id(), stateVariant.toMap().value("stateTypeId").toUuid(), stateVariant.toMap().value("value"), states);
|
|
||||||
states->addState(state);
|
|
||||||
} else {
|
|
||||||
state->setValue(stateVariant.toMap().value("value"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
device->setStates(states);
|
|
||||||
|
|
||||||
return device;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
QVariantMap JsonTypes::packParam(Param *param)
|
|
||||||
{
|
|
||||||
QVariantMap ret;
|
|
||||||
ret.insert("paramTypeId", param->paramTypeId());
|
|
||||||
ret.insert("value", param->value());
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
DeviceClass::SetupMethod JsonTypes::stringToSetupMethod(const QString &setupMethodString)
|
|
||||||
{
|
|
||||||
if (setupMethodString == "SetupMethodJustAdd") {
|
|
||||||
return DeviceClass::SetupMethodJustAdd;
|
|
||||||
} else if (setupMethodString == "SetupMethodDisplayPin") {
|
|
||||||
return DeviceClass::SetupMethodDisplayPin;
|
|
||||||
} else if (setupMethodString == "SetupMethodEnterPin") {
|
|
||||||
return DeviceClass::SetupMethodEnterPin;
|
|
||||||
} else if (setupMethodString == "SetupMethodPushButton") {
|
|
||||||
return DeviceClass::SetupMethodPushButton;
|
|
||||||
} else if (setupMethodString == "SetupMethodOAuth") {
|
|
||||||
return DeviceClass::SetupMethodOAuth;
|
|
||||||
} else if (setupMethodString == "SetupMethodUserAndPassword") {
|
|
||||||
return DeviceClass::SetupMethodUserAndPassword;
|
|
||||||
}
|
|
||||||
return DeviceClass::SetupMethodJustAdd;
|
|
||||||
}
|
|
||||||
|
|
||||||
QPair<Types::Unit, QString> JsonTypes::stringToUnit(const QString &unitString)
|
|
||||||
{
|
|
||||||
if (unitString == "UnitNone") {
|
|
||||||
return QPair<Types::Unit, QString>(Types::UnitNone, "");
|
|
||||||
} else if (unitString == "UnitSeconds") {
|
|
||||||
return QPair<Types::Unit, QString>(Types::UnitSeconds, "s");
|
|
||||||
} else if (unitString == "UnitMinutes") {
|
|
||||||
return QPair<Types::Unit, QString>(Types::UnitMinutes, "m");
|
|
||||||
} else if (unitString == "UnitHours") {
|
|
||||||
return QPair<Types::Unit, QString>(Types::UnitHours, "h");
|
|
||||||
} else if (unitString == "UnitUnixTime") {
|
|
||||||
return QPair<Types::Unit, QString>(Types::UnitUnixTime, "datetime");
|
|
||||||
} else if (unitString == "UnitMeterPerSecond") {
|
|
||||||
return QPair<Types::Unit, QString>(Types::UnitMeterPerSecond, "m/s");
|
|
||||||
} else if (unitString == "UnitKiloMeterPerHour") {
|
|
||||||
return QPair<Types::Unit, QString>(Types::UnitKiloMeterPerHour, "km/h");
|
|
||||||
} else if (unitString == "UnitDegree") {
|
|
||||||
return QPair<Types::Unit, QString>(Types::UnitDegree, "°");
|
|
||||||
} else if (unitString == "UnitRadiant") {
|
|
||||||
return QPair<Types::Unit, QString>(Types::UnitRadiant, "rad");
|
|
||||||
} else if (unitString == "UnitDegreeCelsius") {
|
|
||||||
return QPair<Types::Unit, QString>(Types::UnitDegreeCelsius, "°C");
|
|
||||||
} else if (unitString == "UnitDegreeKelvin") {
|
|
||||||
return QPair<Types::Unit, QString>(Types::UnitDegreeKelvin, "°K");
|
|
||||||
} else if (unitString == "UnitMired") {
|
|
||||||
return QPair<Types::Unit, QString>(Types::UnitMired, "mir");
|
|
||||||
} else if (unitString == "UnitMilliBar") {
|
|
||||||
return QPair<Types::Unit, QString>(Types::UnitMilliBar, "mbar");
|
|
||||||
} else if (unitString == "UnitBar") {
|
|
||||||
return QPair<Types::Unit, QString>(Types::UnitBar, "bar");
|
|
||||||
} else if (unitString == "UnitPascal") {
|
|
||||||
return QPair<Types::Unit, QString>(Types::UnitPascal, "Pa");
|
|
||||||
} else if (unitString == "UnitHectoPascal") {
|
|
||||||
return QPair<Types::Unit, QString>(Types::UnitHectoPascal, "hPa");
|
|
||||||
} else if (unitString == "UnitAtmosphere") {
|
|
||||||
return QPair<Types::Unit, QString>(Types::UnitAtmosphere, "atm");
|
|
||||||
} else if (unitString == "UnitLumen") {
|
|
||||||
return QPair<Types::Unit, QString>(Types::UnitLumen, "lm");
|
|
||||||
} else if (unitString == "UnitLux") {
|
|
||||||
return QPair<Types::Unit, QString>(Types::UnitLux, "lx");
|
|
||||||
} else if (unitString == "UnitCandela") {
|
|
||||||
return QPair<Types::Unit, QString>(Types::UnitCandela, "cd");
|
|
||||||
} else if (unitString == "UnitMilliMeter") {
|
|
||||||
return QPair<Types::Unit, QString>(Types::UnitMilliMeter, "mm");
|
|
||||||
} else if (unitString == "UnitCentiMeter") {
|
|
||||||
return QPair<Types::Unit, QString>(Types::UnitCentiMeter, "cm");
|
|
||||||
} else if (unitString == "UnitMeter") {
|
|
||||||
return QPair<Types::Unit, QString>(Types::UnitMeter, "m");
|
|
||||||
} else if (unitString == "UnitKiloMeter") {
|
|
||||||
return QPair<Types::Unit, QString>(Types::UnitKiloMeter, "km");
|
|
||||||
} else if (unitString == "UnitGram") {
|
|
||||||
return QPair<Types::Unit, QString>(Types::UnitGram, "g");
|
|
||||||
} else if (unitString == "UnitKiloGram") {
|
|
||||||
return QPair<Types::Unit, QString>(Types::UnitKiloGram, "kg");
|
|
||||||
} else if (unitString == "UnitDezibel") {
|
|
||||||
return QPair<Types::Unit, QString>(Types::UnitDezibel, "db");
|
|
||||||
} else if (unitString == "UnitBpm") {
|
|
||||||
return QPair<Types::Unit, QString>(Types::UnitBpm, "bpm");
|
|
||||||
} else if (unitString == "UnitKiloByte") {
|
|
||||||
return QPair<Types::Unit, QString>(Types::UnitKiloByte, "kB");
|
|
||||||
} else if (unitString == "UnitMegaByte") {
|
|
||||||
return QPair<Types::Unit, QString>(Types::UnitMegaByte, "MB");
|
|
||||||
} else if (unitString == "UnitGigaByte") {
|
|
||||||
return QPair<Types::Unit, QString>(Types::UnitGigaByte, "GB");
|
|
||||||
} else if (unitString == "UnitTeraByte") {
|
|
||||||
return QPair<Types::Unit, QString>(Types::UnitTeraByte, "TB");
|
|
||||||
} else if (unitString == "UnitMilliWatt") {
|
|
||||||
return QPair<Types::Unit, QString>(Types::UnitMilliWatt, "mW");
|
|
||||||
} else if (unitString == "UnitWatt") {
|
|
||||||
return QPair<Types::Unit, QString>(Types::UnitWatt, "W");
|
|
||||||
} else if (unitString == "UnitKiloWatt") {
|
|
||||||
return QPair<Types::Unit, QString>(Types::UnitKiloWatt, "kW");
|
|
||||||
} else if (unitString == "UnitKiloWattHour") {
|
|
||||||
return QPair<Types::Unit, QString>(Types::UnitKiloWattHour, "kWh");
|
|
||||||
} else if (unitString == "UnitEuroPerMegaWattHour") {
|
|
||||||
return QPair<Types::Unit, QString>(Types::UnitEuroPerMegaWattHour, "€/MWh");
|
|
||||||
} else if (unitString == "UnitEuroCentPerKiloWattHour") {
|
|
||||||
return QPair<Types::Unit, QString>(Types::UnitEuroCentPerKiloWattHour, "ct/kWh");
|
|
||||||
} else if (unitString == "UnitPercentage") {
|
|
||||||
return QPair<Types::Unit, QString>(Types::UnitPercentage, "%");
|
|
||||||
} else if (unitString == "UnitPartsPerMillion") {
|
|
||||||
return QPair<Types::Unit, QString>(Types::UnitPartsPerMillion, "ppm");
|
|
||||||
} else if (unitString == "UnitEuro") {
|
|
||||||
return QPair<Types::Unit, QString>(Types::UnitEuro, "€");
|
|
||||||
} else if (unitString == "UnitDollar") {
|
|
||||||
return QPair<Types::Unit, QString>(Types::UnitDollar, "$");
|
|
||||||
} else if (unitString == "UnitHerz") { // legacy
|
|
||||||
return QPair<Types::Unit, QString>(Types::UnitHertz, "Hz");
|
|
||||||
} else if (unitString == "UnitHertz") {
|
|
||||||
return QPair<Types::Unit, QString>(Types::UnitHertz, "Hz");
|
|
||||||
} else if (unitString == "UnitAmpere") {
|
|
||||||
return QPair<Types::Unit, QString>(Types::UnitAmpere, "A");
|
|
||||||
} else if (unitString == "UnitMilliAmpere") {
|
|
||||||
return QPair<Types::Unit, QString>(Types::UnitMilliAmpere, "mA");
|
|
||||||
} else if (unitString == "UnitVolt") {
|
|
||||||
return QPair<Types::Unit, QString>(Types::UnitVolt, "V");
|
|
||||||
} else if (unitString == "UnitMilliVolt") {
|
|
||||||
return QPair<Types::Unit, QString>(Types::UnitMilliVolt, "mV");
|
|
||||||
} else if (unitString == "UnitVoltAmpere") {
|
|
||||||
return QPair<Types::Unit, QString>(Types::UnitVoltAmpere, "VA");
|
|
||||||
} else if (unitString == "UnitVoltAmpereReactive") {
|
|
||||||
return QPair<Types::Unit, QString>(Types::UnitVoltAmpereReactive, "VAR");
|
|
||||||
} else if (unitString == "UnitAmpereHour") {
|
|
||||||
return QPair<Types::Unit, QString>(Types::UnitAmpereHour, "Ah");
|
|
||||||
} else if (unitString == "UnitMicroSiemensPerCentimeter") {
|
|
||||||
return QPair<Types::Unit, QString>(Types::UnitMicroSiemensPerCentimeter, "µS/cm");
|
|
||||||
} else if (unitString == "UnitDuration") {
|
|
||||||
return QPair<Types::Unit, QString>(Types::UnitDuration, "s");
|
|
||||||
}
|
|
||||||
|
|
||||||
return QPair<Types::Unit, QString>(Types::UnitNone, "");
|
|
||||||
}
|
|
||||||
|
|
||||||
Types::InputType JsonTypes::stringToInputType(const QString &inputTypeString)
|
|
||||||
{
|
|
||||||
if (inputTypeString == "InputTypeNone") {
|
|
||||||
return Types::InputTypeNone;
|
|
||||||
} else if (inputTypeString == "InputTypeTextLine") {
|
|
||||||
return Types::InputTypeTextLine;
|
|
||||||
} else if (inputTypeString == "InputTypeTextArea") {
|
|
||||||
return Types::InputTypeTextArea;
|
|
||||||
} else if (inputTypeString == "InputTypePassword") {
|
|
||||||
return Types::InputTypePassword;
|
|
||||||
} else if (inputTypeString == "InputTypeSearch") {
|
|
||||||
return Types::InputTypeSearch;
|
|
||||||
} else if (inputTypeString == "InputTypeMail") {
|
|
||||||
return Types::InputTypeMail;
|
|
||||||
} else if (inputTypeString == "InputTypeIPv4Address") {
|
|
||||||
return Types::InputTypeIPv4Address;
|
|
||||||
} else if (inputTypeString == "InputTypeIPv6Address") {
|
|
||||||
return Types::InputTypeIPv6Address;
|
|
||||||
} else if (inputTypeString == "InputTypeUrl") {
|
|
||||||
return Types::InputTypeUrl;
|
|
||||||
} else if (inputTypeString == "InputTypeMacAddress") {
|
|
||||||
return Types::InputTypeMacAddress;
|
|
||||||
}
|
|
||||||
return Types::InputTypeNone;
|
|
||||||
}
|
|
||||||
@ -1,80 +0,0 @@
|
|||||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
||||||
*
|
|
||||||
* Copyright 2013 - 2020, nymea GmbH
|
|
||||||
* Contact: contact@nymea.io
|
|
||||||
*
|
|
||||||
* This file is part of nymea.
|
|
||||||
* This project including source code and documentation is protected by
|
|
||||||
* copyright law, and remains the property of nymea GmbH. All rights, including
|
|
||||||
* reproduction, publication, editing and translation, are reserved. The use of
|
|
||||||
* this project is subject to the terms of a license agreement to be concluded
|
|
||||||
* with nymea GmbH in accordance with the terms of use of nymea GmbH, available
|
|
||||||
* under https://nymea.io/license
|
|
||||||
*
|
|
||||||
* GNU General Public License Usage
|
|
||||||
* Alternatively, this project may be redistributed and/or modified under the
|
|
||||||
* terms of the GNU General Public License as published by the Free Software
|
|
||||||
* Foundation, GNU version 3. This project is distributed in the hope that it
|
|
||||||
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
|
|
||||||
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
|
||||||
* Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along with
|
|
||||||
* this project. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
* For any further details and any questions please contact us under
|
|
||||||
* contact@nymea.io or see our FAQ/Licensing Information on
|
|
||||||
* https://nymea.io/license/faq
|
|
||||||
*
|
|
||||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
||||||
|
|
||||||
#ifndef JSONTYPES_H
|
|
||||||
#define JSONTYPES_H
|
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
#include <QJsonDocument>
|
|
||||||
#include <QVariant>
|
|
||||||
#include <QUuid>
|
|
||||||
|
|
||||||
#include "types/types.h"
|
|
||||||
#include "types/deviceclass.h"
|
|
||||||
|
|
||||||
class Plugin;
|
|
||||||
class Vendor;
|
|
||||||
|
|
||||||
class StateType;
|
|
||||||
class EventType;
|
|
||||||
class ActionType;
|
|
||||||
class ParamType;
|
|
||||||
|
|
||||||
class DeviceManager;
|
|
||||||
class Device;
|
|
||||||
class DeviceClasses;
|
|
||||||
class Param;
|
|
||||||
|
|
||||||
class JsonTypes : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
explicit JsonTypes(QObject *parent = nullptr);
|
|
||||||
|
|
||||||
static Vendor *unpackVendor(const QVariantMap &vendorMap);
|
|
||||||
static Plugin *unpackPlugin(const QVariantMap &pluginMap, QObject *parent);
|
|
||||||
static DeviceClass *unpackDeviceClass(const QVariantMap &deviceClassMap, QObject *parent);
|
|
||||||
static void unpackParam(const QVariantMap ¶mMap, Param *param);
|
|
||||||
static ParamType *unpackParamType(const QVariantMap ¶mTypeMap, QObject *parent);
|
|
||||||
static StateType *unpackStateType(const QVariantMap &stateTypeMap, QObject *parent);
|
|
||||||
static EventType *unpackEventType(const QVariantMap &eventTypeMap, QObject *parent);
|
|
||||||
static ActionType *unpackActionType(const QVariantMap &actionTypeMap, QObject *parent);
|
|
||||||
static Device *unpackDevice(DeviceManager *deviceManager, const QVariantMap &deviceMap, DeviceClasses *deviceClasses, Device *oldDevice = nullptr);
|
|
||||||
|
|
||||||
static QVariantMap packParam(Param *param);
|
|
||||||
|
|
||||||
private:
|
|
||||||
static DeviceClass::SetupMethod stringToSetupMethod(const QString &setupMethodString);
|
|
||||||
static QPair<Types::Unit, QString> stringToUnit(const QString &unitString);
|
|
||||||
static Types::InputType stringToInputType(const QString &inputTypeString);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // JSONTYPES_H
|
|
||||||
@ -36,8 +36,8 @@
|
|||||||
#include "connection/nymeahost.h"
|
#include "connection/nymeahost.h"
|
||||||
#include "connection/discovery/nymeadiscovery.h"
|
#include "connection/discovery/nymeadiscovery.h"
|
||||||
#include "vendorsproxy.h"
|
#include "vendorsproxy.h"
|
||||||
#include "deviceclassesproxy.h"
|
#include "thingclassesproxy.h"
|
||||||
#include "devicesproxy.h"
|
#include "thingsproxy.h"
|
||||||
#include "pluginsproxy.h"
|
#include "pluginsproxy.h"
|
||||||
#include "thingdiscovery.h"
|
#include "thingdiscovery.h"
|
||||||
#include "interfacesmodel.h"
|
#include "interfacesmodel.h"
|
||||||
@ -92,7 +92,7 @@
|
|||||||
#include "ruletemplates/ruleactiontemplate.h"
|
#include "ruletemplates/ruleactiontemplate.h"
|
||||||
#include "ruletemplates/ruleactionparamtemplate.h"
|
#include "ruletemplates/ruleactionparamtemplate.h"
|
||||||
#include "connection/awsclient.h"
|
#include "connection/awsclient.h"
|
||||||
#include "models/devicemodel.h"
|
#include "models/thingmodel.h"
|
||||||
#include "models/sortfilterproxymodel.h"
|
#include "models/sortfilterproxymodel.h"
|
||||||
#include "system/systemcontroller.h"
|
#include "system/systemcontroller.h"
|
||||||
#include "types/package.h"
|
#include "types/package.h"
|
||||||
@ -158,8 +158,7 @@ void registerQmlTypes() {
|
|||||||
|
|
||||||
qmlRegisterType<Engine>(uri, 1, 0, "Engine");
|
qmlRegisterType<Engine>(uri, 1, 0, "Engine");
|
||||||
|
|
||||||
qmlRegisterUncreatableType<DeviceManager>(uri, 1, 0, "ThingManager", "Can't create this in QML. Get it from the Engine.");
|
qmlRegisterUncreatableType<ThingManager>(uri, 1, 0, "ThingManager", "Can't create this in QML. Get it from the Engine.");
|
||||||
qmlRegisterUncreatableType<DeviceManager>(uri, 1, 0, "DeviceManager", "Can't create this in QML. Get it from the Engine.");
|
|
||||||
qmlRegisterUncreatableType<JsonRpcClient>(uri, 1, 0, "JsonRpcClient", "Can't create this in QML. Get it from the Engine.");
|
qmlRegisterUncreatableType<JsonRpcClient>(uri, 1, 0, "JsonRpcClient", "Can't create this in QML. Get it from the Engine.");
|
||||||
qmlRegisterUncreatableType<NymeaConnection>(uri, 1, 0, "NymeaConnection", "Can't create this in QML. Get it from the Engine.");
|
qmlRegisterUncreatableType<NymeaConnection>(uri, 1, 0, "NymeaConnection", "Can't create this in QML. Get it from the Engine.");
|
||||||
|
|
||||||
@ -167,45 +166,39 @@ void registerQmlTypes() {
|
|||||||
qmlRegisterSingletonType<Types>(uri, 1, 0, "Types", typesProvider);
|
qmlRegisterSingletonType<Types>(uri, 1, 0, "Types", typesProvider);
|
||||||
|
|
||||||
qmlRegisterUncreatableType<ParamType>(uri, 1, 0, "ParamType", "Can't create this in QML. Get it from the ParamTypes.");
|
qmlRegisterUncreatableType<ParamType>(uri, 1, 0, "ParamType", "Can't create this in QML. Get it from the ParamTypes.");
|
||||||
qmlRegisterUncreatableType<ParamTypes>(uri, 1, 0, "ParamTypes", "Can't create this in QML. Get it from the DeviceClass.");
|
qmlRegisterUncreatableType<ParamTypes>(uri, 1, 0, "ParamTypes", "Can't create this in QML. Get it from the ThingClass.");
|
||||||
qmlRegisterUncreatableType<EventType>(uri, 1, 0, "EventType", "Can't create this in QML. Get it from the EventTypes.");
|
qmlRegisterUncreatableType<EventType>(uri, 1, 0, "EventType", "Can't create this in QML. Get it from the EventTypes.");
|
||||||
qmlRegisterUncreatableType<EventTypes>(uri, 1, 0, "EventTypes", "Can't create this in QML. Get it from the DeviceClass.");
|
qmlRegisterUncreatableType<EventTypes>(uri, 1, 0, "EventTypes", "Can't create this in QML. Get it from the ThingClass.");
|
||||||
qmlRegisterUncreatableType<StateType>(uri, 1, 0, "StateType", "Can't create this in QML. Get it from the StateTypes.");
|
qmlRegisterUncreatableType<StateType>(uri, 1, 0, "StateType", "Can't create this in QML. Get it from the StateTypes.");
|
||||||
qmlRegisterUncreatableType<StateTypes>(uri, 1, 0, "StateTypes", "Can't create this in QML. Get it from the DeviceClass.");
|
qmlRegisterUncreatableType<StateTypes>(uri, 1, 0, "StateTypes", "Can't create this in QML. Get it from the ThingClass.");
|
||||||
qmlRegisterUncreatableType<ActionType>(uri, 1, 0, "ActionType", "Can't create this in QML. Get it from the ActionTypes.");
|
qmlRegisterUncreatableType<ActionType>(uri, 1, 0, "ActionType", "Can't create this in QML. Get it from the ActionTypes.");
|
||||||
qmlRegisterUncreatableType<ActionTypes>(uri, 1, 0, "ActionTypes", "Can't create this in QML. Get it from the DeviceClass.");
|
qmlRegisterUncreatableType<ActionTypes>(uri, 1, 0, "ActionTypes", "Can't create this in QML. Get it from the ThingClass.");
|
||||||
qmlRegisterType<StateTypesProxy>(uri, 1, 0, "StateTypesProxy");
|
qmlRegisterType<StateTypesProxy>(uri, 1, 0, "StateTypesProxy");
|
||||||
|
|
||||||
qmlRegisterUncreatableType<State>(uri, 1, 0, "State", "Can't create this in QML. Get it from the States.");
|
qmlRegisterUncreatableType<State>(uri, 1, 0, "State", "Can't create this in QML. Get it from the States.");
|
||||||
qmlRegisterUncreatableType<States>(uri, 1, 0, "States", "Can't create this in QML. Get it from the Device.");
|
qmlRegisterUncreatableType<States>(uri, 1, 0, "States", "Can't create this in QML. Get it from the Thing.");
|
||||||
|
|
||||||
qmlRegisterUncreatableType<BrowserItems>(uri, 1, 0, "BrowserItems", "Can't create this in QML. Get it from DeviceManager.");
|
qmlRegisterUncreatableType<BrowserItems>(uri, 1, 0, "BrowserItems", "Can't create this in QML. Get it from ThingManager.");
|
||||||
qmlRegisterUncreatableType<BrowserItem>(uri, 1, 0, "BrowserItem", "Can't create this in QML. Get it from BroweserItems.");
|
qmlRegisterUncreatableType<BrowserItem>(uri, 1, 0, "BrowserItem", "Can't create this in QML. Get it from BrowserItems.");
|
||||||
|
|
||||||
qmlRegisterUncreatableType<Vendor>(uri, 1, 0, "Vendor", "Can't create this in QML. Get it from the Vendors.");
|
qmlRegisterUncreatableType<Vendor>(uri, 1, 0, "Vendor", "Can't create this in QML. Get it from the Vendors.");
|
||||||
qmlRegisterUncreatableType<Vendors>(uri, 1, 0, "Vendors", "Can't create this in QML. Get it from the DeviceManager.");
|
qmlRegisterUncreatableType<Vendors>(uri, 1, 0, "Vendors", "Can't create this in QML. Get it from the ThingManager.");
|
||||||
qmlRegisterType<VendorsProxy>(uri, 1, 0, "VendorsProxy");
|
qmlRegisterType<VendorsProxy>(uri, 1, 0, "VendorsProxy");
|
||||||
|
|
||||||
qmlRegisterUncreatableType<Device>(uri, 1, 0, "Device", "Can't create this in QML. Get it from the Devices.");
|
qmlRegisterUncreatableType<Thing>(uri, 1, 0, "Thing", "Can't create this in QML. Get it from the Things.");
|
||||||
qmlRegisterUncreatableType<Device>(uri, 1, 0, "Thing", "Can't create this in QML. Get it from the Things.");
|
qmlRegisterUncreatableType<Things>(uri, 1, 0, "Things", "Can't create this in QML. Get it from the ThingManager.");
|
||||||
qmlRegisterUncreatableType<Devices>(uri, 1, 0, "Devices", "Can't create this in QML. Get it from the DeviceManager.");
|
qmlRegisterType<ThingsProxy>(uri, 1, 0, "ThingsProxy");
|
||||||
qmlRegisterUncreatableType<Devices>(uri, 1, 0, "Things", "Can't create this in QML. Get it from the ThingManager.");
|
|
||||||
qmlRegisterType<DevicesProxy>(uri, 1, 0, "DevicesProxy");
|
|
||||||
qmlRegisterType<DevicesProxy>(uri, 1, 0, "ThingsProxy");
|
|
||||||
qmlRegisterType<InterfacesModel>(uri, 1, 0, "InterfacesModel");
|
qmlRegisterType<InterfacesModel>(uri, 1, 0, "InterfacesModel");
|
||||||
qmlRegisterType<InterfacesSortModel>(uri, 1, 0, "InterfacesSortModel");
|
qmlRegisterType<InterfacesSortModel>(uri, 1, 0, "InterfacesSortModel");
|
||||||
|
|
||||||
qmlRegisterUncreatableType<DeviceClass>(uri, 1, 0, "ThingClass", "Can't create this in QML. Get it from the ThingClasses.");
|
qmlRegisterUncreatableType<ThingClass>(uri, 1, 0, "ThingClass", "Can't create this in QML. Get it from the ThingClasses.");
|
||||||
qmlRegisterUncreatableType<DeviceClasses>(uri, 1, 0, "ThingClasses", "Can't create this in QML. Get it from the ThingManager.");
|
qmlRegisterUncreatableType<ThingClasses>(uri, 1, 0, "ThingClasses", "Can't create this in QML. Get it from the ThingManager.");
|
||||||
qmlRegisterUncreatableType<DeviceClass>(uri, 1, 0, "DeviceClass", "Can't create this in QML. Get it from the DeviceClasses.");
|
qmlRegisterType<ThingClassesProxy>(uri, 1, 0, "ThingClassesProxy");
|
||||||
qmlRegisterUncreatableType<DeviceClasses>(uri, 1, 0, "DeviceClasses", "Can't create this in QML. Get it from the DeviceManager.");
|
|
||||||
qmlRegisterType<DeviceClassesProxy>(uri, 1, 0, "DeviceClassesProxy");
|
|
||||||
qmlRegisterType<ThingDiscovery>(uri, 1, 0, "ThingDiscovery");
|
qmlRegisterType<ThingDiscovery>(uri, 1, 0, "ThingDiscovery");
|
||||||
qmlRegisterType<ThingDiscoveryProxy>(uri, 1, 0, "ThingDiscoveryProxy");
|
qmlRegisterType<ThingDiscoveryProxy>(uri, 1, 0, "ThingDiscoveryProxy");
|
||||||
qmlRegisterUncreatableType<ThingDescriptor>(uri, 1, 0, "DeviceDescriptor", "Get it from DeviceDiscovery");
|
|
||||||
qmlRegisterUncreatableType<ThingDescriptor>(uri, 1, 0, "ThingDescriptor", "Get it from ThingDiscovery");
|
qmlRegisterUncreatableType<ThingDescriptor>(uri, 1, 0, "ThingDescriptor", "Get it from ThingDiscovery");
|
||||||
|
|
||||||
qmlRegisterType<DeviceModel>(uri, 1, 0, "DeviceModel");
|
qmlRegisterType<ThingModel>(uri, 1, 0, "ThingModel");
|
||||||
|
|
||||||
qmlRegisterUncreatableType<RuleManager>(uri, 1, 0, "RuleManager", "Get it from the Engine");
|
qmlRegisterUncreatableType<RuleManager>(uri, 1, 0, "RuleManager", "Get it from the Engine");
|
||||||
qmlRegisterUncreatableType<Rules>(uri, 1, 0, "Rules", "Get it from RuleManager");
|
qmlRegisterUncreatableType<Rules>(uri, 1, 0, "Rules", "Get it from RuleManager");
|
||||||
@ -239,7 +232,7 @@ void registerQmlTypes() {
|
|||||||
qmlRegisterUncreatableType<ThingGroup>(uri, 1, 0, "ThingGroup", "Uncreatable");
|
qmlRegisterUncreatableType<ThingGroup>(uri, 1, 0, "ThingGroup", "Uncreatable");
|
||||||
|
|
||||||
qmlRegisterUncreatableType<Plugin>(uri, 1, 0, "Plugin", "Can't create this in QML. Get it from the Plugins.");
|
qmlRegisterUncreatableType<Plugin>(uri, 1, 0, "Plugin", "Can't create this in QML. Get it from the Plugins.");
|
||||||
qmlRegisterUncreatableType<Plugins>(uri, 1, 0, "Plugins", "Can't create this in QML. Get it from the DeviceManager.");
|
qmlRegisterUncreatableType<Plugins>(uri, 1, 0, "Plugins", "Can't create this in QML. Get it from the ThingManager.");
|
||||||
qmlRegisterType<PluginsProxy>(uri, 1, 0, "PluginsProxy");
|
qmlRegisterType<PluginsProxy>(uri, 1, 0, "PluginsProxy");
|
||||||
|
|
||||||
qmlRegisterUncreatableType<NymeaConfiguration>(uri, 1, 0, "NymeaConfiguration", "Get it from Engine");
|
qmlRegisterUncreatableType<NymeaConfiguration>(uri, 1, 0, "NymeaConfiguration", "Get it from Engine");
|
||||||
@ -332,7 +325,7 @@ void registerQmlTypes() {
|
|||||||
qmlRegisterUncreatableType<TokenInfo>(uri, 1, 0, "TokenInfo", "Get it from TokenInfos");
|
qmlRegisterUncreatableType<TokenInfo>(uri, 1, 0, "TokenInfo", "Get it from TokenInfos");
|
||||||
qmlRegisterUncreatableType<TokenInfos>(uri, 1, 0, "TokenInfos", "Get it from UserManager");
|
qmlRegisterUncreatableType<TokenInfos>(uri, 1, 0, "TokenInfos", "Get it from UserManager");
|
||||||
|
|
||||||
qmlRegisterUncreatableType<IOConnections>(uri, 1, 0, "IOConnections", "Get it from DeviceManager");
|
qmlRegisterUncreatableType<IOConnections>(uri, 1, 0, "IOConnections", "Get it from ThingManager");
|
||||||
qmlRegisterUncreatableType<IOConnection>(uri, 1, 0, "IOConnection", "Get it from IOConnections");
|
qmlRegisterUncreatableType<IOConnection>(uri, 1, 0, "IOConnection", "Get it from IOConnections");
|
||||||
qmlRegisterType<IOInputConnectionWatcher>(uri, 1, 0, "IOInputConnectionWatcher");
|
qmlRegisterType<IOInputConnectionWatcher>(uri, 1, 0, "IOInputConnectionWatcher");
|
||||||
qmlRegisterType<IOOutputConnectionWatcher>(uri, 1, 0, "IOOutputConnectionWatcher");
|
qmlRegisterType<IOOutputConnectionWatcher>(uri, 1, 0, "IOOutputConnectionWatcher");
|
||||||
|
|||||||
@ -43,8 +43,8 @@ SOURCES += \
|
|||||||
$${PWD}/types/types.cpp \
|
$${PWD}/types/types.cpp \
|
||||||
$${PWD}/types/vendor.cpp \
|
$${PWD}/types/vendor.cpp \
|
||||||
$${PWD}/types/vendors.cpp \
|
$${PWD}/types/vendors.cpp \
|
||||||
$${PWD}/types/deviceclass.cpp \
|
$${PWD}/types/thingclass.cpp \
|
||||||
$${PWD}/types/device.cpp \
|
$${PWD}/types/thing.cpp \
|
||||||
$${PWD}/types/param.cpp \
|
$${PWD}/types/param.cpp \
|
||||||
$${PWD}/types/params.cpp \
|
$${PWD}/types/params.cpp \
|
||||||
$${PWD}/types/paramtype.cpp \
|
$${PWD}/types/paramtype.cpp \
|
||||||
@ -105,14 +105,13 @@ SOURCES += \
|
|||||||
$${PWD}/connection/discovery/upnpdiscovery.cpp \
|
$${PWD}/connection/discovery/upnpdiscovery.cpp \
|
||||||
$${PWD}/connection/discovery/zeroconfdiscovery.cpp \
|
$${PWD}/connection/discovery/zeroconfdiscovery.cpp \
|
||||||
$${PWD}/connection/discovery/bluetoothservicediscovery.cpp \
|
$${PWD}/connection/discovery/bluetoothservicediscovery.cpp \
|
||||||
$${PWD}/devicemanager.cpp \
|
$${PWD}/thingmanager.cpp \
|
||||||
$${PWD}/jsonrpc/jsontypes.cpp \
|
|
||||||
$${PWD}/jsonrpc/jsonrpcclient.cpp \
|
$${PWD}/jsonrpc/jsonrpcclient.cpp \
|
||||||
$${PWD}/jsonrpc/jsonhandler.cpp \
|
$${PWD}/jsonrpc/jsonhandler.cpp \
|
||||||
$${PWD}/devices.cpp \
|
$${PWD}/things.cpp \
|
||||||
$${PWD}/devicesproxy.cpp \
|
$${PWD}/thingsproxy.cpp \
|
||||||
$${PWD}/deviceclasses.cpp \
|
$${PWD}/thingclasses.cpp \
|
||||||
$${PWD}/deviceclassesproxy.cpp \
|
$${PWD}/thingclassesproxy.cpp \
|
||||||
$${PWD}/thingdiscovery.cpp \
|
$${PWD}/thingdiscovery.cpp \
|
||||||
$${PWD}/models/packagesfiltermodel.cpp \
|
$${PWD}/models/packagesfiltermodel.cpp \
|
||||||
$${PWD}/models/taglistmodel.cpp \
|
$${PWD}/models/taglistmodel.cpp \
|
||||||
@ -151,7 +150,7 @@ SOURCES += \
|
|||||||
$${PWD}/configuration/nymeaconfiguration.cpp \
|
$${PWD}/configuration/nymeaconfiguration.cpp \
|
||||||
$${PWD}/configuration/mqttpolicy.cpp \
|
$${PWD}/configuration/mqttpolicy.cpp \
|
||||||
$${PWD}/configuration/mqttpolicies.cpp \
|
$${PWD}/configuration/mqttpolicies.cpp \
|
||||||
$${PWD}/models/devicemodel.cpp \
|
$${PWD}/models/thingmodel.cpp \
|
||||||
$${PWD}/system/systemcontroller.cpp \
|
$${PWD}/system/systemcontroller.cpp \
|
||||||
$${PWD}/thinggroup.cpp \
|
$${PWD}/thinggroup.cpp \
|
||||||
$${PWD}/zigbee/zigbeeadapters.cpp \
|
$${PWD}/zigbee/zigbeeadapters.cpp \
|
||||||
@ -187,8 +186,8 @@ HEADERS += \
|
|||||||
$${PWD}/types/types.h \
|
$${PWD}/types/types.h \
|
||||||
$${PWD}/types/vendor.h \
|
$${PWD}/types/vendor.h \
|
||||||
$${PWD}/types/vendors.h \
|
$${PWD}/types/vendors.h \
|
||||||
$${PWD}/types/deviceclass.h \
|
$${PWD}/types/thingclass.h \
|
||||||
$${PWD}/types/device.h \
|
$${PWD}/types/thing.h \
|
||||||
$${PWD}/types/param.h \
|
$${PWD}/types/param.h \
|
||||||
$${PWD}/types/params.h \
|
$${PWD}/types/params.h \
|
||||||
$${PWD}/types/paramtype.h \
|
$${PWD}/types/paramtype.h \
|
||||||
@ -250,14 +249,13 @@ HEADERS += \
|
|||||||
$${PWD}/connection/discovery/upnpdiscovery.h \
|
$${PWD}/connection/discovery/upnpdiscovery.h \
|
||||||
$${PWD}/connection/discovery/zeroconfdiscovery.h \
|
$${PWD}/connection/discovery/zeroconfdiscovery.h \
|
||||||
$${PWD}/connection/discovery/bluetoothservicediscovery.h \
|
$${PWD}/connection/discovery/bluetoothservicediscovery.h \
|
||||||
$${PWD}/devicemanager.h \
|
$${PWD}/thingmanager.h \
|
||||||
$${PWD}/jsonrpc/jsontypes.h \
|
|
||||||
$${PWD}/jsonrpc/jsonrpcclient.h \
|
$${PWD}/jsonrpc/jsonrpcclient.h \
|
||||||
$${PWD}/jsonrpc/jsonhandler.h \
|
$${PWD}/jsonrpc/jsonhandler.h \
|
||||||
$${PWD}/devices.h \
|
$${PWD}/things.h \
|
||||||
$${PWD}/devicesproxy.h \
|
$${PWD}/thingsproxy.h \
|
||||||
$${PWD}/deviceclasses.h \
|
$${PWD}/thingclasses.h \
|
||||||
$${PWD}/deviceclassesproxy.h \
|
$${PWD}/thingclassesproxy.h \
|
||||||
$${PWD}/thingdiscovery.h \
|
$${PWD}/thingdiscovery.h \
|
||||||
$${PWD}/models/packagesfiltermodel.h \
|
$${PWD}/models/packagesfiltermodel.h \
|
||||||
$${PWD}/models/taglistmodel.h \
|
$${PWD}/models/taglistmodel.h \
|
||||||
@ -296,7 +294,7 @@ HEADERS += \
|
|||||||
$${PWD}/configuration/nymeaconfiguration.h \
|
$${PWD}/configuration/nymeaconfiguration.h \
|
||||||
$${PWD}/configuration/mqttpolicy.h \
|
$${PWD}/configuration/mqttpolicy.h \
|
||||||
$${PWD}/configuration/mqttpolicies.h \
|
$${PWD}/configuration/mqttpolicies.h \
|
||||||
$${PWD}/models/devicemodel.h \
|
$${PWD}/models/thingmodel.h \
|
||||||
$${PWD}/system/systemcontroller.h \
|
$${PWD}/system/systemcontroller.h \
|
||||||
$${PWD}/thinggroup.h \
|
$${PWD}/thinggroup.h \
|
||||||
$${PWD}/zigbee/zigbeeadapters.h \
|
$${PWD}/zigbee/zigbeeadapters.h \
|
||||||
|
|||||||
@ -32,10 +32,10 @@
|
|||||||
|
|
||||||
#include "types/interface.h"
|
#include "types/interface.h"
|
||||||
#include "types/interfaces.h"
|
#include "types/interfaces.h"
|
||||||
#include "types/device.h"
|
#include "types/thing.h"
|
||||||
|
|
||||||
#include "devices.h"
|
#include "things.h"
|
||||||
#include "devicesproxy.h"
|
#include "thingsproxy.h"
|
||||||
|
|
||||||
InterfacesProxy::InterfacesProxy(QObject *parent): QSortFilterProxyModel(parent)
|
InterfacesProxy::InterfacesProxy(QObject *parent): QSortFilterProxyModel(parent)
|
||||||
{
|
{
|
||||||
@ -102,9 +102,9 @@ bool InterfacesProxy::filterAcceptsRow(int source_row, const QModelIndex &source
|
|||||||
// TODO: This could be improved *a lot* by caching interfaces in the devices model...
|
// TODO: This could be improved *a lot* by caching interfaces in the devices model...
|
||||||
bool found = false;
|
bool found = false;
|
||||||
for (int i = 0; i < m_thingsFilter->rowCount(); i++) {
|
for (int i = 0; i < m_thingsFilter->rowCount(); i++) {
|
||||||
Device *d = m_thingsFilter->get(i);
|
Thing *d = m_thingsFilter->get(i);
|
||||||
if (!d->thingClass()) {
|
if (!d->thingClass()) {
|
||||||
qWarning() << "Cannot find DeviceClass for device:" << d->id() << d->name();
|
qWarning() << "Cannot find ThingClass for thing:" << d->id() << d->name();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (d->thingClass()->interfaces().contains(interfaceName)) {
|
if (d->thingClass()->interfaces().contains(interfaceName)) {
|
||||||
@ -120,7 +120,7 @@ bool InterfacesProxy::filterAcceptsRow(int source_row, const QModelIndex &source
|
|||||||
// TODO: This could be improved *a lot* by caching interfaces in the devices model...
|
// TODO: This could be improved *a lot* by caching interfaces in the devices model...
|
||||||
bool found = false;
|
bool found = false;
|
||||||
for (int i = 0; i < m_thingsProxyFilter->rowCount(); i++) {
|
for (int i = 0; i < m_thingsProxyFilter->rowCount(); i++) {
|
||||||
Device *d = m_thingsProxyFilter->get(i);
|
Thing *d = m_thingsProxyFilter->get(i);
|
||||||
if (!d->thingClass()) {
|
if (!d->thingClass()) {
|
||||||
qWarning() << "Cannot find ThingClass for thing:" << d->id() << d->name();
|
qWarning() << "Cannot find ThingClass for thing:" << d->id() << d->name();
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@ -33,8 +33,8 @@
|
|||||||
|
|
||||||
#include <QSortFilterProxyModel>
|
#include <QSortFilterProxyModel>
|
||||||
|
|
||||||
class Devices;
|
class Things;
|
||||||
class DevicesProxy;
|
class ThingsProxy;
|
||||||
class Interface;
|
class Interface;
|
||||||
class Interfaces;
|
class Interfaces;
|
||||||
|
|
||||||
@ -44,8 +44,8 @@ class InterfacesProxy: public QSortFilterProxyModel
|
|||||||
Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
|
Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
|
||||||
|
|
||||||
Q_PROPERTY(QStringList shownInterfaces READ shownInterfaces WRITE setShownInterfaces NOTIFY shownInterfacesChanged)
|
Q_PROPERTY(QStringList shownInterfaces READ shownInterfaces WRITE setShownInterfaces NOTIFY shownInterfacesChanged)
|
||||||
Q_PROPERTY(Devices* thingsFilter READ thingsFilter WRITE setThingsFilter NOTIFY thingsFilterChanged)
|
Q_PROPERTY(Things* thingsFilter READ thingsFilter WRITE setThingsFilter NOTIFY thingsFilterChanged)
|
||||||
Q_PROPERTY(DevicesProxy* thingsProxyFilter READ thingsProxyFilter WRITE setThingsProxyFilter NOTIFY thingsProxyFilterChanged)
|
Q_PROPERTY(ThingsProxy* thingsProxyFilter READ thingsProxyFilter WRITE setThingsProxyFilter NOTIFY thingsProxyFilterChanged)
|
||||||
Q_PROPERTY(bool showEvents READ showEvents WRITE setShowEvents NOTIFY showEventsChanged)
|
Q_PROPERTY(bool showEvents READ showEvents WRITE setShowEvents NOTIFY showEventsChanged)
|
||||||
Q_PROPERTY(bool showActions READ showActions WRITE setShowActions NOTIFY showActionsChanged)
|
Q_PROPERTY(bool showActions READ showActions WRITE setShowActions NOTIFY showActionsChanged)
|
||||||
Q_PROPERTY(bool showStates READ showStates WRITE setShowStates NOTIFY showStatesChanged)
|
Q_PROPERTY(bool showStates READ showStates WRITE setShowStates NOTIFY showStatesChanged)
|
||||||
@ -56,11 +56,11 @@ public:
|
|||||||
QStringList shownInterfaces() const { return m_shownInterfaces; }
|
QStringList shownInterfaces() const { return m_shownInterfaces; }
|
||||||
void setShownInterfaces(const QStringList &shownInterfaces) { m_shownInterfaces = shownInterfaces; emit shownInterfacesChanged(); invalidateFilter(); }
|
void setShownInterfaces(const QStringList &shownInterfaces) { m_shownInterfaces = shownInterfaces; emit shownInterfacesChanged(); invalidateFilter(); }
|
||||||
|
|
||||||
Devices* thingsFilter() const { return m_thingsFilter; }
|
Things* thingsFilter() const { return m_thingsFilter; }
|
||||||
void setThingsFilter(Devices *things) { m_thingsFilter = things; emit thingsFilterChanged(); invalidateFilter(); }
|
void setThingsFilter(Things *things) { m_thingsFilter = things; emit thingsFilterChanged(); invalidateFilter(); }
|
||||||
|
|
||||||
DevicesProxy* thingsProxyFilter() const { return m_thingsProxyFilter; }
|
ThingsProxy* thingsProxyFilter() const { return m_thingsProxyFilter; }
|
||||||
void setThingsProxyFilter(DevicesProxy *thingsProxy) { m_thingsProxyFilter = thingsProxy; emit thingsProxyFilterChanged(); invalidateFilter(); }
|
void setThingsProxyFilter(ThingsProxy *thingsProxy) { m_thingsProxyFilter = thingsProxy; emit thingsProxyFilterChanged(); invalidateFilter(); }
|
||||||
|
|
||||||
bool showEvents() const;
|
bool showEvents() const;
|
||||||
void setShowEvents(bool showEvents);
|
void setShowEvents(bool showEvents);
|
||||||
@ -89,8 +89,8 @@ signals:
|
|||||||
private:
|
private:
|
||||||
Interfaces *m_interfaces = nullptr;
|
Interfaces *m_interfaces = nullptr;
|
||||||
QStringList m_shownInterfaces;
|
QStringList m_shownInterfaces;
|
||||||
Devices* m_thingsFilter = nullptr;
|
Things* m_thingsFilter = nullptr;
|
||||||
DevicesProxy* m_thingsProxyFilter = nullptr;
|
ThingsProxy* m_thingsProxyFilter = nullptr;
|
||||||
bool m_showEvents = false;
|
bool m_showEvents = false;
|
||||||
bool m_showActions = false;
|
bool m_showActions = false;
|
||||||
bool m_showStates = false;
|
bool m_showStates = false;
|
||||||
|
|||||||
@ -71,7 +71,6 @@ QVariant LogsModel::data(const QModelIndex &index, int role) const
|
|||||||
case RoleValue:
|
case RoleValue:
|
||||||
return m_list.at(index.row())->value();
|
return m_list.at(index.row())->value();
|
||||||
case RoleThingId:
|
case RoleThingId:
|
||||||
case RoleDeviceId:
|
|
||||||
return m_list.at(index.row())->thingId();
|
return m_list.at(index.row())->thingId();
|
||||||
case RoleTypeId:
|
case RoleTypeId:
|
||||||
return m_list.at(index.row())->typeId();
|
return m_list.at(index.row())->typeId();
|
||||||
@ -91,7 +90,6 @@ QHash<int, QByteArray> LogsModel::roleNames() const
|
|||||||
roles.insert(RoleTimestamp, "timestamp");
|
roles.insert(RoleTimestamp, "timestamp");
|
||||||
roles.insert(RoleValue, "value");
|
roles.insert(RoleValue, "value");
|
||||||
roles.insert(RoleThingId, "thingId");
|
roles.insert(RoleThingId, "thingId");
|
||||||
roles.insert(RoleDeviceId, "deviceId");
|
|
||||||
roles.insert(RoleTypeId, "typeId");
|
roles.insert(RoleTypeId, "typeId");
|
||||||
roles.insert(RoleSource, "source");
|
roles.insert(RoleSource, "source");
|
||||||
roles.insert(RoleLoggingEventType, "loggingEventType");
|
roles.insert(RoleLoggingEventType, "loggingEventType");
|
||||||
@ -220,12 +218,7 @@ void LogsModel::logsReply(int /*commandId*/, const QVariantMap &data)
|
|||||||
foreach (const QVariant &logEntryVariant, logEntries) {
|
foreach (const QVariant &logEntryVariant, logEntries) {
|
||||||
QVariantMap entryMap = logEntryVariant.toMap();
|
QVariantMap entryMap = logEntryVariant.toMap();
|
||||||
QDateTime timeStamp = QDateTime::fromMSecsSinceEpoch(entryMap.value("timestamp").toLongLong());
|
QDateTime timeStamp = QDateTime::fromMSecsSinceEpoch(entryMap.value("timestamp").toLongLong());
|
||||||
QString thingId;
|
QString thingId = entryMap.value("thingId").toString();
|
||||||
if (m_engine->jsonRpcClient()->ensureServerVersion("5.0")) {
|
|
||||||
thingId = entryMap.value("thingId").toString();
|
|
||||||
} else {
|
|
||||||
thingId = entryMap.value("deviceId").toString();
|
|
||||||
}
|
|
||||||
QString typeId = entryMap.value("typeId").toString();
|
QString typeId = entryMap.value("typeId").toString();
|
||||||
QMetaEnum sourceEnum = QMetaEnum::fromType<LogEntry::LoggingSource>();
|
QMetaEnum sourceEnum = QMetaEnum::fromType<LogEntry::LoggingSource>();
|
||||||
LogEntry::LoggingSource loggingSource = static_cast<LogEntry::LoggingSource>(sourceEnum.keyToValue(entryMap.value("source").toByteArray()));
|
LogEntry::LoggingSource loggingSource = static_cast<LogEntry::LoggingSource>(sourceEnum.keyToValue(entryMap.value("source").toByteArray()));
|
||||||
@ -298,11 +291,7 @@ void LogsModel::fetchMore(const QModelIndex &parent)
|
|||||||
if (!m_thingId.isNull()) {
|
if (!m_thingId.isNull()) {
|
||||||
QVariantList thingIds;
|
QVariantList thingIds;
|
||||||
thingIds.append(m_thingId);
|
thingIds.append(m_thingId);
|
||||||
if (m_engine->jsonRpcClient()->ensureServerVersion("5.0")) {
|
params.insert("thingIds", thingIds);
|
||||||
params.insert("thingIds", thingIds);
|
|
||||||
} else {
|
|
||||||
params.insert("deviceIds", thingIds);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (!m_typeIds.isEmpty()) {
|
if (!m_typeIds.isEmpty()) {
|
||||||
QVariantList typeIds;
|
QVariantList typeIds;
|
||||||
@ -354,12 +343,7 @@ void LogsModel::newLogEntryReceived(const QVariantMap &data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
QVariantMap entryMap = data;
|
QVariantMap entryMap = data;
|
||||||
QUuid thingId;
|
QUuid thingId = entryMap.value("thingId").toUuid();
|
||||||
if (m_engine->jsonRpcClient()->ensureServerVersion("5.0")) {
|
|
||||||
thingId = entryMap.value("deviceId").toUuid();
|
|
||||||
} else {
|
|
||||||
thingId = entryMap.value("thingId").toUuid();
|
|
||||||
}
|
|
||||||
if (!m_thingId.isNull() && thingId != m_thingId) {
|
if (!m_thingId.isNull() && thingId != m_thingId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -43,6 +43,7 @@ class LogsModel : public QAbstractListModel, public QQmlParserStatus
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(Engine* engine READ engine WRITE setEngine NOTIFY engineChanged)
|
Q_PROPERTY(Engine* engine READ engine WRITE setEngine NOTIFY engineChanged)
|
||||||
|
Q_INTERFACES(QQmlParserStatus)
|
||||||
|
|
||||||
Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
|
Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
|
||||||
Q_PROPERTY(bool busy READ busy NOTIFY busyChanged)
|
Q_PROPERTY(bool busy READ busy NOTIFY busyChanged)
|
||||||
@ -58,7 +59,6 @@ public:
|
|||||||
RoleTimestamp,
|
RoleTimestamp,
|
||||||
RoleValue,
|
RoleValue,
|
||||||
RoleThingId,
|
RoleThingId,
|
||||||
RoleDeviceId, // < JSONRPC 5.0
|
|
||||||
RoleTypeId,
|
RoleTypeId,
|
||||||
RoleSource,
|
RoleSource,
|
||||||
RoleLoggingEventType,
|
RoleLoggingEventType,
|
||||||
@ -82,7 +82,7 @@ public:
|
|||||||
void setLive(bool live);
|
void setLive(bool live);
|
||||||
|
|
||||||
QUuid thingId() const;
|
QUuid thingId() const;
|
||||||
void setThingId(const QUuid &deviceId);
|
void setThingId(const QUuid &thingId);
|
||||||
|
|
||||||
QStringList typeIds() const;
|
QStringList typeIds() const;
|
||||||
void setTypeIds(const QStringList &typeIds);
|
void setTypeIds(const QStringList &typeIds);
|
||||||
|
|||||||
@ -71,7 +71,6 @@ QVariant LogsModelNg::data(const QModelIndex &index, int role) const
|
|||||||
case RoleValue:
|
case RoleValue:
|
||||||
return m_list.at(index.row())->value();
|
return m_list.at(index.row())->value();
|
||||||
case RoleThingId:
|
case RoleThingId:
|
||||||
case RoleDeviceId:
|
|
||||||
return m_list.at(index.row())->thingId();
|
return m_list.at(index.row())->thingId();
|
||||||
case RoleTypeId:
|
case RoleTypeId:
|
||||||
return m_list.at(index.row())->typeId();
|
return m_list.at(index.row())->typeId();
|
||||||
@ -89,7 +88,6 @@ QHash<int, QByteArray> LogsModelNg::roleNames() const
|
|||||||
roles.insert(RoleTimestamp, "timestamp");
|
roles.insert(RoleTimestamp, "timestamp");
|
||||||
roles.insert(RoleValue, "value");
|
roles.insert(RoleValue, "value");
|
||||||
roles.insert(RoleThingId, "thingId");
|
roles.insert(RoleThingId, "thingId");
|
||||||
roles.insert(RoleDeviceId, "deviceId");
|
|
||||||
roles.insert(RoleTypeId, "typeId");
|
roles.insert(RoleTypeId, "typeId");
|
||||||
roles.insert(RoleSource, "source");
|
roles.insert(RoleSource, "source");
|
||||||
roles.insert(RoleLoggingEventType, "loggingEventType");
|
roles.insert(RoleLoggingEventType, "loggingEventType");
|
||||||
@ -250,12 +248,7 @@ void LogsModelNg::logsReply(int commandId, const QVariantMap &data)
|
|||||||
foreach (const QVariant &logEntryVariant, logEntries) {
|
foreach (const QVariant &logEntryVariant, logEntries) {
|
||||||
QVariantMap entryMap = logEntryVariant.toMap();
|
QVariantMap entryMap = logEntryVariant.toMap();
|
||||||
QDateTime timeStamp = QDateTime::fromMSecsSinceEpoch(entryMap.value("timestamp").toLongLong());
|
QDateTime timeStamp = QDateTime::fromMSecsSinceEpoch(entryMap.value("timestamp").toLongLong());
|
||||||
QString thingId;
|
QString thingId = entryMap.value("thingId").toString();
|
||||||
if (m_engine->jsonRpcClient()->ensureServerVersion("5.0")) {
|
|
||||||
thingId = entryMap.value("thingId").toString();
|
|
||||||
} else {
|
|
||||||
thingId = entryMap.value("deviceId").toString();
|
|
||||||
}
|
|
||||||
QString typeId = entryMap.value("typeId").toString();
|
QString typeId = entryMap.value("typeId").toString();
|
||||||
QMetaEnum sourceEnum = QMetaEnum::fromType<LogEntry::LoggingSource>();
|
QMetaEnum sourceEnum = QMetaEnum::fromType<LogEntry::LoggingSource>();
|
||||||
LogEntry::LoggingSource loggingSource = static_cast<LogEntry::LoggingSource>(sourceEnum.keyToValue(entryMap.value("source").toByteArray()));
|
LogEntry::LoggingSource loggingSource = static_cast<LogEntry::LoggingSource>(sourceEnum.keyToValue(entryMap.value("source").toByteArray()));
|
||||||
@ -284,13 +277,13 @@ void LogsModelNg::logsReply(int commandId, const QVariantMap &data)
|
|||||||
for (int i = 0; i < newBlock.count(); i++) {
|
for (int i = 0; i < newBlock.count(); i++) {
|
||||||
LogEntry *entry = newBlock.at(i);
|
LogEntry *entry = newBlock.at(i);
|
||||||
m_list.insert(offset + i, entry);
|
m_list.insert(offset + i, entry);
|
||||||
Device *dev = m_engine->deviceManager()->devices()->getDevice(entry->thingId());
|
Thing *thing = m_engine->thingManager()->things()->getThing(entry->thingId());
|
||||||
if (!dev) {
|
if (!thing) {
|
||||||
qWarning() << "Device not found in system. Cannot add item to graph series.";
|
qWarning() << "Thing not found in system. Cannot add item to graph series.";
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
StateType *entryStateType = dev->thingClass()->stateTypes()->getStateType(entry->typeId());
|
StateType *entryStateType = thing->thingClass()->stateTypes()->getStateType(entry->typeId());
|
||||||
|
|
||||||
if (m_graphSeries) {
|
if (m_graphSeries) {
|
||||||
if (entryStateType->type().toLower() == "bool") {
|
if (entryStateType->type().toLower() == "bool") {
|
||||||
@ -394,11 +387,7 @@ void LogsModelNg::fetchMore(const QModelIndex &parent)
|
|||||||
if (!m_thingId.isNull()) {
|
if (!m_thingId.isNull()) {
|
||||||
QVariantList thingIds;
|
QVariantList thingIds;
|
||||||
thingIds.append(m_thingId);
|
thingIds.append(m_thingId);
|
||||||
if (m_engine->jsonRpcClient()->ensureServerVersion("5.0")) {
|
params.insert("thingIds", thingIds);
|
||||||
params.insert("thingIds", thingIds);
|
|
||||||
} else {
|
|
||||||
params.insert("deviceIds", thingIds);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (!m_typeIds.isEmpty()) {
|
if (!m_typeIds.isEmpty()) {
|
||||||
QVariantList typeIds;
|
QVariantList typeIds;
|
||||||
@ -440,12 +429,7 @@ void LogsModelNg::newLogEntryReceived(const QVariantMap &data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
QVariantMap entryMap = data;
|
QVariantMap entryMap = data;
|
||||||
QUuid thingId;
|
QUuid thingId = entryMap.value("thingId").toUuid();
|
||||||
if (m_engine->jsonRpcClient()->ensureServerVersion("5.0")) {
|
|
||||||
thingId = entryMap.value("deviceId").toUuid();
|
|
||||||
} else {
|
|
||||||
thingId = entryMap.value("thingId").toUuid();
|
|
||||||
}
|
|
||||||
if (!m_thingId.isNull() && thingId != m_thingId) {
|
if (!m_thingId.isNull() && thingId != m_thingId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -466,7 +450,7 @@ void LogsModelNg::newLogEntryReceived(const QVariantMap &data)
|
|||||||
m_list.prepend(entry);
|
m_list.prepend(entry);
|
||||||
if (m_graphSeries) {
|
if (m_graphSeries) {
|
||||||
|
|
||||||
Device *dev = m_engine->thingManager()->devices()->getDevice(entry->thingId());
|
Thing *dev = m_engine->thingManager()->things()->getThing(entry->thingId());
|
||||||
|
|
||||||
StateType *entryStateType = dev->thingClass()->stateTypes()->getStateType(entry->typeId());
|
StateType *entryStateType = dev->thingClass()->stateTypes()->getStateType(entry->typeId());
|
||||||
|
|
||||||
|
|||||||
@ -49,7 +49,6 @@ class LogsModelNg : public QAbstractListModel, public QQmlParserStatus
|
|||||||
Q_PROPERTY(bool live READ live WRITE setLive NOTIFY liveChanged)
|
Q_PROPERTY(bool live READ live WRITE setLive NOTIFY liveChanged)
|
||||||
Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
|
Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
|
||||||
Q_PROPERTY(QUuid thingId READ thingId WRITE setThingId NOTIFY thingIdChanged)
|
Q_PROPERTY(QUuid thingId READ thingId WRITE setThingId NOTIFY thingIdChanged)
|
||||||
Q_PROPERTY(QUuid deviceId READ thingId WRITE setThingId NOTIFY thingIdChanged)
|
|
||||||
Q_PROPERTY(QStringList typeIds READ typeIds WRITE setTypeIds NOTIFY typeIdsChanged)
|
Q_PROPERTY(QStringList typeIds READ typeIds WRITE setTypeIds NOTIFY typeIdsChanged)
|
||||||
Q_PROPERTY(QDateTime startTime READ startTime WRITE setStartTime NOTIFY startTimeChanged)
|
Q_PROPERTY(QDateTime startTime READ startTime WRITE setStartTime NOTIFY startTimeChanged)
|
||||||
Q_PROPERTY(QDateTime endTime READ endTime WRITE setEndTime NOTIFY endTimeChanged)
|
Q_PROPERTY(QDateTime endTime READ endTime WRITE setEndTime NOTIFY endTimeChanged)
|
||||||
@ -64,7 +63,6 @@ public:
|
|||||||
RoleTimestamp,
|
RoleTimestamp,
|
||||||
RoleValue,
|
RoleValue,
|
||||||
RoleThingId,
|
RoleThingId,
|
||||||
RoleDeviceId, // < JSONRPC 5.0
|
|
||||||
RoleTypeId,
|
RoleTypeId,
|
||||||
RoleSource,
|
RoleSource,
|
||||||
RoleLoggingEventType
|
RoleLoggingEventType
|
||||||
|
|||||||
@ -113,13 +113,13 @@ bool RulesFilterModel::filterAcceptsRow(int source_row, const QModelIndex &sourc
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!found && rule->stateEvaluator() && rule->stateEvaluator()->containsDevice(m_filterThingId)) {
|
if (!found && rule->stateEvaluator() && rule->stateEvaluator()->containsThing(m_filterThingId)) {
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
if (!found) {
|
if (!found) {
|
||||||
for (int i = 0; i < rule->actions()->rowCount(); i++) {
|
for (int i = 0; i < rule->actions()->rowCount(); i++) {
|
||||||
RuleAction *ra = rule->actions()->get(i);
|
RuleAction *ra = rule->actions()->get(i);
|
||||||
if (ra->deviceId() == m_filterThingId) {
|
if (ra->thingId() == m_filterThingId) {
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -128,7 +128,7 @@ bool RulesFilterModel::filterAcceptsRow(int source_row, const QModelIndex &sourc
|
|||||||
if (!found) {
|
if (!found) {
|
||||||
for (int i = 0; i < rule->exitActions()->rowCount(); i++) {
|
for (int i = 0; i < rule->exitActions()->rowCount(); i++) {
|
||||||
RuleAction *ra = rule->exitActions()->get(i);
|
RuleAction *ra = rule->exitActions()->get(i);
|
||||||
if (ra->deviceId() == m_filterThingId) {
|
if (ra->thingId() == m_filterThingId) {
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -43,7 +43,6 @@ class RulesFilterModel : public QSortFilterProxyModel
|
|||||||
Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
|
Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
|
||||||
Q_PROPERTY(Rules* rules READ rules WRITE setRules NOTIFY rulesChanged)
|
Q_PROPERTY(Rules* rules READ rules WRITE setRules NOTIFY rulesChanged)
|
||||||
Q_PROPERTY(QUuid filterThingId READ filterThingId WRITE setFilterThingId NOTIFY filterThingIdChanged)
|
Q_PROPERTY(QUuid filterThingId READ filterThingId WRITE setFilterThingId NOTIFY filterThingIdChanged)
|
||||||
Q_PROPERTY(QUuid filterDeviceId READ filterThingId WRITE setFilterThingId NOTIFY filterThingIdChanged)
|
|
||||||
Q_PROPERTY(bool filterExecutable READ filterExecutable WRITE setFilterExecutable NOTIFY filterExecutableChanged)
|
Q_PROPERTY(bool filterExecutable READ filterExecutable WRITE setFilterExecutable NOTIFY filterExecutableChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
@ -44,7 +44,6 @@ class TagsProxyModel : public QSortFilterProxyModel
|
|||||||
Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
|
Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
|
||||||
Q_PROPERTY(QString filterTagId READ filterTagId WRITE setFilterTagId NOTIFY filterTagIdChanged)
|
Q_PROPERTY(QString filterTagId READ filterTagId WRITE setFilterTagId NOTIFY filterTagIdChanged)
|
||||||
Q_PROPERTY(QUuid filterThingId READ filterThingId WRITE setFilterThingId NOTIFY filterThingIdChanged)
|
Q_PROPERTY(QUuid filterThingId READ filterThingId WRITE setFilterThingId NOTIFY filterThingIdChanged)
|
||||||
Q_PROPERTY(QUuid filterDeviceId READ filterThingId WRITE setFilterThingId NOTIFY filterThingIdChanged)
|
|
||||||
Q_PROPERTY(QUuid filterRuleId READ filterRuleId WRITE setFilterRuleId NOTIFY filterRuleIdChanged)
|
Q_PROPERTY(QUuid filterRuleId READ filterRuleId WRITE setFilterRuleId NOTIFY filterRuleIdChanged)
|
||||||
Q_PROPERTY(QString filterValue READ filterValue WRITE setFilterValue NOTIFY filterValueChanged)
|
Q_PROPERTY(QString filterValue READ filterValue WRITE setFilterValue NOTIFY filterValueChanged)
|
||||||
|
|
||||||
|
|||||||
@ -28,22 +28,22 @@
|
|||||||
*
|
*
|
||||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
#include "devicemodel.h"
|
#include "thingmodel.h"
|
||||||
|
|
||||||
#include "types/statetype.h"
|
#include "types/statetype.h"
|
||||||
|
|
||||||
DeviceModel::DeviceModel(QObject *parent) : QAbstractListModel(parent)
|
ThingModel::ThingModel(QObject *parent) : QAbstractListModel(parent)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int DeviceModel::rowCount(const QModelIndex &parent) const
|
int ThingModel::rowCount(const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
Q_UNUSED(parent)
|
Q_UNUSED(parent)
|
||||||
return m_list.count();
|
return m_list.count();
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant DeviceModel::data(const QModelIndex &index, int role) const
|
QVariant ThingModel::data(const QModelIndex &index, int role) const
|
||||||
{
|
{
|
||||||
if (role == RoleId) {
|
if (role == RoleId) {
|
||||||
return m_list.at(index.row());
|
return m_list.at(index.row());
|
||||||
@ -83,7 +83,7 @@ QVariant DeviceModel::data(const QModelIndex &index, int role) const
|
|||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
QHash<int, QByteArray> DeviceModel::roleNames() const
|
QHash<int, QByteArray> ThingModel::roleNames() const
|
||||||
{
|
{
|
||||||
QHash<int, QByteArray> roles;
|
QHash<int, QByteArray> roles;
|
||||||
roles.insert(RoleId, "id");
|
roles.insert(RoleId, "id");
|
||||||
@ -93,7 +93,7 @@ QHash<int, QByteArray> DeviceModel::roleNames() const
|
|||||||
return roles;
|
return roles;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant DeviceModel::getData(int index, int role) const
|
QVariant ThingModel::getData(int index, int role) const
|
||||||
{
|
{
|
||||||
if (index < 0 || index >= m_list.count()) {
|
if (index < 0 || index >= m_list.count()) {
|
||||||
return QVariant();
|
return QVariant();
|
||||||
@ -101,26 +101,26 @@ QVariant DeviceModel::getData(int index, int role) const
|
|||||||
return data(this->index(index), role);
|
return data(this->index(index), role);
|
||||||
}
|
}
|
||||||
|
|
||||||
Device *DeviceModel::device() const
|
Thing *ThingModel::thing() const
|
||||||
{
|
{
|
||||||
return m_device;
|
return m_device;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceModel::setDevice(Device *device)
|
void ThingModel::setThing(Thing *device)
|
||||||
{
|
{
|
||||||
if (m_device != device) {
|
if (m_device != device) {
|
||||||
m_device = device;
|
m_device = device;
|
||||||
emit deviceChanged();
|
emit thingChanged();
|
||||||
updateList();
|
updateList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeviceModel::showStates() const
|
bool ThingModel::showStates() const
|
||||||
{
|
{
|
||||||
return m_showStates;
|
return m_showStates;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceModel::setShowStates(bool showStates)
|
void ThingModel::setShowStates(bool showStates)
|
||||||
{
|
{
|
||||||
if (m_showStates != showStates) {
|
if (m_showStates != showStates) {
|
||||||
m_showStates = showStates;
|
m_showStates = showStates;
|
||||||
@ -129,12 +129,12 @@ void DeviceModel::setShowStates(bool showStates)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeviceModel::showActions() const
|
bool ThingModel::showActions() const
|
||||||
{
|
{
|
||||||
return m_showActions;
|
return m_showActions;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceModel::setShowActions(bool showActions)
|
void ThingModel::setShowActions(bool showActions)
|
||||||
{
|
{
|
||||||
if (m_showActions != showActions) {
|
if (m_showActions != showActions) {
|
||||||
m_showActions = showActions;
|
m_showActions = showActions;
|
||||||
@ -143,12 +143,12 @@ void DeviceModel::setShowActions(bool showActions)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeviceModel::showEvents() const
|
bool ThingModel::showEvents() const
|
||||||
{
|
{
|
||||||
return m_showEvents;
|
return m_showEvents;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceModel::setShowEvents(bool showEvents)
|
void ThingModel::setShowEvents(bool showEvents)
|
||||||
{
|
{
|
||||||
if (m_showEvents != showEvents) {
|
if (m_showEvents != showEvents) {
|
||||||
m_showEvents = showEvents;
|
m_showEvents = showEvents;
|
||||||
@ -157,7 +157,7 @@ void DeviceModel::setShowEvents(bool showEvents)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceModel::updateList()
|
void ThingModel::updateList()
|
||||||
{
|
{
|
||||||
if (!m_device) {
|
if (!m_device) {
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
@ -28,21 +28,21 @@
|
|||||||
*
|
*
|
||||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
#ifndef DEVICEMODEL_H
|
#ifndef THINGMODEL_H
|
||||||
#define DEVICEMODEL_H
|
#define THINGMODEL_H
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
#include "types/device.h"
|
#include "types/thing.h"
|
||||||
#include "types/deviceclass.h"
|
#include "types/thingclass.h"
|
||||||
|
|
||||||
class DeviceModel : public QAbstractListModel
|
class ThingModel : public QAbstractListModel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
|
Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
|
||||||
|
|
||||||
Q_PROPERTY(Device* device READ device WRITE setDevice NOTIFY deviceChanged)
|
Q_PROPERTY(Thing* thing READ thing WRITE setThing NOTIFY thingChanged)
|
||||||
|
|
||||||
Q_PROPERTY(bool showStates READ showStates WRITE setShowStates NOTIFY showStatesChanged)
|
Q_PROPERTY(bool showStates READ showStates WRITE setShowStates NOTIFY showStatesChanged)
|
||||||
Q_PROPERTY(bool showActions READ showActions WRITE setShowActions NOTIFY showActionsChanged)
|
Q_PROPERTY(bool showActions READ showActions WRITE setShowActions NOTIFY showActionsChanged)
|
||||||
@ -63,15 +63,15 @@ public:
|
|||||||
};
|
};
|
||||||
Q_ENUM(Type)
|
Q_ENUM(Type)
|
||||||
|
|
||||||
explicit DeviceModel(QObject *parent = nullptr);
|
explicit ThingModel(QObject *parent = nullptr);
|
||||||
|
|
||||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||||
QVariant data(const QModelIndex &index, int role) const override;
|
QVariant data(const QModelIndex &index, int role) const override;
|
||||||
QHash<int, QByteArray> roleNames() const override;
|
QHash<int, QByteArray> roleNames() const override;
|
||||||
Q_INVOKABLE QVariant getData(int index, int role) const;
|
Q_INVOKABLE QVariant getData(int index, int role) const;
|
||||||
|
|
||||||
Device* device() const;
|
Thing* thing() const;
|
||||||
void setDevice(Device *device);
|
void setThing(Thing *device);
|
||||||
|
|
||||||
bool showStates() const;
|
bool showStates() const;
|
||||||
void setShowStates(bool showStates);
|
void setShowStates(bool showStates);
|
||||||
@ -83,7 +83,7 @@ public:
|
|||||||
void setShowEvents(bool showEvents);
|
void setShowEvents(bool showEvents);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void deviceChanged();
|
void thingChanged();
|
||||||
|
|
||||||
void countChanged();
|
void countChanged();
|
||||||
|
|
||||||
@ -95,7 +95,7 @@ private:
|
|||||||
void updateList();
|
void updateList();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Device *m_device = nullptr;
|
Thing *m_device = nullptr;
|
||||||
|
|
||||||
bool m_showStates = true;
|
bool m_showStates = true;
|
||||||
bool m_showActions = true;
|
bool m_showActions = true;
|
||||||
@ -104,4 +104,4 @@ private:
|
|||||||
QList<QUuid> m_list;
|
QList<QUuid> m_list;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DEVICEMODEL_H
|
#endif // THINGMODEL_H
|
||||||
@ -31,7 +31,6 @@
|
|||||||
#include "rulemanager.h"
|
#include "rulemanager.h"
|
||||||
|
|
||||||
#include "jsonrpc/jsonrpcclient.h"
|
#include "jsonrpc/jsonrpcclient.h"
|
||||||
#include "jsonrpc/jsontypes.h"
|
|
||||||
#include "types/rule.h"
|
#include "types/rule.h"
|
||||||
#include "types/eventdescriptor.h"
|
#include "types/eventdescriptor.h"
|
||||||
#include "types/eventdescriptors.h"
|
#include "types/eventdescriptors.h"
|
||||||
@ -50,6 +49,7 @@
|
|||||||
#include "types/calendaritem.h"
|
#include "types/calendaritem.h"
|
||||||
|
|
||||||
#include <QMetaEnum>
|
#include <QMetaEnum>
|
||||||
|
#include <QJsonDocument>
|
||||||
|
|
||||||
RuleManager::RuleManager(JsonRpcClient* jsonClient, QObject *parent) :
|
RuleManager::RuleManager(JsonRpcClient* jsonClient, QObject *parent) :
|
||||||
JsonHandler(parent),
|
JsonHandler(parent),
|
||||||
@ -246,11 +246,7 @@ void RuleManager::parseEventDescriptors(const QVariantList &eventDescriptorList,
|
|||||||
{
|
{
|
||||||
foreach (const QVariant &eventDescriptorVariant, eventDescriptorList) {
|
foreach (const QVariant &eventDescriptorVariant, eventDescriptorList) {
|
||||||
EventDescriptor *eventDescriptor = new EventDescriptor(rule);
|
EventDescriptor *eventDescriptor = new EventDescriptor(rule);
|
||||||
if (m_jsonClient->ensureServerVersion("5.0")) {
|
eventDescriptor->setThingId(eventDescriptorVariant.toMap().value("thingId").toString());
|
||||||
eventDescriptor->setThingId(eventDescriptorVariant.toMap().value("thingId").toString());
|
|
||||||
} else {
|
|
||||||
eventDescriptor->setThingId(eventDescriptorVariant.toMap().value("deviceId").toString());
|
|
||||||
}
|
|
||||||
eventDescriptor->setEventTypeId(eventDescriptorVariant.toMap().value("eventTypeId").toString());
|
eventDescriptor->setEventTypeId(eventDescriptorVariant.toMap().value("eventTypeId").toString());
|
||||||
eventDescriptor->setInterfaceName(eventDescriptorVariant.toMap().value("interface").toString());
|
eventDescriptor->setInterfaceName(eventDescriptorVariant.toMap().value("interface").toString());
|
||||||
eventDescriptor->setInterfaceEvent(eventDescriptorVariant.toMap().value("interfaceEvent").toString());
|
eventDescriptor->setInterfaceEvent(eventDescriptorVariant.toMap().value("interfaceEvent").toString());
|
||||||
@ -263,7 +259,7 @@ void RuleManager::parseEventDescriptors(const QVariantList &eventDescriptorList,
|
|||||||
paramDescriptor->setOperatorType((ParamDescriptor::ValueOperator)operatorEnum.keyToValue(paramDescriptorVariant.toMap().value("operator").toString().toLocal8Bit()));
|
paramDescriptor->setOperatorType((ParamDescriptor::ValueOperator)operatorEnum.keyToValue(paramDescriptorVariant.toMap().value("operator").toString().toLocal8Bit()));
|
||||||
eventDescriptor->paramDescriptors()->addParamDescriptor(paramDescriptor);
|
eventDescriptor->paramDescriptors()->addParamDescriptor(paramDescriptor);
|
||||||
}
|
}
|
||||||
// qDebug() << "Adding eventdescriptor" << eventDescriptor->deviceId() << eventDescriptor->eventTypeId();
|
// qDebug() << "Adding eventdescriptor" << eventDescriptor->thingId() << eventDescriptor->eventTypeId();
|
||||||
rule->eventDescriptors()->addEventDescriptor(eventDescriptor);
|
rule->eventDescriptors()->addEventDescriptor(eventDescriptor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -280,8 +276,8 @@ StateEvaluator *RuleManager::parseStateEvaluator(const QVariantMap &stateEvaluat
|
|||||||
StateDescriptor::ValueOperator op = (StateDescriptor::ValueOperator)operatorEnum.keyToValue(sdMap.value("operator").toByteArray());
|
StateDescriptor::ValueOperator op = (StateDescriptor::ValueOperator)operatorEnum.keyToValue(sdMap.value("operator").toByteArray());
|
||||||
|
|
||||||
StateDescriptor *sd = nullptr;
|
StateDescriptor *sd = nullptr;
|
||||||
if (sdMap.contains("deviceId") && sdMap.contains("stateTypeId")) {
|
if (sdMap.contains("thingId") && sdMap.contains("stateTypeId")) {
|
||||||
sd = new StateDescriptor(sdMap.value("deviceId").toUuid(), sdMap.value("stateTypeId").toUuid(), op, sdMap.value("value"), stateEvaluator);
|
sd = new StateDescriptor(sdMap.value("thingId").toUuid(), sdMap.value("stateTypeId").toUuid(), op, sdMap.value("value"), stateEvaluator);
|
||||||
} else {
|
} else {
|
||||||
sd = new StateDescriptor(sdMap.value("interface").toString(), sdMap.value("interfaceState").toString(), op, sdMap.value("value"), stateEvaluator);
|
sd = new StateDescriptor(sdMap.value("interface").toString(), sdMap.value("interfaceState").toString(), op, sdMap.value("value"), stateEvaluator);
|
||||||
}
|
}
|
||||||
@ -315,11 +311,11 @@ void RuleManager::parseRuleExitActions(const QVariantList &ruleActions, Rule *ru
|
|||||||
RuleAction *RuleManager::parseRuleAction(const QVariantMap &ruleAction)
|
RuleAction *RuleManager::parseRuleAction(const QVariantMap &ruleAction)
|
||||||
{
|
{
|
||||||
RuleAction *ret = new RuleAction();
|
RuleAction *ret = new RuleAction();
|
||||||
if (ruleAction.contains("deviceId") && ruleAction.contains("actionTypeId")) {
|
if (ruleAction.contains("thingId") && ruleAction.contains("actionTypeId")) {
|
||||||
ret->setDeviceId(ruleAction.value("deviceId").toUuid());
|
ret->setThingId(ruleAction.value("thingId").toUuid());
|
||||||
ret->setActionTypeId(ruleAction.value("actionTypeId").toUuid());
|
ret->setActionTypeId(ruleAction.value("actionTypeId").toUuid());
|
||||||
} else if (ruleAction.contains("deviceId") && ruleAction.contains("browserItemId")) {
|
} else if (ruleAction.contains("thingId") && ruleAction.contains("browserItemId")) {
|
||||||
ret->setDeviceId(ruleAction.value("deviceId").toUuid());
|
ret->setThingId(ruleAction.value("thingId").toUuid());
|
||||||
ret->setBrowserItemId(ruleAction.value("browserItemId").toString());
|
ret->setBrowserItemId(ruleAction.value("browserItemId").toString());
|
||||||
} else {
|
} else {
|
||||||
ret->setInterfaceName(ruleAction.value("interface").toString());
|
ret->setInterfaceName(ruleAction.value("interface").toString());
|
||||||
@ -332,7 +328,7 @@ RuleAction *RuleManager::parseRuleAction(const QVariantMap &ruleAction)
|
|||||||
param->setValue(ruleActionParamVariant.toMap().value("value"));
|
param->setValue(ruleActionParamVariant.toMap().value("value"));
|
||||||
param->setEventTypeId(ruleActionParamVariant.toMap().value("eventTypeId").toString());
|
param->setEventTypeId(ruleActionParamVariant.toMap().value("eventTypeId").toString());
|
||||||
param->setEventParamTypeId(ruleActionParamVariant.toMap().value("eventParamTypeId").toString());
|
param->setEventParamTypeId(ruleActionParamVariant.toMap().value("eventParamTypeId").toString());
|
||||||
param->setStateDeviceId(ruleActionParamVariant.toMap().value("stateDeviceId").toString());
|
param->setStateThingId(ruleActionParamVariant.toMap().value("stateThingId").toString());
|
||||||
param->setStateTypeId(ruleActionParamVariant.toMap().value("stateTypeId").toString());
|
param->setStateTypeId(ruleActionParamVariant.toMap().value("stateTypeId").toString());
|
||||||
ret->ruleActionParams()->addRuleActionParam(param);
|
ret->ruleActionParams()->addRuleActionParam(param);
|
||||||
}
|
}
|
||||||
@ -415,11 +411,7 @@ QVariantList RuleManager::packEventDescriptors(EventDescriptors *eventDescriptor
|
|||||||
EventDescriptor* eventDescriptor = eventDescriptors->get(i);
|
EventDescriptor* eventDescriptor = eventDescriptors->get(i);
|
||||||
if (!eventDescriptor->thingId().isNull() && !eventDescriptor->eventTypeId().isNull()) {
|
if (!eventDescriptor->thingId().isNull() && !eventDescriptor->eventTypeId().isNull()) {
|
||||||
eventDescriptorMap.insert("eventTypeId", eventDescriptor->eventTypeId());
|
eventDescriptorMap.insert("eventTypeId", eventDescriptor->eventTypeId());
|
||||||
if (m_jsonClient->ensureServerVersion("5.0")) {
|
eventDescriptorMap.insert("thingId", eventDescriptor->thingId());
|
||||||
eventDescriptorMap.insert("thingId", eventDescriptor->thingId());
|
|
||||||
} else {
|
|
||||||
eventDescriptorMap.insert("deviceId", eventDescriptor->thingId());
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
eventDescriptorMap.insert("interface", eventDescriptor->interfaceName());
|
eventDescriptorMap.insert("interface", eventDescriptor->interfaceName());
|
||||||
eventDescriptorMap.insert("interfaceEvent", eventDescriptor->interfaceEvent());
|
eventDescriptorMap.insert("interfaceEvent", eventDescriptor->interfaceEvent());
|
||||||
@ -512,11 +504,11 @@ QVariantList RuleManager::packRuleActions(RuleActions *ruleActions)
|
|||||||
for (int i = 0; i < ruleActions->rowCount(); i++) {
|
for (int i = 0; i < ruleActions->rowCount(); i++) {
|
||||||
QVariantMap ruleAction;
|
QVariantMap ruleAction;
|
||||||
RuleAction *ra = ruleActions->get(i);
|
RuleAction *ra = ruleActions->get(i);
|
||||||
if (!ra->actionTypeId().isNull() && !ra->deviceId().isNull()) {
|
if (!ra->actionTypeId().isNull() && !ra->thingId().isNull()) {
|
||||||
ruleAction.insert("deviceId", ra->deviceId());
|
ruleAction.insert("thingId", ra->thingId());
|
||||||
ruleAction.insert("actionTypeId", ra->actionTypeId());
|
ruleAction.insert("actionTypeId", ra->actionTypeId());
|
||||||
} else if (!ra->deviceId().isNull() && !ra->browserItemId().isEmpty()) {
|
} else if (!ra->thingId().isNull() && !ra->browserItemId().isEmpty()) {
|
||||||
ruleAction.insert("deviceId", ra->deviceId());
|
ruleAction.insert("thingId", ra->thingId());
|
||||||
ruleAction.insert("browserItemId", ra->browserItemId());
|
ruleAction.insert("browserItemId", ra->browserItemId());
|
||||||
} else {
|
} else {
|
||||||
ruleAction.insert("interface", ra->interfaceName());
|
ruleAction.insert("interface", ra->interfaceName());
|
||||||
@ -538,7 +530,7 @@ QVariantList RuleManager::packRuleActions(RuleActions *ruleActions)
|
|||||||
ruleActionParam.insert("eventTypeId", rap->eventTypeId());
|
ruleActionParam.insert("eventTypeId", rap->eventTypeId());
|
||||||
ruleActionParam.insert("eventParamTypeId", rap->eventParamTypeId());
|
ruleActionParam.insert("eventParamTypeId", rap->eventParamTypeId());
|
||||||
} else {
|
} else {
|
||||||
ruleActionParam.insert("stateDeviceId", rap->stateDeviceId());
|
ruleActionParam.insert("stateThingId", rap->stateThingId());
|
||||||
ruleActionParam.insert("stateTypeId", rap->stateTypeId());
|
ruleActionParam.insert("stateTypeId", rap->stateTypeId());
|
||||||
}
|
}
|
||||||
ruleActionParams.append(ruleActionParam);
|
ruleActionParams.append(ruleActionParam);
|
||||||
@ -557,8 +549,8 @@ QVariantMap RuleManager::packStateEvaluator(StateEvaluator *stateEvaluator)
|
|||||||
QMetaEnum stateOperatorEnum = QMetaEnum::fromType<StateEvaluator::StateOperator>();
|
QMetaEnum stateOperatorEnum = QMetaEnum::fromType<StateEvaluator::StateOperator>();
|
||||||
ret.insert("operator", stateOperatorEnum.valueToKey(stateEvaluator->stateOperator()));
|
ret.insert("operator", stateOperatorEnum.valueToKey(stateEvaluator->stateOperator()));
|
||||||
QVariantMap stateDescriptor;
|
QVariantMap stateDescriptor;
|
||||||
if (!stateEvaluator->stateDescriptor()->deviceId().isNull() && !stateEvaluator->stateDescriptor()->stateTypeId().isNull()) {
|
if (!stateEvaluator->stateDescriptor()->thingId().isNull() && !stateEvaluator->stateDescriptor()->stateTypeId().isNull()) {
|
||||||
stateDescriptor.insert("deviceId", stateEvaluator->stateDescriptor()->deviceId());
|
stateDescriptor.insert("thingId", stateEvaluator->stateDescriptor()->thingId());
|
||||||
stateDescriptor.insert("stateTypeId", stateEvaluator->stateDescriptor()->stateTypeId());
|
stateDescriptor.insert("stateTypeId", stateEvaluator->stateDescriptor()->stateTypeId());
|
||||||
} else {
|
} else {
|
||||||
stateDescriptor.insert("interface", stateEvaluator->stateDescriptor()->interfaceName());
|
stateDescriptor.insert("interface", stateEvaluator->stateDescriptor()->interfaceName());
|
||||||
|
|||||||
@ -42,7 +42,7 @@
|
|||||||
#include "types/ruleactionparam.h"
|
#include "types/ruleactionparam.h"
|
||||||
#include "types/ruleactionparams.h"
|
#include "types/ruleactionparams.h"
|
||||||
#include "types/repeatingoption.h"
|
#include "types/repeatingoption.h"
|
||||||
#include "devicesproxy.h"
|
#include "thingsproxy.h"
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
@ -297,7 +297,7 @@ bool RuleTemplatesFilterModel::filterAcceptsRow(int source_row, const QModelInde
|
|||||||
|
|
||||||
|
|
||||||
// Make sure we have all the things to satisfy all of the templates events/states/actions
|
// Make sure we have all the things to satisfy all of the templates events/states/actions
|
||||||
if (m_filterDevicesProxy && !thingsSatisfyRuleTemplate(t, m_filterDevicesProxy)) {
|
if (m_filterThingsProxy && !thingsSatisfyRuleTemplate(t, m_filterThingsProxy)) {
|
||||||
qDebug() << "Filtering out" << t->description() << "because required no thing in the provided filter proxy satisfies definitions";
|
qDebug() << "Filtering out" << t->description() << "because required no thing in the provided filter proxy satisfies definitions";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -330,7 +330,7 @@ bool RuleTemplatesFilterModel::stateEvaluatorTemplateContainsInterface(StateEval
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RuleTemplatesFilterModel::thingsSatisfyRuleTemplate(RuleTemplate *ruleTemplate, DevicesProxy *things) const
|
bool RuleTemplatesFilterModel::thingsSatisfyRuleTemplate(RuleTemplate *ruleTemplate, ThingsProxy *things) const
|
||||||
{
|
{
|
||||||
// For improved performance it would be better to just cycle things once and flag satisfied states/events/actions
|
// For improved performance it would be better to just cycle things once and flag satisfied states/events/actions
|
||||||
// instead of looping over all things for every entry, but for the amount of templates we have right now
|
// instead of looping over all things for every entry, but for the amount of templates we have right now
|
||||||
@ -340,7 +340,7 @@ bool RuleTemplatesFilterModel::thingsSatisfyRuleTemplate(RuleTemplate *ruleTempl
|
|||||||
foreach (const QString &interfaceName, ruleTemplate->interfaces()) {
|
foreach (const QString &interfaceName, ruleTemplate->interfaces()) {
|
||||||
bool haveThing = false;
|
bool haveThing = false;
|
||||||
for (int i = 0; i < things->rowCount(); i++) {
|
for (int i = 0; i < things->rowCount(); i++) {
|
||||||
Device *thing = things->get(i);
|
Thing *thing = things->get(i);
|
||||||
if (thing->thingClass()->interfaces().contains(interfaceName)) {
|
if (thing->thingClass()->interfaces().contains(interfaceName)) {
|
||||||
haveThing = true;
|
haveThing = true;
|
||||||
break;
|
break;
|
||||||
@ -357,7 +357,7 @@ bool RuleTemplatesFilterModel::thingsSatisfyRuleTemplate(RuleTemplate *ruleTempl
|
|||||||
EventDescriptorTemplate *eventDescriptorTemplate = ruleTemplate->eventDescriptorTemplates()->get(i);
|
EventDescriptorTemplate *eventDescriptorTemplate = ruleTemplate->eventDescriptorTemplates()->get(i);
|
||||||
bool haveThing = false;
|
bool haveThing = false;
|
||||||
for (int j = 0; j < things->rowCount(); j++) {
|
for (int j = 0; j < things->rowCount(); j++) {
|
||||||
Device *thing = things->get(j);
|
Thing *thing = things->get(j);
|
||||||
if (thing->thingClass()->eventTypes()->findByName(eventDescriptorTemplate->eventName())) {
|
if (thing->thingClass()->eventTypes()->findByName(eventDescriptorTemplate->eventName())) {
|
||||||
haveThing = true;
|
haveThing = true;
|
||||||
break;
|
break;
|
||||||
@ -378,7 +378,7 @@ bool RuleTemplatesFilterModel::thingsSatisfyRuleTemplate(RuleTemplate *ruleTempl
|
|||||||
RuleActionTemplate *ruleActionTemplate = ruleTemplate->ruleActionTemplates()->get(i);
|
RuleActionTemplate *ruleActionTemplate = ruleTemplate->ruleActionTemplates()->get(i);
|
||||||
bool haveThing = false;
|
bool haveThing = false;
|
||||||
for (int j = 0; j < things->rowCount(); j++) {
|
for (int j = 0; j < things->rowCount(); j++) {
|
||||||
Device *thing = things->get(j);
|
Thing *thing = things->get(j);
|
||||||
if (thing->thingClass()->actionTypes()->findByName(ruleActionTemplate->actionName())) {
|
if (thing->thingClass()->actionTypes()->findByName(ruleActionTemplate->actionName())) {
|
||||||
haveThing = true;
|
haveThing = true;
|
||||||
break;
|
break;
|
||||||
@ -394,7 +394,7 @@ bool RuleTemplatesFilterModel::thingsSatisfyRuleTemplate(RuleTemplate *ruleTempl
|
|||||||
RuleActionTemplate *ruleExitActionTemplate = ruleTemplate->ruleExitActionTemplates()->get(i);
|
RuleActionTemplate *ruleExitActionTemplate = ruleTemplate->ruleExitActionTemplates()->get(i);
|
||||||
bool haveThing = false;
|
bool haveThing = false;
|
||||||
for (int j = 0; j < things->rowCount(); j++) {
|
for (int j = 0; j < things->rowCount(); j++) {
|
||||||
Device *thing = things->get(j);
|
Thing *thing = things->get(j);
|
||||||
if (thing->thingClass()->actionTypes()->findByName(ruleExitActionTemplate->actionName())) {
|
if (thing->thingClass()->actionTypes()->findByName(ruleExitActionTemplate->actionName())) {
|
||||||
haveThing = true;
|
haveThing = true;
|
||||||
break;
|
break;
|
||||||
@ -409,12 +409,12 @@ bool RuleTemplatesFilterModel::thingsSatisfyRuleTemplate(RuleTemplate *ruleTempl
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RuleTemplatesFilterModel::thingsSatisfyStateEvaluatorTemplate(StateEvaluatorTemplate *stateEvaluatorTemplate, DevicesProxy *things) const
|
bool RuleTemplatesFilterModel::thingsSatisfyStateEvaluatorTemplate(StateEvaluatorTemplate *stateEvaluatorTemplate, ThingsProxy *things) const
|
||||||
{
|
{
|
||||||
if (stateEvaluatorTemplate->stateDescriptorTemplate()) {
|
if (stateEvaluatorTemplate->stateDescriptorTemplate()) {
|
||||||
bool haveThing = false;
|
bool haveThing = false;
|
||||||
for (int i = 0; i < things->rowCount(); i++) {
|
for (int i = 0; i < things->rowCount(); i++) {
|
||||||
Device *thing = things->get(i);
|
Thing *thing = things->get(i);
|
||||||
if (thing->thingClass()->stateTypes()->findByName(stateEvaluatorTemplate->stateDescriptorTemplate()->stateName())) {
|
if (thing->thingClass()->stateTypes()->findByName(stateEvaluatorTemplate->stateDescriptorTemplate()->stateName())) {
|
||||||
haveThing = true;
|
haveThing = true;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@ -37,8 +37,8 @@ class RuleTemplate;
|
|||||||
class StateEvaluatorTemplate;
|
class StateEvaluatorTemplate;
|
||||||
class TimeDescriptorTemplate;
|
class TimeDescriptorTemplate;
|
||||||
class RepeatingOption;
|
class RepeatingOption;
|
||||||
class DevicesProxy;
|
class ThingsProxy;
|
||||||
class Device;
|
class Thing;
|
||||||
|
|
||||||
class RuleTemplates : public QAbstractListModel
|
class RuleTemplates : public QAbstractListModel
|
||||||
{
|
{
|
||||||
@ -79,7 +79,7 @@ class RuleTemplatesFilterModel: public QSortFilterProxyModel
|
|||||||
Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
|
Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
|
||||||
Q_PROPERTY(RuleTemplates* ruleTemplates READ ruleTemplates WRITE setRuleTemplates NOTIFY ruleTemplatesChanged)
|
Q_PROPERTY(RuleTemplates* ruleTemplates READ ruleTemplates WRITE setRuleTemplates NOTIFY ruleTemplatesChanged)
|
||||||
Q_PROPERTY(QStringList filterInterfaceNames READ filterInterfaceNames WRITE setFilterInterfaceNames NOTIFY filterInterfaceNamesChanged)
|
Q_PROPERTY(QStringList filterInterfaceNames READ filterInterfaceNames WRITE setFilterInterfaceNames NOTIFY filterInterfaceNamesChanged)
|
||||||
Q_PROPERTY(DevicesProxy* filterByDevices READ filterByDevices WRITE setFilterByDevices NOTIFY filterByDevicesChanged)
|
Q_PROPERTY(ThingsProxy* filterByThings READ filterByThings WRITE setFilterByThings NOTIFY filterByThingsChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
RuleTemplatesFilterModel(QObject *parent = nullptr): QSortFilterProxyModel(parent) {}
|
RuleTemplatesFilterModel(QObject *parent = nullptr): QSortFilterProxyModel(parent) {}
|
||||||
@ -87,8 +87,8 @@ public:
|
|||||||
void setRuleTemplates(RuleTemplates* ruleTemplates) { if (m_ruleTemplates != ruleTemplates) { m_ruleTemplates = ruleTemplates; setSourceModel(ruleTemplates); emit ruleTemplatesChanged(); invalidateFilter(); emit countChanged();}}
|
void setRuleTemplates(RuleTemplates* ruleTemplates) { if (m_ruleTemplates != ruleTemplates) { m_ruleTemplates = ruleTemplates; setSourceModel(ruleTemplates); emit ruleTemplatesChanged(); invalidateFilter(); emit countChanged();}}
|
||||||
QStringList filterInterfaceNames() const { return m_filterInterfaceNames; }
|
QStringList filterInterfaceNames() const { return m_filterInterfaceNames; }
|
||||||
void setFilterInterfaceNames(const QStringList &filterInterfaceNames) { if (m_filterInterfaceNames != filterInterfaceNames) { m_filterInterfaceNames = filterInterfaceNames; emit filterInterfaceNamesChanged(); invalidateFilter(); emit countChanged(); }}
|
void setFilterInterfaceNames(const QStringList &filterInterfaceNames) { if (m_filterInterfaceNames != filterInterfaceNames) { m_filterInterfaceNames = filterInterfaceNames; emit filterInterfaceNamesChanged(); invalidateFilter(); emit countChanged(); }}
|
||||||
DevicesProxy* filterByDevices() const { return m_filterDevicesProxy; }
|
ThingsProxy* filterByThings() const { return m_filterThingsProxy; }
|
||||||
void setFilterByDevices(DevicesProxy* filterDevicesProxy) {if (m_filterDevicesProxy != filterDevicesProxy) { m_filterDevicesProxy = filterDevicesProxy; emit filterByDevicesChanged(); invalidateFilter(); }}
|
void setFilterByThings(ThingsProxy* filterThingsProxy) {if (m_filterThingsProxy != filterThingsProxy) { m_filterThingsProxy = filterThingsProxy; emit filterByThingsChanged(); invalidateFilter(); }}
|
||||||
Q_INVOKABLE RuleTemplate* get(int index) {
|
Q_INVOKABLE RuleTemplate* get(int index) {
|
||||||
if (index < 0 || index >= rowCount()) {
|
if (index < 0 || index >= rowCount()) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@ -101,18 +101,18 @@ protected:
|
|||||||
signals:
|
signals:
|
||||||
void ruleTemplatesChanged();
|
void ruleTemplatesChanged();
|
||||||
void filterInterfaceNamesChanged();
|
void filterInterfaceNamesChanged();
|
||||||
void filterByDevicesChanged();
|
void filterByThingsChanged();
|
||||||
void countChanged();
|
void countChanged();
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool thingsSatisfyRuleTemplate(RuleTemplate *ruleTemplate, DevicesProxy *things) const;
|
bool thingsSatisfyRuleTemplate(RuleTemplate *ruleTemplate, ThingsProxy *things) const;
|
||||||
bool thingsSatisfyStateEvaluatorTemplate(StateEvaluatorTemplate *stateEvaluatorTemplate, DevicesProxy *things) const;
|
bool thingsSatisfyStateEvaluatorTemplate(StateEvaluatorTemplate *stateEvaluatorTemplate, ThingsProxy *things) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
RuleTemplates* m_ruleTemplates = nullptr;
|
RuleTemplates* m_ruleTemplates = nullptr;
|
||||||
QStringList m_filterInterfaceNames;
|
QStringList m_filterInterfaceNames;
|
||||||
DevicesProxy* m_filterDevicesProxy = nullptr;
|
ThingsProxy* m_filterThingsProxy = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // RULETEMPLATES_H
|
#endif // RULETEMPLATES_H
|
||||||
|
|||||||
@ -168,9 +168,9 @@ void CodeCompletion::update()
|
|||||||
|
|
||||||
QRegExp thingIdExp(".*thingId: \"[a-zA-ZÀ-ž0-9- ]*");
|
QRegExp thingIdExp(".*thingId: \"[a-zA-ZÀ-ž0-9- ]*");
|
||||||
if (thingIdExp.exactMatch(blockText)) {
|
if (thingIdExp.exactMatch(blockText)) {
|
||||||
for (int i = 0; i < m_engine->deviceManager()->devices()->rowCount(); i++) {
|
for (int i = 0; i < m_engine->thingManager()->things()->rowCount(); i++) {
|
||||||
Device *dev = m_engine->deviceManager()->devices()->get(i);
|
Thing *thing = m_engine->thingManager()->things()->get(i);
|
||||||
entries.append(CompletionModel::Entry(dev->id().toString() + "\" // " + dev->name(), dev->name(), "thing", dev->thingClass()->interfaces().join(",")));
|
entries.append(CompletionModel::Entry(thing->id().toString() + "\" // " + thing->name(), thing->name(), "thing", thing->thingClass()->interfaces().join(",")));
|
||||||
}
|
}
|
||||||
blockText.remove(QRegExp(".*thingId: \""));
|
blockText.remove(QRegExp(".*thingId: \""));
|
||||||
m_model->update(entries);
|
m_model->update(entries);
|
||||||
@ -189,13 +189,13 @@ void CodeCompletion::update()
|
|||||||
thingId = info.properties.value("thingId");
|
thingId = info.properties.value("thingId");
|
||||||
|
|
||||||
qDebug() << "selected thingId" << thingId;
|
qDebug() << "selected thingId" << thingId;
|
||||||
Device *device = m_engine->deviceManager()->devices()->getDevice(thingId);
|
Thing *thing = m_engine->thingManager()->things()->getThing(thingId);
|
||||||
if (!device) {
|
if (!thing) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < device->thingClass()->stateTypes()->rowCount(); i++) {
|
for (int i = 0; i < thing->thingClass()->stateTypes()->rowCount(); i++) {
|
||||||
StateType *stateType = device->thingClass()->stateTypes()->get(i);
|
StateType *stateType = thing->thingClass()->stateTypes()->get(i);
|
||||||
entries.append(CompletionModel::Entry(stateType->id().toString() + "\" // " + stateType->name(), stateType->name(), "stateType"));
|
entries.append(CompletionModel::Entry(stateType->id().toString() + "\" // " + stateType->name(), stateType->name(), "stateType"));
|
||||||
}
|
}
|
||||||
blockText.remove(QRegExp(".*stateTypeId: \""));
|
blockText.remove(QRegExp(".*stateTypeId: \""));
|
||||||
@ -217,14 +217,14 @@ void CodeCompletion::update()
|
|||||||
thingId = info.properties.value("thingId");
|
thingId = info.properties.value("thingId");
|
||||||
|
|
||||||
qDebug() << "selected thingId" << thingId;
|
qDebug() << "selected thingId" << thingId;
|
||||||
Device *device = m_engine->deviceManager()->devices()->getDevice(thingId);
|
Thing *thing = m_engine->thingManager()->things()->getThing(thingId);
|
||||||
if (!device) {
|
if (!thing) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
qDebug() << "Device is" << device->name();
|
qDebug() << "Thing is" << thing->name();
|
||||||
|
|
||||||
for (int i = 0; i < device->thingClass()->stateTypes()->rowCount(); i++) {
|
for (int i = 0; i < thing->thingClass()->stateTypes()->rowCount(); i++) {
|
||||||
StateType *stateType = device->thingClass()->stateTypes()->get(i);
|
StateType *stateType = thing->thingClass()->stateTypes()->get(i);
|
||||||
entries.append(CompletionModel::Entry(stateType->name() + "\"", stateType->name(), "stateType"));
|
entries.append(CompletionModel::Entry(stateType->name() + "\"", stateType->name(), "stateType"));
|
||||||
}
|
}
|
||||||
blockText.remove(QRegExp(".*stateName: \""));
|
blockText.remove(QRegExp(".*stateName: \""));
|
||||||
@ -244,13 +244,13 @@ void CodeCompletion::update()
|
|||||||
thingId = info.properties.value("thingId");
|
thingId = info.properties.value("thingId");
|
||||||
|
|
||||||
qDebug() << "selected thingId" << thingId;
|
qDebug() << "selected thingId" << thingId;
|
||||||
Device *device = m_engine->deviceManager()->devices()->getDevice(thingId);
|
Thing *thing = m_engine->thingManager()->things()->getThing(thingId);
|
||||||
if (!device) {
|
if (!thing) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < device->thingClass()->actionTypes()->rowCount(); i++) {
|
for (int i = 0; i < thing->thingClass()->actionTypes()->rowCount(); i++) {
|
||||||
ActionType *actionType = device->thingClass()->actionTypes()->get(i);
|
ActionType *actionType = thing->thingClass()->actionTypes()->get(i);
|
||||||
entries.append(CompletionModel::Entry(actionType->id().toString() + "\" // " + actionType->name(), actionType->name(), "actionType"));
|
entries.append(CompletionModel::Entry(actionType->id().toString() + "\" // " + actionType->name(), actionType->name(), "actionType"));
|
||||||
}
|
}
|
||||||
blockText.remove(QRegExp(".*actionTypeId: \""));
|
blockText.remove(QRegExp(".*actionTypeId: \""));
|
||||||
@ -270,7 +270,7 @@ void CodeCompletion::update()
|
|||||||
if (info.properties.contains("thingId")) {
|
if (info.properties.contains("thingId")) {
|
||||||
QString thingId = info.properties.value("thingId");
|
QString thingId = info.properties.value("thingId");
|
||||||
qDebug() << "selected thingId" << thingId;
|
qDebug() << "selected thingId" << thingId;
|
||||||
Device *thing = m_engine->thingManager()->things()->getThing(thingId);
|
Thing *thing = m_engine->thingManager()->things()->getThing(thingId);
|
||||||
if (!thing) {
|
if (!thing) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -308,13 +308,13 @@ void CodeCompletion::update()
|
|||||||
thingId = info.properties.value("thingId");
|
thingId = info.properties.value("thingId");
|
||||||
|
|
||||||
qDebug() << "selected thingId" << thingId;
|
qDebug() << "selected thingId" << thingId;
|
||||||
Device *device = m_engine->deviceManager()->devices()->getDevice(thingId);
|
Thing *thing= m_engine->thingManager()->things()->getThing(thingId);
|
||||||
if (!device) {
|
if (!thing) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < device->thingClass()->eventTypes()->rowCount(); i++) {
|
for (int i = 0; i < thing->thingClass()->eventTypes()->rowCount(); i++) {
|
||||||
EventType *eventType = device->thingClass()->eventTypes()->get(i);
|
EventType *eventType = thing->thingClass()->eventTypes()->get(i);
|
||||||
entries.append(CompletionModel::Entry(eventType->id().toString() + "\" // " + eventType->name(), eventType->name(), "eventType"));
|
entries.append(CompletionModel::Entry(eventType->id().toString() + "\" // " + eventType->name(), eventType->name(), "eventType"));
|
||||||
}
|
}
|
||||||
blockText.remove(QRegExp(".*eventTypeId: \""));
|
blockText.remove(QRegExp(".*eventTypeId: \""));
|
||||||
@ -331,7 +331,7 @@ void CodeCompletion::update()
|
|||||||
EventTypes *eventTypes = nullptr;
|
EventTypes *eventTypes = nullptr;
|
||||||
if (info.properties.contains("thingId")) {
|
if (info.properties.contains("thingId")) {
|
||||||
QString thingId = info.properties.value("thingId");
|
QString thingId = info.properties.value("thingId");
|
||||||
Device *thing = m_engine->thingManager()->things()->getThing(thingId);
|
Thing *thing = m_engine->thingManager()->things()->getThing(thingId);
|
||||||
if (!thing) {
|
if (!thing) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -454,7 +454,7 @@ void CodeCompletion::update()
|
|||||||
if (blockPosition >= 0) {
|
if (blockPosition >= 0) {
|
||||||
if (blockInfo.valid) {
|
if (blockInfo.valid) {
|
||||||
QString thingId = blockInfo.properties.value("thingId");
|
QString thingId = blockInfo.properties.value("thingId");
|
||||||
Device *d = m_engine->thingManager()->things()->getDevice(QUuid(thingId));
|
Thing *d = m_engine->thingManager()->things()->getThing(QUuid(thingId));
|
||||||
if (d) {
|
if (d) {
|
||||||
ActionType *at = nullptr;
|
ActionType *at = nullptr;
|
||||||
if (blockInfo.properties.contains("actionTypeId")) {
|
if (blockInfo.properties.contains("actionTypeId")) {
|
||||||
|
|||||||
@ -31,8 +31,8 @@
|
|||||||
#include "scriptsyntaxhighlighter.h"
|
#include "scriptsyntaxhighlighter.h"
|
||||||
|
|
||||||
#include "engine.h"
|
#include "engine.h"
|
||||||
#include "devicemanager.h"
|
#include "thingmanager.h"
|
||||||
#include "devices.h"
|
#include "things.h"
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QMetaObject>
|
#include <QMetaObject>
|
||||||
@ -59,7 +59,7 @@ private:
|
|||||||
BlockStateNone = 0,
|
BlockStateNone = 0,
|
||||||
BlockStateImport = 1,
|
BlockStateImport = 1,
|
||||||
BlockStateAction,
|
BlockStateAction,
|
||||||
BlockstateDeviceId,
|
BlockstateThingId,
|
||||||
};
|
};
|
||||||
struct HighlightingRule
|
struct HighlightingRule
|
||||||
{
|
{
|
||||||
@ -202,8 +202,8 @@ void ScriptSyntaxHighlighterPrivate::highlightBlock(const QString &text)
|
|||||||
setCurrentBlockState(BlockStateImport);
|
setCurrentBlockState(BlockStateImport);
|
||||||
} else if (text.trimmed().startsWith("Action")) {
|
} else if (text.trimmed().startsWith("Action")) {
|
||||||
setCurrentBlockState(BlockStateAction);
|
setCurrentBlockState(BlockStateAction);
|
||||||
} else if (text.trimmed().startsWith("deviceId:")) {
|
} else if (text.trimmed().startsWith("thingId:")) {
|
||||||
setCurrentBlockState(BlockstateDeviceId);
|
setCurrentBlockState(BlockstateThingId);
|
||||||
} else {
|
} else {
|
||||||
setCurrentBlockState(0);
|
setCurrentBlockState(0);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -72,7 +72,7 @@ int TagsManager::tagThing(const QString &thingId, const QString &tagId, const QS
|
|||||||
{
|
{
|
||||||
QVariantMap params;
|
QVariantMap params;
|
||||||
QVariantMap tag;
|
QVariantMap tag;
|
||||||
tag.insert("deviceId", thingId);
|
tag.insert("thingId", thingId);
|
||||||
tag.insert("appId", "nymea:app");
|
tag.insert("appId", "nymea:app");
|
||||||
tag.insert("tagId", tagId);
|
tag.insert("tagId", tagId);
|
||||||
tag.insert("value", value);
|
tag.insert("value", value);
|
||||||
@ -84,7 +84,7 @@ int TagsManager::untagThing(const QString &thingId, const QString &tagId)
|
|||||||
{
|
{
|
||||||
QVariantMap params;
|
QVariantMap params;
|
||||||
QVariantMap tag;
|
QVariantMap tag;
|
||||||
tag.insert("deviceId", thingId);
|
tag.insert("thingId", thingId);
|
||||||
tag.insert("appId", "nymea:app");
|
tag.insert("appId", "nymea:app");
|
||||||
tag.insert("tagId", tagId);
|
tag.insert("tagId", tagId);
|
||||||
params.insert("tag", tag);
|
params.insert("tag", tag);
|
||||||
@ -133,12 +133,7 @@ void TagsManager::handleTagsNotification(const QVariantMap ¶ms)
|
|||||||
} else if (notification == "Tags.TagRemoved") {
|
} else if (notification == "Tags.TagRemoved") {
|
||||||
for (int i = 0; i < m_tags->rowCount(); i++) {
|
for (int i = 0; i < m_tags->rowCount(); i++) {
|
||||||
Tag* tag = m_tags->get(i);
|
Tag* tag = m_tags->get(i);
|
||||||
QUuid thingId;
|
QUuid thingId = tagMap.value("thingId").toUuid();
|
||||||
if (m_jsonClient->ensureServerVersion("5.0")) {
|
|
||||||
thingId = tagMap.value("thingId").toUuid();
|
|
||||||
} else {
|
|
||||||
thingId = tagMap.value("deviceId").toUuid();
|
|
||||||
}
|
|
||||||
QUuid ruleId = tagMap.value("ruleId").toUuid();
|
QUuid ruleId = tagMap.value("ruleId").toUuid();
|
||||||
QString tagId = tagMap.value("tagId").toString();
|
QString tagId = tagMap.value("tagId").toString();
|
||||||
if (thingId == tag->thingId() && ruleId == tag->ruleId() && tagId == tag->tagId()) {
|
if (thingId == tag->thingId() && ruleId == tag->ruleId() && tagId == tag->tagId()) {
|
||||||
@ -149,12 +144,7 @@ void TagsManager::handleTagsNotification(const QVariantMap ¶ms)
|
|||||||
} else if (notification == "Tags.TagValueChanged") {
|
} else if (notification == "Tags.TagValueChanged") {
|
||||||
for (int i = 0; i < m_tags->rowCount(); i++) {
|
for (int i = 0; i < m_tags->rowCount(); i++) {
|
||||||
Tag* tag = m_tags->get(i);
|
Tag* tag = m_tags->get(i);
|
||||||
QUuid thingId;
|
QUuid thingId = tagMap.value("thingId").toUuid();
|
||||||
if (m_jsonClient->ensureServerVersion("5.0")) {
|
|
||||||
thingId = tagMap.value("thingId").toUuid();
|
|
||||||
} else {
|
|
||||||
thingId = tagMap.value("deviceId").toUuid();
|
|
||||||
}
|
|
||||||
QUuid ruleId = tagMap.value("ruleId").toUuid();
|
QUuid ruleId = tagMap.value("ruleId").toUuid();
|
||||||
QString tagId = tagMap.value("tagId").toString();
|
QString tagId = tagMap.value("tagId").toString();
|
||||||
if (thingId == tag->thingId() && ruleId == tag->ruleId() && tagId == tag->tagId()) {
|
if (thingId == tag->thingId() && ruleId == tag->ruleId() && tagId == tag->tagId()) {
|
||||||
@ -191,12 +181,7 @@ void TagsManager::removeTagReply(int commandId, const QVariantMap ¶ms)
|
|||||||
|
|
||||||
Tag* TagsManager::unpackTag(const QVariantMap &tagMap)
|
Tag* TagsManager::unpackTag(const QVariantMap &tagMap)
|
||||||
{
|
{
|
||||||
QString thingId;
|
QString thingId = tagMap.value("thingId").toString();
|
||||||
if (m_jsonClient->ensureServerVersion("5.0")) {
|
|
||||||
thingId = tagMap.value("thingId").toString();
|
|
||||||
} else {
|
|
||||||
thingId = tagMap.value("deviceId").toString();
|
|
||||||
}
|
|
||||||
QString ruleId = tagMap.value("ruleId").toString();
|
QString ruleId = tagMap.value("ruleId").toString();
|
||||||
QString tagId = tagMap.value("tagId").toString();
|
QString tagId = tagMap.value("tagId").toString();
|
||||||
QString value = tagMap.value("value").toString();
|
QString value = tagMap.value("value").toString();
|
||||||
@ -208,7 +193,7 @@ Tag* TagsManager::unpackTag(const QVariantMap &tagMap)
|
|||||||
tag = new Tag(tagId, value);
|
tag = new Tag(tagId, value);
|
||||||
tag->setRuleId(ruleId);
|
tag->setRuleId(ruleId);
|
||||||
} else {
|
} else {
|
||||||
qWarning() << "Invalid tag. Neither deviceId nor ruleId are set. Skipping...";
|
qWarning() << "Invalid tag. Neither thingId nor ruleId are set. Skipping...";
|
||||||
tag->deleteLater();
|
tag->deleteLater();
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,93 +28,93 @@
|
|||||||
*
|
*
|
||||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
#include "deviceclasses.h"
|
#include "thingclasses.h"
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
DeviceClasses::DeviceClasses(QObject *parent) :
|
ThingClasses::ThingClasses(QObject *parent) :
|
||||||
QAbstractListModel(parent)
|
QAbstractListModel(parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<DeviceClass *> DeviceClasses::deviceClasses()
|
QList<ThingClass *> ThingClasses::thingClasses()
|
||||||
{
|
{
|
||||||
return m_deviceClasses;
|
return m_thingClasses;
|
||||||
}
|
}
|
||||||
|
|
||||||
int DeviceClasses::rowCount(const QModelIndex &parent) const
|
int ThingClasses::rowCount(const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
Q_UNUSED(parent)
|
Q_UNUSED(parent)
|
||||||
return m_deviceClasses.count();
|
return m_thingClasses.count();
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant DeviceClasses::data(const QModelIndex &index, int role) const
|
QVariant ThingClasses::data(const QModelIndex &index, int role) const
|
||||||
{
|
{
|
||||||
if (index.row() < 0 || index.row() >= m_deviceClasses.count())
|
if (index.row() < 0 || index.row() >= m_thingClasses.count())
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
||||||
DeviceClass *deviceClass = m_deviceClasses.at(index.row());
|
ThingClass *thingClass = m_thingClasses.at(index.row());
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case RoleId:
|
case RoleId:
|
||||||
return deviceClass->id().toString();
|
return thingClass->id().toString();
|
||||||
case RoleName:
|
case RoleName:
|
||||||
return deviceClass->name();
|
return thingClass->name();
|
||||||
case RoleDisplayName:
|
case RoleDisplayName:
|
||||||
return deviceClass->displayName();
|
return thingClass->displayName();
|
||||||
case RolePluginId:
|
case RolePluginId:
|
||||||
return deviceClass->pluginId().toString();
|
return thingClass->pluginId().toString();
|
||||||
case RoleVendorId:
|
case RoleVendorId:
|
||||||
return deviceClass->vendorId().toString();
|
return thingClass->vendorId().toString();
|
||||||
case RoleInterfaces:
|
case RoleInterfaces:
|
||||||
return deviceClass->interfaces();
|
return thingClass->interfaces();
|
||||||
case RoleBaseInterface:
|
case RoleBaseInterface:
|
||||||
return deviceClass->baseInterface();
|
return thingClass->baseInterface();
|
||||||
}
|
}
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
int DeviceClasses::count() const
|
int ThingClasses::count() const
|
||||||
{
|
{
|
||||||
return m_deviceClasses.count();
|
return m_thingClasses.count();
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceClass *DeviceClasses::get(int index) const
|
ThingClass *ThingClasses::get(int index) const
|
||||||
{
|
{
|
||||||
if (index < 0 || index >= m_deviceClasses.count()) {
|
if (index < 0 || index >= m_thingClasses.count()) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return m_deviceClasses.at(index);
|
return m_thingClasses.at(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceClass *DeviceClasses::getDeviceClass(QUuid deviceClassId) const
|
ThingClass *ThingClasses::getThingClass(QUuid thingClassId) const
|
||||||
{
|
{
|
||||||
foreach (DeviceClass *deviceClass, m_deviceClasses) {
|
foreach (ThingClass *thingClass, m_thingClasses) {
|
||||||
if (deviceClass->id() == deviceClassId) {
|
if (thingClass->id() == thingClassId) {
|
||||||
return deviceClass;
|
return thingClass;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceClasses::addDeviceClass(DeviceClass *deviceClass)
|
void ThingClasses::addThingClass(ThingClass *thingClass)
|
||||||
{
|
{
|
||||||
beginInsertRows(QModelIndex(), m_deviceClasses.count(), m_deviceClasses.count());
|
thingClass->setParent(this);
|
||||||
//qDebug() << "DeviceClasses: loaded deviceClass" << deviceClass->name();
|
beginInsertRows(QModelIndex(), m_thingClasses.count(), m_thingClasses.count());
|
||||||
m_deviceClasses.append(deviceClass);
|
m_thingClasses.append(thingClass);
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
emit countChanged();
|
emit countChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceClasses::clearModel()
|
void ThingClasses::clearModel()
|
||||||
{
|
{
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
qDeleteAll(m_deviceClasses);
|
qDeleteAll(m_thingClasses);
|
||||||
m_deviceClasses.clear();
|
m_thingClasses.clear();
|
||||||
endResetModel();
|
endResetModel();
|
||||||
emit countChanged();
|
emit countChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
QHash<int, QByteArray> DeviceClasses::roleNames() const
|
QHash<int, QByteArray> ThingClasses::roleNames() const
|
||||||
{
|
{
|
||||||
QHash<int, QByteArray> roles;
|
QHash<int, QByteArray> roles;
|
||||||
roles[RoleId] = "id";
|
roles[RoleId] = "id";
|
||||||
@ -28,14 +28,14 @@
|
|||||||
*
|
*
|
||||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
#ifndef DEVICECLASSMODEL_H
|
#ifndef THINGCLASSES_H
|
||||||
#define DEVICECLASSMODEL_H
|
#define THINGCLASSES_H
|
||||||
|
|
||||||
#include <QAbstractListModel>
|
#include <QAbstractListModel>
|
||||||
|
|
||||||
#include "types/deviceclass.h"
|
#include "types/thingclass.h"
|
||||||
|
|
||||||
class DeviceClasses : public QAbstractListModel
|
class ThingClasses : public QAbstractListModel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
|
Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
|
||||||
@ -50,18 +50,18 @@ public:
|
|||||||
RoleBaseInterface
|
RoleBaseInterface
|
||||||
};
|
};
|
||||||
|
|
||||||
explicit DeviceClasses(QObject *parent = nullptr);
|
explicit ThingClasses(QObject *parent = nullptr);
|
||||||
|
|
||||||
QList<DeviceClass *> deviceClasses();
|
QList<ThingClass *> thingClasses();
|
||||||
|
|
||||||
int rowCount(const QModelIndex & parent = QModelIndex()) const;
|
int rowCount(const QModelIndex & parent = QModelIndex()) const override;
|
||||||
QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
|
QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const override;
|
||||||
|
|
||||||
Q_INVOKABLE int count() const;
|
Q_INVOKABLE int count() const;
|
||||||
Q_INVOKABLE DeviceClass *get(int index) const;
|
Q_INVOKABLE ThingClass *get(int index) const;
|
||||||
Q_INVOKABLE DeviceClass *getDeviceClass(QUuid deviceClassId) const;
|
Q_INVOKABLE ThingClass *getThingClass(QUuid thingClassId) const;
|
||||||
|
|
||||||
void addDeviceClass(DeviceClass *deviceClass);
|
void addThingClass(ThingClass *thingClass);
|
||||||
|
|
||||||
void clearModel();
|
void clearModel();
|
||||||
|
|
||||||
@ -69,11 +69,11 @@ signals:
|
|||||||
void countChanged();
|
void countChanged();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QHash<int, QByteArray> roleNames() const;
|
QHash<int, QByteArray> roleNames() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<DeviceClass *> m_deviceClasses;
|
QList<ThingClass *> m_thingClasses;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DEVICECLASSMODEL_H
|
#endif // THINGCLASSES_H
|
||||||
@ -28,26 +28,26 @@
|
|||||||
*
|
*
|
||||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
#include "deviceclassesproxy.h"
|
#include "thingclassesproxy.h"
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
DeviceClassesProxy::DeviceClassesProxy(QObject *parent) :
|
ThingClassesProxy::ThingClassesProxy(QObject *parent) :
|
||||||
QSortFilterProxyModel(parent)
|
QSortFilterProxyModel(parent)
|
||||||
{
|
{
|
||||||
setSortRole(DeviceClasses::RoleDisplayName);
|
setSortRole(ThingClasses::RoleDisplayName);
|
||||||
}
|
}
|
||||||
|
|
||||||
Engine *DeviceClassesProxy::engine() const
|
Engine *ThingClassesProxy::engine() const
|
||||||
{
|
{
|
||||||
return m_engine;
|
return m_engine;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceClassesProxy::setEngine(Engine *engine)
|
void ThingClassesProxy::setEngine(Engine *engine)
|
||||||
{
|
{
|
||||||
if (m_engine != engine) {
|
if (m_engine != engine) {
|
||||||
m_engine = engine;
|
m_engine = engine;
|
||||||
setSourceModel(engine->deviceManager()->deviceClasses());
|
setSourceModel(engine->thingManager()->thingClasses());
|
||||||
emit engineChanged();
|
emit engineChanged();
|
||||||
emit countChanged();
|
emit countChanged();
|
||||||
sort(0);
|
sort(0);
|
||||||
@ -55,12 +55,12 @@ void DeviceClassesProxy::setEngine(Engine *engine)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QString DeviceClassesProxy::filterInterface() const
|
QString ThingClassesProxy::filterInterface() const
|
||||||
{
|
{
|
||||||
return m_filterInterface;
|
return m_filterInterface;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceClassesProxy::setFilterInterface(const QString &filterInterface)
|
void ThingClassesProxy::setFilterInterface(const QString &filterInterface)
|
||||||
{
|
{
|
||||||
if (m_filterInterface != filterInterface) {
|
if (m_filterInterface != filterInterface) {
|
||||||
m_filterInterface = filterInterface;
|
m_filterInterface = filterInterface;
|
||||||
@ -70,12 +70,12 @@ void DeviceClassesProxy::setFilterInterface(const QString &filterInterface)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString DeviceClassesProxy::filterDisplayName() const
|
QString ThingClassesProxy::filterDisplayName() const
|
||||||
{
|
{
|
||||||
return m_filterDisplayName;
|
return m_filterDisplayName;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceClassesProxy::setFilterDisplayName(const QString &filter)
|
void ThingClassesProxy::setFilterDisplayName(const QString &filter)
|
||||||
{
|
{
|
||||||
if (m_filterDisplayName != filter) {
|
if (m_filterDisplayName != filter) {
|
||||||
m_filterDisplayName = filter;
|
m_filterDisplayName = filter;
|
||||||
@ -85,12 +85,12 @@ void DeviceClassesProxy::setFilterDisplayName(const QString &filter)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QUuid DeviceClassesProxy::filterVendorId() const
|
QUuid ThingClassesProxy::filterVendorId() const
|
||||||
{
|
{
|
||||||
return m_filterVendorId;
|
return m_filterVendorId;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceClassesProxy::setFilterVendorId(const QUuid &filterVendorId)
|
void ThingClassesProxy::setFilterVendorId(const QUuid &filterVendorId)
|
||||||
{
|
{
|
||||||
if (m_filterVendorId != filterVendorId) {
|
if (m_filterVendorId != filterVendorId) {
|
||||||
m_filterVendorId = filterVendorId;
|
m_filterVendorId = filterVendorId;
|
||||||
@ -100,12 +100,12 @@ void DeviceClassesProxy::setFilterVendorId(const QUuid &filterVendorId)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString DeviceClassesProxy::filterVendorName() const
|
QString ThingClassesProxy::filterVendorName() const
|
||||||
{
|
{
|
||||||
return m_filterVendorName;
|
return m_filterVendorName;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceClassesProxy::setFilterVendorName(const QString &filterVendorName)
|
void ThingClassesProxy::setFilterVendorName(const QString &filterVendorName)
|
||||||
{
|
{
|
||||||
if (m_filterVendorName != filterVendorName) {
|
if (m_filterVendorName != filterVendorName) {
|
||||||
m_filterVendorName = filterVendorName;
|
m_filterVendorName = filterVendorName;
|
||||||
@ -115,12 +115,12 @@ void DeviceClassesProxy::setFilterVendorName(const QString &filterVendorName)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString DeviceClassesProxy::filterString() const
|
QString ThingClassesProxy::filterString() const
|
||||||
{
|
{
|
||||||
return m_filterString;
|
return m_filterString;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceClassesProxy::setFilterString(const QString &filterString)
|
void ThingClassesProxy::setFilterString(const QString &filterString)
|
||||||
{
|
{
|
||||||
if (m_filterString != filterString) {
|
if (m_filterString != filterString) {
|
||||||
m_filterString = filterString;
|
m_filterString = filterString;
|
||||||
@ -130,12 +130,12 @@ void DeviceClassesProxy::setFilterString(const QString &filterString)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeviceClassesProxy::groupByInterface() const
|
bool ThingClassesProxy::groupByInterface() const
|
||||||
{
|
{
|
||||||
return m_groupByInterface;
|
return m_groupByInterface;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceClassesProxy::setGroupByInterface(bool groupByInterface)
|
void ThingClassesProxy::setGroupByInterface(bool groupByInterface)
|
||||||
{
|
{
|
||||||
if (m_groupByInterface != groupByInterface) {
|
if (m_groupByInterface != groupByInterface) {
|
||||||
m_groupByInterface = groupByInterface;
|
m_groupByInterface = groupByInterface;
|
||||||
@ -144,13 +144,13 @@ void DeviceClassesProxy::setGroupByInterface(bool groupByInterface)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceClass *DeviceClassesProxy::get(int index) const
|
ThingClass *ThingClassesProxy::get(int index) const
|
||||||
{
|
{
|
||||||
return m_engine->deviceManager()->deviceClasses()->get(mapToSource(this->index(index, 0)).row());
|
return m_engine->thingManager()->thingClasses()->get(mapToSource(this->index(index, 0)).row());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void DeviceClassesProxy::resetFilter()
|
void ThingClassesProxy::resetFilter()
|
||||||
{
|
{
|
||||||
m_filterVendorId = QUuid();
|
m_filterVendorId = QUuid();
|
||||||
m_filterInterface.clear();
|
m_filterInterface.clear();
|
||||||
@ -160,31 +160,31 @@ void DeviceClassesProxy::resetFilter()
|
|||||||
emit countChanged();
|
emit countChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeviceClassesProxy::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
|
bool ThingClassesProxy::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
|
||||||
{
|
{
|
||||||
Q_UNUSED(sourceParent)
|
Q_UNUSED(sourceParent)
|
||||||
|
|
||||||
DeviceClass *deviceClass = m_engine->deviceManager()->deviceClasses()->get(sourceRow);
|
ThingClass *thingClass = m_engine->thingManager()->thingClasses()->get(sourceRow);
|
||||||
|
|
||||||
// filter auto devices
|
// filter auto things
|
||||||
if (deviceClass->createMethods().count() == 1 && deviceClass->createMethods().contains("CreateMethodAuto"))
|
if (thingClass->createMethods().count() == 1 && thingClass->createMethods().contains("CreateMethodAuto"))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!m_filterVendorId.isNull() && deviceClass->vendorId() != m_filterVendorId)
|
if (!m_filterVendorId.isNull() && thingClass->vendorId() != m_filterVendorId)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!m_filterInterface.isEmpty() && !deviceClass->interfaces().contains(m_filterInterface)) {
|
if (!m_filterInterface.isEmpty() && !thingClass->interfaces().contains(m_filterInterface)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_filterDisplayName.isEmpty() && !deviceClass->displayName().toLower().contains(m_filterDisplayName.toLower())) {
|
if (!m_filterDisplayName.isEmpty() && !thingClass->displayName().toLower().contains(m_filterDisplayName.toLower())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_filterVendorName.isEmpty()) {
|
if (!m_filterVendorName.isEmpty()) {
|
||||||
Vendor *vendor = m_engine->deviceManager()->vendors()->getVendor(deviceClass->vendorId());
|
Vendor *vendor = m_engine->thingManager()->vendors()->getVendor(thingClass->vendorId());
|
||||||
if (!vendor) {
|
if (!vendor) {
|
||||||
qWarning() << "Invalid vendor for deviceClass:" << deviceClass->name() << deviceClass->vendorId();
|
qWarning() << "Invalid vendor for thingClass:" << thingClass->name() << thingClass->vendorId();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!vendor->displayName().toLower().contains(m_filterVendorName.toLower())) {
|
if (!vendor->displayName().toLower().contains(m_filterVendorName.toLower())) {
|
||||||
@ -193,12 +193,12 @@ bool DeviceClassesProxy::filterAcceptsRow(int sourceRow, const QModelIndex &sour
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!m_filterString.isEmpty()) {
|
if (!m_filterString.isEmpty()) {
|
||||||
Vendor *vendor = m_engine->deviceManager()->vendors()->getVendor(deviceClass->vendorId());
|
Vendor *vendor = m_engine->thingManager()->vendors()->getVendor(thingClass->vendorId());
|
||||||
if (!vendor) {
|
if (!vendor) {
|
||||||
qWarning() << "Invalid vendor for deviceClass:" << deviceClass->name() << deviceClass->vendorId();
|
qWarning() << "Invalid vendor for thingClass:" << thingClass->name() << thingClass->vendorId();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!vendor->displayName().toLower().contains(m_filterString.toLower()) && !deviceClass->displayName().toLower().contains(m_filterString.toLower())) {
|
if (!vendor->displayName().toLower().contains(m_filterString.toLower()) && !thingClass->displayName().toLower().contains(m_filterString.toLower())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -206,17 +206,17 @@ bool DeviceClassesProxy::filterAcceptsRow(int sourceRow, const QModelIndex &sour
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeviceClassesProxy::lessThan(const QModelIndex &left, const QModelIndex &right) const
|
bool ThingClassesProxy::lessThan(const QModelIndex &left, const QModelIndex &right) const
|
||||||
{
|
{
|
||||||
if (m_groupByInterface) {
|
if (m_groupByInterface) {
|
||||||
QString leftBaseInterface = sourceModel()->data(left, DeviceClasses::RoleBaseInterface).toString();
|
QString leftBaseInterface = sourceModel()->data(left, ThingClasses::RoleBaseInterface).toString();
|
||||||
QString rightBaseInterface = sourceModel()->data(right, DeviceClasses::RoleBaseInterface).toString();
|
QString rightBaseInterface = sourceModel()->data(right, ThingClasses::RoleBaseInterface).toString();
|
||||||
if (leftBaseInterface != rightBaseInterface) {
|
if (leftBaseInterface != rightBaseInterface) {
|
||||||
return QString::localeAwareCompare(leftBaseInterface, rightBaseInterface) < 0;
|
return QString::localeAwareCompare(leftBaseInterface, rightBaseInterface) < 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
QString leftName = sourceModel()->data(left, DeviceClasses::RoleDisplayName).toString();
|
QString leftName = sourceModel()->data(left, ThingClasses::RoleDisplayName).toString();
|
||||||
QString rightName = sourceModel()->data(right, DeviceClasses::RoleDisplayName).toString();
|
QString rightName = sourceModel()->data(right, ThingClasses::RoleDisplayName).toString();
|
||||||
|
|
||||||
return QString::localeAwareCompare(leftName, rightName) < 0;
|
return QString::localeAwareCompare(leftName, rightName) < 0;
|
||||||
}
|
}
|
||||||
@ -28,18 +28,18 @@
|
|||||||
*
|
*
|
||||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
#ifndef DEVICECLASSFILERMODEL_H
|
#ifndef THINGCLASSESPROXY_H
|
||||||
#define DEVICECLASSFILERMODEL_H
|
#define THINGCLASSESPROXY_H
|
||||||
|
|
||||||
#include <QUuid>
|
#include <QUuid>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QSortFilterProxyModel>
|
#include <QSortFilterProxyModel>
|
||||||
|
|
||||||
#include "engine.h"
|
#include "engine.h"
|
||||||
#include "deviceclasses.h"
|
#include "thingclasses.h"
|
||||||
#include "types/deviceclass.h"
|
#include "types/thingclass.h"
|
||||||
|
|
||||||
class DeviceClassesProxy : public QSortFilterProxyModel
|
class ThingClassesProxy : public QSortFilterProxyModel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
|
Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
|
||||||
@ -50,13 +50,13 @@ class DeviceClassesProxy : public QSortFilterProxyModel
|
|||||||
Q_PROPERTY(QUuid filterVendorId READ filterVendorId WRITE setFilterVendorId NOTIFY filterVendorIdChanged)
|
Q_PROPERTY(QUuid filterVendorId READ filterVendorId WRITE setFilterVendorId NOTIFY filterVendorIdChanged)
|
||||||
Q_PROPERTY(QString filterVendorName READ filterVendorName WRITE setFilterVendorName NOTIFY filterVendorNameChanged)
|
Q_PROPERTY(QString filterVendorName READ filterVendorName WRITE setFilterVendorName NOTIFY filterVendorNameChanged)
|
||||||
|
|
||||||
// Filters by deviceClass' displayName or vendor's displayName
|
// Filters by thingClass' displayName or vendor's displayName
|
||||||
Q_PROPERTY(QString filterString READ filterString WRITE setFilterString NOTIFY filterStringChanged)
|
Q_PROPERTY(QString filterString READ filterString WRITE setFilterString NOTIFY filterStringChanged)
|
||||||
|
|
||||||
Q_PROPERTY(bool groupByInterface READ groupByInterface WRITE setGroupByInterface NOTIFY groupByInterfaceChanged)
|
Q_PROPERTY(bool groupByInterface READ groupByInterface WRITE setGroupByInterface NOTIFY groupByInterfaceChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit DeviceClassesProxy(QObject *parent = nullptr);
|
explicit ThingClassesProxy(QObject *parent = nullptr);
|
||||||
|
|
||||||
Engine *engine() const;
|
Engine *engine() const;
|
||||||
void setEngine(Engine *engine);
|
void setEngine(Engine *engine);
|
||||||
@ -79,7 +79,7 @@ public:
|
|||||||
bool groupByInterface() const;
|
bool groupByInterface() const;
|
||||||
void setGroupByInterface(bool groupByInterface);
|
void setGroupByInterface(bool groupByInterface);
|
||||||
|
|
||||||
Q_INVOKABLE DeviceClass *get(int index) const;
|
Q_INVOKABLE ThingClass *get(int index) const;
|
||||||
|
|
||||||
Q_INVOKABLE void resetFilter();
|
Q_INVOKABLE void resetFilter();
|
||||||
|
|
||||||
@ -107,4 +107,4 @@ private:
|
|||||||
bool m_groupByInterface = false;
|
bool m_groupByInterface = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DEVICECLASSFILERMODEL_H
|
#endif // THINGCLASSESPROXY_H
|
||||||
@ -40,20 +40,20 @@ ThingDiscovery::ThingDiscovery(QObject *parent) :
|
|||||||
int ThingDiscovery::rowCount(const QModelIndex &parent) const
|
int ThingDiscovery::rowCount(const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
Q_UNUSED(parent)
|
Q_UNUSED(parent)
|
||||||
return m_foundDevices.count();
|
return m_foundThings.count();
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant ThingDiscovery::data(const QModelIndex &index, int role) const
|
QVariant ThingDiscovery::data(const QModelIndex &index, int role) const
|
||||||
{
|
{
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case RoleId:
|
case RoleId:
|
||||||
return m_foundDevices.at(index.row())->id();
|
return m_foundThings.at(index.row())->id();
|
||||||
case RoleName:
|
case RoleName:
|
||||||
return m_foundDevices.at(index.row())->name();
|
return m_foundThings.at(index.row())->name();
|
||||||
case RoleDescription:
|
case RoleDescription:
|
||||||
return m_foundDevices.at(index.row())->description();
|
return m_foundThings.at(index.row())->description();
|
||||||
case RoleDeviceId:
|
case RoleThingId:
|
||||||
return m_foundDevices.at(index.row())->thingId();
|
return m_foundThings.at(index.row())->thingId();
|
||||||
}
|
}
|
||||||
|
|
||||||
return QVariant();
|
return QVariant();
|
||||||
@ -63,38 +63,38 @@ QHash<int, QByteArray> ThingDiscovery::roleNames() const
|
|||||||
{
|
{
|
||||||
QHash<int, QByteArray> roles;
|
QHash<int, QByteArray> roles;
|
||||||
roles.insert(RoleId, "id");
|
roles.insert(RoleId, "id");
|
||||||
roles.insert(RoleDeviceId, "deviceId");
|
roles.insert(RoleThingId, "thingId");
|
||||||
roles.insert(RoleName, "name");
|
roles.insert(RoleName, "name");
|
||||||
roles.insert(RoleDescription, "description");
|
roles.insert(RoleDescription, "description");
|
||||||
return roles;
|
return roles;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ThingDiscovery::discoverThings(const QUuid &deviceClassId, const QVariantList &discoveryParams)
|
void ThingDiscovery::discoverThings(const QUuid &thingClassId, const QVariantList &discoveryParams)
|
||||||
{
|
{
|
||||||
if (m_busy) {
|
if (m_busy) {
|
||||||
qWarning() << "Busy... not restarting discovery";
|
qWarning() << "Busy... not restarting discovery";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
m_foundDevices.clear();
|
m_foundThings.clear();
|
||||||
endResetModel();
|
endResetModel();
|
||||||
emit countChanged();
|
emit countChanged();
|
||||||
|
|
||||||
if (!m_engine) {
|
if (!m_engine) {
|
||||||
qWarning() << "Cannot discover devices. No Engine set";
|
qWarning() << "Cannot discover things. No Engine set";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!m_engine->jsonRpcClient()->connected()) {
|
if (!m_engine->jsonRpcClient()->connected()) {
|
||||||
qWarning() << "Cannot discover devices. Not connected.";
|
qWarning() << "Cannot discover things. Not connected.";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariantMap params;
|
QVariantMap params;
|
||||||
params.insert("deviceClassId", deviceClassId.toString());
|
params.insert("thingClassId", thingClassId.toString());
|
||||||
if (!discoveryParams.isEmpty()) {
|
if (!discoveryParams.isEmpty()) {
|
||||||
params.insert("discoveryParams", discoveryParams);
|
params.insert("discoveryParams", discoveryParams);
|
||||||
}
|
}
|
||||||
m_engine->jsonRpcClient()->sendCommand("Devices.GetDiscoveredDevices", params, this, "discoverThingsResponse");
|
m_engine->jsonRpcClient()->sendCommand("Integrations.DiscoverThings", params, this, "discoverThingsResponse");
|
||||||
m_busy = true;
|
m_busy = true;
|
||||||
m_displayMessage.clear();
|
m_displayMessage.clear();
|
||||||
emit busyChanged();
|
emit busyChanged();
|
||||||
@ -102,10 +102,10 @@ void ThingDiscovery::discoverThings(const QUuid &deviceClassId, const QVariantLi
|
|||||||
|
|
||||||
ThingDescriptor *ThingDiscovery::get(int index) const
|
ThingDescriptor *ThingDiscovery::get(int index) const
|
||||||
{
|
{
|
||||||
if (index < 0 || index >= m_foundDevices.count()) {
|
if (index < 0 || index >= m_foundThings.count()) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return m_foundDevices.at(index);
|
return m_foundThings.at(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
Engine *ThingDiscovery::engine() const
|
Engine *ThingDiscovery::engine() const
|
||||||
@ -138,9 +138,9 @@ void ThingDiscovery::discoverThingsResponse(int /*commandId*/, const QVariantMap
|
|||||||
foreach (const QVariant &descriptorVariant, descriptors) {
|
foreach (const QVariant &descriptorVariant, descriptors) {
|
||||||
qDebug() << "Found device. Descriptor:" << descriptorVariant;
|
qDebug() << "Found device. Descriptor:" << descriptorVariant;
|
||||||
if (!contains(descriptorVariant.toMap().value("id").toUuid())) {
|
if (!contains(descriptorVariant.toMap().value("id").toUuid())) {
|
||||||
beginInsertRows(QModelIndex(), m_foundDevices.count(), m_foundDevices.count());
|
beginInsertRows(QModelIndex(), m_foundThings.count(), m_foundThings.count());
|
||||||
ThingDescriptor *descriptor = new ThingDescriptor(descriptorVariant.toMap().value("id").toUuid(),
|
ThingDescriptor *descriptor = new ThingDescriptor(descriptorVariant.toMap().value("id").toUuid(),
|
||||||
descriptorVariant.toMap().value("deviceId").toString(),
|
descriptorVariant.toMap().value("thingId").toString(),
|
||||||
descriptorVariant.toMap().value("title").toString(),
|
descriptorVariant.toMap().value("title").toString(),
|
||||||
descriptorVariant.toMap().value("description").toString());
|
descriptorVariant.toMap().value("description").toString());
|
||||||
foreach (const QVariant ¶mVariant, descriptorVariant.toMap().value("deviceParams").toList()) {
|
foreach (const QVariant ¶mVariant, descriptorVariant.toMap().value("deviceParams").toList()) {
|
||||||
@ -148,7 +148,7 @@ void ThingDiscovery::discoverThingsResponse(int /*commandId*/, const QVariantMap
|
|||||||
Param* p = new Param(paramVariant.toMap().value("paramTypeId").toString(), paramVariant.toMap().value("value"));
|
Param* p = new Param(paramVariant.toMap().value("paramTypeId").toString(), paramVariant.toMap().value("value"));
|
||||||
descriptor->params()->addParam(p);
|
descriptor->params()->addParam(p);
|
||||||
}
|
}
|
||||||
m_foundDevices.append(descriptor);
|
m_foundThings.append(descriptor);
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
emit countChanged();
|
emit countChanged();
|
||||||
}
|
}
|
||||||
@ -161,7 +161,7 @@ void ThingDiscovery::discoverThingsResponse(int /*commandId*/, const QVariantMap
|
|||||||
|
|
||||||
bool ThingDiscovery::contains(const QUuid &deviceDescriptorId) const
|
bool ThingDiscovery::contains(const QUuid &deviceDescriptorId) const
|
||||||
{
|
{
|
||||||
foreach (ThingDescriptor *descriptor, m_foundDevices) {
|
foreach (ThingDescriptor *descriptor, m_foundThings) {
|
||||||
if (descriptor->id() == deviceDescriptorId) {
|
if (descriptor->id() == deviceDescriptorId) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -263,10 +263,10 @@ QUuid ThingDiscoveryProxy::filterThingId() const
|
|||||||
return m_filterThingId;
|
return m_filterThingId;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ThingDiscoveryProxy::setFilterThingId(const QUuid &filterDeviceId)
|
void ThingDiscoveryProxy::setFilterThingId(const QUuid &filterThingId)
|
||||||
{
|
{
|
||||||
if (m_filterThingId != filterDeviceId) {
|
if (m_filterThingId != filterThingId) {
|
||||||
m_filterThingId = filterDeviceId;
|
m_filterThingId = filterThingId;
|
||||||
emit filterThingIdChanged();
|
emit filterThingIdChanged();
|
||||||
invalidateFilter();
|
invalidateFilter();
|
||||||
emit countChanged();
|
emit countChanged();
|
||||||
|
|||||||
@ -70,7 +70,7 @@ class ThingDiscovery : public QAbstractListModel
|
|||||||
public:
|
public:
|
||||||
enum Roles {
|
enum Roles {
|
||||||
RoleId,
|
RoleId,
|
||||||
RoleDeviceId,
|
RoleThingId,
|
||||||
RoleName,
|
RoleName,
|
||||||
RoleDescription
|
RoleDescription
|
||||||
};
|
};
|
||||||
@ -106,7 +106,7 @@ private:
|
|||||||
QString m_displayMessage;
|
QString m_displayMessage;
|
||||||
|
|
||||||
bool contains(const QUuid &deviceDescriptorId) const;
|
bool contains(const QUuid &deviceDescriptorId) const;
|
||||||
QList<ThingDescriptor*> m_foundDevices;
|
QList<ThingDescriptor*> m_foundThings;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ThingDiscoveryProxy: public QSortFilterProxyModel
|
class ThingDiscoveryProxy: public QSortFilterProxyModel
|
||||||
@ -131,7 +131,7 @@ public:
|
|||||||
void setShowNew(bool showNew);
|
void setShowNew(bool showNew);
|
||||||
|
|
||||||
QUuid filterThingId() const;
|
QUuid filterThingId() const;
|
||||||
void setFilterThingId(const QUuid &filterDeviceId);
|
void setFilterThingId(const QUuid &filterThingId);
|
||||||
|
|
||||||
Q_INVOKABLE ThingDescriptor* get(int index) const;
|
Q_INVOKABLE ThingDescriptor* get(int index) const;
|
||||||
|
|
||||||
|
|||||||
@ -29,33 +29,33 @@
|
|||||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
#include "thinggroup.h"
|
#include "thinggroup.h"
|
||||||
#include "devicemanager.h"
|
#include "thingmanager.h"
|
||||||
#include "devicesproxy.h"
|
#include "thingsproxy.h"
|
||||||
#include "types/statetypes.h"
|
#include "types/statetypes.h"
|
||||||
#include "types/actiontype.h"
|
#include "types/actiontype.h"
|
||||||
|
|
||||||
ThingGroup::ThingGroup(DeviceManager *deviceManager, DeviceClass *deviceClass, DevicesProxy *devices, QObject *parent):
|
ThingGroup::ThingGroup(ThingManager *thingManager, ThingClass *thingClass, ThingsProxy *things, QObject *parent):
|
||||||
Device(deviceManager, deviceClass, QUuid::createUuid(), parent),
|
Thing(thingManager, thingClass, QUuid::createUuid(), parent),
|
||||||
m_things(devices)
|
m_things(things)
|
||||||
{
|
{
|
||||||
deviceClass->setParent(this);
|
thingClass->setParent(this);
|
||||||
|
|
||||||
States *states = new States(this);
|
States *states = new States(this);
|
||||||
for (int i = 0; i < deviceClass->stateTypes()->rowCount(); i++) {
|
for (int i = 0; i < thingClass->stateTypes()->rowCount(); i++) {
|
||||||
StateType *st = deviceClass->stateTypes()->get(i);
|
StateType *st = thingClass->stateTypes()->get(i);
|
||||||
State *state = new State(id(), st->id(), QVariant(), this);
|
State *state = new State(id(), st->id(), QVariant(), this);
|
||||||
qDebug() << "Adding state" << st->name() << st->minValue() << st->maxValue();
|
qDebug() << "Adding state" << st->name() << st->minValue() << st->maxValue();
|
||||||
states->addState(state);
|
states->addState(state);
|
||||||
}
|
}
|
||||||
setStates(states);
|
setStates(states);
|
||||||
syncStates();
|
syncStates();
|
||||||
setName(deviceClass->displayName());
|
setName(thingClass->displayName());
|
||||||
|
|
||||||
connect(devices, &DevicesProxy::dataChanged, this, [this](const QModelIndex &/*topLeft*/, const QModelIndex &/*bottomRight*/, const QVector<int> &/*roles*/){
|
connect(things, &ThingsProxy::dataChanged, this, [this](const QModelIndex &/*topLeft*/, const QModelIndex &/*bottomRight*/, const QVector<int> &/*roles*/){
|
||||||
syncStates();
|
syncStates();
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(m_thingManager, &DeviceManager::executeActionReply, this, [this](int commandId, const QVariantMap ¶ms){
|
connect(m_thingManager, &ThingManager::executeActionReply, this, [this](int commandId, Thing::ThingError error, const QString &displayMessage){
|
||||||
// This should maybe check the params and create a sensible group result instead of just forwarding the result of the last reply
|
// This should maybe check the params and create a sensible group result instead of just forwarding the result of the last reply
|
||||||
qDebug() << "action reply:" << commandId;
|
qDebug() << "action reply:" << commandId;
|
||||||
foreach (int id, m_pendingGroupActions.keys()) {
|
foreach (int id, m_pendingGroupActions.keys()) {
|
||||||
@ -63,7 +63,7 @@ ThingGroup::ThingGroup(DeviceManager *deviceManager, DeviceClass *deviceClass, D
|
|||||||
m_pendingGroupActions[id].removeAll(commandId);
|
m_pendingGroupActions[id].removeAll(commandId);
|
||||||
if (m_pendingGroupActions[id].isEmpty()) {
|
if (m_pendingGroupActions[id].isEmpty()) {
|
||||||
m_pendingGroupActions.remove(id);
|
m_pendingGroupActions.remove(id);
|
||||||
emit executeActionReply(id, params);
|
emit executeActionReply(id, error, displayMessage);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -84,8 +84,8 @@ int ThingGroup::executeAction(const QString &actionName, const QVariantList &par
|
|||||||
|
|
||||||
qDebug() << "Execute action for group:" << this;
|
qDebug() << "Execute action for group:" << this;
|
||||||
for (int i = 0; i < m_things->rowCount(); i++) {
|
for (int i = 0; i < m_things->rowCount(); i++) {
|
||||||
Device *thing = m_things->get(i);
|
Thing *thing = m_things->get(i);
|
||||||
if (thing->setupStatus() != Device::ThingSetupStatusComplete) {
|
if (thing->setupStatus() != Thing::ThingSetupStatusComplete) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ActionType *actionType = thing->thingClass()->actionTypes()->findByName(actionName);
|
ActionType *actionType = thing->thingClass()->actionTypes()->findByName(actionName);
|
||||||
@ -135,7 +135,7 @@ void ThingGroup::syncStates()
|
|||||||
QVariant value;
|
QVariant value;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for (int j = 0; j < m_things->rowCount(); j++) {
|
for (int j = 0; j < m_things->rowCount(); j++) {
|
||||||
Device *d = m_things->get(j);
|
Thing *d = m_things->get(j);
|
||||||
// Skip things that don't have the required state
|
// Skip things that don't have the required state
|
||||||
StateType *ds = d->thingClass()->stateTypes()->findByName(stateType->name());
|
StateType *ds = d->thingClass()->stateTypes()->findByName(stateType->name());
|
||||||
if (!ds) {
|
if (!ds) {
|
||||||
|
|||||||
@ -33,17 +33,17 @@
|
|||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
#include "types/device.h"
|
#include "types/thing.h"
|
||||||
|
|
||||||
class DevicesProxy;
|
class ThingsProxy;
|
||||||
class DeviceManager;
|
class ThingManager;
|
||||||
class ParamType;
|
class ParamType;
|
||||||
|
|
||||||
class ThingGroup : public Device
|
class ThingGroup : public Thing
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit ThingGroup(DeviceManager *deviceManager, DeviceClass *deviceClass, DevicesProxy *devices, QObject *parent = nullptr);
|
explicit ThingGroup(ThingManager *thingManager, ThingClass *thingClass, ThingsProxy *things, QObject *parent = nullptr);
|
||||||
|
|
||||||
Q_INVOKABLE int executeAction(const QString &actionName, const QVariantList ¶ms) override;
|
Q_INVOKABLE int executeAction(const QString &actionName, const QVariantList ¶ms) override;
|
||||||
|
|
||||||
@ -53,7 +53,7 @@ private:
|
|||||||
QVariant mapValue(const QVariant &value, ParamType *fromParamType, ParamType *toParamType) const;
|
QVariant mapValue(const QVariant &value, ParamType *fromParamType, ParamType *toParamType) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DevicesProxy* m_things = nullptr;
|
ThingsProxy* m_things = nullptr;
|
||||||
|
|
||||||
int m_idCounter = 0;
|
int m_idCounter = 0;
|
||||||
QHash<int, QList<int>> m_pendingGroupActions;
|
QHash<int, QList<int>> m_pendingGroupActions;
|
||||||
|
|||||||
1148
libnymea-app/thingmanager.cpp
Normal file
1148
libnymea-app/thingmanager.cpp
Normal file
File diff suppressed because it is too large
Load Diff
@ -28,14 +28,14 @@
|
|||||||
*
|
*
|
||||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
#ifndef DEVICEMANAGER_H
|
#ifndef THINGMANAGER_H
|
||||||
#define DEVICEMANAGER_H
|
#define THINGMANAGER_H
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
#include "types/vendors.h"
|
#include "types/vendors.h"
|
||||||
#include "devices.h"
|
#include "things.h"
|
||||||
#include "deviceclasses.h"
|
#include "thingclasses.h"
|
||||||
#include "interfacesmodel.h"
|
#include "interfacesmodel.h"
|
||||||
#include "types/plugins.h"
|
#include "types/plugins.h"
|
||||||
#include "jsonrpc/jsonhandler.h"
|
#include "jsonrpc/jsonhandler.h"
|
||||||
@ -49,14 +49,13 @@ class IOConnections;
|
|||||||
class EventHandler;
|
class EventHandler;
|
||||||
class IntegrationsHandler;
|
class IntegrationsHandler;
|
||||||
|
|
||||||
class DeviceManager : public JsonHandler
|
class ThingManager : public JsonHandler
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(Vendors* vendors READ vendors CONSTANT)
|
Q_PROPERTY(Vendors* vendors READ vendors CONSTANT)
|
||||||
Q_PROPERTY(Plugins* plugins READ plugins CONSTANT)
|
Q_PROPERTY(Plugins* plugins READ plugins CONSTANT)
|
||||||
Q_PROPERTY(Devices* things READ things CONSTANT)
|
Q_PROPERTY(Things* things READ things CONSTANT)
|
||||||
Q_PROPERTY(Devices* devices READ devices CONSTANT)
|
Q_PROPERTY(ThingClasses* thingClasses READ thingClasses CONSTANT)
|
||||||
Q_PROPERTY(DeviceClasses* deviceClasses READ deviceClasses CONSTANT)
|
|
||||||
Q_PROPERTY(IOConnections* ioConnections READ ioConnections CONSTANT)
|
Q_PROPERTY(IOConnections* ioConnections READ ioConnections CONSTANT)
|
||||||
|
|
||||||
Q_PROPERTY(bool fetchingData READ fetchingData NOTIFY fetchingDataChanged)
|
Q_PROPERTY(bool fetchingData READ fetchingData NOTIFY fetchingDataChanged)
|
||||||
@ -70,7 +69,7 @@ public:
|
|||||||
};
|
};
|
||||||
Q_ENUM(RemovePolicy)
|
Q_ENUM(RemovePolicy)
|
||||||
|
|
||||||
explicit DeviceManager(JsonRpcClient *jsonclient, QObject *parent = nullptr);
|
explicit ThingManager(JsonRpcClient *jsonclient, QObject *parent = nullptr);
|
||||||
|
|
||||||
void clear();
|
void clear();
|
||||||
void init();
|
void init();
|
||||||
@ -79,33 +78,30 @@ public:
|
|||||||
|
|
||||||
Vendors* vendors() const;
|
Vendors* vendors() const;
|
||||||
Plugins* plugins() const;
|
Plugins* plugins() const;
|
||||||
Devices* devices() const;
|
Things* things() const;
|
||||||
Devices* things() const;
|
ThingClasses* thingClasses() const;
|
||||||
DeviceClasses* deviceClasses() const;
|
|
||||||
DeviceClasses* thingClasses() const;
|
|
||||||
IOConnections* ioConnections() const;
|
IOConnections* ioConnections() const;
|
||||||
|
|
||||||
bool fetchingData() const;
|
bool fetchingData() const;
|
||||||
|
|
||||||
Q_INVOKABLE int addDevice(const QUuid &deviceClassId, const QString &name, const QVariantList &deviceParams);
|
Q_INVOKABLE int addThing(const QUuid &thingClassId, const QString &name, const QVariantList &thingParams);
|
||||||
// param deviceClassId is deprecated and should be removed when minimum JSONRPC version is 3.1
|
// Param thingClassId is deprecated as of jsonrpc 5.4
|
||||||
Q_INVOKABLE int addDiscoveredDevice(const QUuid &deviceClassId, const QUuid &deviceDescriptorId, const QString &name, const QVariantList &deviceParams);
|
Q_INVOKABLE int addDiscoveredThing(const QUuid &thingClassId, const QUuid &thingDescriptorId, const QString &name, const QVariantList &thingParams);
|
||||||
Q_INVOKABLE int pairDevice(const QUuid &deviceClassId, const QVariantList &deviceParams, const QString &name);
|
Q_INVOKABLE int pairThing(const QUuid &thingClassId, const QVariantList &thingParams, const QString &name);
|
||||||
// param deviceClassId is deprecated and should be removed when minimum JSONRPC version is 3.1
|
Q_INVOKABLE int pairDiscoveredThing(const QUuid &thingDescriptorId, const QVariantList &thingParams, const QString &name);
|
||||||
Q_INVOKABLE int pairDiscoveredDevice(const QUuid &deviceClassId, const QUuid &deviceDescriptorId, const QVariantList &deviceParams, const QString &name);
|
Q_INVOKABLE int rePairThing(const QUuid &thingId, const QVariantList &thingParams, const QString &name = QString());
|
||||||
Q_INVOKABLE int rePairDevice(const QUuid &deviceId, const QVariantList &deviceParams, const QString &name = QString());
|
|
||||||
Q_INVOKABLE int confirmPairing(const QUuid &pairingTransactionId, const QString &secret = QString(), const QString &username = QString());
|
Q_INVOKABLE int confirmPairing(const QUuid &pairingTransactionId, const QString &secret = QString(), const QString &username = QString());
|
||||||
Q_INVOKABLE int removeThing(const QUuid &thingId, RemovePolicy policy = RemovePolicyNone);
|
Q_INVOKABLE int removeThing(const QUuid &thingId, RemovePolicy policy = RemovePolicyNone);
|
||||||
Q_INVOKABLE int editThing(const QUuid &thingId, const QString &name);
|
Q_INVOKABLE int editThing(const QUuid &thingId, const QString &name);
|
||||||
Q_INVOKABLE int setDeviceSettings(const QUuid &deviceId, const QVariantList &settings);
|
Q_INVOKABLE int setThingSettings(const QUuid &thingId, const QVariantList &settings);
|
||||||
Q_INVOKABLE int reconfigureDevice(const QUuid &deviceId, const QVariantList &deviceParams);
|
Q_INVOKABLE int reconfigureThing(const QUuid &thingId, const QVariantList &thingParams);
|
||||||
Q_INVOKABLE int reconfigureDiscoveredDevice(const QUuid &deviceId, const QUuid &deviceDescriptorId, const QVariantList ¶mOverride);
|
Q_INVOKABLE int reconfigureDiscoveredThing(const QUuid &thingDescriptorId, const QVariantList ¶mOverride);
|
||||||
Q_INVOKABLE int executeAction(const QUuid &deviceId, const QUuid &actionTypeId, const QVariantList ¶ms = QVariantList());
|
Q_INVOKABLE int executeAction(const QUuid &thingId, const QUuid &actionTypeId, const QVariantList ¶ms = QVariantList());
|
||||||
Q_INVOKABLE BrowserItems* browseDevice(const QUuid &deviceId, const QString &itemId = QString());
|
Q_INVOKABLE BrowserItems* browseThing(const QUuid &thingId, const QString &itemId = QString());
|
||||||
Q_INVOKABLE void refreshBrowserItems(BrowserItems *browserItems);
|
Q_INVOKABLE void refreshBrowserItems(BrowserItems *browserItems);
|
||||||
Q_INVOKABLE BrowserItem* browserItem(const QUuid &deviceId, const QString &itemId);
|
Q_INVOKABLE BrowserItem* browserItem(const QUuid &thingId, const QString &itemId);
|
||||||
Q_INVOKABLE int executeBrowserItem(const QUuid &deviceId, const QString &itemId);
|
Q_INVOKABLE int executeBrowserItem(const QUuid &thingId, const QString &itemId);
|
||||||
Q_INVOKABLE int executeBrowserItemAction(const QUuid &deviceId, const QString &itemId, const QUuid &actionTypeId, const QVariantList ¶ms = QVariantList());
|
Q_INVOKABLE int executeBrowserItemAction(const QUuid &thingId, const QString &itemId, const QUuid &actionTypeId, const QVariantList ¶ms = QVariantList());
|
||||||
|
|
||||||
Q_INVOKABLE int connectIO(const QUuid &inputThingId, const QUuid &inputStateTypeId, const QUuid &outputThingId, const QUuid &outputStateTypeId, bool inverted);
|
Q_INVOKABLE int connectIO(const QUuid &inputThingId, const QUuid &inputStateTypeId, const QUuid &outputThingId, const QUuid &outputStateTypeId, bool inverted);
|
||||||
Q_INVOKABLE int disconnectIO(const QUuid &ioConnectionId);
|
Q_INVOKABLE int disconnectIO(const QUuid &ioConnectionId);
|
||||||
@ -113,19 +109,19 @@ public:
|
|||||||
private:
|
private:
|
||||||
Q_INVOKABLE void notificationReceived(const QVariantMap &data);
|
Q_INVOKABLE void notificationReceived(const QVariantMap &data);
|
||||||
Q_INVOKABLE void getVendorsResponse(int commandId, const QVariantMap ¶ms);
|
Q_INVOKABLE void getVendorsResponse(int commandId, const QVariantMap ¶ms);
|
||||||
Q_INVOKABLE void getSupportedDevicesResponse(int commandId, const QVariantMap ¶ms);
|
Q_INVOKABLE void getThingClassesResponse(int commandId, const QVariantMap ¶ms);
|
||||||
Q_INVOKABLE void getPluginsResponse(int commandId, const QVariantMap ¶ms);
|
Q_INVOKABLE void getPluginsResponse(int commandId, const QVariantMap ¶ms);
|
||||||
Q_INVOKABLE void getPluginConfigResponse(int commandId, const QVariantMap ¶ms);
|
Q_INVOKABLE void getPluginConfigResponse(int commandId, const QVariantMap ¶ms);
|
||||||
Q_INVOKABLE void getConfiguredDevicesResponse(int commandId, const QVariantMap ¶ms);
|
Q_INVOKABLE void getThingsResponse(int commandId, const QVariantMap ¶ms);
|
||||||
Q_INVOKABLE void addDeviceResponse(int commandId, const QVariantMap ¶ms);
|
Q_INVOKABLE void addThingResponse(int commandId, const QVariantMap ¶ms);
|
||||||
Q_INVOKABLE void removeThingResponse(int commandId, const QVariantMap ¶ms);
|
Q_INVOKABLE void removeThingResponse(int commandId, const QVariantMap ¶ms);
|
||||||
Q_INVOKABLE void pairDeviceResponse(int commandId, const QVariantMap ¶ms);
|
Q_INVOKABLE void pairThingResponse(int commandId, const QVariantMap ¶ms);
|
||||||
Q_INVOKABLE void confirmPairingResponse(int commandId, const QVariantMap ¶ms);
|
Q_INVOKABLE void confirmPairingResponse(int commandId, const QVariantMap ¶ms);
|
||||||
Q_INVOKABLE void setPluginConfigResponse(int commandId, const QVariantMap ¶ms);
|
Q_INVOKABLE void setPluginConfigResponse(int commandId, const QVariantMap ¶ms);
|
||||||
Q_INVOKABLE void editThingResponse(int commandId, const QVariantMap ¶ms);
|
Q_INVOKABLE void editThingResponse(int commandId, const QVariantMap ¶ms);
|
||||||
Q_INVOKABLE void executeActionResponse(int commandId, const QVariantMap ¶ms);
|
Q_INVOKABLE void executeActionResponse(int commandId, const QVariantMap ¶ms);
|
||||||
Q_INVOKABLE void reconfigureDeviceResponse(int commandId, const QVariantMap ¶ms);
|
Q_INVOKABLE void reconfigureThingResponse(int commandId, const QVariantMap ¶ms);
|
||||||
Q_INVOKABLE void browseDeviceResponse(int commandId, const QVariantMap ¶ms);
|
Q_INVOKABLE void browseThingResponse(int commandId, const QVariantMap ¶ms);
|
||||||
Q_INVOKABLE void browserItemResponse(int commandId, const QVariantMap ¶ms);
|
Q_INVOKABLE void browserItemResponse(int commandId, const QVariantMap ¶ms);
|
||||||
Q_INVOKABLE void executeBrowserItemResponse(int commandId, const QVariantMap ¶ms);
|
Q_INVOKABLE void executeBrowserItemResponse(int commandId, const QVariantMap ¶ms);
|
||||||
Q_INVOKABLE void executeBrowserItemActionResponse(int commandId, const QVariantMap ¶ms);
|
Q_INVOKABLE void executeBrowserItemActionResponse(int commandId, const QVariantMap ¶ms);
|
||||||
@ -136,30 +132,48 @@ private:
|
|||||||
public slots:
|
public slots:
|
||||||
int savePluginConfig(const QUuid &pluginId);
|
int savePluginConfig(const QUuid &pluginId);
|
||||||
|
|
||||||
ThingGroup* createGroup(Interface *interface, DevicesProxy *things);
|
ThingGroup* createGroup(Interface *interface, ThingsProxy *things);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void pairDeviceReply(int commandId, const QVariantMap ¶ms);
|
void addThingReply(int commandId, Thing::ThingError thingError, const QUuid &thingId, const QString &displayMessage);
|
||||||
void confirmPairingReply(int commandId, const QVariantMap ¶ms);
|
void pairThingReply(int commandId, Thing::ThingError thingError, const QUuid &pairingTransactionId, const QString &setupMethod, const QString &displayMessage, const QString &oAuthUrl);
|
||||||
void addDeviceReply(int commandId, const QVariantMap ¶ms);
|
void confirmPairingReply(int commandId, Thing::ThingError thingError, const QUuid &thingId, const QString &displayMessage);
|
||||||
void removeThingReply(int commandId, const QVariantMap ¶ms);
|
void removeThingReply(int commandId, Thing::ThingError thingError, const QStringList ruleIds);
|
||||||
void savePluginConfigReply(int commandId, const QVariantMap ¶ms);
|
void savePluginConfigReply(int commandId, Thing::ThingError thingError);
|
||||||
void editThingReply(int commandId, const QVariantMap ¶ms);
|
void editThingReply(int commandId, Thing::ThingError thingError);
|
||||||
void reconfigureDeviceReply(int commandId, const QVariantMap ¶ms);
|
void reconfigureThingReply(int commandId, Thing::ThingError thingError, const QString &displayMessage);
|
||||||
void executeActionReply(int commandId, const QVariantMap ¶ms);
|
void executeActionReply(int commandId, Thing::ThingError thingError, const QString &displayMessage);
|
||||||
void executeBrowserItemReply(int commandId, const QVariantMap ¶ms);
|
void executeBrowserItemReply(int commandId, Thing::ThingError thingError, const QString &displayMessage);
|
||||||
void executeBrowserItemActionReply(int commandId, const QVariantMap ¶ms);
|
void executeBrowserItemActionReply(int commandId, Thing::ThingError thingError, const QString &displayMessage);
|
||||||
void fetchingDataChanged();
|
void fetchingDataChanged();
|
||||||
void notificationReceived(const QString &deviceId, const QString &eventTypeId, const QVariantList ¶ms);
|
void notificationReceived(const QString &thingId, const QString &eventTypeId, const QVariantList ¶ms);
|
||||||
|
|
||||||
void eventTriggered(const QUuid &deviceId, const QUuid &eventTypeId, const QVariantMap params);
|
void eventTriggered(const QUuid &thingId, const QUuid &eventTypeId, const QVariantMap params);
|
||||||
void thingStateChanged(const QUuid &deviceId, const QUuid &stateTypeId, const QVariant &value);
|
void thingStateChanged(const QUuid &thingId, const QUuid &stateTypeId, const QVariant &value);
|
||||||
|
|
||||||
|
private:
|
||||||
|
static Vendor *unpackVendor(const QVariantMap &vendorMap);
|
||||||
|
static Plugin *unpackPlugin(const QVariantMap &pluginMap, QObject *parent);
|
||||||
|
static ThingClass *unpackThingClass(const QVariantMap &thingClassMap);
|
||||||
|
static void unpackParam(const QVariantMap ¶mMap, Param *param);
|
||||||
|
static ParamType *unpackParamType(const QVariantMap ¶mTypeMap, QObject *parent);
|
||||||
|
static StateType *unpackStateType(const QVariantMap &stateTypeMap, QObject *parent);
|
||||||
|
static EventType *unpackEventType(const QVariantMap &eventTypeMap, QObject *parent);
|
||||||
|
static ActionType *unpackActionType(const QVariantMap &actionTypeMap, QObject *parent);
|
||||||
|
static Thing *unpackThing(ThingManager *thingManager, const QVariantMap &thingMap, ThingClasses *thingClasses, Thing *oldThing = nullptr);
|
||||||
|
|
||||||
|
static QVariantMap packParam(Param *param);
|
||||||
|
|
||||||
|
static Thing::ThingError errorFromString(const QByteArray &thingErrorString);
|
||||||
|
static ThingClass::SetupMethod stringToSetupMethod(const QString &setupMethodString);
|
||||||
|
static QPair<Types::Unit, QString> stringToUnit(const QString &unitString);
|
||||||
|
static Types::InputType stringToInputType(const QString &inputTypeString);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Vendors *m_vendors;
|
Vendors *m_vendors;
|
||||||
Plugins *m_plugins;
|
Plugins *m_plugins;
|
||||||
Devices *m_devices;
|
Things *m_things;
|
||||||
DeviceClasses *m_thingClasses;
|
ThingClasses *m_thingClasses;
|
||||||
IOConnections *m_ioConnections;
|
IOConnections *m_ioConnections;
|
||||||
|
|
||||||
bool m_fetchingData = false;
|
bool m_fetchingData = false;
|
||||||
@ -218,4 +232,4 @@ private:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DEVICEMANAGER_H
|
#endif // THINGMANAGER_H
|
||||||
@ -28,22 +28,22 @@
|
|||||||
*
|
*
|
||||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
#include "devices.h"
|
#include "things.h"
|
||||||
#include "engine.h"
|
#include "engine.h"
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
Devices::Devices(QObject *parent) :
|
Things::Things(QObject *parent) :
|
||||||
QAbstractListModel(parent)
|
QAbstractListModel(parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<Device *> Devices::devices()
|
QList<Thing *> Things::devices()
|
||||||
{
|
{
|
||||||
return m_things;
|
return m_things;
|
||||||
}
|
}
|
||||||
|
|
||||||
Device *Devices::get(int index) const
|
Thing *Things::get(int index) const
|
||||||
{
|
{
|
||||||
if (index < 0 || index >= m_things.count()) {
|
if (index < 0 || index >= m_things.count()) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@ -51,9 +51,9 @@ Device *Devices::get(int index) const
|
|||||||
return m_things.at(index);
|
return m_things.at(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
Device *Devices::getThing(const QUuid &thingId) const
|
Thing *Things::getThing(const QUuid &thingId) const
|
||||||
{
|
{
|
||||||
foreach (Device *thing, m_things) {
|
foreach (Thing *thing, m_things) {
|
||||||
if (thing->id() == thingId) {
|
if (thing->id() == thingId) {
|
||||||
return thing;
|
return thing;
|
||||||
}
|
}
|
||||||
@ -61,33 +61,27 @@ Device *Devices::getThing(const QUuid &thingId) const
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
Device *Devices::getDevice(const QUuid &deviceId) const
|
int Things::rowCount(const QModelIndex &parent) const
|
||||||
{
|
|
||||||
return getThing(deviceId);
|
|
||||||
}
|
|
||||||
|
|
||||||
int Devices::rowCount(const QModelIndex &parent) const
|
|
||||||
{
|
{
|
||||||
Q_UNUSED(parent)
|
Q_UNUSED(parent)
|
||||||
return m_things.count();
|
return m_things.count();
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant Devices::data(const QModelIndex &index, int role) const
|
QVariant Things::data(const QModelIndex &index, int role) const
|
||||||
{
|
{
|
||||||
if (index.row() < 0 || index.row() >= m_things.count())
|
if (index.row() < 0 || index.row() >= m_things.count())
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
||||||
Device *thing = m_things.at(index.row());
|
Thing *thing = m_things.at(index.row());
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case RoleName:
|
case RoleName:
|
||||||
return thing->name();
|
return thing->name();
|
||||||
case RoleId:
|
case RoleId:
|
||||||
return thing->id().toString();
|
return thing->id().toString();
|
||||||
case RoleDeviceClass:
|
|
||||||
case RoleThingClass:
|
case RoleThingClass:
|
||||||
return thing->thingClassId().toString();
|
return thing->thingClassId().toString();
|
||||||
case RoleParentDeviceId:
|
case RoleParentId:
|
||||||
return thing->parentDeviceId().toString();
|
return thing->parentId().toString();
|
||||||
case RoleSetupStatus:
|
case RoleSetupStatus:
|
||||||
return thing->setupStatus();
|
return thing->setupStatus();
|
||||||
case RoleSetupDisplayMessage:
|
case RoleSetupDisplayMessage:
|
||||||
@ -100,33 +94,32 @@ QVariant Devices::data(const QModelIndex &index, int role) const
|
|||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Devices::addDevice(Device *device)
|
void Things::addThing(Thing *thing)
|
||||||
{
|
{
|
||||||
device->setParent(this);
|
thing->setParent(this);
|
||||||
beginInsertRows(QModelIndex(), m_things.count(), m_things.count());
|
beginInsertRows(QModelIndex(), m_things.count(), m_things.count());
|
||||||
// qDebug() << "Devices: add device" << device->name();
|
m_things.append(thing);
|
||||||
m_things.append(device);
|
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
connect(device, &Device::nameChanged, this, [device, this]() {
|
connect(thing, &Thing::nameChanged, this, [thing, this]() {
|
||||||
int idx = m_things.indexOf(device);
|
int idx = m_things.indexOf(thing);
|
||||||
if (idx < 0) return;
|
if (idx < 0) return;
|
||||||
emit dataChanged(index(idx), index(idx), {RoleName});
|
emit dataChanged(index(idx), index(idx), {RoleName});
|
||||||
});
|
});
|
||||||
connect(device, &Device::setupStatusChanged, this, [device, this]() {
|
connect(thing, &Thing::setupStatusChanged, this, [thing, this]() {
|
||||||
int idx = m_things.indexOf(device);
|
int idx = m_things.indexOf(thing);
|
||||||
if (idx < 0) return;
|
if (idx < 0) return;
|
||||||
emit dataChanged(index(idx), index(idx), {RoleSetupStatus, RoleSetupDisplayMessage});
|
emit dataChanged(index(idx), index(idx), {RoleSetupStatus, RoleSetupDisplayMessage});
|
||||||
});
|
});
|
||||||
connect(device->states(), &States::dataChanged, this, [device, this]() {
|
connect(thing->states(), &States::dataChanged, this, [thing, this]() {
|
||||||
int idx = m_things.indexOf(device);
|
int idx = m_things.indexOf(thing);
|
||||||
if (idx < 0) return;
|
if (idx < 0) return;
|
||||||
emit dataChanged(index(idx), index(idx));
|
emit dataChanged(index(idx), index(idx));
|
||||||
});
|
});
|
||||||
emit countChanged();
|
emit countChanged();
|
||||||
emit thingAdded(device);
|
emit thingAdded(thing);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Devices::removeThing(Device *thing)
|
void Things::removeThing(Thing *thing)
|
||||||
{
|
{
|
||||||
int index = m_things.indexOf(thing);
|
int index = m_things.indexOf(thing);
|
||||||
beginRemoveRows(QModelIndex(), index, index);
|
beginRemoveRows(QModelIndex(), index, index);
|
||||||
@ -137,7 +130,7 @@ void Devices::removeThing(Device *thing)
|
|||||||
emit thingRemoved(thing);
|
emit thingRemoved(thing);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Devices::clearModel()
|
void Things::clearModel()
|
||||||
{
|
{
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
qDeleteAll(m_things);
|
qDeleteAll(m_things);
|
||||||
@ -146,14 +139,13 @@ void Devices::clearModel()
|
|||||||
emit countChanged();
|
emit countChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
QHash<int, QByteArray> Devices::roleNames() const
|
QHash<int, QByteArray> Things::roleNames() const
|
||||||
{
|
{
|
||||||
QHash<int, QByteArray> roles;
|
QHash<int, QByteArray> roles;
|
||||||
roles[RoleName] = "name";
|
roles[RoleName] = "name";
|
||||||
roles[RoleId] = "id";
|
roles[RoleId] = "id";
|
||||||
roles[RoleDeviceClass] = "deviceClassId";
|
|
||||||
roles[RoleThingClass] = "thingClassId";
|
roles[RoleThingClass] = "thingClassId";
|
||||||
roles[RoleParentDeviceId] = "parentDeviceId";
|
roles[RoleParentId] = "parentId";
|
||||||
roles[RoleSetupStatus] = "setupStatus";
|
roles[RoleSetupStatus] = "setupStatus";
|
||||||
roles[RoleSetupDisplayMessage] = "setupDisplayMessage";
|
roles[RoleSetupDisplayMessage] = "setupDisplayMessage";
|
||||||
roles[RoleInterfaces] = "interfaces";
|
roles[RoleInterfaces] = "interfaces";
|
||||||
@ -28,15 +28,15 @@
|
|||||||
*
|
*
|
||||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
#ifndef DEVICES_H
|
#ifndef THINGS_H
|
||||||
#define DEVICES_H
|
#define THINGS_H
|
||||||
|
|
||||||
#include <QAbstractListModel>
|
#include <QAbstractListModel>
|
||||||
|
|
||||||
#include "types/device.h"
|
#include "types/thing.h"
|
||||||
#include "types/deviceclass.h"
|
#include "types/thingclass.h"
|
||||||
|
|
||||||
class Devices : public QAbstractListModel
|
class Things : public QAbstractListModel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
|
Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
|
||||||
@ -44,8 +44,7 @@ public:
|
|||||||
enum Roles {
|
enum Roles {
|
||||||
RoleName,
|
RoleName,
|
||||||
RoleId,
|
RoleId,
|
||||||
RoleParentDeviceId,
|
RoleParentId,
|
||||||
RoleDeviceClass,
|
|
||||||
RoleThingClass,
|
RoleThingClass,
|
||||||
RoleSetupStatus,
|
RoleSetupStatus,
|
||||||
RoleSetupDisplayMessage,
|
RoleSetupDisplayMessage,
|
||||||
@ -54,33 +53,32 @@ public:
|
|||||||
};
|
};
|
||||||
Q_ENUM(Roles)
|
Q_ENUM(Roles)
|
||||||
|
|
||||||
explicit Devices(QObject *parent = nullptr);
|
explicit Things(QObject *parent = nullptr);
|
||||||
|
|
||||||
QList<Device *> devices();
|
QList<Thing *> devices();
|
||||||
|
|
||||||
Q_INVOKABLE Device *get(int index) const;
|
Q_INVOKABLE Thing *get(int index) const;
|
||||||
Q_INVOKABLE Device *getThing(const QUuid &thingId) const;
|
Q_INVOKABLE Thing *getThing(const QUuid &thingId) const;
|
||||||
Q_INVOKABLE Device *getDevice(const QUuid &deviceId) const;
|
|
||||||
|
|
||||||
int rowCount(const QModelIndex & parent = QModelIndex()) const;
|
int rowCount(const QModelIndex & parent = QModelIndex()) const override;
|
||||||
QVariant data(const QModelIndex & index, int role = RoleName) const;
|
QVariant data(const QModelIndex & index, int role = RoleName) const override;
|
||||||
|
|
||||||
void addDevice(Device *device);
|
void addThing(Thing *thing);
|
||||||
void removeThing(Device *thing);
|
void removeThing(Thing *thing);
|
||||||
|
|
||||||
void clearModel();
|
void clearModel();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QHash<int, QByteArray> roleNames() const;
|
QHash<int, QByteArray> roleNames() const override;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void countChanged();
|
void countChanged();
|
||||||
void thingAdded(Device *device);
|
void thingAdded(Thing *device);
|
||||||
void thingRemoved(Device *device);
|
void thingRemoved(Thing *device);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<Device *> m_things;
|
QList<Thing *> m_things;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DEVICES_H
|
#endif // THINGS_H
|
||||||
@ -28,26 +28,26 @@
|
|||||||
*
|
*
|
||||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
#include "devicesproxy.h"
|
#include "thingsproxy.h"
|
||||||
#include "engine.h"
|
#include "engine.h"
|
||||||
#include "tagsmanager.h"
|
#include "tagsmanager.h"
|
||||||
#include "types/tag.h"
|
#include "types/tag.h"
|
||||||
|
|
||||||
DevicesProxy::DevicesProxy(QObject *parent) :
|
ThingsProxy::ThingsProxy(QObject *parent) :
|
||||||
QSortFilterProxyModel(parent)
|
QSortFilterProxyModel(parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Engine *DevicesProxy::engine() const
|
Engine *ThingsProxy::engine() const
|
||||||
{
|
{
|
||||||
return m_engine;
|
return m_engine;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevicesProxy::setEngine(Engine *engine)
|
void ThingsProxy::setEngine(Engine *engine)
|
||||||
{
|
{
|
||||||
if (m_engine != engine) {
|
if (m_engine != engine) {
|
||||||
if (m_engine) {
|
if (m_engine) {
|
||||||
disconnect(m_engine->tagsManager()->tags(), &Tags::countChanged, this, &DevicesProxy::invalidateFilter);
|
disconnect(m_engine->tagsManager()->tags(), &Tags::countChanged, this, &ThingsProxy::invalidateFilter);
|
||||||
}
|
}
|
||||||
m_engine = engine;
|
m_engine = engine;
|
||||||
emit engineChanged();
|
emit engineChanged();
|
||||||
@ -55,12 +55,12 @@ void DevicesProxy::setEngine(Engine *engine)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
connect(m_engine->tagsManager()->tags(), &Tags::countChanged, this, &DevicesProxy::invalidateFilter);
|
connect(m_engine->tagsManager()->tags(), &Tags::countChanged, this, &ThingsProxy::invalidateFilter);
|
||||||
|
|
||||||
if (!sourceModel()) {
|
if (!sourceModel()) {
|
||||||
setSourceModel(m_engine->deviceManager()->devices());
|
setSourceModel(m_engine->thingManager()->things());
|
||||||
|
|
||||||
setSortRole(Devices::RoleName);
|
setSortRole(Things::RoleName);
|
||||||
sort(0);
|
sort(0);
|
||||||
connect(sourceModel(), SIGNAL(countChanged()), this, SIGNAL(countChanged()));
|
connect(sourceModel(), SIGNAL(countChanged()), this, SIGNAL(countChanged()));
|
||||||
connect(sourceModel(), &QAbstractItemModel::dataChanged, this, [this]() {
|
connect(sourceModel(), &QAbstractItemModel::dataChanged, this, [this]() {
|
||||||
@ -72,12 +72,12 @@ void DevicesProxy::setEngine(Engine *engine)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DevicesProxy *DevicesProxy::parentProxy() const
|
ThingsProxy *ThingsProxy::parentProxy() const
|
||||||
{
|
{
|
||||||
return m_parentProxy;
|
return m_parentProxy;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevicesProxy::setParentProxy(DevicesProxy *parentProxy)
|
void ThingsProxy::setParentProxy(ThingsProxy *parentProxy)
|
||||||
{
|
{
|
||||||
if (m_parentProxy != parentProxy) {
|
if (m_parentProxy != parentProxy) {
|
||||||
m_parentProxy = parentProxy;
|
m_parentProxy = parentProxy;
|
||||||
@ -86,7 +86,7 @@ void DevicesProxy::setParentProxy(DevicesProxy *parentProxy)
|
|||||||
if (!m_engine) {
|
if (!m_engine) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setSortRole(Devices::RoleName);
|
setSortRole(Things::RoleName);
|
||||||
sort(0);
|
sort(0);
|
||||||
connect(m_parentProxy, SIGNAL(countChanged()), this, SIGNAL(countChanged()));
|
connect(m_parentProxy, SIGNAL(countChanged()), this, SIGNAL(countChanged()));
|
||||||
connect(m_parentProxy, &QAbstractItemModel::dataChanged, this, [this]() {
|
connect(m_parentProxy, &QAbstractItemModel::dataChanged, this, [this]() {
|
||||||
@ -105,12 +105,12 @@ void DevicesProxy::setParentProxy(DevicesProxy *parentProxy)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString DevicesProxy::filterTagId() const
|
QString ThingsProxy::filterTagId() const
|
||||||
{
|
{
|
||||||
return m_filterTagId;
|
return m_filterTagId;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevicesProxy::setFilterTagId(const QString &filterTag)
|
void ThingsProxy::setFilterTagId(const QString &filterTag)
|
||||||
{
|
{
|
||||||
if (m_filterTagId != filterTag) {
|
if (m_filterTagId != filterTag) {
|
||||||
m_filterTagId = filterTag;
|
m_filterTagId = filterTag;
|
||||||
@ -120,12 +120,12 @@ void DevicesProxy::setFilterTagId(const QString &filterTag)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString DevicesProxy::filterTagValue() const
|
QString ThingsProxy::filterTagValue() const
|
||||||
{
|
{
|
||||||
return m_filterTagValue;
|
return m_filterTagValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevicesProxy::setFilterTagValue(const QString &tagValue)
|
void ThingsProxy::setFilterTagValue(const QString &tagValue)
|
||||||
{
|
{
|
||||||
if (m_filterTagValue != tagValue) {
|
if (m_filterTagValue != tagValue) {
|
||||||
m_filterTagValue = tagValue;
|
m_filterTagValue = tagValue;
|
||||||
@ -135,42 +135,42 @@ void DevicesProxy::setFilterTagValue(const QString &tagValue)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString DevicesProxy::filterDeviceClassId() const
|
QString ThingsProxy::filterThingClassId() const
|
||||||
{
|
{
|
||||||
return m_filterDeviceClassId;
|
return m_filterThingClassId;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevicesProxy::setFilterDeviceClassId(const QString &filterDeviceClassId)
|
void ThingsProxy::setFilterThingClassId(const QString &filterThingClassId)
|
||||||
{
|
{
|
||||||
if (m_filterDeviceClassId != filterDeviceClassId) {
|
if (m_filterThingClassId != filterThingClassId) {
|
||||||
m_filterDeviceClassId = filterDeviceClassId;
|
m_filterThingClassId = filterThingClassId;
|
||||||
emit filterDeviceClassIdChanged();
|
emit filterThingClassIdChanged();
|
||||||
invalidateFilter();
|
invalidateFilter();
|
||||||
emit countChanged();
|
emit countChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString DevicesProxy::filterDeviceId() const
|
QString ThingsProxy::filterThingId() const
|
||||||
{
|
{
|
||||||
return m_filterDeviceId;
|
return m_filterThingId;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevicesProxy::setFilterDeviceId(const QString &filterDeviceId)
|
void ThingsProxy::setFilterThingId(const QString &filterThingId)
|
||||||
{
|
{
|
||||||
if (m_filterDeviceId != filterDeviceId) {
|
if (m_filterThingId != filterThingId) {
|
||||||
m_filterDeviceId = filterDeviceId;
|
m_filterThingId = filterThingId;
|
||||||
emit filterDeviceIdChanged();
|
emit filterThingIdChanged();
|
||||||
invalidateFilter();
|
invalidateFilter();
|
||||||
emit countChanged();
|
emit countChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList DevicesProxy::shownInterfaces() const
|
QStringList ThingsProxy::shownInterfaces() const
|
||||||
{
|
{
|
||||||
return m_shownInterfaces;
|
return m_shownInterfaces;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevicesProxy::setShownInterfaces(const QStringList &shownInterfaces)
|
void ThingsProxy::setShownInterfaces(const QStringList &shownInterfaces)
|
||||||
{
|
{
|
||||||
if (m_shownInterfaces != shownInterfaces) {
|
if (m_shownInterfaces != shownInterfaces) {
|
||||||
m_shownInterfaces = shownInterfaces;
|
m_shownInterfaces = shownInterfaces;
|
||||||
@ -180,12 +180,12 @@ void DevicesProxy::setShownInterfaces(const QStringList &shownInterfaces)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList DevicesProxy::hiddenInterfaces() const
|
QStringList ThingsProxy::hiddenInterfaces() const
|
||||||
{
|
{
|
||||||
return m_hiddenInterfaces;
|
return m_hiddenInterfaces;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevicesProxy::setHiddenInterfaces(const QStringList &hiddenInterfaces)
|
void ThingsProxy::setHiddenInterfaces(const QStringList &hiddenInterfaces)
|
||||||
{
|
{
|
||||||
if (m_hiddenInterfaces != hiddenInterfaces) {
|
if (m_hiddenInterfaces != hiddenInterfaces) {
|
||||||
m_hiddenInterfaces = hiddenInterfaces;
|
m_hiddenInterfaces = hiddenInterfaces;
|
||||||
@ -195,12 +195,12 @@ void DevicesProxy::setHiddenInterfaces(const QStringList &hiddenInterfaces)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString DevicesProxy::nameFilter() const
|
QString ThingsProxy::nameFilter() const
|
||||||
{
|
{
|
||||||
return m_nameFilter;
|
return m_nameFilter;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevicesProxy::setNameFilter(const QString &nameFilter)
|
void ThingsProxy::setNameFilter(const QString &nameFilter)
|
||||||
{
|
{
|
||||||
if (m_nameFilter != nameFilter) {
|
if (m_nameFilter != nameFilter) {
|
||||||
m_nameFilter = nameFilter;
|
m_nameFilter = nameFilter;
|
||||||
@ -210,12 +210,12 @@ void DevicesProxy::setNameFilter(const QString &nameFilter)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString DevicesProxy::requiredEventName() const
|
QString ThingsProxy::requiredEventName() const
|
||||||
{
|
{
|
||||||
return m_requiredEventName;
|
return m_requiredEventName;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevicesProxy::setRequiredEventName(const QString &requiredEventName)
|
void ThingsProxy::setRequiredEventName(const QString &requiredEventName)
|
||||||
{
|
{
|
||||||
if (m_requiredEventName != requiredEventName) {
|
if (m_requiredEventName != requiredEventName) {
|
||||||
m_requiredEventName = requiredEventName;
|
m_requiredEventName = requiredEventName;
|
||||||
@ -225,12 +225,12 @@ void DevicesProxy::setRequiredEventName(const QString &requiredEventName)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString DevicesProxy::requiredStateName() const
|
QString ThingsProxy::requiredStateName() const
|
||||||
{
|
{
|
||||||
return m_requiredStateName;
|
return m_requiredStateName;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevicesProxy::setRequiredStateName(const QString &requiredStateName)
|
void ThingsProxy::setRequiredStateName(const QString &requiredStateName)
|
||||||
{
|
{
|
||||||
if (m_requiredStateName != requiredStateName) {
|
if (m_requiredStateName != requiredStateName) {
|
||||||
m_requiredStateName = requiredStateName;
|
m_requiredStateName = requiredStateName;
|
||||||
@ -240,12 +240,12 @@ void DevicesProxy::setRequiredStateName(const QString &requiredStateName)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString DevicesProxy::requiredActionName() const
|
QString ThingsProxy::requiredActionName() const
|
||||||
{
|
{
|
||||||
return m_requiredActionName;
|
return m_requiredActionName;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevicesProxy::setRequiredActionName(const QString &requiredActionName)
|
void ThingsProxy::setRequiredActionName(const QString &requiredActionName)
|
||||||
{
|
{
|
||||||
if (m_requiredActionName != requiredActionName) {
|
if (m_requiredActionName != requiredActionName) {
|
||||||
m_requiredActionName = requiredActionName;
|
m_requiredActionName = requiredActionName;
|
||||||
@ -255,12 +255,12 @@ void DevicesProxy::setRequiredActionName(const QString &requiredActionName)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DevicesProxy::showDigitalInputs() const
|
bool ThingsProxy::showDigitalInputs() const
|
||||||
{
|
{
|
||||||
return m_showDigitalInputs;
|
return m_showDigitalInputs;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevicesProxy::setShowDigitalInputs(bool showDigitalInputs)
|
void ThingsProxy::setShowDigitalInputs(bool showDigitalInputs)
|
||||||
{
|
{
|
||||||
if (m_showDigitalInputs != showDigitalInputs) {
|
if (m_showDigitalInputs != showDigitalInputs) {
|
||||||
m_showDigitalInputs = showDigitalInputs;
|
m_showDigitalInputs = showDigitalInputs;
|
||||||
@ -270,12 +270,12 @@ void DevicesProxy::setShowDigitalInputs(bool showDigitalInputs)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DevicesProxy::showDigitalOutputs() const
|
bool ThingsProxy::showDigitalOutputs() const
|
||||||
{
|
{
|
||||||
return m_showDigitalOutputs;
|
return m_showDigitalOutputs;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevicesProxy::setShowDigitalOutputs(bool showDigitalOutputs)
|
void ThingsProxy::setShowDigitalOutputs(bool showDigitalOutputs)
|
||||||
{
|
{
|
||||||
if (m_showDigitalOutputs != showDigitalOutputs) {
|
if (m_showDigitalOutputs != showDigitalOutputs) {
|
||||||
m_showDigitalOutputs = showDigitalOutputs;
|
m_showDigitalOutputs = showDigitalOutputs;
|
||||||
@ -285,12 +285,12 @@ void DevicesProxy::setShowDigitalOutputs(bool showDigitalOutputs)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DevicesProxy::showAnalogInputs() const
|
bool ThingsProxy::showAnalogInputs() const
|
||||||
{
|
{
|
||||||
return m_showAnalogInputs;
|
return m_showAnalogInputs;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevicesProxy::setShowAnalogInputs(bool showAnalogInputs)
|
void ThingsProxy::setShowAnalogInputs(bool showAnalogInputs)
|
||||||
{
|
{
|
||||||
if (m_showAnalogInputs != showAnalogInputs) {
|
if (m_showAnalogInputs != showAnalogInputs) {
|
||||||
m_showAnalogInputs = showAnalogInputs;
|
m_showAnalogInputs = showAnalogInputs;
|
||||||
@ -300,12 +300,12 @@ void DevicesProxy::setShowAnalogInputs(bool showAnalogInputs)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DevicesProxy::showAnalogOutputs() const
|
bool ThingsProxy::showAnalogOutputs() const
|
||||||
{
|
{
|
||||||
return m_showDigitalOutputs;
|
return m_showDigitalOutputs;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevicesProxy::setShowAnalogOutputs(bool showAnalogOutputs)
|
void ThingsProxy::setShowAnalogOutputs(bool showAnalogOutputs)
|
||||||
{
|
{
|
||||||
if (m_showAnalogOutputs != showAnalogOutputs) {
|
if (m_showAnalogOutputs != showAnalogOutputs) {
|
||||||
m_showAnalogOutputs = showAnalogOutputs;
|
m_showAnalogOutputs = showAnalogOutputs;
|
||||||
@ -315,12 +315,12 @@ void DevicesProxy::setShowAnalogOutputs(bool showAnalogOutputs)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DevicesProxy::filterBatteryCritical() const
|
bool ThingsProxy::filterBatteryCritical() const
|
||||||
{
|
{
|
||||||
return m_filterBatteryCritical;
|
return m_filterBatteryCritical;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevicesProxy::setFilterBatteryCritical(bool filterBatteryCritical)
|
void ThingsProxy::setFilterBatteryCritical(bool filterBatteryCritical)
|
||||||
{
|
{
|
||||||
if (m_filterBatteryCritical != filterBatteryCritical) {
|
if (m_filterBatteryCritical != filterBatteryCritical) {
|
||||||
m_filterBatteryCritical = filterBatteryCritical;
|
m_filterBatteryCritical = filterBatteryCritical;
|
||||||
@ -330,12 +330,12 @@ void DevicesProxy::setFilterBatteryCritical(bool filterBatteryCritical)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DevicesProxy::filterDisconnected() const
|
bool ThingsProxy::filterDisconnected() const
|
||||||
{
|
{
|
||||||
return m_filterDisconnected;
|
return m_filterDisconnected;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevicesProxy::setFilterDisconnected(bool filterDisconnected)
|
void ThingsProxy::setFilterDisconnected(bool filterDisconnected)
|
||||||
{
|
{
|
||||||
if (m_filterDisconnected != filterDisconnected) {
|
if (m_filterDisconnected != filterDisconnected) {
|
||||||
m_filterDisconnected = filterDisconnected;
|
m_filterDisconnected = filterDisconnected;
|
||||||
@ -345,12 +345,12 @@ void DevicesProxy::setFilterDisconnected(bool filterDisconnected)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DevicesProxy::filterSetupFailed() const
|
bool ThingsProxy::filterSetupFailed() const
|
||||||
{
|
{
|
||||||
return m_filterSetupFailed;
|
return m_filterSetupFailed;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevicesProxy::setFilterSetupFailed(bool filterSetupFailed)
|
void ThingsProxy::setFilterSetupFailed(bool filterSetupFailed)
|
||||||
{
|
{
|
||||||
if (m_filterSetupFailed != filterSetupFailed) {
|
if (m_filterSetupFailed != filterSetupFailed) {
|
||||||
m_filterSetupFailed = filterSetupFailed;
|
m_filterSetupFailed = filterSetupFailed;
|
||||||
@ -360,12 +360,12 @@ void DevicesProxy::setFilterSetupFailed(bool filterSetupFailed)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DevicesProxy::filterUpdates() const
|
bool ThingsProxy::filterUpdates() const
|
||||||
{
|
{
|
||||||
return m_filterUpdates;
|
return m_filterUpdates;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevicesProxy::setFilterUpdates(bool filterUpdates)
|
void ThingsProxy::setFilterUpdates(bool filterUpdates)
|
||||||
{
|
{
|
||||||
if (m_filterUpdates != filterUpdates) {
|
if (m_filterUpdates != filterUpdates) {
|
||||||
m_filterUpdates = filterUpdates;
|
m_filterUpdates = filterUpdates;
|
||||||
@ -375,12 +375,12 @@ void DevicesProxy::setFilterUpdates(bool filterUpdates)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DevicesProxy::groupByInterface() const
|
bool ThingsProxy::groupByInterface() const
|
||||||
{
|
{
|
||||||
return m_groupByInterface;
|
return m_groupByInterface;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevicesProxy::setGroupByInterface(bool groupByInterface)
|
void ThingsProxy::setGroupByInterface(bool groupByInterface)
|
||||||
{
|
{
|
||||||
if (m_groupByInterface != groupByInterface) {
|
if (m_groupByInterface != groupByInterface) {
|
||||||
m_groupByInterface = groupByInterface;
|
m_groupByInterface = groupByInterface;
|
||||||
@ -390,70 +390,65 @@ void DevicesProxy::setGroupByInterface(bool groupByInterface)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Device *DevicesProxy::get(int index) const
|
Thing *ThingsProxy::get(int index) const
|
||||||
{
|
{
|
||||||
return getInternal(mapToSource(this->index(index, 0)).row());
|
return getInternal(mapToSource(this->index(index, 0)).row());
|
||||||
}
|
}
|
||||||
|
|
||||||
Device *DevicesProxy::getDevice(const QUuid &deviceId) const
|
Thing *ThingsProxy::getThing(const QUuid &thingId) const
|
||||||
{
|
{
|
||||||
return getThing(deviceId);
|
Things *d = qobject_cast<Things*>(sourceModel());
|
||||||
}
|
|
||||||
|
|
||||||
Device *DevicesProxy::getThing(const QUuid &thingId) const
|
|
||||||
{
|
|
||||||
Devices *d = qobject_cast<Devices*>(sourceModel());
|
|
||||||
if (d) {
|
if (d) {
|
||||||
return d->getThing(thingId);
|
return d->getThing(thingId);
|
||||||
}
|
}
|
||||||
DevicesProxy *dp = qobject_cast<DevicesProxy*>(sourceModel());
|
ThingsProxy *dp = qobject_cast<ThingsProxy*>(sourceModel());
|
||||||
if (dp) {
|
if (dp) {
|
||||||
return dp->getThing(thingId);
|
return dp->getThing(thingId);
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
Device *DevicesProxy::getInternal(int source_index) const
|
Thing *ThingsProxy::getInternal(int source_index) const
|
||||||
{
|
{
|
||||||
Devices* d = qobject_cast<Devices*>(sourceModel());
|
Things* d = qobject_cast<Things*>(sourceModel());
|
||||||
if (d) {
|
if (d) {
|
||||||
return d->get(source_index);
|
return d->get(source_index);
|
||||||
}
|
}
|
||||||
DevicesProxy *dp = qobject_cast<DevicesProxy*>(sourceModel());
|
ThingsProxy *dp = qobject_cast<ThingsProxy*>(sourceModel());
|
||||||
if (dp) {
|
if (dp) {
|
||||||
return dp->get(source_index);
|
return dp->get(source_index);
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DevicesProxy::lessThan(const QModelIndex &left, const QModelIndex &right) const
|
bool ThingsProxy::lessThan(const QModelIndex &left, const QModelIndex &right) const
|
||||||
{
|
{
|
||||||
if (m_groupByInterface) {
|
if (m_groupByInterface) {
|
||||||
QString leftBaseInterface = sourceModel()->data(left, Devices::RoleBaseInterface).toString();
|
QString leftBaseInterface = sourceModel()->data(left, Things::RoleBaseInterface).toString();
|
||||||
QString rightBaseInterface = sourceModel()->data(right, Devices::RoleBaseInterface).toString();
|
QString rightBaseInterface = sourceModel()->data(right, Things::RoleBaseInterface).toString();
|
||||||
if (leftBaseInterface != rightBaseInterface) {
|
if (leftBaseInterface != rightBaseInterface) {
|
||||||
return QString::localeAwareCompare(leftBaseInterface, rightBaseInterface) < 0;
|
return QString::localeAwareCompare(leftBaseInterface, rightBaseInterface) < 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
QString leftName = sourceModel()->data(left, Devices::RoleName).toString();
|
QString leftName = sourceModel()->data(left, Things::RoleName).toString();
|
||||||
QString rightName = sourceModel()->data(right, Devices::RoleName).toString();
|
QString rightName = sourceModel()->data(right, Things::RoleName).toString();
|
||||||
|
|
||||||
int comparison = QString::localeAwareCompare(leftName, rightName);
|
int comparison = QString::localeAwareCompare(leftName, rightName);
|
||||||
if (comparison == 0) {
|
if (comparison == 0) {
|
||||||
// If there are 2 identically named things we don't want undefined behavor as it may cause items
|
// If there are 2 identically named things we don't want undefined behavor as it may cause items
|
||||||
// to reorder randomly. Use something static like thingId as fallback
|
// to reorder randomly. Use something static like thingId as fallback
|
||||||
QString leftThingId = sourceModel()->data(left, Devices::RoleId).toString();
|
QString leftThingId = sourceModel()->data(left, Things::RoleId).toString();
|
||||||
QString rightThingId = sourceModel()->data(right, Devices::RoleId).toString();
|
QString rightThingId = sourceModel()->data(right, Things::RoleId).toString();
|
||||||
comparison = QString::localeAwareCompare(leftThingId, rightThingId);
|
comparison = QString::localeAwareCompare(leftThingId, rightThingId);
|
||||||
}
|
}
|
||||||
return comparison < 0;
|
return comparison < 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DevicesProxy::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
|
bool ThingsProxy::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
|
||||||
{
|
{
|
||||||
Device *device = getInternal(source_row);
|
Thing *thing = getInternal(source_row);
|
||||||
if (!m_filterTagId.isEmpty()) {
|
if (!m_filterTagId.isEmpty()) {
|
||||||
Tag *tag = m_engine->tagsManager()->tags()->findDeviceTag(device->id().toString(), m_filterTagId);
|
Tag *tag = m_engine->tagsManager()->tags()->findThingTag(thing->id().toString(), m_filterTagId);
|
||||||
if (!tag) {
|
if (!tag) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -461,22 +456,22 @@ bool DevicesProxy::filterAcceptsRow(int source_row, const QModelIndex &source_pa
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!m_filterDeviceClassId.isEmpty()) {
|
if (!m_filterThingClassId.isEmpty()) {
|
||||||
if (device->deviceClassId() != QUuid(m_filterDeviceClassId)) {
|
if (thing->thingClassId() != QUuid(m_filterThingClassId)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!m_filterDeviceId.isEmpty()) {
|
if (!m_filterThingId.isEmpty()) {
|
||||||
if (device->id() != QUuid(m_filterDeviceId)) {
|
if (thing->id() != QUuid(m_filterThingId)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DeviceClass *deviceClass = m_engine->deviceManager()->deviceClasses()->getDeviceClass(device->deviceClassId());
|
ThingClass *thingClass = m_engine->thingManager()->thingClasses()->getThingClass(thing->thingClassId());
|
||||||
// qDebug() << "Checking device" << deviceClass->name() << deviceClass->interfaces();
|
// qDebug() << "Checking thing" << thingClass->name() << thingClass->interfaces();
|
||||||
if (!m_shownInterfaces.isEmpty()) {
|
if (!m_shownInterfaces.isEmpty()) {
|
||||||
bool foundMatch = false;
|
bool foundMatch = false;
|
||||||
foreach (const QString &filterInterface, m_shownInterfaces) {
|
foreach (const QString &filterInterface, m_shownInterfaces) {
|
||||||
if (deviceClass->interfaces().contains(filterInterface)) {
|
if (thingClass->interfaces().contains(filterInterface)) {
|
||||||
foundMatch = true;
|
foundMatch = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -488,72 +483,72 @@ bool DevicesProxy::filterAcceptsRow(int source_row, const QModelIndex &source_pa
|
|||||||
|
|
||||||
if (!m_hiddenInterfaces.isEmpty()) {
|
if (!m_hiddenInterfaces.isEmpty()) {
|
||||||
foreach (const QString &filterInterface, m_hiddenInterfaces) {
|
foreach (const QString &filterInterface, m_hiddenInterfaces) {
|
||||||
if (deviceClass->interfaces().contains(filterInterface)) {
|
if (thingClass->interfaces().contains(filterInterface)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_showDigitalInputs || m_showDigitalOutputs || m_showAnalogInputs || m_showAnalogOutputs) {
|
if (m_showDigitalInputs || m_showDigitalOutputs || m_showAnalogInputs || m_showAnalogOutputs) {
|
||||||
if (m_showDigitalInputs && deviceClass->stateTypes()->ioStateTypes(Types::IOTypeDigitalInput).isEmpty()) {
|
if (m_showDigitalInputs && thingClass->stateTypes()->ioStateTypes(Types::IOTypeDigitalInput).isEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (m_showDigitalOutputs && deviceClass->stateTypes()->ioStateTypes(Types::IOTypeDigitalOutput).isEmpty()) {
|
if (m_showDigitalOutputs && thingClass->stateTypes()->ioStateTypes(Types::IOTypeDigitalOutput).isEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (m_showAnalogInputs && deviceClass->stateTypes()->ioStateTypes(Types::IOTypeAnalogInput).isEmpty()) {
|
if (m_showAnalogInputs && thingClass->stateTypes()->ioStateTypes(Types::IOTypeAnalogInput).isEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (m_showAnalogOutputs && deviceClass->stateTypes()->ioStateTypes(Types::IOTypeAnalogOutput).isEmpty()) {
|
if (m_showAnalogOutputs && thingClass->stateTypes()->ioStateTypes(Types::IOTypeAnalogOutput).isEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_filterBatteryCritical) {
|
if (m_filterBatteryCritical) {
|
||||||
if (!deviceClass->interfaces().contains("battery") || device->stateValue(deviceClass->stateTypes()->findByName("batteryCritical")->id()).toBool() == false) {
|
if (!thingClass->interfaces().contains("battery") || thing->stateValue(thingClass->stateTypes()->findByName("batteryCritical")->id()).toBool() == false) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_filterDisconnected) {
|
if (m_filterDisconnected) {
|
||||||
if (!deviceClass->interfaces().contains("connectable") || device->stateValue(deviceClass->stateTypes()->findByName("connected")->id()).toBool() == true) {
|
if (!thingClass->interfaces().contains("connectable") || thing->stateValue(thingClass->stateTypes()->findByName("connected")->id()).toBool() == true) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_filterSetupFailed) {
|
if (m_filterSetupFailed) {
|
||||||
if (device->setupStatus() != Device::ThingSetupStatusFailed) {
|
if (thing->setupStatus() != Thing::ThingSetupStatusFailed) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_filterUpdates) {
|
if (m_filterUpdates) {
|
||||||
if (!deviceClass->interfaces().contains("update")) {
|
if (!thingClass->interfaces().contains("update")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (device->stateValue(deviceClass->stateTypes()->findByName("updateStatus")->id()).toString() == "idle") {
|
if (thing->stateValue(thingClass->stateTypes()->findByName("updateStatus")->id()).toString() == "idle") {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_nameFilter.isEmpty()) {
|
if (!m_nameFilter.isEmpty()) {
|
||||||
if (!device->name().toLower().contains(m_nameFilter.toLower().trimmed())) {
|
if (!thing->name().toLower().contains(m_nameFilter.toLower().trimmed())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_requiredEventName.isEmpty()) {
|
if (!m_requiredEventName.isEmpty()) {
|
||||||
if (!device->thingClass()->eventTypes()->findByName(m_requiredEventName)) {
|
if (!thing->thingClass()->eventTypes()->findByName(m_requiredEventName)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!m_requiredStateName.isEmpty()) {
|
if (!m_requiredStateName.isEmpty()) {
|
||||||
if (!device->thingClass()->stateTypes()->findByName(m_requiredStateName)) {
|
if (!thing->thingClass()->stateTypes()->findByName(m_requiredStateName)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!m_requiredActionName.isEmpty()) {
|
if (!m_requiredActionName.isEmpty()) {
|
||||||
if (!device->thingClass()->actionTypes()->findByName(m_requiredActionName)) {
|
if (!thing->thingClass()->actionTypes()->findByName(m_requiredActionName)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -28,27 +28,27 @@
|
|||||||
*
|
*
|
||||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
#ifndef DEVICESPROXY_H
|
#ifndef THINGSPROXY_H
|
||||||
#define DEVICESPROXY_H
|
#define THINGSPROXY_H
|
||||||
|
|
||||||
#include <QUuid>
|
#include <QUuid>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QSortFilterProxyModel>
|
#include <QSortFilterProxyModel>
|
||||||
|
|
||||||
#include "devices.h"
|
#include "things.h"
|
||||||
|
|
||||||
class Engine;
|
class Engine;
|
||||||
|
|
||||||
class DevicesProxy : public QSortFilterProxyModel
|
class ThingsProxy : public QSortFilterProxyModel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
|
Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
|
||||||
Q_PROPERTY(Engine* engine READ engine WRITE setEngine NOTIFY engineChanged)
|
Q_PROPERTY(Engine* engine READ engine WRITE setEngine NOTIFY engineChanged)
|
||||||
Q_PROPERTY(DevicesProxy *parentProxy READ parentProxy WRITE setParentProxy NOTIFY parentProxyChanged)
|
Q_PROPERTY(ThingsProxy *parentProxy READ parentProxy WRITE setParentProxy NOTIFY parentProxyChanged)
|
||||||
Q_PROPERTY(QString filterTagId READ filterTagId WRITE setFilterTagId NOTIFY filterTagIdChanged)
|
Q_PROPERTY(QString filterTagId READ filterTagId WRITE setFilterTagId NOTIFY filterTagIdChanged)
|
||||||
Q_PROPERTY(QString filterTagValue READ filterTagValue WRITE setFilterTagValue NOTIFY filterTagValueChanged)
|
Q_PROPERTY(QString filterTagValue READ filterTagValue WRITE setFilterTagValue NOTIFY filterTagValueChanged)
|
||||||
Q_PROPERTY(QString filterDeviceClassId READ filterDeviceClassId WRITE setFilterDeviceClassId NOTIFY filterDeviceClassIdChanged)
|
Q_PROPERTY(QString filterThingClassId READ filterThingClassId WRITE setFilterThingClassId NOTIFY filterThingClassIdChanged)
|
||||||
Q_PROPERTY(QString filterDeviceId READ filterDeviceId WRITE setFilterDeviceId NOTIFY filterDeviceIdChanged)
|
Q_PROPERTY(QString filterThingId READ filterThingId WRITE setFilterThingId NOTIFY filterThingIdChanged)
|
||||||
Q_PROPERTY(QStringList shownInterfaces READ shownInterfaces WRITE setShownInterfaces NOTIFY shownInterfacesChanged)
|
Q_PROPERTY(QStringList shownInterfaces READ shownInterfaces WRITE setShownInterfaces NOTIFY shownInterfacesChanged)
|
||||||
Q_PROPERTY(QStringList hiddenInterfaces READ hiddenInterfaces WRITE setHiddenInterfaces NOTIFY hiddenInterfacesChanged)
|
Q_PROPERTY(QStringList hiddenInterfaces READ hiddenInterfaces WRITE setHiddenInterfaces NOTIFY hiddenInterfacesChanged)
|
||||||
Q_PROPERTY(QString nameFilter READ nameFilter WRITE setNameFilter NOTIFY nameFilterChanged)
|
Q_PROPERTY(QString nameFilter READ nameFilter WRITE setNameFilter NOTIFY nameFilterChanged)
|
||||||
@ -76,13 +76,13 @@ class DevicesProxy : public QSortFilterProxyModel
|
|||||||
Q_PROPERTY(bool groupByInterface READ groupByInterface WRITE setGroupByInterface NOTIFY groupByInterfaceChanged)
|
Q_PROPERTY(bool groupByInterface READ groupByInterface WRITE setGroupByInterface NOTIFY groupByInterfaceChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit DevicesProxy(QObject *parent = nullptr);
|
explicit ThingsProxy(QObject *parent = nullptr);
|
||||||
|
|
||||||
Engine *engine() const;
|
Engine *engine() const;
|
||||||
void setEngine(Engine *engine);
|
void setEngine(Engine *engine);
|
||||||
|
|
||||||
DevicesProxy *parentProxy() const;
|
ThingsProxy *parentProxy() const;
|
||||||
void setParentProxy(DevicesProxy *parentProxy);
|
void setParentProxy(ThingsProxy *parentProxy);
|
||||||
|
|
||||||
QString filterTagId() const;
|
QString filterTagId() const;
|
||||||
void setFilterTagId(const QString &filterTag);
|
void setFilterTagId(const QString &filterTag);
|
||||||
@ -90,11 +90,11 @@ public:
|
|||||||
QString filterTagValue() const;
|
QString filterTagValue() const;
|
||||||
void setFilterTagValue(const QString &tagValue);
|
void setFilterTagValue(const QString &tagValue);
|
||||||
|
|
||||||
QString filterDeviceClassId() const;
|
QString filterThingClassId() const;
|
||||||
void setFilterDeviceClassId(const QString &filterDeviceClassId);
|
void setFilterThingClassId(const QString &filterThingClassId);
|
||||||
|
|
||||||
QString filterDeviceId() const;
|
QString filterThingId() const;
|
||||||
void setFilterDeviceId(const QString &filterDeviceId);
|
void setFilterThingId(const QString &filterThingId);
|
||||||
|
|
||||||
QStringList shownInterfaces() const;
|
QStringList shownInterfaces() const;
|
||||||
void setShownInterfaces(const QStringList &shownInterfaces);
|
void setShownInterfaces(const QStringList &shownInterfaces);
|
||||||
@ -141,17 +141,16 @@ public:
|
|||||||
bool groupByInterface() const;
|
bool groupByInterface() const;
|
||||||
void setGroupByInterface(bool groupByInterface);
|
void setGroupByInterface(bool groupByInterface);
|
||||||
|
|
||||||
Q_INVOKABLE Device *get(int index) const;
|
Q_INVOKABLE Thing *get(int index) const;
|
||||||
Q_INVOKABLE Device *getDevice(const QUuid &deviceId) const;
|
Q_INVOKABLE Thing *getThing(const QUuid &thingId) const;
|
||||||
Q_INVOKABLE Device *getThing(const QUuid &thingId) const;
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void engineChanged();
|
void engineChanged();
|
||||||
void parentProxyChanged();
|
void parentProxyChanged();
|
||||||
void filterTagIdChanged();
|
void filterTagIdChanged();
|
||||||
void filterTagValueChanged();
|
void filterTagValueChanged();
|
||||||
void filterDeviceClassIdChanged();
|
void filterThingClassIdChanged();
|
||||||
void filterDeviceIdChanged();
|
void filterThingIdChanged();
|
||||||
void shownInterfacesChanged();
|
void shownInterfacesChanged();
|
||||||
void hiddenInterfacesChanged();
|
void hiddenInterfacesChanged();
|
||||||
void nameFilterChanged();
|
void nameFilterChanged();
|
||||||
@ -170,14 +169,14 @@ signals:
|
|||||||
void countChanged();
|
void countChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Device *getInternal(int source_index) const;
|
Thing *getInternal(int source_index) const;
|
||||||
|
|
||||||
Engine *m_engine = nullptr;
|
Engine *m_engine = nullptr;
|
||||||
DevicesProxy *m_parentProxy = nullptr;
|
ThingsProxy *m_parentProxy = nullptr;
|
||||||
QString m_filterTagId;
|
QString m_filterTagId;
|
||||||
QString m_filterTagValue;
|
QString m_filterTagValue;
|
||||||
QString m_filterDeviceClassId;
|
QString m_filterThingClassId;
|
||||||
QString m_filterDeviceId;
|
QString m_filterThingId;
|
||||||
QStringList m_shownInterfaces;
|
QStringList m_shownInterfaces;
|
||||||
QStringList m_hiddenInterfaces;
|
QStringList m_hiddenInterfaces;
|
||||||
QString m_nameFilter;
|
QString m_nameFilter;
|
||||||
@ -203,4 +202,4 @@ protected:
|
|||||||
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override;
|
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DEVICESPROXY_H
|
#endif // THINGSPROXY_H
|
||||||
@ -33,9 +33,9 @@
|
|||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
BrowserItems::BrowserItems(const QUuid &deviceId, const QString &itemId, QObject *parent):
|
BrowserItems::BrowserItems(const QUuid &thingId, const QString &itemId, QObject *parent):
|
||||||
QAbstractListModel (parent),
|
QAbstractListModel (parent),
|
||||||
m_deviceId(deviceId),
|
m_thingId(thingId),
|
||||||
m_itemId(itemId)
|
m_itemId(itemId)
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -46,9 +46,9 @@ BrowserItems::~BrowserItems()
|
|||||||
qDebug() << "Deleting BrowserItems";
|
qDebug() << "Deleting BrowserItems";
|
||||||
}
|
}
|
||||||
|
|
||||||
QUuid BrowserItems::deviceId() const
|
QUuid BrowserItems::thingId() const
|
||||||
{
|
{
|
||||||
return m_deviceId;
|
return m_thingId;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString BrowserItems::itemId() const
|
QString BrowserItems::itemId() const
|
||||||
|
|||||||
@ -57,10 +57,10 @@ public:
|
|||||||
};
|
};
|
||||||
Q_ENUM(Roles)
|
Q_ENUM(Roles)
|
||||||
|
|
||||||
explicit BrowserItems(const QUuid &deviceId, const QString &itemId, QObject *parent = nullptr);
|
explicit BrowserItems(const QUuid &thingId, const QString &itemId, QObject *parent = nullptr);
|
||||||
virtual ~BrowserItems() override;
|
virtual ~BrowserItems() override;
|
||||||
|
|
||||||
QUuid deviceId() const;
|
QUuid thingId() const;
|
||||||
QString itemId() const;
|
QString itemId() const;
|
||||||
|
|
||||||
bool busy() const;
|
bool busy() const;
|
||||||
@ -89,7 +89,7 @@ protected:
|
|||||||
bool m_busy = false;
|
bool m_busy = false;
|
||||||
QList<BrowserItem*> m_list;
|
QList<BrowserItem*> m_list;
|
||||||
|
|
||||||
QUuid m_deviceId;
|
QUuid m_thingId;
|
||||||
QString m_itemId;
|
QString m_itemId;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -40,7 +40,6 @@ class EventDescriptor : public QObject
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(QUuid thingId READ thingId WRITE setThingId NOTIFY thingIdChanged)
|
Q_PROPERTY(QUuid thingId READ thingId WRITE setThingId NOTIFY thingIdChanged)
|
||||||
Q_PROPERTY(QUuid deviceId READ thingId WRITE setThingId NOTIFY thingIdChanged)
|
|
||||||
Q_PROPERTY(QUuid eventTypeId READ eventTypeId WRITE setEventTypeId NOTIFY eventTypeIdChanged)
|
Q_PROPERTY(QUuid eventTypeId READ eventTypeId WRITE setEventTypeId NOTIFY eventTypeIdChanged)
|
||||||
|
|
||||||
Q_PROPERTY(QString interfaceName READ interfaceName WRITE setInterfaceName NOTIFY interfaceNameChanged)
|
Q_PROPERTY(QString interfaceName READ interfaceName WRITE setInterfaceName NOTIFY interfaceNameChanged)
|
||||||
|
|||||||
@ -49,7 +49,6 @@ QVariant EventDescriptors::data(const QModelIndex &index, int role) const
|
|||||||
{
|
{
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case RoleThingId:
|
case RoleThingId:
|
||||||
case RoleDeviceId:
|
|
||||||
return m_list.at(index.row())->thingId();
|
return m_list.at(index.row())->thingId();
|
||||||
case RoleEventTypeId:
|
case RoleEventTypeId:
|
||||||
return m_list.at(index.row())->eventTypeId();
|
return m_list.at(index.row())->eventTypeId();
|
||||||
@ -61,7 +60,6 @@ QHash<int, QByteArray> EventDescriptors::roleNames() const
|
|||||||
{
|
{
|
||||||
QHash<int, QByteArray> roles;
|
QHash<int, QByteArray> roles;
|
||||||
roles.insert(RoleThingId, "thingId");
|
roles.insert(RoleThingId, "thingId");
|
||||||
roles.insert(RoleDeviceId, "deviceId");
|
|
||||||
roles.insert(RoleEventTypeId, "eventId");
|
roles.insert(RoleEventTypeId, "eventId");
|
||||||
return roles;
|
return roles;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -42,7 +42,6 @@ class EventDescriptors : public QAbstractListModel
|
|||||||
public:
|
public:
|
||||||
enum Roles {
|
enum Roles {
|
||||||
RoleThingId,
|
RoleThingId,
|
||||||
RoleDeviceId,
|
|
||||||
RoleEventTypeId
|
RoleEventTypeId
|
||||||
};
|
};
|
||||||
explicit EventDescriptors(QObject *parent = nullptr);
|
explicit EventDescriptors(QObject *parent = nullptr);
|
||||||
|
|||||||
@ -33,7 +33,7 @@
|
|||||||
#include "eventtypes.h"
|
#include "eventtypes.h"
|
||||||
#include "statetypes.h"
|
#include "statetypes.h"
|
||||||
#include "actiontypes.h"
|
#include "actiontypes.h"
|
||||||
#include "deviceclass.h"
|
#include "thingclass.h"
|
||||||
|
|
||||||
Interface::Interface(const QString &name, const QString &displayName, QObject *parent) :
|
Interface::Interface(const QString &name, const QString &displayName, QObject *parent) :
|
||||||
QObject(parent),
|
QObject(parent),
|
||||||
@ -71,9 +71,9 @@ ActionTypes* Interface::actionTypes() const
|
|||||||
return m_actionTypes;
|
return m_actionTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceClass *Interface::createDeviceClass()
|
ThingClass *Interface::createThingClass()
|
||||||
{
|
{
|
||||||
DeviceClass* dc = new DeviceClass();
|
ThingClass* dc = new ThingClass();
|
||||||
dc->setName(m_name);
|
dc->setName(m_name);
|
||||||
dc->setParamTypes(new ParamTypes(dc));
|
dc->setParamTypes(new ParamTypes(dc));
|
||||||
dc->setSettingsTypes(new ParamTypes(dc));
|
dc->setSettingsTypes(new ParamTypes(dc));
|
||||||
|
|||||||
@ -36,7 +36,7 @@
|
|||||||
class EventTypes;
|
class EventTypes;
|
||||||
class StateTypes;
|
class StateTypes;
|
||||||
class ActionTypes;
|
class ActionTypes;
|
||||||
class DeviceClass;
|
class ThingClass;
|
||||||
|
|
||||||
class Interface : public QObject
|
class Interface : public QObject
|
||||||
{
|
{
|
||||||
@ -56,7 +56,7 @@ public:
|
|||||||
StateTypes* stateTypes() const;
|
StateTypes* stateTypes() const;
|
||||||
ActionTypes* actionTypes() const;
|
ActionTypes* actionTypes() const;
|
||||||
|
|
||||||
DeviceClass* createDeviceClass();
|
ThingClass* createThingClass();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_name;
|
QString m_name;
|
||||||
|
|||||||
@ -38,7 +38,7 @@
|
|||||||
#include "statetype.h"
|
#include "statetype.h"
|
||||||
#include "statetypes.h"
|
#include "statetypes.h"
|
||||||
|
|
||||||
#include "device.h"
|
#include "thing.h"
|
||||||
|
|
||||||
#include "paramtypes.h"
|
#include "paramtypes.h"
|
||||||
|
|
||||||
|
|||||||
@ -38,7 +38,7 @@
|
|||||||
class Interface;
|
class Interface;
|
||||||
class ParamType;
|
class ParamType;
|
||||||
class ParamTypes;
|
class ParamTypes;
|
||||||
class Devices;
|
class Things;
|
||||||
|
|
||||||
class Interfaces : public QAbstractListModel
|
class Interfaces : public QAbstractListModel
|
||||||
{
|
{
|
||||||
|
|||||||
@ -41,7 +41,6 @@ class LogEntry : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(QVariant value READ value CONSTANT)
|
Q_PROPERTY(QVariant value READ value CONSTANT)
|
||||||
Q_PROPERTY(QUuid thingId READ thingId CONSTANT)
|
Q_PROPERTY(QUuid thingId READ thingId CONSTANT)
|
||||||
Q_PROPERTY(QUuid deviceId READ thingId CONSTANT)
|
|
||||||
Q_PROPERTY(QUuid typeId READ typeId CONSTANT)
|
Q_PROPERTY(QUuid typeId READ typeId CONSTANT)
|
||||||
Q_PROPERTY(LoggingSource source READ source CONSTANT)
|
Q_PROPERTY(LoggingSource source READ source CONSTANT)
|
||||||
Q_PROPERTY(LoggingEventType loggingEventType READ loggingEventType CONSTANT)
|
Q_PROPERTY(LoggingEventType loggingEventType READ loggingEventType CONSTANT)
|
||||||
|
|||||||
@ -262,8 +262,8 @@ QDebug operator <<(QDebug &dbg, Rule *rule)
|
|||||||
for (int i = 0; i < rule->actions()->rowCount(); i++) {
|
for (int i = 0; i < rule->actions()->rowCount(); i++) {
|
||||||
RuleAction *ra = rule->actions()->get(i);
|
RuleAction *ra = rule->actions()->get(i);
|
||||||
dbg << " " << i << ":";
|
dbg << " " << i << ":";
|
||||||
if (!ra->deviceId().isNull() && !ra->actionTypeId().isNull()) {
|
if (!ra->thingId().isNull() && !ra->actionTypeId().isNull()) {
|
||||||
dbg << "Device ID:" << ra->deviceId() << "Action Type ID:" << ra->actionTypeId() << endl;
|
dbg << "Thing ID:" << ra->thingId() << "Action Type ID:" << ra->actionTypeId() << endl;
|
||||||
} else {
|
} else {
|
||||||
dbg << "Interface Name:" << ra->interfaceName() << "Action Name:" << ra->interfaceAction() << endl;
|
dbg << "Interface Name:" << ra->interfaceName() << "Action Name:" << ra->interfaceAction() << endl;
|
||||||
}
|
}
|
||||||
@ -283,8 +283,8 @@ QDebug operator <<(QDebug &dbg, Rule *rule)
|
|||||||
for (int i = 0; i < rule->exitActions()->rowCount(); i++) {
|
for (int i = 0; i < rule->exitActions()->rowCount(); i++) {
|
||||||
RuleAction *ra = rule->exitActions()->get(i);
|
RuleAction *ra = rule->exitActions()->get(i);
|
||||||
dbg << " " << i << ":";
|
dbg << " " << i << ":";
|
||||||
if (!ra->deviceId().isNull() && !ra->actionTypeId().isNull()) {
|
if (!ra->thingId().isNull() && !ra->actionTypeId().isNull()) {
|
||||||
dbg << "Device ID:" << ra->deviceId() << "Action Type ID:" << ra->actionTypeId() << endl;;
|
dbg << "Thing ID:" << ra->thingId() << "Action Type ID:" << ra->actionTypeId() << endl;;
|
||||||
} else {
|
} else {
|
||||||
dbg << "Interface Name:" << ra->interfaceName() << "Action Name:" << ra->interfaceAction() << endl;;
|
dbg << "Interface Name:" << ra->interfaceName() << "Action Name:" << ra->interfaceAction() << endl;;
|
||||||
}
|
}
|
||||||
@ -305,8 +305,8 @@ QDebug printStateEvaluator(QDebug &dbg, StateEvaluator *stateEvaluator, int inde
|
|||||||
if (stateEvaluator->stateDescriptor()) {
|
if (stateEvaluator->stateDescriptor()) {
|
||||||
for (int i = 0; i < indentLevel; i++) { dbg << " "; }
|
for (int i = 0; i < indentLevel; i++) { dbg << " "; }
|
||||||
dbg << "State Descriptor:";
|
dbg << "State Descriptor:";
|
||||||
if (!stateEvaluator->stateDescriptor()->deviceId().isNull() && !stateEvaluator->stateDescriptor()->stateTypeId().isNull()) {
|
if (!stateEvaluator->stateDescriptor()->thingId().isNull() && !stateEvaluator->stateDescriptor()->stateTypeId().isNull()) {
|
||||||
dbg << "Device ID:" << stateEvaluator->stateDescriptor()->deviceId().toString() << "State Type ID:" << stateEvaluator->stateDescriptor()->stateTypeId().toString();
|
dbg << "Thing ID:" << stateEvaluator->stateDescriptor()->thingId().toString() << "State Type ID:" << stateEvaluator->stateDescriptor()->stateTypeId().toString();
|
||||||
} else {
|
} else {
|
||||||
dbg << "Interface name:" << stateEvaluator->stateDescriptor()->interfaceName() << "State Name:" << stateEvaluator->stateDescriptor()->interfaceState();
|
dbg << "Interface name:" << stateEvaluator->stateDescriptor()->interfaceName() << "State Name:" << stateEvaluator->stateDescriptor()->interfaceState();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -40,16 +40,16 @@ RuleAction::RuleAction(QObject *parent) : QObject(parent)
|
|||||||
m_ruleActionParams = new RuleActionParams(this);
|
m_ruleActionParams = new RuleActionParams(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
QUuid RuleAction::deviceId() const
|
QUuid RuleAction::thingId() const
|
||||||
{
|
{
|
||||||
return m_deviceId;
|
return m_thingId;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RuleAction::setDeviceId(const QUuid &deviceId)
|
void RuleAction::setThingId(const QUuid &thingId)
|
||||||
{
|
{
|
||||||
if (m_deviceId != deviceId) {
|
if (m_thingId != thingId) {
|
||||||
m_deviceId = deviceId;
|
m_thingId = thingId;
|
||||||
emit deviceIdChanged();
|
emit thingIdChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,7 +113,7 @@ RuleActionParams *RuleAction::ruleActionParams() const
|
|||||||
RuleAction *RuleAction::clone() const
|
RuleAction *RuleAction::clone() const
|
||||||
{
|
{
|
||||||
RuleAction *ret = new RuleAction();
|
RuleAction *ret = new RuleAction();
|
||||||
ret->setDeviceId(deviceId());
|
ret->setThingId(thingId());
|
||||||
ret->setActionTypeId(actionTypeId());
|
ret->setActionTypeId(actionTypeId());
|
||||||
ret->setBrowserItemId(browserItemId());
|
ret->setBrowserItemId(browserItemId());
|
||||||
ret->setInterfaceName(interfaceName());
|
ret->setInterfaceName(interfaceName());
|
||||||
@ -128,7 +128,7 @@ RuleAction *RuleAction::clone() const
|
|||||||
#define COMPARE_PTR(a, b) if (!a->operator==(b)) { qDebug() << a << "!=" << b; return false; }
|
#define COMPARE_PTR(a, b) if (!a->operator==(b)) { qDebug() << a << "!=" << b; return false; }
|
||||||
bool RuleAction::operator==(RuleAction *other) const
|
bool RuleAction::operator==(RuleAction *other) const
|
||||||
{
|
{
|
||||||
COMPARE(m_deviceId, other->deviceId());
|
COMPARE(m_thingId, other->thingId());
|
||||||
COMPARE(m_actionTypeId, other->actionTypeId());
|
COMPARE(m_actionTypeId, other->actionTypeId());
|
||||||
COMPARE(m_interfaceName, other->interfaceName());
|
COMPARE(m_interfaceName, other->interfaceName());
|
||||||
COMPARE(m_interfaceAction, other->interfaceAction());
|
COMPARE(m_interfaceAction, other->interfaceAction());
|
||||||
|
|||||||
@ -39,8 +39,7 @@ class RuleActionParams;
|
|||||||
class RuleAction : public QObject
|
class RuleAction : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(QUuid thingId READ deviceId WRITE setDeviceId NOTIFY deviceIdChanged)
|
Q_PROPERTY(QUuid thingId READ thingId WRITE setThingId NOTIFY thingIdChanged)
|
||||||
Q_PROPERTY(QUuid deviceId READ deviceId WRITE setDeviceId NOTIFY deviceIdChanged)
|
|
||||||
Q_PROPERTY(QUuid actionTypeId READ actionTypeId WRITE setActionTypeId NOTIFY actionTypeIdChanged)
|
Q_PROPERTY(QUuid actionTypeId READ actionTypeId WRITE setActionTypeId NOTIFY actionTypeIdChanged)
|
||||||
Q_PROPERTY(QString interfaceName READ interfaceName WRITE setInterfaceName NOTIFY interfaceNameChanged)
|
Q_PROPERTY(QString interfaceName READ interfaceName WRITE setInterfaceName NOTIFY interfaceNameChanged)
|
||||||
Q_PROPERTY(QString interfaceAction READ interfaceAction WRITE setInterfaceAction NOTIFY interfaceActionChanged)
|
Q_PROPERTY(QString interfaceAction READ interfaceAction WRITE setInterfaceAction NOTIFY interfaceActionChanged)
|
||||||
@ -50,8 +49,8 @@ class RuleAction : public QObject
|
|||||||
public:
|
public:
|
||||||
explicit RuleAction(QObject *parent = nullptr);
|
explicit RuleAction(QObject *parent = nullptr);
|
||||||
|
|
||||||
QUuid deviceId() const;
|
QUuid thingId() const;
|
||||||
void setDeviceId(const QUuid &deviceId);
|
void setThingId(const QUuid &thingId);
|
||||||
|
|
||||||
QUuid actionTypeId() const;
|
QUuid actionTypeId() const;
|
||||||
void setActionTypeId(const QUuid &actionTypeId);
|
void setActionTypeId(const QUuid &actionTypeId);
|
||||||
@ -71,14 +70,14 @@ public:
|
|||||||
bool operator==(RuleAction *other) const;
|
bool operator==(RuleAction *other) const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void deviceIdChanged();
|
void thingIdChanged();
|
||||||
void actionTypeIdChanged();
|
void actionTypeIdChanged();
|
||||||
void interfaceNameChanged();
|
void interfaceNameChanged();
|
||||||
void interfaceActionChanged();
|
void interfaceActionChanged();
|
||||||
bool browserItemIdChanged();
|
bool browserItemIdChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QUuid m_deviceId;
|
QUuid m_thingId;
|
||||||
QUuid m_actionTypeId;
|
QUuid m_actionTypeId;
|
||||||
QString m_interfaceName;
|
QString m_interfaceName;
|
||||||
QString m_interfaceAction;
|
QString m_interfaceAction;
|
||||||
|
|||||||
@ -87,16 +87,16 @@ void RuleActionParam::setEventParamTypeId(const QString &eventParamTypeId)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString RuleActionParam::stateDeviceId() const
|
QString RuleActionParam::stateThingId() const
|
||||||
{
|
{
|
||||||
return m_stateDeviceId;
|
return m_stateThingId;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RuleActionParam::setStateDeviceId(const QString &stateDeviceId)
|
void RuleActionParam::setStateThingId(const QString &stateThingId)
|
||||||
{
|
{
|
||||||
if (m_stateDeviceId != stateDeviceId) {
|
if (m_stateThingId != stateThingId) {
|
||||||
m_stateDeviceId = stateDeviceId;
|
m_stateThingId = stateThingId;
|
||||||
emit stateDeviceIdChanged();
|
emit stateThingIdChanged();
|
||||||
emit isStateValueBasedChanged();
|
emit isStateValueBasedChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -127,7 +127,7 @@ bool RuleActionParam::isEventParamBased() const
|
|||||||
|
|
||||||
bool RuleActionParam::isStateValueBased() const
|
bool RuleActionParam::isStateValueBased() const
|
||||||
{
|
{
|
||||||
return !m_stateDeviceId.isNull() && !m_stateTypeId.isNull();
|
return !m_stateThingId.isNull() && !m_stateTypeId.isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
RuleActionParam *RuleActionParam::clone() const
|
RuleActionParam *RuleActionParam::clone() const
|
||||||
@ -138,7 +138,7 @@ RuleActionParam *RuleActionParam::clone() const
|
|||||||
ret->setValue(value());
|
ret->setValue(value());
|
||||||
ret->setEventTypeId(eventTypeId());
|
ret->setEventTypeId(eventTypeId());
|
||||||
ret->setEventParamTypeId(eventParamTypeId());
|
ret->setEventParamTypeId(eventParamTypeId());
|
||||||
ret->setStateDeviceId(stateDeviceId());
|
ret->setStateThingId(stateThingId());
|
||||||
ret->setStateTypeId(stateTypeId());
|
ret->setStateTypeId(stateTypeId());
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -151,7 +151,7 @@ bool RuleActionParam::operator==(RuleActionParam *other) const
|
|||||||
COMPARE(m_paramName, other->paramName());
|
COMPARE(m_paramName, other->paramName());
|
||||||
COMPARE(m_eventTypeId, other->eventTypeId());
|
COMPARE(m_eventTypeId, other->eventTypeId());
|
||||||
COMPARE(m_eventParamTypeId, other->eventParamTypeId());
|
COMPARE(m_eventParamTypeId, other->eventParamTypeId());
|
||||||
COMPARE(m_stateDeviceId, other->stateDeviceId());
|
COMPARE(m_stateThingId, other->stateThingId());
|
||||||
COMPARE(m_stateTypeId, other->stateTypeId());
|
COMPARE(m_stateTypeId, other->stateTypeId());
|
||||||
COMPARE(m_value, other->value());
|
COMPARE(m_value, other->value());
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@ -43,7 +43,7 @@ class RuleActionParam : public Param
|
|||||||
Q_PROPERTY(QString paramName READ paramName WRITE setParamName NOTIFY paramNameChanged)
|
Q_PROPERTY(QString paramName READ paramName WRITE setParamName NOTIFY paramNameChanged)
|
||||||
Q_PROPERTY(QString eventTypeId READ eventTypeId WRITE setEventTypeId NOTIFY eventTypeIdChanged)
|
Q_PROPERTY(QString eventTypeId READ eventTypeId WRITE setEventTypeId NOTIFY eventTypeIdChanged)
|
||||||
Q_PROPERTY(QString eventParamTypeId READ eventParamTypeId WRITE setEventParamTypeId NOTIFY eventParamTypeIdChanged)
|
Q_PROPERTY(QString eventParamTypeId READ eventParamTypeId WRITE setEventParamTypeId NOTIFY eventParamTypeIdChanged)
|
||||||
Q_PROPERTY(QString stateDeviceId READ stateDeviceId WRITE setStateDeviceId NOTIFY stateDeviceIdChanged)
|
Q_PROPERTY(QString stateThingId READ stateThingId WRITE setStateThingId NOTIFY stateThingIdChanged)
|
||||||
Q_PROPERTY(QString stateTypeId READ stateTypeId WRITE setStateTypeId NOTIFY stateTypeIdChanged)
|
Q_PROPERTY(QString stateTypeId READ stateTypeId WRITE setStateTypeId NOTIFY stateTypeIdChanged)
|
||||||
|
|
||||||
Q_PROPERTY(bool isValueBased READ isValueBased NOTIFY isValueBasedChanged)
|
Q_PROPERTY(bool isValueBased READ isValueBased NOTIFY isValueBasedChanged)
|
||||||
@ -63,8 +63,8 @@ public:
|
|||||||
QString eventParamTypeId() const;
|
QString eventParamTypeId() const;
|
||||||
void setEventParamTypeId(const QString &eventParamTypeId);
|
void setEventParamTypeId(const QString &eventParamTypeId);
|
||||||
|
|
||||||
QString stateDeviceId() const;
|
QString stateThingId() const;
|
||||||
void setStateDeviceId(const QString &stateDeviceId);
|
void setStateThingId(const QString &stateThingId);
|
||||||
|
|
||||||
QString stateTypeId() const;
|
QString stateTypeId() const;
|
||||||
void setStateTypeId(const QString &stateTypeId);
|
void setStateTypeId(const QString &stateTypeId);
|
||||||
@ -79,7 +79,7 @@ signals:
|
|||||||
void paramNameChanged();
|
void paramNameChanged();
|
||||||
void eventTypeIdChanged();
|
void eventTypeIdChanged();
|
||||||
void eventParamTypeIdChanged();
|
void eventParamTypeIdChanged();
|
||||||
void stateDeviceIdChanged();
|
void stateThingIdChanged();
|
||||||
void stateTypeIdChanged();
|
void stateTypeIdChanged();
|
||||||
|
|
||||||
void isValueBasedChanged();
|
void isValueBasedChanged();
|
||||||
@ -90,7 +90,7 @@ protected:
|
|||||||
QString m_paramName;
|
QString m_paramName;
|
||||||
QString m_eventTypeId;
|
QString m_eventTypeId;
|
||||||
QString m_eventParamTypeId;
|
QString m_eventParamTypeId;
|
||||||
QString m_stateDeviceId;
|
QString m_stateThingId;
|
||||||
QString m_stateTypeId;
|
QString m_stateTypeId;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -141,34 +141,34 @@ void RuleActionParams::setRuleActionParamEventByName(const QString ¶mName, c
|
|||||||
addRuleActionParam(rap);
|
addRuleActionParam(rap);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RuleActionParams::setRuleActionParamState(const QString ¶mTypeId, const QString &stateDeviceId, const QString &stateTypeId)
|
void RuleActionParams::setRuleActionParamState(const QString ¶mTypeId, const QString &stateThingId, const QString &stateTypeId)
|
||||||
{
|
{
|
||||||
foreach (RuleActionParam *rap, m_list) {
|
foreach (RuleActionParam *rap, m_list) {
|
||||||
if (rap->paramTypeId() == paramTypeId) {
|
if (rap->paramTypeId() == paramTypeId) {
|
||||||
rap->setStateDeviceId(stateDeviceId);
|
rap->setStateThingId(stateThingId);
|
||||||
rap->setStateTypeId(stateTypeId);
|
rap->setStateTypeId(stateTypeId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RuleActionParam *rap = new RuleActionParam(this);
|
RuleActionParam *rap = new RuleActionParam(this);
|
||||||
rap->setParamTypeId(paramTypeId);
|
rap->setParamTypeId(paramTypeId);
|
||||||
rap->setStateDeviceId(stateDeviceId);
|
rap->setStateThingId(stateThingId);
|
||||||
rap->setStateTypeId(stateTypeId);
|
rap->setStateTypeId(stateTypeId);
|
||||||
addRuleActionParam(rap);
|
addRuleActionParam(rap);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RuleActionParams::setRuleActionParamStateByName(const QString ¶mName, const QString &stateDeviceId, const QString &stateTypeId)
|
void RuleActionParams::setRuleActionParamStateByName(const QString ¶mName, const QString &stateThingId, const QString &stateTypeId)
|
||||||
{
|
{
|
||||||
foreach (RuleActionParam *rap, m_list) {
|
foreach (RuleActionParam *rap, m_list) {
|
||||||
if (rap->paramName() == paramName) {
|
if (rap->paramName() == paramName) {
|
||||||
rap->setStateDeviceId(stateDeviceId);
|
rap->setStateThingId(stateThingId);
|
||||||
rap->setStateTypeId(stateTypeId);
|
rap->setStateTypeId(stateTypeId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RuleActionParam *rap = new RuleActionParam(this);
|
RuleActionParam *rap = new RuleActionParam(this);
|
||||||
rap->setParamName(paramName);
|
rap->setParamName(paramName);
|
||||||
rap->setStateDeviceId(stateDeviceId);
|
rap->setStateThingId(stateThingId);
|
||||||
rap->setStateTypeId(stateTypeId);
|
rap->setStateTypeId(stateTypeId);
|
||||||
addRuleActionParam(rap);
|
addRuleActionParam(rap);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -60,8 +60,8 @@ public:
|
|||||||
Q_INVOKABLE void setRuleActionParamByName(const QString ¶mName, const QVariant &value);
|
Q_INVOKABLE void setRuleActionParamByName(const QString ¶mName, const QVariant &value);
|
||||||
Q_INVOKABLE void setRuleActionParamEvent(const QString ¶mTypeId, const QString &eventTypeId, const QString &eventParamTypeId);
|
Q_INVOKABLE void setRuleActionParamEvent(const QString ¶mTypeId, const QString &eventTypeId, const QString &eventParamTypeId);
|
||||||
Q_INVOKABLE void setRuleActionParamEventByName(const QString ¶mName, const QString &eventTypeId, const QString &eventParamTypeId);
|
Q_INVOKABLE void setRuleActionParamEventByName(const QString ¶mName, const QString &eventTypeId, const QString &eventParamTypeId);
|
||||||
Q_INVOKABLE void setRuleActionParamState(const QString ¶mTypeId, const QString &stateDeviceId, const QString &stateTypeId);
|
Q_INVOKABLE void setRuleActionParamState(const QString ¶mTypeId, const QString &stateThingId, const QString &stateTypeId);
|
||||||
Q_INVOKABLE void setRuleActionParamStateByName(const QString ¶mName, const QString &stateDeviceId, const QString &stateTypeId);
|
Q_INVOKABLE void setRuleActionParamStateByName(const QString ¶mName, const QString &stateThingId, const QString &stateTypeId);
|
||||||
|
|
||||||
Q_INVOKABLE RuleActionParam* get(int index) const;
|
Q_INVOKABLE RuleActionParam* get(int index) const;
|
||||||
|
|
||||||
|
|||||||
@ -32,17 +32,17 @@
|
|||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
State::State(const QUuid &deviceId, const QUuid &stateTypeId, const QVariant &value, QObject *parent) :
|
State::State(const QUuid &thingId, const QUuid &stateTypeId, const QVariant &value, QObject *parent) :
|
||||||
QObject(parent),
|
QObject(parent),
|
||||||
m_deviceId(deviceId),
|
m_thingId(thingId),
|
||||||
m_stateTypeId(stateTypeId),
|
m_stateTypeId(stateTypeId),
|
||||||
m_value(value)
|
m_value(value)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
QUuid State::deviceId() const
|
QUuid State::thingId() const
|
||||||
{
|
{
|
||||||
return m_deviceId;
|
return m_thingId;
|
||||||
}
|
}
|
||||||
|
|
||||||
QUuid State::stateTypeId() const
|
QUuid State::stateTypeId() const
|
||||||
|
|||||||
@ -38,21 +38,21 @@
|
|||||||
class State : public QObject
|
class State : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(QUuid deviceId READ deviceId CONSTANT)
|
Q_PROPERTY(QUuid thingId READ thingId CONSTANT)
|
||||||
Q_PROPERTY(QUuid stateTypeId READ stateTypeId CONSTANT)
|
Q_PROPERTY(QUuid stateTypeId READ stateTypeId CONSTANT)
|
||||||
Q_PROPERTY(QVariant value READ value NOTIFY valueChanged)
|
Q_PROPERTY(QVariant value READ value NOTIFY valueChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit State(const QUuid &deviceId, const QUuid &stateTypeId, const QVariant &value, QObject *parent = nullptr);
|
explicit State(const QUuid &thingId, const QUuid &stateTypeId, const QVariant &value, QObject *parent = nullptr);
|
||||||
|
|
||||||
QUuid deviceId() const;
|
QUuid thingId() const;
|
||||||
QUuid stateTypeId() const;
|
QUuid stateTypeId() const;
|
||||||
|
|
||||||
QVariant value() const;
|
QVariant value() const;
|
||||||
void setValue(const QVariant &value);
|
void setValue(const QVariant &value);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QUuid m_deviceId;
|
QUuid m_thingId;
|
||||||
QUuid m_stateTypeId;
|
QUuid m_stateTypeId;
|
||||||
QVariant m_value;
|
QVariant m_value;
|
||||||
|
|
||||||
|
|||||||
@ -32,9 +32,9 @@
|
|||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
StateDescriptor::StateDescriptor(const QUuid &deviceId, const QUuid &stateTypeId, StateDescriptor::ValueOperator valueOperator, const QVariant &value, QObject *parent):
|
StateDescriptor::StateDescriptor(const QUuid &thingId, const QUuid &stateTypeId, StateDescriptor::ValueOperator valueOperator, const QVariant &value, QObject *parent):
|
||||||
QObject(parent),
|
QObject(parent),
|
||||||
m_deviceId(deviceId),
|
m_thingId(thingId),
|
||||||
m_stateTypeId(stateTypeId),
|
m_stateTypeId(stateTypeId),
|
||||||
m_operator(valueOperator),
|
m_operator(valueOperator),
|
||||||
m_value(value)
|
m_value(value)
|
||||||
@ -57,16 +57,16 @@ StateDescriptor::StateDescriptor(QObject *parent) : QObject(parent)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QUuid StateDescriptor::deviceId() const
|
QUuid StateDescriptor::thingId() const
|
||||||
{
|
{
|
||||||
return m_deviceId;
|
return m_thingId;
|
||||||
}
|
}
|
||||||
|
|
||||||
void StateDescriptor::setDeviceId(const QUuid &deviceId)
|
void StateDescriptor::setThingId(const QUuid &thingId)
|
||||||
{
|
{
|
||||||
if (m_deviceId != deviceId) {
|
if (m_thingId != thingId) {
|
||||||
m_deviceId = deviceId;
|
m_thingId = thingId;
|
||||||
emit deviceIdChanged();
|
emit thingIdChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,7 +137,7 @@ void StateDescriptor::setValue(const QVariant &value)
|
|||||||
|
|
||||||
StateDescriptor *StateDescriptor::clone() const
|
StateDescriptor *StateDescriptor::clone() const
|
||||||
{
|
{
|
||||||
StateDescriptor *ret = new StateDescriptor(deviceId(), stateTypeId(), valueOperator(), value());
|
StateDescriptor *ret = new StateDescriptor(thingId(), stateTypeId(), valueOperator(), value());
|
||||||
ret->setInterfaceName(interfaceName());
|
ret->setInterfaceName(interfaceName());
|
||||||
ret->setInterfaceState(interfaceState());
|
ret->setInterfaceState(interfaceState());
|
||||||
return ret;
|
return ret;
|
||||||
@ -147,7 +147,7 @@ StateDescriptor *StateDescriptor::clone() const
|
|||||||
#define COMPARE_PTR(a, b) if (!a->operator==(b)) { qDebug() << a << "!=" << b; return false; }
|
#define COMPARE_PTR(a, b) if (!a->operator==(b)) { qDebug() << a << "!=" << b; return false; }
|
||||||
bool StateDescriptor::operator==(StateDescriptor *other) const
|
bool StateDescriptor::operator==(StateDescriptor *other) const
|
||||||
{
|
{
|
||||||
COMPARE(m_deviceId, other->deviceId());
|
COMPARE(m_thingId, other->thingId());
|
||||||
COMPARE(m_stateTypeId, other->stateTypeId());
|
COMPARE(m_stateTypeId, other->stateTypeId());
|
||||||
COMPARE(m_interfaceName, other->interfaceName());
|
COMPARE(m_interfaceName, other->interfaceName());
|
||||||
COMPARE(m_interfaceState, other->interfaceState());
|
COMPARE(m_interfaceState, other->interfaceState());
|
||||||
|
|||||||
@ -38,7 +38,7 @@
|
|||||||
class StateDescriptor : public QObject
|
class StateDescriptor : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(QUuid deviceId READ deviceId WRITE setDeviceId NOTIFY deviceIdChanged)
|
Q_PROPERTY(QUuid thingId READ thingId WRITE setThingId NOTIFY thingIdChanged)
|
||||||
Q_PROPERTY(QUuid stateTypeId READ stateTypeId WRITE setStateTypeId NOTIFY stateTypeIdChanged)
|
Q_PROPERTY(QUuid stateTypeId READ stateTypeId WRITE setStateTypeId NOTIFY stateTypeIdChanged)
|
||||||
Q_PROPERTY(QString interfaceName READ interfaceName WRITE setInterfaceName NOTIFY interfaceNameChanged)
|
Q_PROPERTY(QString interfaceName READ interfaceName WRITE setInterfaceName NOTIFY interfaceNameChanged)
|
||||||
Q_PROPERTY(QString interfaceState READ interfaceState WRITE setInterfaceState NOTIFY interfaceStateChanged)
|
Q_PROPERTY(QString interfaceState READ interfaceState WRITE setInterfaceState NOTIFY interfaceStateChanged)
|
||||||
@ -56,12 +56,12 @@ public:
|
|||||||
};
|
};
|
||||||
Q_ENUM(ValueOperator)
|
Q_ENUM(ValueOperator)
|
||||||
|
|
||||||
explicit StateDescriptor(const QUuid &deviceId, const QUuid &stateTypeId, ValueOperator valueOperator, const QVariant &value, QObject *parent = nullptr);
|
explicit StateDescriptor(const QUuid &thingId, const QUuid &stateTypeId, ValueOperator valueOperator, const QVariant &value, QObject *parent = nullptr);
|
||||||
explicit StateDescriptor(const QString &interfaceName, const QString &interfaceState, ValueOperator valueOperator, const QVariant &value, QObject *parent = nullptr);
|
explicit StateDescriptor(const QString &interfaceName, const QString &interfaceState, ValueOperator valueOperator, const QVariant &value, QObject *parent = nullptr);
|
||||||
StateDescriptor(QObject *parent = nullptr);
|
StateDescriptor(QObject *parent = nullptr);
|
||||||
|
|
||||||
QUuid deviceId() const;
|
QUuid thingId() const;
|
||||||
void setDeviceId(const QUuid &deviceId);
|
void setThingId(const QUuid &thingId);
|
||||||
|
|
||||||
QUuid stateTypeId() const;
|
QUuid stateTypeId() const;
|
||||||
void setStateTypeId(const QUuid &stateTypeId);
|
void setStateTypeId(const QUuid &stateTypeId);
|
||||||
@ -82,7 +82,7 @@ public:
|
|||||||
bool operator==(StateDescriptor *other) const;
|
bool operator==(StateDescriptor *other) const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void deviceIdChanged();
|
void thingIdChanged();
|
||||||
void stateTypeIdChanged();
|
void stateTypeIdChanged();
|
||||||
void interfaceNameChanged();
|
void interfaceNameChanged();
|
||||||
void interfaceStateChanged();
|
void interfaceStateChanged();
|
||||||
@ -90,7 +90,7 @@ signals:
|
|||||||
void valueChanged();
|
void valueChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QUuid m_deviceId;
|
QUuid m_thingId;
|
||||||
QUuid m_stateTypeId;
|
QUuid m_stateTypeId;
|
||||||
QString m_interfaceName;
|
QString m_interfaceName;
|
||||||
QString m_interfaceState;
|
QString m_interfaceState;
|
||||||
|
|||||||
@ -72,13 +72,13 @@ void StateEvaluator::setStateDescriptor(StateDescriptor *stateDescriptor)
|
|||||||
m_stateDescriptor = stateDescriptor;
|
m_stateDescriptor = stateDescriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StateEvaluator::containsDevice(const QUuid &deviceId) const
|
bool StateEvaluator::containsThing(const QUuid &thingId) const
|
||||||
{
|
{
|
||||||
if (m_stateDescriptor && m_stateDescriptor->deviceId() == deviceId) {
|
if (m_stateDescriptor && m_stateDescriptor->thingId() == thingId) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < m_childEvaluators->rowCount(); i++) {
|
for (int i = 0; i < m_childEvaluators->rowCount(); i++) {
|
||||||
if (m_childEvaluators->get(i)->containsDevice(deviceId)) {
|
if (m_childEvaluators->get(i)->containsThing(thingId)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -96,7 +96,7 @@ StateEvaluator *StateEvaluator::clone() const
|
|||||||
{
|
{
|
||||||
StateEvaluator *ret = new StateEvaluator();
|
StateEvaluator *ret = new StateEvaluator();
|
||||||
ret->m_operator = this->m_operator;
|
ret->m_operator = this->m_operator;
|
||||||
ret->m_stateDescriptor->setDeviceId(this->m_stateDescriptor->deviceId());
|
ret->m_stateDescriptor->setThingId(this->m_stateDescriptor->thingId());
|
||||||
ret->m_stateDescriptor->setStateTypeId(this->m_stateDescriptor->stateTypeId());
|
ret->m_stateDescriptor->setStateTypeId(this->m_stateDescriptor->stateTypeId());
|
||||||
ret->m_stateDescriptor->setInterfaceName(this->m_stateDescriptor->interfaceName());
|
ret->m_stateDescriptor->setInterfaceName(this->m_stateDescriptor->interfaceName());
|
||||||
ret->m_stateDescriptor->setInterfaceState(this->m_stateDescriptor->interfaceState());
|
ret->m_stateDescriptor->setInterfaceState(this->m_stateDescriptor->interfaceState());
|
||||||
|
|||||||
@ -59,7 +59,7 @@ public:
|
|||||||
StateDescriptor* stateDescriptor() const;
|
StateDescriptor* stateDescriptor() const;
|
||||||
void setStateDescriptor(StateDescriptor *stateDescriptor);
|
void setStateDescriptor(StateDescriptor *stateDescriptor);
|
||||||
|
|
||||||
bool containsDevice(const QUuid &deviceId) const;
|
bool containsThing(const QUuid &thingId) const;
|
||||||
|
|
||||||
Q_INVOKABLE StateEvaluator* addChildEvaluator();
|
Q_INVOKABLE StateEvaluator* addChildEvaluator();
|
||||||
|
|
||||||
|
|||||||
@ -38,7 +38,6 @@ class Tag : public QObject
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(QUuid thingId READ thingId CONSTANT)
|
Q_PROPERTY(QUuid thingId READ thingId CONSTANT)
|
||||||
Q_PROPERTY(QUuid deviceId READ thingId CONSTANT)
|
|
||||||
Q_PROPERTY(QUuid ruleId READ ruleId CONSTANT)
|
Q_PROPERTY(QUuid ruleId READ ruleId CONSTANT)
|
||||||
Q_PROPERTY(QString tagId READ tagId CONSTANT)
|
Q_PROPERTY(QString tagId READ tagId CONSTANT)
|
||||||
Q_PROPERTY(QString value READ value NOTIFY valueChanged)
|
Q_PROPERTY(QString value READ value NOTIFY valueChanged)
|
||||||
|
|||||||
@ -48,7 +48,6 @@ QVariant Tags::data(const QModelIndex &index, int role) const
|
|||||||
{
|
{
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case RoleThingId:
|
case RoleThingId:
|
||||||
case RoleDeviceId:
|
|
||||||
return m_list.at(index.row())->thingId();
|
return m_list.at(index.row())->thingId();
|
||||||
case RoleRuleId:
|
case RoleRuleId:
|
||||||
return m_list.at(index.row())->ruleId();
|
return m_list.at(index.row())->ruleId();
|
||||||
@ -64,7 +63,6 @@ QHash<int, QByteArray> Tags::roleNames() const
|
|||||||
{
|
{
|
||||||
QHash<int, QByteArray> roles;
|
QHash<int, QByteArray> roles;
|
||||||
roles.insert(RoleThingId, "thingId");
|
roles.insert(RoleThingId, "thingId");
|
||||||
roles.insert(RoleDeviceId, "deviceId");
|
|
||||||
roles.insert(RoleRuleId, "ruleId");
|
roles.insert(RoleRuleId, "ruleId");
|
||||||
roles.insert(RoleTagId, "tagId");
|
roles.insert(RoleTagId, "tagId");
|
||||||
roles.insert(RoleValue, "value");
|
roles.insert(RoleValue, "value");
|
||||||
@ -129,11 +127,6 @@ Tag *Tags::findThingTag(const QUuid &thingId, const QString &tagId) const
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
Tag *Tags::findDeviceTag(const QUuid &deviceId, const QString &tagId) const
|
|
||||||
{
|
|
||||||
return findThingTag(deviceId, tagId);
|
|
||||||
}
|
|
||||||
|
|
||||||
Tag *Tags::findRuleTag(const QString &ruleId, const QString &tagId) const
|
Tag *Tags::findRuleTag(const QString &ruleId, const QString &tagId) const
|
||||||
{
|
{
|
||||||
foreach (Tag *tag, m_list) {
|
foreach (Tag *tag, m_list) {
|
||||||
|
|||||||
@ -42,7 +42,6 @@ class Tags: public QAbstractListModel
|
|||||||
public:
|
public:
|
||||||
enum Roles {
|
enum Roles {
|
||||||
RoleThingId,
|
RoleThingId,
|
||||||
RoleDeviceId,
|
|
||||||
RoleRuleId,
|
RoleRuleId,
|
||||||
RoleTagId,
|
RoleTagId,
|
||||||
RoleValue
|
RoleValue
|
||||||
@ -62,7 +61,6 @@ public:
|
|||||||
Q_INVOKABLE Tag* get(int index) const;
|
Q_INVOKABLE Tag* get(int index) const;
|
||||||
|
|
||||||
Q_INVOKABLE Tag* findThingTag(const QUuid &thingId, const QString &tagId) const;
|
Q_INVOKABLE Tag* findThingTag(const QUuid &thingId, const QString &tagId) const;
|
||||||
Q_INVOKABLE Tag* findDeviceTag(const QUuid &deviceId, const QString &tagId) const;
|
|
||||||
Q_INVOKABLE Tag* findRuleTag(const QString &ruleId, const QString &tagId) const;
|
Q_INVOKABLE Tag* findRuleTag(const QString &ruleId, const QString &tagId) const;
|
||||||
|
|
||||||
void clear();
|
void clear();
|
||||||
|
|||||||
@ -28,78 +28,73 @@
|
|||||||
*
|
*
|
||||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
#include "device.h"
|
#include "thing.h"
|
||||||
#include "deviceclass.h"
|
#include "thingclass.h"
|
||||||
#include "devicemanager.h"
|
#include "thingmanager.h"
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
Device::Device(DeviceManager *thingManager, DeviceClass *thingClass, const QUuid &parentId, QObject *parent) :
|
Thing::Thing(ThingManager *thingManager, ThingClass *thingClass, const QUuid &parentId, QObject *parent) :
|
||||||
QObject(parent),
|
QObject(parent),
|
||||||
m_thingManager(thingManager),
|
m_thingManager(thingManager),
|
||||||
m_parentId(parentId),
|
m_parentId(parentId),
|
||||||
m_thingClass(thingClass)
|
m_thingClass(thingClass)
|
||||||
{
|
{
|
||||||
connect(thingManager, &DeviceManager::executeActionReply, this, [=](int commandId, const QVariantMap ¶ms){
|
connect(thingManager, &ThingManager::executeActionReply, this, [=](int commandId, Thing::ThingError thingError, const QString &displayMessage){
|
||||||
if (m_pendingActions.contains(commandId)) {
|
if (m_pendingActions.contains(commandId)) {
|
||||||
m_pendingActions.removeAll(commandId);
|
m_pendingActions.removeAll(commandId);
|
||||||
emit executeActionReply(commandId, params);
|
emit executeActionReply(commandId, thingError, displayMessage);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Device::name() const
|
QString Thing::name() const
|
||||||
{
|
{
|
||||||
return m_name;
|
return m_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Device::setName(const QString &name)
|
void Thing::setName(const QString &name)
|
||||||
{
|
{
|
||||||
m_name = name;
|
m_name = name;
|
||||||
emit nameChanged();
|
emit nameChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
QUuid Device::id() const
|
QUuid Thing::id() const
|
||||||
{
|
{
|
||||||
return m_id;
|
return m_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Device::setId(const QUuid &id)
|
void Thing::setId(const QUuid &id)
|
||||||
{
|
{
|
||||||
m_id = id;
|
m_id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
QUuid Device::deviceClassId() const
|
QUuid Thing::thingClassId() const
|
||||||
{
|
{
|
||||||
return m_thingClass->id();
|
return m_thingClass->id();
|
||||||
}
|
}
|
||||||
|
|
||||||
QUuid Device::thingClassId() const
|
QUuid Thing::parentId() const
|
||||||
{
|
|
||||||
return m_thingClass->id();
|
|
||||||
}
|
|
||||||
|
|
||||||
QUuid Device::parentDeviceId() const
|
|
||||||
{
|
{
|
||||||
return m_parentId;
|
return m_parentId;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Device::isChild() const
|
bool Thing::isChild() const
|
||||||
{
|
{
|
||||||
return !m_parentId.isNull();
|
return !m_parentId.isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
Device::ThingSetupStatus Device::setupStatus() const
|
Thing::ThingSetupStatus Thing::setupStatus() const
|
||||||
{
|
{
|
||||||
return m_setupStatus;
|
return m_setupStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Device::setupDisplayMessage() const
|
QString Thing::setupDisplayMessage() const
|
||||||
{
|
{
|
||||||
return m_setupDisplayMessage;
|
return m_setupDisplayMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Device::setSetupStatus(Device::ThingSetupStatus setupStatus, const QString &displayMessage)
|
void Thing::setSetupStatus(Thing::ThingSetupStatus setupStatus, const QString &displayMessage)
|
||||||
{
|
{
|
||||||
if (m_setupStatus != setupStatus || m_setupDisplayMessage != displayMessage) {
|
if (m_setupStatus != setupStatus || m_setupDisplayMessage != displayMessage) {
|
||||||
m_setupStatus = setupStatus;
|
m_setupStatus = setupStatus;
|
||||||
@ -108,12 +103,12 @@ void Device::setSetupStatus(Device::ThingSetupStatus setupStatus, const QString
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Params *Device::params() const
|
Params *Thing::params() const
|
||||||
{
|
{
|
||||||
return m_params;
|
return m_params;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Device::setParams(Params *params)
|
void Thing::setParams(Params *params)
|
||||||
{
|
{
|
||||||
if (m_params != params) {
|
if (m_params != params) {
|
||||||
if (m_params) {
|
if (m_params) {
|
||||||
@ -125,12 +120,12 @@ void Device::setParams(Params *params)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Params *Device::settings() const
|
Params *Thing::settings() const
|
||||||
{
|
{
|
||||||
return m_settings;
|
return m_settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Device::setSettings(Params *settings)
|
void Thing::setSettings(Params *settings)
|
||||||
{
|
{
|
||||||
if (m_settings != settings) {
|
if (m_settings != settings) {
|
||||||
if (m_settings) {
|
if (m_settings) {
|
||||||
@ -142,12 +137,12 @@ void Device::setSettings(Params *settings)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
States *Device::states() const
|
States *Thing::states() const
|
||||||
{
|
{
|
||||||
return m_states;
|
return m_states;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Device::setStates(States *states)
|
void Thing::setStates(States *states)
|
||||||
{
|
{
|
||||||
if (m_states != states) {
|
if (m_states != states) {
|
||||||
if (m_states) {
|
if (m_states) {
|
||||||
@ -159,12 +154,12 @@ void Device::setStates(States *states)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
State *Device::state(const QUuid &stateTypeId) const
|
State *Thing::state(const QUuid &stateTypeId) const
|
||||||
{
|
{
|
||||||
return m_states->getState(stateTypeId);
|
return m_states->getState(stateTypeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
State *Device::stateByName(const QString &stateName) const
|
State *Thing::stateByName(const QString &stateName) const
|
||||||
{
|
{
|
||||||
StateType *st = m_thingClass->stateTypes()->findByName(stateName);
|
StateType *st = m_thingClass->stateTypes()->findByName(stateName);
|
||||||
if (!st) {
|
if (!st) {
|
||||||
@ -173,12 +168,12 @@ State *Device::stateByName(const QString &stateName) const
|
|||||||
return m_states->getState(st->id());
|
return m_states->getState(st->id());
|
||||||
}
|
}
|
||||||
|
|
||||||
Param *Device::param(const QUuid ¶mTypeId) const
|
Param *Thing::param(const QUuid ¶mTypeId) const
|
||||||
{
|
{
|
||||||
return m_params->getParam(paramTypeId);
|
return m_params->getParam(paramTypeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
Param *Device::paramByName(const QString ¶mName) const
|
Param *Thing::paramByName(const QString ¶mName) const
|
||||||
{
|
{
|
||||||
ParamType *paramType = m_thingClass->paramTypes()->findByName(paramName);
|
ParamType *paramType = m_thingClass->paramTypes()->findByName(paramName);
|
||||||
if (!paramType) {
|
if (!paramType) {
|
||||||
@ -187,12 +182,12 @@ Param *Device::paramByName(const QString ¶mName) const
|
|||||||
return m_params->getParam(paramType->id());
|
return m_params->getParam(paramType->id());
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceClass *Device::thingClass() const
|
ThingClass *Thing::thingClass() const
|
||||||
{
|
{
|
||||||
return m_thingClass;
|
return m_thingClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Device::hasState(const QUuid &stateTypeId) const
|
bool Thing::hasState(const QUuid &stateTypeId) const
|
||||||
{
|
{
|
||||||
foreach (State *state, states()->states()) {
|
foreach (State *state, states()->states()) {
|
||||||
if (state->stateTypeId() == stateTypeId) {
|
if (state->stateTypeId() == stateTypeId) {
|
||||||
@ -202,7 +197,7 @@ bool Device::hasState(const QUuid &stateTypeId) const
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant Device::stateValue(const QUuid &stateTypeId) const
|
QVariant Thing::stateValue(const QUuid &stateTypeId) const
|
||||||
{
|
{
|
||||||
foreach (State *state, states()->states()) {
|
foreach (State *state, states()->states()) {
|
||||||
if (state->stateTypeId() == stateTypeId) {
|
if (state->stateTypeId() == stateTypeId) {
|
||||||
@ -212,7 +207,7 @@ QVariant Device::stateValue(const QUuid &stateTypeId) const
|
|||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Device::setStateValue(const QUuid &stateTypeId, const QVariant &value)
|
void Thing::setStateValue(const QUuid &stateTypeId, const QVariant &value)
|
||||||
{
|
{
|
||||||
foreach (State *state, states()->states()) {
|
foreach (State *state, states()->states()) {
|
||||||
if (state->stateTypeId() == stateTypeId) {
|
if (state->stateTypeId() == stateTypeId) {
|
||||||
@ -222,7 +217,7 @@ void Device::setStateValue(const QUuid &stateTypeId, const QVariant &value)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int Device::executeAction(const QString &actionName, const QVariantList ¶ms)
|
int Thing::executeAction(const QString &actionName, const QVariantList ¶ms)
|
||||||
{
|
{
|
||||||
ActionType *actionType = m_thingClass->actionTypes()->findByName(actionName);
|
ActionType *actionType = m_thingClass->actionTypes()->findByName(actionName);
|
||||||
|
|
||||||
@ -240,7 +235,7 @@ int Device::executeAction(const QString &actionName, const QVariantList ¶ms)
|
|||||||
return commandId;
|
return commandId;
|
||||||
}
|
}
|
||||||
|
|
||||||
QDebug operator<<(QDebug &dbg, Device *thing)
|
QDebug operator<<(QDebug &dbg, Thing *thing)
|
||||||
{
|
{
|
||||||
dbg.nospace() << "Thing: " << thing->name() << " (" << thing->id().toString() << ") Class:" << thing->thingClass()->name() << " (" << thing->thingClassId().toString() << ")" << endl;
|
dbg.nospace() << "Thing: " << thing->name() << " (" << thing->id().toString() << ") Class:" << thing->thingClass()->name() << " (" << thing->thingClassId().toString() << ")" << endl;
|
||||||
for (int i = 0; i < thing->thingClass()->paramTypes()->rowCount(); i++) {
|
for (int i = 0; i < thing->thingClass()->paramTypes()->rowCount(); i++) {
|
||||||
@ -28,8 +28,8 @@
|
|||||||
*
|
*
|
||||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
#ifndef DEVICE_H
|
#ifndef THING_H
|
||||||
#define DEVICE_H
|
#define THING_H
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QUuid>
|
#include <QUuid>
|
||||||
@ -38,16 +38,15 @@
|
|||||||
#include "states.h"
|
#include "states.h"
|
||||||
#include "statesproxy.h"
|
#include "statesproxy.h"
|
||||||
|
|
||||||
class DeviceClass;
|
class ThingClass;
|
||||||
class DeviceManager;
|
class ThingManager;
|
||||||
|
|
||||||
class Device : public QObject
|
class Thing : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(QUuid id READ id CONSTANT)
|
Q_PROPERTY(QUuid id READ id CONSTANT)
|
||||||
Q_PROPERTY(QUuid deviceClassId READ deviceClassId CONSTANT)
|
|
||||||
Q_PROPERTY(QUuid thingClassId READ thingClassId CONSTANT)
|
Q_PROPERTY(QUuid thingClassId READ thingClassId CONSTANT)
|
||||||
Q_PROPERTY(QUuid parentDeviceId READ parentDeviceId CONSTANT)
|
Q_PROPERTY(QUuid parentId READ parentId CONSTANT)
|
||||||
Q_PROPERTY(bool isChild READ isChild CONSTANT)
|
Q_PROPERTY(bool isChild READ isChild CONSTANT)
|
||||||
Q_PROPERTY(QString name READ name NOTIFY nameChanged)
|
Q_PROPERTY(QString name READ name NOTIFY nameChanged)
|
||||||
Q_PROPERTY(ThingSetupStatus setupStatus READ setupStatus NOTIFY setupStatusChanged)
|
Q_PROPERTY(ThingSetupStatus setupStatus READ setupStatus NOTIFY setupStatusChanged)
|
||||||
@ -55,8 +54,7 @@ class Device : public QObject
|
|||||||
Q_PROPERTY(Params *params READ params NOTIFY paramsChanged)
|
Q_PROPERTY(Params *params READ params NOTIFY paramsChanged)
|
||||||
Q_PROPERTY(Params *settings READ settings NOTIFY settingsChanged)
|
Q_PROPERTY(Params *settings READ settings NOTIFY settingsChanged)
|
||||||
Q_PROPERTY(States *states READ states NOTIFY statesChanged)
|
Q_PROPERTY(States *states READ states NOTIFY statesChanged)
|
||||||
Q_PROPERTY(DeviceClass *deviceClass READ thingClass CONSTANT)
|
Q_PROPERTY(ThingClass *thingClass READ thingClass CONSTANT)
|
||||||
Q_PROPERTY(DeviceClass *thingClass READ thingClass CONSTANT)
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum ThingSetupStatus {
|
enum ThingSetupStatus {
|
||||||
@ -67,7 +65,38 @@ public:
|
|||||||
};
|
};
|
||||||
Q_ENUM(ThingSetupStatus)
|
Q_ENUM(ThingSetupStatus)
|
||||||
|
|
||||||
explicit Device(DeviceManager *thingManager, DeviceClass *thingClass, const QUuid &parentId = QUuid(), QObject *parent = nullptr);
|
enum ThingError {
|
||||||
|
ThingErrorNoError,
|
||||||
|
ThingErrorPluginNotFound,
|
||||||
|
ThingErrorVendorNotFound,
|
||||||
|
ThingErrorThingNotFound,
|
||||||
|
ThingErrorThingClassNotFound,
|
||||||
|
ThingErrorActionTypeNotFound,
|
||||||
|
ThingErrorStateTypeNotFound,
|
||||||
|
ThingErrorEventTypeNotFound,
|
||||||
|
ThingErrorThingDescriptorNotFound,
|
||||||
|
ThingErrorMissingParameter,
|
||||||
|
ThingErrorInvalidParameter,
|
||||||
|
ThingErrorSetupFailed,
|
||||||
|
ThingErrorDuplicateUuid,
|
||||||
|
ThingErrorCreationMethodNotSupported,
|
||||||
|
ThingErrorSetupMethodNotSupported,
|
||||||
|
ThingErrorHardwareNotAvailable,
|
||||||
|
ThingErrorHardwareFailure,
|
||||||
|
ThingErrorAuthenticationFailure,
|
||||||
|
ThingErrorThingInUse,
|
||||||
|
ThingErrorThingInRule,
|
||||||
|
ThingErrorThingIsChild,
|
||||||
|
ThingErrorPairingTransactionIdNotFound,
|
||||||
|
ThingErrorParameterNotWritable,
|
||||||
|
ThingErrorItemNotFound,
|
||||||
|
ThingErrorItemNotExecutable,
|
||||||
|
ThingErrorUnsupportedFeature,
|
||||||
|
ThingErrorTimeout,
|
||||||
|
};
|
||||||
|
Q_ENUM(ThingError)
|
||||||
|
|
||||||
|
explicit Thing(ThingManager *thingManager, ThingClass *thingClass, const QUuid &parentId = QUuid(), QObject *parent = nullptr);
|
||||||
|
|
||||||
QUuid id() const;
|
QUuid id() const;
|
||||||
void setId(const QUuid &id);
|
void setId(const QUuid &id);
|
||||||
@ -75,14 +104,13 @@ public:
|
|||||||
QString name() const;
|
QString name() const;
|
||||||
void setName(const QString &name);
|
void setName(const QString &name);
|
||||||
|
|
||||||
QUuid deviceClassId() const;
|
|
||||||
QUuid thingClassId() const;
|
QUuid thingClassId() const;
|
||||||
QUuid parentDeviceId() const;
|
QUuid parentId() const;
|
||||||
bool isChild() const;
|
bool isChild() const;
|
||||||
|
|
||||||
Device::ThingSetupStatus setupStatus() const;
|
Thing::ThingSetupStatus setupStatus() const;
|
||||||
QString setupDisplayMessage() const;
|
QString setupDisplayMessage() const;
|
||||||
void setSetupStatus(Device::ThingSetupStatus setupStatus, const QString &displayMessage);
|
void setSetupStatus(Thing::ThingSetupStatus setupStatus, const QString &displayMessage);
|
||||||
|
|
||||||
Params *params() const;
|
Params *params() const;
|
||||||
void setParams(Params *params);
|
void setParams(Params *params);
|
||||||
@ -94,7 +122,7 @@ public:
|
|||||||
void setStates(States *states);
|
void setStates(States *states);
|
||||||
void setStateValue(const QUuid &stateTypeId, const QVariant &value);
|
void setStateValue(const QUuid &stateTypeId, const QVariant &value);
|
||||||
|
|
||||||
DeviceClass *thingClass() const;
|
ThingClass *thingClass() const;
|
||||||
|
|
||||||
Q_INVOKABLE bool hasState(const QUuid &stateTypeId) const;
|
Q_INVOKABLE bool hasState(const QUuid &stateTypeId) const;
|
||||||
Q_INVOKABLE State *state(const QUuid &stateTypeId) const;
|
Q_INVOKABLE State *state(const QUuid &stateTypeId) const;
|
||||||
@ -115,10 +143,10 @@ signals:
|
|||||||
void eventTriggered(const QUuid &eventTypeId, const QVariantMap ¶ms);
|
void eventTriggered(const QUuid &eventTypeId, const QVariantMap ¶ms);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void executeActionReply(int commandId, const QVariantMap ¶ms);
|
void executeActionReply(int commandId, Thing::ThingError thingError, const QString &displayMessage);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
DeviceManager *m_thingManager = nullptr;
|
ThingManager *m_thingManager = nullptr;
|
||||||
QString m_name;
|
QString m_name;
|
||||||
QUuid m_id;
|
QUuid m_id;
|
||||||
QUuid m_parentId;
|
QUuid m_parentId;
|
||||||
@ -127,11 +155,12 @@ protected:
|
|||||||
Params *m_params = nullptr;
|
Params *m_params = nullptr;
|
||||||
Params *m_settings = nullptr;
|
Params *m_settings = nullptr;
|
||||||
States *m_states = nullptr;
|
States *m_states = nullptr;
|
||||||
DeviceClass *m_thingClass = nullptr;
|
ThingClass *m_thingClass = nullptr;
|
||||||
|
|
||||||
QList<int> m_pendingActions;
|
QList<int> m_pendingActions;
|
||||||
};
|
};
|
||||||
|
Q_DECLARE_METATYPE(Thing::ThingError)
|
||||||
|
|
||||||
QDebug operator<<(QDebug &dbg, Device* thing);
|
QDebug operator<<(QDebug &dbg, Thing* thing);
|
||||||
|
|
||||||
#endif // DEVICE_H
|
#endif // THING_H
|
||||||
@ -28,96 +28,96 @@
|
|||||||
*
|
*
|
||||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
#include "deviceclass.h"
|
#include "thingclass.h"
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
DeviceClass::DeviceClass(QObject *parent) :
|
ThingClass::ThingClass(QObject *parent) :
|
||||||
QObject(parent)
|
QObject(parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
QUuid DeviceClass::id() const
|
QUuid ThingClass::id() const
|
||||||
{
|
{
|
||||||
return m_id;
|
return m_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceClass::setId(const QUuid &id)
|
void ThingClass::setId(const QUuid &id)
|
||||||
{
|
{
|
||||||
m_id = id;
|
m_id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
QUuid DeviceClass::vendorId() const
|
QUuid ThingClass::vendorId() const
|
||||||
{
|
{
|
||||||
return m_vendorId;
|
return m_vendorId;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceClass::setVendorId(const QUuid &vendorId)
|
void ThingClass::setVendorId(const QUuid &vendorId)
|
||||||
{
|
{
|
||||||
m_vendorId = vendorId;
|
m_vendorId = vendorId;
|
||||||
}
|
}
|
||||||
|
|
||||||
QUuid DeviceClass::pluginId() const
|
QUuid ThingClass::pluginId() const
|
||||||
{
|
{
|
||||||
return m_pluginId;
|
return m_pluginId;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceClass::setPluginId(const QUuid &pluginId)
|
void ThingClass::setPluginId(const QUuid &pluginId)
|
||||||
{
|
{
|
||||||
m_pluginId = pluginId;
|
m_pluginId = pluginId;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString DeviceClass::name() const
|
QString ThingClass::name() const
|
||||||
{
|
{
|
||||||
return m_name;
|
return m_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceClass::setName(const QString &name)
|
void ThingClass::setName(const QString &name)
|
||||||
{
|
{
|
||||||
m_name = name;
|
m_name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString DeviceClass::displayName() const
|
QString ThingClass::displayName() const
|
||||||
{
|
{
|
||||||
return m_displayName;
|
return m_displayName;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceClass::setDisplayName(const QString &displayName)
|
void ThingClass::setDisplayName(const QString &displayName)
|
||||||
{
|
{
|
||||||
m_displayName = displayName;
|
m_displayName = displayName;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList DeviceClass::createMethods() const
|
QStringList ThingClass::createMethods() const
|
||||||
{
|
{
|
||||||
return m_createMethods;
|
return m_createMethods;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceClass::setCreateMethods(const QStringList &createMethods)
|
void ThingClass::setCreateMethods(const QStringList &createMethods)
|
||||||
{
|
{
|
||||||
m_createMethods = createMethods;
|
m_createMethods = createMethods;
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceClass::SetupMethod DeviceClass::setupMethod() const
|
ThingClass::SetupMethod ThingClass::setupMethod() const
|
||||||
{
|
{
|
||||||
return m_setupMethod;
|
return m_setupMethod;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceClass::setSetupMethod(DeviceClass::SetupMethod setupMethod)
|
void ThingClass::setSetupMethod(ThingClass::SetupMethod setupMethod)
|
||||||
{
|
{
|
||||||
m_setupMethod = setupMethod;
|
m_setupMethod = setupMethod;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList DeviceClass::interfaces() const
|
QStringList ThingClass::interfaces() const
|
||||||
{
|
{
|
||||||
return m_interfaces;
|
return m_interfaces;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceClass::setInterfaces(const QStringList &interfaces)
|
void ThingClass::setInterfaces(const QStringList &interfaces)
|
||||||
{
|
{
|
||||||
m_interfaces = interfaces;
|
m_interfaces = interfaces;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString DeviceClass::baseInterface() const
|
QString ThingClass::baseInterface() const
|
||||||
{
|
{
|
||||||
foreach (const QString &interface, m_interfaces) {
|
foreach (const QString &interface, m_interfaces) {
|
||||||
if (interface == "gateway") {
|
if (interface == "gateway") {
|
||||||
@ -181,22 +181,22 @@ QString DeviceClass::baseInterface() const
|
|||||||
return "uncategorized";
|
return "uncategorized";
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeviceClass::browsable() const
|
bool ThingClass::browsable() const
|
||||||
{
|
{
|
||||||
return m_browsable;
|
return m_browsable;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceClass::setBrowsable(bool browsable)
|
void ThingClass::setBrowsable(bool browsable)
|
||||||
{
|
{
|
||||||
m_browsable = browsable;
|
m_browsable = browsable;
|
||||||
}
|
}
|
||||||
|
|
||||||
ParamTypes *DeviceClass::paramTypes() const
|
ParamTypes *ThingClass::paramTypes() const
|
||||||
{
|
{
|
||||||
return m_paramTypes;
|
return m_paramTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceClass::setParamTypes(ParamTypes *paramTypes)
|
void ThingClass::setParamTypes(ParamTypes *paramTypes)
|
||||||
{
|
{
|
||||||
if (m_paramTypes) {
|
if (m_paramTypes) {
|
||||||
m_paramTypes->deleteLater();
|
m_paramTypes->deleteLater();
|
||||||
@ -205,12 +205,12 @@ void DeviceClass::setParamTypes(ParamTypes *paramTypes)
|
|||||||
emit paramTypesChanged();
|
emit paramTypesChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
ParamTypes *DeviceClass::settingsTypes() const
|
ParamTypes *ThingClass::settingsTypes() const
|
||||||
{
|
{
|
||||||
return m_settingsTypes;
|
return m_settingsTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceClass::setSettingsTypes(ParamTypes *settingsTypes)
|
void ThingClass::setSettingsTypes(ParamTypes *settingsTypes)
|
||||||
{
|
{
|
||||||
if (m_settingsTypes) {
|
if (m_settingsTypes) {
|
||||||
m_settingsTypes->deleteLater();
|
m_settingsTypes->deleteLater();
|
||||||
@ -219,12 +219,12 @@ void DeviceClass::setSettingsTypes(ParamTypes *settingsTypes)
|
|||||||
emit settingsTypesChanged();
|
emit settingsTypesChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
ParamTypes *DeviceClass::discoveryParamTypes() const
|
ParamTypes *ThingClass::discoveryParamTypes() const
|
||||||
{
|
{
|
||||||
return m_discoveryParamTypes;
|
return m_discoveryParamTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceClass::setDiscoveryParamTypes(ParamTypes *paramTypes)
|
void ThingClass::setDiscoveryParamTypes(ParamTypes *paramTypes)
|
||||||
{
|
{
|
||||||
if (m_discoveryParamTypes) {
|
if (m_discoveryParamTypes) {
|
||||||
m_discoveryParamTypes->deleteLater();
|
m_discoveryParamTypes->deleteLater();
|
||||||
@ -233,12 +233,12 @@ void DeviceClass::setDiscoveryParamTypes(ParamTypes *paramTypes)
|
|||||||
emit discoveryParamTypesChanged();
|
emit discoveryParamTypesChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
StateTypes *DeviceClass::stateTypes() const
|
StateTypes *ThingClass::stateTypes() const
|
||||||
{
|
{
|
||||||
return m_stateTypes;
|
return m_stateTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceClass::setStateTypes(StateTypes *stateTypes)
|
void ThingClass::setStateTypes(StateTypes *stateTypes)
|
||||||
{
|
{
|
||||||
if (m_stateTypes) {
|
if (m_stateTypes) {
|
||||||
m_stateTypes->deleteLater();
|
m_stateTypes->deleteLater();
|
||||||
@ -247,12 +247,12 @@ void DeviceClass::setStateTypes(StateTypes *stateTypes)
|
|||||||
emit stateTypesChanged();
|
emit stateTypesChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
EventTypes *DeviceClass::eventTypes() const
|
EventTypes *ThingClass::eventTypes() const
|
||||||
{
|
{
|
||||||
return m_eventTypes;
|
return m_eventTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceClass::setEventTypes(EventTypes *eventTypes)
|
void ThingClass::setEventTypes(EventTypes *eventTypes)
|
||||||
{
|
{
|
||||||
if (m_eventTypes) {
|
if (m_eventTypes) {
|
||||||
m_eventTypes->deleteLater();
|
m_eventTypes->deleteLater();
|
||||||
@ -261,12 +261,12 @@ void DeviceClass::setEventTypes(EventTypes *eventTypes)
|
|||||||
emit eventTypesChanged();
|
emit eventTypesChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
ActionTypes *DeviceClass::actionTypes() const
|
ActionTypes *ThingClass::actionTypes() const
|
||||||
{
|
{
|
||||||
return m_actionTypes;
|
return m_actionTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceClass::setActionTypes(ActionTypes *actionTypes)
|
void ThingClass::setActionTypes(ActionTypes *actionTypes)
|
||||||
{
|
{
|
||||||
if (m_actionTypes) {
|
if (m_actionTypes) {
|
||||||
m_actionTypes->deleteLater();
|
m_actionTypes->deleteLater();
|
||||||
@ -275,12 +275,12 @@ void DeviceClass::setActionTypes(ActionTypes *actionTypes)
|
|||||||
emit actionTypesChanged();
|
emit actionTypesChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
ActionTypes *DeviceClass::browserItemActionTypes() const
|
ActionTypes *ThingClass::browserItemActionTypes() const
|
||||||
{
|
{
|
||||||
return m_browserItemActionTypes;
|
return m_browserItemActionTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceClass::setBrowserItemActionTypes(ActionTypes *browserActionTypes)
|
void ThingClass::setBrowserItemActionTypes(ActionTypes *browserActionTypes)
|
||||||
{
|
{
|
||||||
if (m_browserItemActionTypes) {
|
if (m_browserItemActionTypes) {
|
||||||
m_browserItemActionTypes->deleteLater();
|
m_browserItemActionTypes->deleteLater();
|
||||||
@ -289,7 +289,7 @@ void DeviceClass::setBrowserItemActionTypes(ActionTypes *browserActionTypes)
|
|||||||
emit browserItemActionTypesChanged();
|
emit browserItemActionTypesChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeviceClass::hasActionType(const QString &actionTypeId)
|
bool ThingClass::hasActionType(const QString &actionTypeId)
|
||||||
{
|
{
|
||||||
foreach (ActionType *actionType, m_actionTypes->actionTypes()) {
|
foreach (ActionType *actionType, m_actionTypes->actionTypes()) {
|
||||||
if (actionType->id() == actionTypeId) {
|
if (actionType->id() == actionTypeId) {
|
||||||
@ -28,8 +28,8 @@
|
|||||||
*
|
*
|
||||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
#ifndef DEVICECLASS_H
|
#ifndef THINGCLASS_H
|
||||||
#define DEVICECLASS_H
|
#define THINGCLASS_H
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QUuid>
|
#include <QUuid>
|
||||||
@ -41,7 +41,7 @@
|
|||||||
#include "eventtypes.h"
|
#include "eventtypes.h"
|
||||||
#include "actiontypes.h"
|
#include "actiontypes.h"
|
||||||
|
|
||||||
class DeviceClass : public QObject
|
class ThingClass : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
@ -74,7 +74,7 @@ public:
|
|||||||
};
|
};
|
||||||
Q_ENUM(SetupMethod)
|
Q_ENUM(SetupMethod)
|
||||||
|
|
||||||
DeviceClass(QObject *parent = nullptr);
|
ThingClass(QObject *parent = nullptr);
|
||||||
|
|
||||||
QString name() const;
|
QString name() const;
|
||||||
void setName(const QString &name);
|
void setName(const QString &name);
|
||||||
@ -156,4 +156,4 @@ private:
|
|||||||
ActionTypes *m_actionTypes = nullptr;
|
ActionTypes *m_actionTypes = nullptr;
|
||||||
ActionTypes *m_browserItemActionTypes = nullptr;
|
ActionTypes *m_browserItemActionTypes = nullptr;
|
||||||
};
|
};
|
||||||
#endif // DEVICECLASS_H
|
#endif // THINGCLASS_H
|
||||||
@ -1,5 +1,5 @@
|
|||||||
#include "nfcthingactionwriter.h"
|
#include "nfcthingactionwriter.h"
|
||||||
#include "types/deviceclass.h"
|
#include "types/thingclass.h"
|
||||||
#include "types/statetype.h"
|
#include "types/statetype.h"
|
||||||
#include "types/ruleaction.h"
|
#include "types/ruleaction.h"
|
||||||
#include "types/ruleactionparams.h"
|
#include "types/ruleactionparams.h"
|
||||||
@ -50,12 +50,12 @@ void NfcThingActionWriter::setEngine(Engine *engine)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Device *NfcThingActionWriter::thing() const
|
Thing *NfcThingActionWriter::thing() const
|
||||||
{
|
{
|
||||||
return m_thing;
|
return m_thing;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NfcThingActionWriter::setThing(Device *thing)
|
void NfcThingActionWriter::setThing(Thing *thing)
|
||||||
{
|
{
|
||||||
if (m_thing != thing) {
|
if (m_thing != thing) {
|
||||||
m_thing = thing;
|
m_thing = thing;
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
#include <QNearFieldManager>
|
#include <QNearFieldManager>
|
||||||
#include <QNdefMessage>
|
#include <QNdefMessage>
|
||||||
|
|
||||||
#include "types/device.h"
|
#include "types/thing.h"
|
||||||
#include "engine.h"
|
#include "engine.h"
|
||||||
#include "types/ruleactions.h"
|
#include "types/ruleactions.h"
|
||||||
|
|
||||||
@ -14,7 +14,7 @@ class NfcThingActionWriter : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(bool isAvailable READ isAvailable CONSTANT)
|
Q_PROPERTY(bool isAvailable READ isAvailable CONSTANT)
|
||||||
Q_PROPERTY(Engine *engine READ engine WRITE setEngine NOTIFY engineChanged)
|
Q_PROPERTY(Engine *engine READ engine WRITE setEngine NOTIFY engineChanged)
|
||||||
Q_PROPERTY(Device *thing READ thing WRITE setThing NOTIFY thingChanged)
|
Q_PROPERTY(Thing *thing READ thing WRITE setThing NOTIFY thingChanged)
|
||||||
Q_PROPERTY(RuleActions *actions READ actions CONSTANT)
|
Q_PROPERTY(RuleActions *actions READ actions CONSTANT)
|
||||||
Q_PROPERTY(int messageSize READ messageSize NOTIFY messageSizeChanged)
|
Q_PROPERTY(int messageSize READ messageSize NOTIFY messageSizeChanged)
|
||||||
Q_PROPERTY(TagStatus status READ status NOTIFY statusChanged)
|
Q_PROPERTY(TagStatus status READ status NOTIFY statusChanged)
|
||||||
@ -39,8 +39,8 @@ public:
|
|||||||
Engine *engine() const;
|
Engine *engine() const;
|
||||||
void setEngine(Engine *engine);
|
void setEngine(Engine *engine);
|
||||||
|
|
||||||
Device *thing() const;
|
Thing *thing() const;
|
||||||
void setThing(Device *thing);
|
void setThing(Thing *thing);
|
||||||
|
|
||||||
RuleActions *actions() const;
|
RuleActions *actions() const;
|
||||||
|
|
||||||
@ -64,7 +64,7 @@ private slots:
|
|||||||
private:
|
private:
|
||||||
QNearFieldManager *m_manager = nullptr;
|
QNearFieldManager *m_manager = nullptr;
|
||||||
Engine *m_engine = nullptr;
|
Engine *m_engine = nullptr;
|
||||||
Device *m_thing = nullptr;
|
Thing *m_thing = nullptr;
|
||||||
RuleActions* m_actions;
|
RuleActions* m_actions;
|
||||||
|
|
||||||
TagStatus m_status = TagStatusWaiting;
|
TagStatus m_status = TagStatusWaiting;
|
||||||
|
|||||||
@ -47,31 +47,31 @@
|
|||||||
<file>ui/customviews/GenericTypeLogView.qml</file>
|
<file>ui/customviews/GenericTypeLogView.qml</file>
|
||||||
<file>ui/customviews/WeatherView.qml</file>
|
<file>ui/customviews/WeatherView.qml</file>
|
||||||
<file>ui/devicepages/MediaThingPage.qml</file>
|
<file>ui/devicepages/MediaThingPage.qml</file>
|
||||||
<file>ui/devicepages/ButtonDevicePage.qml</file>
|
<file>ui/devicepages/ButtonThingPage.qml</file>
|
||||||
<file>ui/devicepages/GenericDevicePage.qml</file>
|
<file>ui/devicepages/GenericDevicePage.qml</file>
|
||||||
<file>ui/devicepages/WeatherDevicePage.qml</file>
|
<file>ui/devicepages/WeatherDevicePage.qml</file>
|
||||||
<file>ui/devicepages/SensorDevicePage.qml</file>
|
<file>ui/devicepages/SensorDevicePage.qml</file>
|
||||||
<file>ui/devicepages/DevicePageBase.qml</file>
|
<file>ui/devicepages/ThingPageBase.qml</file>
|
||||||
<file>ui/devicepages/InputTriggerDevicePage.qml</file>
|
<file>ui/devicepages/InputTriggerDevicePage.qml</file>
|
||||||
<file>ui/devicepages/StateLogPage.qml</file>
|
<file>ui/devicepages/StateLogPage.qml</file>
|
||||||
<file>ui/devicepages/ShutterDevicePage.qml</file>
|
<file>ui/devicepages/ShutterDevicePage.qml</file>
|
||||||
<file>ui/devicepages/GarageThingPage.qml</file>
|
<file>ui/devicepages/GarageThingPage.qml</file>
|
||||||
<file>ui/devicepages/AwningDevicePage.qml</file>
|
<file>ui/devicepages/AwningThingPage.qml</file>
|
||||||
<file>ui/devicepages/NotificationsDevicePage.qml</file>
|
<file>ui/devicepages/NotificationsDevicePage.qml</file>
|
||||||
<file>ui/devicepages/LightDevicePage.qml</file>
|
<file>ui/devicepages/LightDevicePage.qml</file>
|
||||||
<file>ui/devicepages/FingerprintReaderDevicePage.qml</file>
|
<file>ui/devicepages/FingerprintReaderDevicePage.qml</file>
|
||||||
<file>ui/devicepages/DeviceLogPage.qml</file>
|
<file>ui/devicepages/DeviceLogPage.qml</file>
|
||||||
<file>ui/devicelistpages/GenericDeviceListPage.qml</file>
|
<file>ui/devicelistpages/GenericThingsListPage.qml</file>
|
||||||
<file>ui/devicelistpages/ClosablesDeviceListPage.qml</file>
|
<file>ui/devicelistpages/ClosablesThingsListPage.qml</file>
|
||||||
<file>ui/devicelistpages/GarageThingListPage.qml</file>
|
<file>ui/devicelistpages/GarageThingsListPage.qml</file>
|
||||||
<file>ui/devicelistpages/AwningDeviceListPage.qml</file>
|
<file>ui/devicelistpages/AwningThingsListPage.qml</file>
|
||||||
<file>ui/devicelistpages/ShutterDeviceListPage.qml</file>
|
<file>ui/devicelistpages/ShutterDeviceListPage.qml</file>
|
||||||
<file>ui/devicelistpages/BlindDeviceListPage.qml</file>
|
<file>ui/devicelistpages/BlindThingsListPage.qml</file>
|
||||||
<file>ui/devicelistpages/LightsDeviceListPage.qml</file>
|
<file>ui/devicelistpages/LightThingsListPage.qml</file>
|
||||||
<file>ui/devicelistpages/SensorsDeviceListPage.qml</file>
|
<file>ui/devicelistpages/SensorsDeviceListPage.qml</file>
|
||||||
<file>ui/devicelistpages/WeatherDeviceListPage.qml</file>
|
<file>ui/devicelistpages/WeatherDeviceListPage.qml</file>
|
||||||
<file>ui/devicelistpages/DeviceListPageBase.qml</file>
|
<file>ui/devicelistpages/ThingsListPageBase.qml</file>
|
||||||
<file>ui/magic/DeviceRulesPage.qml</file>
|
<file>ui/magic/ThingRulesPage.qml</file>
|
||||||
<file>ui/magic/EditRulePage.qml</file>
|
<file>ui/magic/EditRulePage.qml</file>
|
||||||
<file>ui/magic/SelectThingPage.qml</file>
|
<file>ui/magic/SelectThingPage.qml</file>
|
||||||
<file>ui/magic/ComposeEventDescriptorPage.qml</file>
|
<file>ui/magic/ComposeEventDescriptorPage.qml</file>
|
||||||
|
|||||||
@ -59,9 +59,7 @@ Page {
|
|||||||
RuleTemplatesFilterModel {
|
RuleTemplatesFilterModel {
|
||||||
id: ruleTemplatesModel
|
id: ruleTemplatesModel
|
||||||
ruleTemplates: RuleTemplates {}
|
ruleTemplates: RuleTemplates {}
|
||||||
readonly property var deviceClass: root.device ? engine.deviceManager.deviceClasses.getDeviceClass(root.device.deviceClassId) : null
|
filterByThings: ThingsProxy { engine: _engine }
|
||||||
filterByDevices: DevicesProxy { engine: _engine }
|
|
||||||
filterInterfaceNames: deviceClass ? deviceClass.interfaces : []
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function addRule() {
|
function addRule() {
|
||||||
|
|||||||
@ -228,7 +228,7 @@ Page {
|
|||||||
ColumnLayout {
|
ColumnLayout {
|
||||||
anchors { left: parent.left; right: parent.right; verticalCenter: parent.verticalCenter; margins: app.margins }
|
anchors { left: parent.left; right: parent.right; verticalCenter: parent.verticalCenter; margins: app.margins }
|
||||||
spacing: app.margins
|
spacing: app.margins
|
||||||
visible: engine.deviceManager.fetchingData
|
visible: engine.thingManager.fetchingData
|
||||||
BusyIndicator {
|
BusyIndicator {
|
||||||
Layout.alignment: Qt.AlignHCenter
|
Layout.alignment: Qt.AlignHCenter
|
||||||
running: parent.visible
|
running: parent.visible
|
||||||
|
|||||||
@ -366,10 +366,17 @@ Item {
|
|||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
onInvalidProtocolVersion: {
|
onInvalidMinimumVersion: {
|
||||||
var popup = invalidVersionComponent.createObject(app.contentItem);
|
var popup = invalidVersionComponent.createObject(app.contentItem);
|
||||||
popup.actualVersion = actualVersion;
|
popup.actualVersion = actualVersion;
|
||||||
popup.minimumVersion = minimumVersion
|
popup.minVersion = minVersion;
|
||||||
|
popup.open()
|
||||||
|
tabSettings.lastConnectedHost = ""
|
||||||
|
}
|
||||||
|
onInvalidMaximumVersion: {
|
||||||
|
var popup = invalidVersionComponent.createObject(app.contentItem);
|
||||||
|
popup.actualVersion = actualVersion;
|
||||||
|
popup.maxVersion = maxVersion;
|
||||||
popup.open()
|
popup.open()
|
||||||
tabSettings.lastConnectedHost = ""
|
tabSettings.lastConnectedHost = ""
|
||||||
}
|
}
|
||||||
@ -421,8 +428,9 @@ Item {
|
|||||||
Popup {
|
Popup {
|
||||||
id: popup
|
id: popup
|
||||||
|
|
||||||
property string actualVersion: "0.0"
|
property string actualVersion: ""
|
||||||
property string minimumVersion: "1.10"
|
property string minVersion: ""
|
||||||
|
property string maxVersion: ""
|
||||||
|
|
||||||
width: app.width * .8
|
width: app.width * .8
|
||||||
height: col.childrenRect.height + app.margins * 2
|
height: col.childrenRect.height + app.margins * 2
|
||||||
@ -439,7 +447,9 @@ Item {
|
|||||||
font.pixelSize: app.largeFont
|
font.pixelSize: app.largeFont
|
||||||
}
|
}
|
||||||
Label {
|
Label {
|
||||||
text: qsTr("Sorry, the version of the %1:core you are trying to connect to is too old. This app requires at least version %2 but this %1:core only supports %3").arg(app.systemName).arg(popup.minimumVersion).arg(popup.actualVersion)
|
text: popup.minVersion != ""
|
||||||
|
? qsTr("The version of the %1:core you are trying to connect to is too old. This app requires at least version %2 but this %1:core only supports %3. Please update your %1:core system.").arg(app.systemName).arg(popup.minVersion).arg(popup.actualVersion)
|
||||||
|
: qsTr("The version of the %1:core you are trying to connect to is too new. This app supports only up to version %2 but this %1:core provides %3. Please update %1:app.").arg(app.systemName).arg(popup.maxVersion).arg(popup.actualVersion)
|
||||||
wrapMode: Text.WordWrap
|
wrapMode: Text.WordWrap
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
}
|
}
|
||||||
|
|||||||
@ -106,7 +106,6 @@ Page {
|
|||||||
Pane {
|
Pane {
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Material.elevation: layout.isGrid ? 1 : 0
|
Material.elevation: layout.isGrid ? 1 : 0
|
||||||
visible: engine.jsonRpcClient.ensureServerVersion("1.9")
|
|
||||||
|
|
||||||
padding: 0
|
padding: 0
|
||||||
NymeaSwipeDelegate {
|
NymeaSwipeDelegate {
|
||||||
|
|||||||
@ -37,7 +37,7 @@ import "../delegates"
|
|||||||
MeaDialog {
|
MeaDialog {
|
||||||
id: root
|
id: root
|
||||||
|
|
||||||
property Device device
|
property Thing thing
|
||||||
property string itemId
|
property string itemId
|
||||||
property alias actionTypeIds: actionListView.model
|
property alias actionTypeIds: actionListView.model
|
||||||
|
|
||||||
@ -63,7 +63,7 @@ MeaDialog {
|
|||||||
width: parent.width
|
width: parent.width
|
||||||
text: actionType.displayName
|
text: actionType.displayName
|
||||||
progressive: false
|
progressive: false
|
||||||
property ActionType actionType: root.device.deviceClass.browserItemActionTypes.getActionType(modelData)
|
property ActionType actionType: root.thing.thingClass.browserItemActionTypes.getActionType(modelData)
|
||||||
onClicked: {
|
onClicked: {
|
||||||
var hasParams = actionType.paramTypes.count > 0
|
var hasParams = actionType.paramTypes.count > 0
|
||||||
if (hasParams) {
|
if (hasParams) {
|
||||||
|
|||||||
@ -39,11 +39,11 @@ import "../customviews"
|
|||||||
Item {
|
Item {
|
||||||
id: root
|
id: root
|
||||||
|
|
||||||
property Device thing: null
|
property Thing thing: null
|
||||||
readonly property DeviceClass thingClass: thing.deviceClass
|
readonly property ThingClass thingClass: thing.thingClass
|
||||||
|
|
||||||
readonly property string type: "shutter"
|
readonly property string type: "shutter"
|
||||||
readonly property bool isExtended: thing.deviceClass.interfaces.indexOf("extendedclosable") >= 0
|
readonly property bool isExtended: thing.thingClass.interfaces.indexOf("extendedclosable") >= 0
|
||||||
|
|
||||||
readonly property State movingState: isExtended ? thing.states.getState(thingClass.stateTypes.findByName("moving").id) : 0
|
readonly property State movingState: isExtended ? thing.states.getState(thingClass.stateTypes.findByName("moving").id) : 0
|
||||||
readonly property State percentageState: isExtended ? thing.states.getState(thingClass.stateTypes.findByName("percentage").id) : 0
|
readonly property State percentageState: isExtended ? thing.states.getState(thingClass.stateTypes.findByName("percentage").id) : 0
|
||||||
@ -155,7 +155,7 @@ Item {
|
|||||||
percentageParam["value"] = percentage
|
percentageParam["value"] = percentage
|
||||||
params.push(percentageParam);
|
params.push(percentageParam);
|
||||||
print("executing", percentage)
|
print("executing", percentage)
|
||||||
engine.deviceManager.executeAction(root.thing.id, actionType.id, params);
|
engine.thingManager.executeAction(root.thing.id, actionType.id, params);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -38,9 +38,13 @@ MeaDialog {
|
|||||||
title: qsTr("Oh snap!")
|
title: qsTr("Oh snap!")
|
||||||
headerIcon: "../images/dialog-error-symbolic.svg"
|
headerIcon: "../images/dialog-error-symbolic.svg"
|
||||||
|
|
||||||
|
property int error: 0
|
||||||
|
|
||||||
|
// Legacy as some places might still use strings instead of enums
|
||||||
property string errorCode: ""
|
property string errorCode: ""
|
||||||
|
|
||||||
text: qsTr("An unexpected error happened. We're sorry for that.") +
|
text: qsTr("An unexpected error happened. We're sorry for that.") +
|
||||||
(errorCode.length > 0 ? "\n\n" + qsTr("Error code: %1").arg(errorCode) : "")
|
(errorCode.length > 0 ? "\n\n" + qsTr("Error code: %1").arg(errorCode) : "") +
|
||||||
|
(error != 0 ? "\n\n" + qsTr("Error code: %1").arg(error) : "")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -47,9 +47,9 @@ Item {
|
|||||||
}
|
}
|
||||||
onModelChanged: canvas.requestPaint()
|
onModelChanged: canvas.requestPaint()
|
||||||
|
|
||||||
readonly property var device: root.model ? engine.deviceManager.devices.getDevice(root.model.deviceId) : null
|
readonly property Thing thing: root.model ? engine.thingManager.things.getThing(root.model.thingId) : null
|
||||||
readonly property var deviceClass: device ? engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId) : null
|
readonly property ThingClass thingClass: thing ? engine.thingManager.thingClasses.getThingClass(thing.thingClassId) : null
|
||||||
readonly property var stateType: deviceClass ? deviceClass.stateTypes.getStateType(root.model.typeIds[0]) : null
|
readonly property StateType stateType: thingClass ? thingClass.stateTypes.getStateType(root.model.typeIds[0]) : null
|
||||||
|
|
||||||
Label {
|
Label {
|
||||||
anchors.centerIn: parent
|
anchors.centerIn: parent
|
||||||
|
|||||||
@ -70,13 +70,13 @@ Item {
|
|||||||
target: engine.thingManager
|
target: engine.thingManager
|
||||||
onExecuteBrowserItemReply: {
|
onExecuteBrowserItemReply: {
|
||||||
if (commandId == d.pendingItemExecutionId) {
|
if (commandId == d.pendingItemExecutionId) {
|
||||||
if (params.thingError === "ThingErrorNoError") {
|
if (thingError === Thing.ThingErrorNoError) {
|
||||||
root.itemLaunched();
|
root.itemLaunched();
|
||||||
} else {
|
} else {
|
||||||
var errorDialog = Qt.createComponent(Qt.resolvedUrl("ErrorDialog.qml"));
|
var errorDialog = Qt.createComponent(Qt.resolvedUrl("ErrorDialog.qml"));
|
||||||
var text = qsTr("Sorry. An error happened launching the item. (Error code: %1)").arg(params.error);
|
var text = qsTr("Sorry. An error happened launching the item. (Error code: %1)").arg(params.error);
|
||||||
if (params.displayMessage.length > 0) {
|
if (displayMessage.length > 0) {
|
||||||
text = params.displayMessage;
|
text = displayMessage;
|
||||||
}
|
}
|
||||||
var popup = errorDialog.createObject(app, {text: text})
|
var popup = errorDialog.createObject(app, {text: text})
|
||||||
popup.open()
|
popup.open()
|
||||||
@ -102,7 +102,7 @@ Item {
|
|||||||
// Need to keep a explicit property here or the GC will eat it too early
|
// Need to keep a explicit property here or the GC will eat it too early
|
||||||
property BrowserItems browserItems: null
|
property BrowserItems browserItems: null
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
browserItems = engine.thingManager.browseDevice(root.thing.id, nodeId);
|
browserItems = engine.thingManager.browseThing(root.thing.id, nodeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
delegate: BrowserItemDelegate {
|
delegate: BrowserItemDelegate {
|
||||||
|
|||||||
@ -79,12 +79,12 @@ Item {
|
|||||||
target: engine.thingManager
|
target: engine.thingManager
|
||||||
onExecuteActionReply: {
|
onExecuteActionReply: {
|
||||||
if (commandId == d.pendingCallId) {
|
if (commandId == d.pendingCallId) {
|
||||||
if (params.deviceError !== "DeviceErrorNoError") {
|
if (thingError !== Thing.ThingErrorNoError) {
|
||||||
var errorDialog = Qt.createComponent(Qt.resolvedUrl("../components/ErrorDialog.qml"));
|
var errorDialog = Qt.createComponent(Qt.resolvedUrl("../components/ErrorDialog.qml"));
|
||||||
var dialogParams = {}
|
var dialogParams = {}
|
||||||
dialogParams.errorCode = params.deviceError
|
dialogParams.error = thingError
|
||||||
if (params.displayMessage && params.displayMessage.length > 0) {
|
if (displayMessage.length > 0) {
|
||||||
dialogParams.text = params.displayMessage
|
dialogParams.text = displayMessage
|
||||||
}
|
}
|
||||||
var popup = errorDialog.createObject(app, dialogParams)
|
var popup = errorDialog.createObject(app, dialogParams)
|
||||||
popup.open()
|
popup.open()
|
||||||
@ -392,7 +392,7 @@ Item {
|
|||||||
anchors.margins: app.margins
|
anchors.margins: app.margins
|
||||||
spacing: app.margins
|
spacing: app.margins
|
||||||
|
|
||||||
NavigationPad { Layout.fillWidth: true; Layout.fillHeight: true; device: root.thing }
|
NavigationPad { Layout.fillWidth: true; Layout.fillHeight: true; thing: root.thing }
|
||||||
MediaControls { Layout.fillWidth: true; thing: root.thing }
|
MediaControls { Layout.fillWidth: true; thing: root.thing }
|
||||||
ShuffleRepeatVolumeControl { Layout.fillWidth: true; Layout.fillHeight: false; Layout.preferredHeight: app.iconSize; thing: root.thing }
|
ShuffleRepeatVolumeControl { Layout.fillWidth: true; Layout.fillHeight: false; Layout.preferredHeight: app.iconSize; thing: root.thing }
|
||||||
}
|
}
|
||||||
|
|||||||
@ -37,11 +37,11 @@ import QtQuick.Layouts 1.3
|
|||||||
Item {
|
Item {
|
||||||
id: root
|
id: root
|
||||||
|
|
||||||
property Device device: null
|
property Thing thing: null
|
||||||
|
|
||||||
readonly property bool isExtended: device && device.deviceClass.interfaces.indexOf("extendednavigationpad") >= 0
|
readonly property bool isExtended: thing && thing.thingClass.interfaces.indexOf("extendednavigationpad") >= 0
|
||||||
|
|
||||||
readonly property ActionType navigateActionType: device ? device.deviceClass.actionTypes.findByName("navigate") : null
|
readonly property ActionType navigateActionType: thing ? thing.thingClass.actionTypes.findByName("navigate") : null
|
||||||
|
|
||||||
Pane {
|
Pane {
|
||||||
id: pane
|
id: pane
|
||||||
@ -75,7 +75,7 @@ Item {
|
|||||||
anchors { right: parent.right; top: parent.top; margins: parent.width * .1 }
|
anchors { right: parent.right; top: parent.top; margins: parent.width * .1 }
|
||||||
height: app.iconSize
|
height: app.iconSize
|
||||||
width: app.iconSize
|
width: app.iconSize
|
||||||
visible: root.device.deviceClass.interfaces.indexOf("extendednavigationpad") >= 0
|
visible: root.thing.thingClass.interfaces.indexOf("extendednavigationpad") >= 0
|
||||||
imageSource: "../images/navigation-menu.svg"
|
imageSource: "../images/navigation-menu.svg"
|
||||||
Item { id: menuButtonArea; anchors.centerIn: parent; width: pane.width / 4; height: width; rotation: 45 }
|
Item { id: menuButtonArea; anchors.centerIn: parent; width: pane.width / 4; height: width; rotation: 45 }
|
||||||
}
|
}
|
||||||
@ -85,7 +85,7 @@ Item {
|
|||||||
height: app.iconSize
|
height: app.iconSize
|
||||||
width: app.iconSize
|
width: app.iconSize
|
||||||
imageSource: "../images/home.svg"
|
imageSource: "../images/home.svg"
|
||||||
visible: root.device.deviceClass.interfaces.indexOf("extendednavigationpad") >= 0
|
visible: root.thing.thingClass.interfaces.indexOf("extendednavigationpad") >= 0
|
||||||
Item { id: homeButtonArea; anchors.centerIn: parent; width: pane.width / 4; height: width; rotation: 45 }
|
Item { id: homeButtonArea; anchors.centerIn: parent; width: pane.width / 4; height: width; rotation: 45 }
|
||||||
}
|
}
|
||||||
KeypadButton {
|
KeypadButton {
|
||||||
@ -94,7 +94,7 @@ Item {
|
|||||||
height: app.iconSize
|
height: app.iconSize
|
||||||
width: app.iconSize
|
width: app.iconSize
|
||||||
imageSource: "../images/info.svg"
|
imageSource: "../images/info.svg"
|
||||||
visible: root.device.deviceClass.interfaces.indexOf("extendednavigationpad") >= 0
|
visible: root.thing.thingClass.interfaces.indexOf("extendednavigationpad") >= 0
|
||||||
Item { id: infoButtonArea; anchors.centerIn: parent; width: pane.width / 4; height: width; rotation: 45 }
|
Item { id: infoButtonArea; anchors.centerIn: parent; width: pane.width / 4; height: width; rotation: 45 }
|
||||||
}
|
}
|
||||||
Rectangle {
|
Rectangle {
|
||||||
@ -259,7 +259,7 @@ Item {
|
|||||||
param["paramTypeId"] = root.navigateActionType.paramTypes.findByName("to").id;
|
param["paramTypeId"] = root.navigateActionType.paramTypes.findByName("to").id;
|
||||||
param["value"] = direction;
|
param["value"] = direction;
|
||||||
params.push(param);
|
params.push(param);
|
||||||
engine.deviceManager.executeAction(root.device.id, root.navigateActionType.id, params)
|
engine.thingManager.executeAction(root.thing.id, root.navigateActionType.id, params)
|
||||||
PlatformHelper.vibrate(PlatformHelper.HapticsFeedbackSelection)
|
PlatformHelper.vibrate(PlatformHelper.HapticsFeedbackSelection)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -40,7 +40,7 @@ Dialog {
|
|||||||
y: (parent.height - height) / 2
|
y: (parent.height - height) / 2
|
||||||
modal: true
|
modal: true
|
||||||
|
|
||||||
property var device: null
|
property Thing thing: null
|
||||||
property var rulesList: null
|
property var rulesList: null
|
||||||
|
|
||||||
ColumnLayout {
|
ColumnLayout {
|
||||||
@ -73,7 +73,7 @@ Dialog {
|
|||||||
text: qsTr("Remove all those rules")
|
text: qsTr("Remove all those rules")
|
||||||
progressive: false
|
progressive: false
|
||||||
onClicked: {
|
onClicked: {
|
||||||
engine.thingManager.removeThing(root.device.id, DeviceManager.RemovePolicyCascade)
|
engine.thingManager.removeThing(root.thing.id, ThingManager.RemovePolicyCascade)
|
||||||
root.close()
|
root.close()
|
||||||
root.destroy();
|
root.destroy();
|
||||||
}
|
}
|
||||||
@ -84,7 +84,7 @@ Dialog {
|
|||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
progressive: false
|
progressive: false
|
||||||
onClicked: {
|
onClicked: {
|
||||||
engine.thingManager.removeThing(root.device.id, DeviceManager.RemovePolicyUpdate)
|
engine.thingManager.removeThing(root.thing.id, ThingManager.RemovePolicyUpdate)
|
||||||
root.close()
|
root.close()
|
||||||
root.destroy();
|
root.destroy();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -37,11 +37,9 @@ import Nymea 1.0
|
|||||||
RowLayout {
|
RowLayout {
|
||||||
id: root
|
id: root
|
||||||
|
|
||||||
property Device thing: null
|
property Thing thing: null
|
||||||
property alias device: root.thing
|
readonly property State openState: thing.stateByName("state")
|
||||||
readonly property var deviceClass: device ? engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId) : null
|
readonly property bool canStop: thing && thing.thingClass.actionTypes.findByName("stop")
|
||||||
readonly property var openState: device ? device.states.getState(deviceClass.stateTypes.findByName("state").id) : null
|
|
||||||
readonly property bool canStop: device && device.deviceClass.actionTypes.findByName("stop")
|
|
||||||
|
|
||||||
property bool invert: false
|
property bool invert: false
|
||||||
|
|
||||||
@ -54,7 +52,7 @@ RowLayout {
|
|||||||
imageSource: root.invert ? "../images/down.svg" : "../images/up.svg"
|
imageSource: root.invert ? "../images/down.svg" : "../images/up.svg"
|
||||||
color: root.openState && root.openState.value === "opening" ? Material.accent : Style.iconColor
|
color: root.openState && root.openState.value === "opening" ? Material.accent : Style.iconColor
|
||||||
onClicked: {
|
onClicked: {
|
||||||
engine.deviceManager.executeAction(root.device.id, root.deviceClass.actionTypes.findByName("open").id)
|
engine.thingManager.executeAction(root.thing.id, root.thing.thingClass.actionTypes.findByName("open").id)
|
||||||
root.activated("open")
|
root.activated("open")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -66,7 +64,7 @@ RowLayout {
|
|||||||
longpressEnabled: false
|
longpressEnabled: false
|
||||||
imageSource: "../images/media-playback-stop.svg"
|
imageSource: "../images/media-playback-stop.svg"
|
||||||
onClicked: {
|
onClicked: {
|
||||||
engine.deviceManager.executeAction(root.device.id, root.deviceClass.actionTypes.findByName("stop").id)
|
engine.thingManager.executeAction(root.thing.id, root.thing.thingClass.actionTypes.findByName("stop").id)
|
||||||
root.activated("stop")
|
root.activated("stop")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -78,7 +76,7 @@ RowLayout {
|
|||||||
longpressEnabled: false
|
longpressEnabled: false
|
||||||
color: root.openState && root.openState.value === "closing" ? Material.accent : Style.iconColor
|
color: root.openState && root.openState.value === "closing" ? Material.accent : Style.iconColor
|
||||||
onClicked: {
|
onClicked: {
|
||||||
engine.deviceManager.executeAction(root.device.id, root.deviceClass.actionTypes.findByName("close").id)
|
engine.thingManager.executeAction(root.thing.id, root.thing.thingClass.actionTypes.findByName("close").id)
|
||||||
root.activated("close")
|
root.activated("close")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -99,7 +99,7 @@ ChartView {
|
|||||||
|
|
||||||
onClicked: {
|
onClicked: {
|
||||||
print("clicked slice", slice, d.sliceMap[slice], meters.get(d.sliceMap[slice]))
|
print("clicked slice", slice, d.sliceMap[slice], meters.get(d.sliceMap[slice]))
|
||||||
pageStack.push("../devicepages/SmartMeterDevicePage.qml", {device: meters.get(d.sliceMap[slice])})
|
pageStack.push("../devicepages/SmartMeterDevicePage.qml", {thing: meters.get(d.sliceMap[slice])})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -22,21 +22,19 @@ AutoSizeMenu {
|
|||||||
root.addItem(menuEntryComponent.createObject(root, {text: qsTr("Logs"), iconSource: "../images/logs.svg", functionName: "openThingLogPage"}))
|
root.addItem(menuEntryComponent.createObject(root, {text: qsTr("Logs"), iconSource: "../images/logs.svg", functionName: "openThingLogPage"}))
|
||||||
}
|
}
|
||||||
|
|
||||||
if (engine.jsonRpcClient.ensureServerVersion("1.6")) {
|
root.addItem(menuEntryComponent.createObject(root,
|
||||||
root.addItem(menuEntryComponent.createObject(root,
|
{
|
||||||
{
|
text: Qt.binding(function() { return favoritesProxy.count === 0 ? qsTr("Mark as favorite") : qsTr("Remove from favorites")}),
|
||||||
text: Qt.binding(function() { return favoritesProxy.count === 0 ? qsTr("Mark as favorite") : qsTr("Remove from favorites")}),
|
iconSource: Qt.binding(function() { return favoritesProxy.count === 0 ? "../images/starred.svg" : "../images/non-starred.svg"}),
|
||||||
iconSource: Qt.binding(function() { return favoritesProxy.count === 0 ? "../images/starred.svg" : "../images/non-starred.svg"}),
|
functionName: "toggleFavorite"
|
||||||
functionName: "toggleFavorite"
|
}))
|
||||||
}))
|
|
||||||
|
|
||||||
root.addItem(menuEntryComponent.createObject(root,
|
root.addItem(menuEntryComponent.createObject(root,
|
||||||
{
|
{
|
||||||
text: qsTr("Grouping"),
|
text: qsTr("Grouping"),
|
||||||
iconSource: "../images/view-grid-symbolic.svg",
|
iconSource: "../images/view-grid-symbolic.svg",
|
||||||
functionName: "addToGroup"
|
functionName: "addToGroup"
|
||||||
}))
|
}))
|
||||||
}
|
|
||||||
|
|
||||||
print("*** creating menu")
|
print("*** creating menu")
|
||||||
print("NFC", NfcHelper.isAvailable)
|
print("NFC", NfcHelper.isAvailable)
|
||||||
@ -52,7 +50,7 @@ AutoSizeMenu {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function openThingMagicPage() {
|
function openThingMagicPage() {
|
||||||
pageStack.push(Qt.resolvedUrl("../magic/DeviceRulesPage.qml"), {thing: root.thing})
|
pageStack.push(Qt.resolvedUrl("../magic/ThingRulesPage.qml"), {thing: root.thing})
|
||||||
}
|
}
|
||||||
function openGenericThingPage() {
|
function openGenericThingPage() {
|
||||||
pageStack.push(Qt.resolvedUrl("../devicepages/GenericDevicePage.qml"), {thing: root.thing})
|
pageStack.push(Qt.resolvedUrl("../devicepages/GenericDevicePage.qml"), {thing: root.thing})
|
||||||
@ -84,7 +82,7 @@ AutoSizeMenu {
|
|||||||
TagsProxyModel {
|
TagsProxyModel {
|
||||||
id: favoritesProxy
|
id: favoritesProxy
|
||||||
tags: engine.tagsManager.tags
|
tags: engine.tagsManager.tags
|
||||||
filterDeviceId: root.thing.id
|
filterThingId: root.thing.id
|
||||||
filterTagId: "favorites"
|
filterTagId: "favorites"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,7 +153,7 @@ AutoSizeMenu {
|
|||||||
id: innerProxy
|
id: innerProxy
|
||||||
engine: _engine
|
engine: _engine
|
||||||
filterTagId: model.tagId
|
filterTagId: model.tagId
|
||||||
filterDeviceId: root.thing.id
|
filterThingId: root.thing.id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -41,23 +41,22 @@ Item {
|
|||||||
id: root
|
id: root
|
||||||
implicitHeight: width * .6
|
implicitHeight: width * .6
|
||||||
|
|
||||||
property Device device: null
|
property Thing thing: null
|
||||||
property StateType stateType: null
|
property StateType stateType: null
|
||||||
property int roundTo: 2
|
property int roundTo: 2
|
||||||
property color color: Style.accentColor
|
property color color: Style.accentColor
|
||||||
property string iconSource: ""
|
property string iconSource: ""
|
||||||
property alias title: titleLabel.text
|
property alias title: titleLabel.text
|
||||||
|
|
||||||
readonly property var valueState: device.states.getState(stateType.id)
|
readonly property var valueState: thing.states.getState(stateType.id)
|
||||||
readonly property var deviceClass: engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId);
|
readonly property bool hasConnectable: thing.thingClass.interfaces.indexOf("connectable") >= 0
|
||||||
readonly property bool hasConnectable: deviceClass.interfaces.indexOf("connectable") >= 0
|
readonly property StateType connectedStateType: hasConnectable ? thing.thingClass.stateTypes.findByName("connected") : null
|
||||||
readonly property var connectedStateType: hasConnectable ? deviceClass.stateTypes.findByName("connected") : null
|
|
||||||
|
|
||||||
|
|
||||||
LogsModelNg {
|
LogsModelNg {
|
||||||
id: logsModelNg
|
id: logsModelNg
|
||||||
engine: _engine
|
engine: _engine
|
||||||
deviceId: root.device.id
|
thingId: root.thing.id
|
||||||
typeIds: [root.stateType.id]
|
typeIds: [root.stateType.id]
|
||||||
live: true
|
live: true
|
||||||
graphSeries: lineSeries1
|
graphSeries: lineSeries1
|
||||||
@ -67,7 +66,7 @@ Item {
|
|||||||
LogsModelNg {
|
LogsModelNg {
|
||||||
id: connectedLogsModel
|
id: connectedLogsModel
|
||||||
engine: root.hasConnectable ? _engine : null // don't even try to poll if we don't have a connectable interface
|
engine: root.hasConnectable ? _engine : null // don't even try to poll if we don't have a connectable interface
|
||||||
deviceId: root.device.id
|
thingId: root.thing.id
|
||||||
typeIds: root.hasConnectable ? [root.connectedStateType.id] : []
|
typeIds: root.hasConnectable ? [root.connectedStateType.id] : []
|
||||||
live: true
|
live: true
|
||||||
graphSeries: connectedLineSeries
|
graphSeries: connectedLineSeries
|
||||||
|
|||||||
@ -54,10 +54,8 @@ Item {
|
|||||||
SwipeDelegateGroup {}
|
SwipeDelegateGroup {}
|
||||||
|
|
||||||
onContentYChanged: {
|
onContentYChanged: {
|
||||||
if (!engine.jsonRpcClient.ensureServerVersion("1.10")) {
|
if (!logsModel.busy && contentY - originY < 5 * height) {
|
||||||
if (!logsModel.busy && contentY - originY < 5 * height) {
|
logsModel.fetchEarlier(24)
|
||||||
logsModel.fetchEarlier(24)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,11 +63,11 @@ Item {
|
|||||||
id: logEntryDelegate
|
id: logEntryDelegate
|
||||||
width: parent.width
|
width: parent.width
|
||||||
implicitHeight: app.delegateHeight
|
implicitHeight: app.delegateHeight
|
||||||
property var device: engine.deviceManager.devices.getDevice(model.deviceId)
|
property Thing thing: engine.thingManager.things.getThing(model.thingId)
|
||||||
property var deviceClass: engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId)
|
property Thing thingClass: engine.thingManager.thingClasses.getThingClass(thing.thingClassId)
|
||||||
iconName: "../images/event.svg"
|
iconName: "../images/event.svg"
|
||||||
text: Qt.formatDateTime(model.timestamp,"dd.MM.yy - hh:mm:ss")
|
text: Qt.formatDateTime(model.timestamp,"dd.MM.yy - hh:mm:ss")
|
||||||
subText: deviceClass.eventTypes.getEventType(model.typeId).displayName + (model.value.length > 0 ? (": " + model.value.trim()) : "")
|
subText: thingClass.eventTypes.getEventType(model.typeId).displayName + (model.value.length > 0 ? (": " + model.value.trim()) : "")
|
||||||
prominentSubText: true
|
prominentSubText: true
|
||||||
progressive: false
|
progressive: false
|
||||||
contextOptions: [
|
contextOptions: [
|
||||||
|
|||||||
@ -48,7 +48,8 @@ NymeaSwipeDelegate {
|
|||||||
secondaryIconName: model.actionTypeIds.length > 0 ? "../images/navigation-menu.svg" : ""
|
secondaryIconName: model.actionTypeIds.length > 0 ? "../images/navigation-menu.svg" : ""
|
||||||
secondaryIconClickable: true
|
secondaryIconClickable: true
|
||||||
|
|
||||||
property Device device: null
|
property Thing thing: null
|
||||||
|
property alias device: root.thing
|
||||||
|
|
||||||
onPressAndHold: openContextMenu()
|
onPressAndHold: openContextMenu()
|
||||||
onSecondaryIconClicked: openContextMenu()
|
onSecondaryIconClicked: openContextMenu()
|
||||||
@ -63,7 +64,7 @@ NymeaSwipeDelegate {
|
|||||||
var actionDialogComponent = Qt.createComponent(Qt.resolvedUrl("../components/BrowserContextMenu.qml"));
|
var actionDialogComponent = Qt.createComponent(Qt.resolvedUrl("../components/BrowserContextMenu.qml"));
|
||||||
var popup = actionDialogComponent.createObject(app,
|
var popup = actionDialogComponent.createObject(app,
|
||||||
{
|
{
|
||||||
device: root.device,
|
thing: root.thing,
|
||||||
title: model.displayName,
|
title: model.displayName,
|
||||||
itemId: model.id,
|
itemId: model.id,
|
||||||
actionTypeIds: model.actionTypeIds
|
actionTypeIds: model.actionTypeIds
|
||||||
|
|||||||
@ -47,26 +47,26 @@ MainPageTile {
|
|||||||
updateStatus: thingsSubProxyUpdates.count > 0
|
updateStatus: thingsSubProxyUpdates.count > 0
|
||||||
|
|
||||||
property Interface iface: null
|
property Interface iface: null
|
||||||
property alias filterTagId: devicesProxy.filterTagId
|
property alias filterTagId: thingsProxy.filterTagId
|
||||||
|
|
||||||
backgroundImage: inlineControlLoader.item && inlineControlLoader.item.hasOwnProperty("backgroundImage") ? inlineControlLoader.item.backgroundImage : ""
|
backgroundImage: inlineControlLoader.item && inlineControlLoader.item.hasOwnProperty("backgroundImage") ? inlineControlLoader.item.backgroundImage : ""
|
||||||
|
|
||||||
onClicked: {
|
onClicked: {
|
||||||
var page;
|
var page;
|
||||||
// Only one item? Go streight to the thing page
|
// Only one item? Go streight to the thing page
|
||||||
if (devicesProxy.count === 1) {
|
if (thingsProxy.count === 1) {
|
||||||
if (!iface) {
|
if (!iface) {
|
||||||
page = "GenericDevicePage.qml";
|
page = "GenericDevicePage.qml";
|
||||||
} else {
|
} else {
|
||||||
page = NymeaUtils.interfaceListToDevicePage([iface.name]);
|
page = NymeaUtils.interfaceListToDevicePage([iface.name]);
|
||||||
}
|
}
|
||||||
pageStack.push(Qt.resolvedUrl("../devicepages/" + page), {thing: devicesProxy.get(0)})
|
pageStack.push(Qt.resolvedUrl("../devicepages/" + page), {thing: thingsProxy.get(0)})
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// No (supported by app) interfaces at all? Open generic list
|
// No (supported by app) interfaces at all? Open generic list
|
||||||
if (!iface) {
|
if (!iface) {
|
||||||
page = "GenericDeviceListPage.qml"
|
page = "GenericThingsListPage.qml"
|
||||||
pageStack.push(Qt.resolvedUrl("../devicelistpages/" + page), {hiddenInterfaces: app.supportedInterfaces, filterTagId: root.filterTagId})
|
pageStack.push(Qt.resolvedUrl("../devicelistpages/" + page), {hiddenInterfaces: app.supportedInterfaces, filterTagId: root.filterTagId})
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -81,22 +81,22 @@ MainPageTile {
|
|||||||
page = "WeatherDeviceListPage.qml"
|
page = "WeatherDeviceListPage.qml"
|
||||||
break;
|
break;
|
||||||
case "light":
|
case "light":
|
||||||
page = "LightsDeviceListPage.qml"
|
page = "LightThingsListPage.qml"
|
||||||
break;
|
break;
|
||||||
case "smartmeter":
|
case "smartmeter":
|
||||||
page ="SmartMeterDeviceListPage.qml";
|
page ="SmartMeterDeviceListPage.qml";
|
||||||
break;
|
break;
|
||||||
case "garagegate": // Deprecated, might not inherit garagedoor in old versions
|
case "garagegate": // Deprecated, might not inherit garagedoor in old versions
|
||||||
case "garagedoor":
|
case "garagedoor":
|
||||||
page = "GarageThingListPage.qml";
|
page = "GarageThingsListPage.qml";
|
||||||
break;
|
break;
|
||||||
case "awning":
|
case "awning":
|
||||||
case "extendedAwning":
|
case "extendedAwning":
|
||||||
page = "AwningDeviceListPage.qml";
|
page = "AwningThingsListPage.qml";
|
||||||
break;
|
break;
|
||||||
case "blind":
|
case "blind":
|
||||||
case "extendedBlind":
|
case "extendedBlind":
|
||||||
page = "ShutterDeviceListPage.qml";
|
page = "BlindThingsListPage.qml";
|
||||||
break;
|
break;
|
||||||
case "shutter":
|
case "shutter":
|
||||||
case "extendedShutter":
|
case "extendedShutter":
|
||||||
@ -109,46 +109,46 @@ MainPageTile {
|
|||||||
page = "MediaDeviceListPage.qml";
|
page = "MediaDeviceListPage.qml";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
page = "GenericDeviceListPage.qml"
|
page = "GenericThingsListPage.qml"
|
||||||
}
|
}
|
||||||
print("entering for shown interfaces:", iface.name)
|
print("entering for shown interfaces:", iface.name)
|
||||||
pageStack.push(Qt.resolvedUrl("../devicelistpages/" + page), {shownInterfaces: [iface.name], filterTagId: root.filterTagId})
|
pageStack.push(Qt.resolvedUrl("../devicelistpages/" + page), {shownInterfaces: [iface.name], filterTagId: root.filterTagId})
|
||||||
}
|
}
|
||||||
|
|
||||||
DevicesProxy {
|
ThingsProxy {
|
||||||
id: devicesProxy
|
id: thingsProxy
|
||||||
engine: _engine
|
engine: _engine
|
||||||
shownInterfaces: iface ? [iface.name] : []
|
shownInterfaces: iface ? [iface.name] : []
|
||||||
hiddenInterfaces: iface ? [] : app.supportedInterfaces
|
hiddenInterfaces: iface ? [] : app.supportedInterfaces
|
||||||
}
|
}
|
||||||
|
|
||||||
DevicesProxy {
|
ThingsProxy {
|
||||||
id: devicesSubProxyConnectables
|
id: devicesSubProxyConnectables
|
||||||
engine: _engine
|
engine: _engine
|
||||||
parentProxy: devicesProxy
|
parentProxy: thingsProxy
|
||||||
filterDisconnected: true
|
filterDisconnected: true
|
||||||
}
|
}
|
||||||
DevicesProxy {
|
ThingsProxy {
|
||||||
id: devicesSubProxyBattery
|
id: devicesSubProxyBattery
|
||||||
engine: _engine
|
engine: _engine
|
||||||
parentProxy: devicesProxy
|
parentProxy: thingsProxy
|
||||||
filterBatteryCritical: true
|
filterBatteryCritical: true
|
||||||
}
|
}
|
||||||
DevicesProxy {
|
ThingsProxy {
|
||||||
id: thingsSubProxySetupFailure
|
id: thingsSubProxySetupFailure
|
||||||
engine: _engine
|
engine: _engine
|
||||||
parentProxy: devicesProxy
|
parentProxy: thingsProxy
|
||||||
filterSetupFailed: true
|
filterSetupFailed: true
|
||||||
}
|
}
|
||||||
ThingsProxy {
|
ThingsProxy {
|
||||||
id: thingsSubProxyUpdates
|
id: thingsSubProxyUpdates
|
||||||
engine: _engine
|
engine: _engine
|
||||||
parentProxy: devicesProxy
|
parentProxy: thingsProxy
|
||||||
filterUpdates: true
|
filterUpdates: true
|
||||||
}
|
}
|
||||||
|
|
||||||
property int currentDeviceIndex: 0
|
property int currentDeviceIndex: 0
|
||||||
readonly property Device currentDevice: devicesProxy.get(currentDeviceIndex)
|
readonly property Thing currentDevice: thingsProxy.get(currentDeviceIndex)
|
||||||
|
|
||||||
contentItem: Loader {
|
contentItem: Loader {
|
||||||
id: inlineControlLoader
|
id: inlineControlLoader
|
||||||
@ -200,7 +200,7 @@ MainPageTile {
|
|||||||
onClicked: {
|
onClicked: {
|
||||||
switch (iface.name) {
|
switch (iface.name) {
|
||||||
case "light":
|
case "light":
|
||||||
var group = engine.thingManager.createGroup(Interfaces.findByName("colorlight"), devicesProxy);
|
var group = engine.thingManager.createGroup(Interfaces.findByName("colorlight"), thingsProxy);
|
||||||
print("opening lights page for group", group)
|
print("opening lights page for group", group)
|
||||||
pageStack.push("../devicepages/LightDevicePage.qml", {thing: group})
|
pageStack.push("../devicepages/LightDevicePage.qml", {thing: group})
|
||||||
}
|
}
|
||||||
@ -216,16 +216,16 @@ MainPageTile {
|
|||||||
property string backgroundImage: artworkState ? artworkState.value : ""
|
property string backgroundImage: artworkState ? artworkState.value : ""
|
||||||
|
|
||||||
property int currentDeviceIndex: 0
|
property int currentDeviceIndex: 0
|
||||||
readonly property Device currentDevice: devicesProxy.get(currentDeviceIndex)
|
readonly property Thing currentDevice: thingsProxy.get(currentDeviceIndex)
|
||||||
readonly property StateType playbackStateType: currentDevice.deviceClass.stateTypes.findByName("playbackStatus")
|
readonly property StateType playbackStateType: currentDevice.thingClass.stateTypes.findByName("playbackStatus")
|
||||||
readonly property State playbackState: currentDevice.states.getState(playbackStateType.id)
|
readonly property State playbackState: currentDevice.states.getState(playbackStateType.id)
|
||||||
readonly property StateType artworkStateType: currentDevice.deviceClass.stateTypes.findByName("artwork")
|
readonly property StateType artworkStateType: currentDevice.thingClass.stateTypes.findByName("artwork")
|
||||||
readonly property State artworkState: artworkStateType ? currentDevice.states.getState(artworkStateType.id) : null
|
readonly property State artworkState: artworkStateType ? currentDevice.states.getState(artworkStateType.id) : null
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
for (var i = 0; i < devicesProxy.count; i++) {
|
for (var i = 0; i < thingsProxy.count; i++) {
|
||||||
var d = devicesProxy.get(i);
|
var d = thingsProxy.get(i);
|
||||||
var st = d.deviceClass.stateTypes.findByName("playbackStatus")
|
var st = d.thingClass.stateTypes.findByName("playbackStatus")
|
||||||
var s = d.states.getState(st.id)
|
var s = d.states.getState(st.id)
|
||||||
s.valueChanged.connect(function() {inlineMediaControl.updateTile()})
|
s.valueChanged.connect(function() {inlineMediaControl.updateTile()})
|
||||||
}
|
}
|
||||||
@ -235,9 +235,9 @@ MainPageTile {
|
|||||||
function updateTile() {
|
function updateTile() {
|
||||||
var playingIndex = -1;
|
var playingIndex = -1;
|
||||||
var pausedIndex = -1;
|
var pausedIndex = -1;
|
||||||
for (var i = 0; i < devicesProxy.count; i++) {
|
for (var i = 0; i < thingsProxy.count; i++) {
|
||||||
var d = devicesProxy.get(i);
|
var d = thingsProxy.get(i);
|
||||||
var st = d.deviceClass.stateTypes.findByName("playbackStatus");
|
var st = d.thingClass.stateTypes.findByName("playbackStatus");
|
||||||
if (!st) continue;
|
if (!st) continue;
|
||||||
var s = d.states.getState(st.id);
|
var s = d.states.getState(st.id);
|
||||||
if (playingIndex === -1 && s.value === "Playing") {
|
if (playingIndex === -1 && s.value === "Playing") {
|
||||||
@ -275,17 +275,15 @@ MainPageTile {
|
|||||||
text: {
|
text: {
|
||||||
switch (iface.name) {
|
switch (iface.name) {
|
||||||
case "media":
|
case "media":
|
||||||
return devicesProxy.get(0).name;
|
return thingsProxy.get(0).name;
|
||||||
case "light":
|
case "light":
|
||||||
case "irrigation":
|
case "irrigation":
|
||||||
case "ventilation":
|
case "ventilation":
|
||||||
case "powersocket":
|
case "powersocket":
|
||||||
var count = 0;
|
var count = 0;
|
||||||
for (var i = 0; i < devicesProxy.count; i++) {
|
for (var i = 0; i < thingsProxy.count; i++) {
|
||||||
var device = devicesProxy.get(i);
|
var thing = thingsProxy.get(i);
|
||||||
var deviceClass = engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId);
|
if (thing.stateByName("power").value === true) {
|
||||||
var stateType = deviceClass.stateTypes.findByName("power")
|
|
||||||
if (device.states.getState(stateType.id).value === true) {
|
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -298,7 +296,7 @@ MainPageTile {
|
|||||||
case "shutter":
|
case "shutter":
|
||||||
case "extendedshutter":
|
case "extendedshutter":
|
||||||
return ""
|
return ""
|
||||||
// return qsTr("%1 installed").arg(devicesProxy.count)
|
// return qsTr("%1 installed").arg(thingsProxy.count)
|
||||||
}
|
}
|
||||||
console.warn("InterfaceTile, inlineButtonControl: Unhandled interface", model.name)
|
console.warn("InterfaceTile, inlineButtonControl: Unhandled interface", model.name)
|
||||||
}
|
}
|
||||||
@ -318,7 +316,7 @@ MainPageTile {
|
|||||||
case "ventilation":
|
case "ventilation":
|
||||||
return ""
|
return ""
|
||||||
case "garagedoor":
|
case "garagedoor":
|
||||||
var dev = devicesProxy.get(0)
|
var dev = thingsProxy.get(0)
|
||||||
if (dev.thingClass.interfaces.indexOf("simplegaragedoor") >= 0
|
if (dev.thingClass.interfaces.indexOf("simplegaragedoor") >= 0
|
||||||
|| dev.thingClass.interfaces.indexOf("statefulgaragedoor") >= 0
|
|| dev.thingClass.interfaces.indexOf("statefulgaragedoor") >= 0
|
||||||
|| dev.thingClass.interfaces.indexOf("extendedstatefulgaragedoor") >= 0
|
|| dev.thingClass.interfaces.indexOf("extendedstatefulgaragedoor") >= 0
|
||||||
@ -347,15 +345,15 @@ MainPageTile {
|
|||||||
case "ventilation":
|
case "ventilation":
|
||||||
break;
|
break;
|
||||||
case "garagedoor":
|
case "garagedoor":
|
||||||
for (var i = 0; i < devicesProxy.count; i++) {
|
for (var i = 0; i < thingsProxy.count; i++) {
|
||||||
var thing = devicesProxy.get(i);
|
var thing = thingsProxy.get(i);
|
||||||
if (thing.thingClass.interfaces.indexOf("simplegaragedoor") >= 0
|
if (thing.thingClass.interfaces.indexOf("simplegaragedoor") >= 0
|
||||||
|| thing.thingClass.interfaces.indexOf("statefulgaragedoor") >= 0
|
|| thing.thingClass.interfaces.indexOf("statefulgaragedoor") >= 0
|
||||||
|| thing.thingClass.interfaces.indexOf("extendedstatefulgaragedoor") >= 0
|
|| thing.thingClass.interfaces.indexOf("extendedstatefulgaragedoor") >= 0
|
||||||
|| thing.thingClass.interfaces.indexOf("garagegate") >= 0) {
|
|| thing.thingClass.interfaces.indexOf("garagegate") >= 0) {
|
||||||
|
|
||||||
var actionType = thing.thingClass.actionTypes.findByName("open");
|
var actionType = thing.thingClass.actionTypes.findByName("open");
|
||||||
engine.deviceManager.executeAction(thing.id, actionType.id)
|
engine.thingManager.executeAction(thing.id, actionType.id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -366,11 +364,10 @@ MainPageTile {
|
|||||||
case "awning":
|
case "awning":
|
||||||
case "extendedawning":
|
case "extendedawning":
|
||||||
case "simpleclosable":
|
case "simpleclosable":
|
||||||
for (var i = 0; i < devicesProxy.count; i++) {
|
for (var i = 0; i < thingsProxy.count; i++) {
|
||||||
var device = devicesProxy.get(i);
|
var thing = thingsProxy.get(i);
|
||||||
var deviceClass = engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId);
|
var actionType = thing.thingClass.actionTypes.findByName("open");
|
||||||
var actionType = deviceClass.actionTypes.findByName("open");
|
engine.thingManager.executeAction(device.id, actionType.id)
|
||||||
engine.deviceManager.executeAction(device.id, actionType.id)
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -393,7 +390,7 @@ MainPageTile {
|
|||||||
case "ventilation":
|
case "ventilation":
|
||||||
return ""
|
return ""
|
||||||
case "garagedoor":
|
case "garagedoor":
|
||||||
var dev = devicesProxy.get(0)
|
var dev = thingsProxy.get(0)
|
||||||
if (dev.thingClass.interfaces.indexOf("simplegaragedoor") >= 0
|
if (dev.thingClass.interfaces.indexOf("simplegaragedoor") >= 0
|
||||||
|| dev.thingClass.interfaces.indexOf("statefulgaragedoor") >= 0
|
|| dev.thingClass.interfaces.indexOf("statefulgaragedoor") >= 0
|
||||||
|| dev.thingClass.interfaces.indexOf("extendedstatefulgaragedoor") >= 0
|
|| dev.thingClass.interfaces.indexOf("extendedstatefulgaragedoor") >= 0
|
||||||
@ -422,8 +419,8 @@ MainPageTile {
|
|||||||
case "ventilation":
|
case "ventilation":
|
||||||
break;
|
break;
|
||||||
case "garagedoor":
|
case "garagedoor":
|
||||||
for (var i = 0; i < devicesProxy.count; i++) {
|
for (var i = 0; i < thingsProxy.count; i++) {
|
||||||
var thing = devicesProxy.get(i);
|
var thing = thingsProxy.get(i);
|
||||||
if (thing.thingClass.interfaces.indexOf("simplegaragedoor") >= 0
|
if (thing.thingClass.interfaces.indexOf("simplegaragedoor") >= 0
|
||||||
|| thing.thingClass.interfaces.indexOf("statefulgaragedoor") >= 0
|
|| thing.thingClass.interfaces.indexOf("statefulgaragedoor") >= 0
|
||||||
|| thing.thingClass.interfaces.indexOf("extendedstatefulgaragedoor") >= 0
|
|| thing.thingClass.interfaces.indexOf("extendedstatefulgaragedoor") >= 0
|
||||||
@ -441,11 +438,10 @@ MainPageTile {
|
|||||||
case "awning":
|
case "awning":
|
||||||
case "extendedawning":
|
case "extendedawning":
|
||||||
case "simpleclosable":
|
case "simpleclosable":
|
||||||
for (var i = 0; i < devicesProxy.count; i++) {
|
for (var i = 0; i < thingsProxy.count; i++) {
|
||||||
var device = devicesProxy.get(i);
|
var thing = thingsProxy.get(i);
|
||||||
var deviceClass = engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId);
|
var actionType = thing.thingClass.actionTypes.findByName("stop");
|
||||||
var actionType = deviceClass.actionTypes.findByName("stop");
|
engine.thingManager.executeAction(device.id, actionType.id)
|
||||||
engine.deviceManager.executeAction(device.id, actionType.id)
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -461,9 +457,8 @@ MainPageTile {
|
|||||||
imageSource: {
|
imageSource: {
|
||||||
switch (iface.name) {
|
switch (iface.name) {
|
||||||
case "media":
|
case "media":
|
||||||
var device = devicesProxy.get(0)
|
var thing = thingsProxy.get(0)
|
||||||
var deviceClass = engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId);
|
var stateType = thing.thingClass.stateTypes.findByName("playbackStatus");
|
||||||
var stateType = deviceClass.stateTypes.findByName("playbackStatus");
|
|
||||||
var state = device.states.getState(stateType.id)
|
var state = device.states.getState(stateType.id)
|
||||||
return state.value === "Playing" ? "../images/media-playback-pause.svg" :
|
return state.value === "Playing" ? "../images/media-playback-pause.svg" :
|
||||||
state.value === "Paused" ? "../images/media-playback-start.svg" :
|
state.value === "Paused" ? "../images/media-playback-start.svg" :
|
||||||
@ -474,7 +469,7 @@ MainPageTile {
|
|||||||
case "ventilation":
|
case "ventilation":
|
||||||
return "../images/system-shutdown.svg"
|
return "../images/system-shutdown.svg"
|
||||||
case "garagedoor":
|
case "garagedoor":
|
||||||
var dev = devicesProxy.get(0)
|
var dev = thingsProxy.get(0)
|
||||||
if (dev.thingClass.interfaces.indexOf("simplegaragedoor") >= 0
|
if (dev.thingClass.interfaces.indexOf("simplegaragedoor") >= 0
|
||||||
|| dev.thingClass.interfaces.indexOf("statefulgaragedoor") >= 0
|
|| dev.thingClass.interfaces.indexOf("statefulgaragedoor") >= 0
|
||||||
|| dev.thingClass.interfaces.indexOf("extendedstatefulgaragedoor") >= 0
|
|| dev.thingClass.interfaces.indexOf("extendedstatefulgaragedoor") >= 0
|
||||||
@ -504,32 +499,29 @@ MainPageTile {
|
|||||||
case "irrigation":
|
case "irrigation":
|
||||||
case "ventilation":
|
case "ventilation":
|
||||||
var allOff = true;
|
var allOff = true;
|
||||||
for (var i = 0; i < devicesProxy.count; i++) {
|
for (var i = 0; i < thingsProxy.count; i++) {
|
||||||
var device = devicesProxy.get(i);
|
var thing = thingsProxy.get(i);
|
||||||
if (device.states.getState(device.deviceClass.stateTypes.findByName("power").id).value === true) {
|
if (thing.stateByName("power").value === true) {
|
||||||
allOff = false;
|
allOff = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var i = 0; i < devicesProxy.count; i++) {
|
for (var i = 0; i < thingsProxy.count; i++) {
|
||||||
var device = devicesProxy.get(i);
|
var thing = thingsProxy.get(i);
|
||||||
var deviceClass = engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId);
|
var actionType = thing.thingClass.actionTypes.findByName("power");
|
||||||
var actionType = deviceClass.actionTypes.findByName("power");
|
|
||||||
|
|
||||||
var params = [];
|
var params = [];
|
||||||
var param1 = {};
|
var param1 = {};
|
||||||
param1["paramTypeId"] = actionType.paramTypes.get(0).id;
|
param1["paramTypeId"] = actionType.paramTypes.get(0).id;
|
||||||
param1["value"] = allOff ? true : false;
|
param1["value"] = allOff ? true : false;
|
||||||
params.push(param1)
|
params.push(param1)
|
||||||
engine.deviceManager.executeAction(device.id, actionType.id, params)
|
engine.thingManager.executeAction(thing.id, actionType.id, params)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "media":
|
case "media":
|
||||||
var device = devicesProxy.get(0)
|
var thing = thingsProxy.get(0)
|
||||||
var deviceClass = engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId);
|
var state = thing.stateByName("playbackStatus")
|
||||||
var stateType = deviceClass.stateTypes.findByName("playbackStatus");
|
|
||||||
var state = device.states.getState(stateType.id)
|
|
||||||
|
|
||||||
var actionName
|
var actionName
|
||||||
switch (state.value) {
|
switch (state.value) {
|
||||||
@ -540,25 +532,25 @@ MainPageTile {
|
|||||||
actionName = "play";
|
actionName = "play";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
var actionTypeId = deviceClass.actionTypes.findByName(actionName).id;
|
var actionTypeId = thing.thingClass.actionTypes.findByName(actionName).id;
|
||||||
|
|
||||||
print("executing", device, device.id, actionTypeId, actionName, deviceClass.actionTypes)
|
print("executing", thing, thing.id, actionTypeId, actionName, thing.thingClass.actionTypes)
|
||||||
|
|
||||||
engine.deviceManager.executeAction(device.id, actionTypeId)
|
engine.thingManager.executeAction(thing.id, actionTypeId)
|
||||||
case "garagedoor":
|
case "garagedoor":
|
||||||
for (var i = 0; i < devicesProxy.count; i++) {
|
for (var i = 0; i < thingsProxy.count; i++) {
|
||||||
var thing = devicesProxy.get(i);
|
var thing = thingsProxy.get(i);
|
||||||
if (thing.thingClass.interfaces.indexOf("simplegaragedoor") >= 0
|
if (thing.thingClass.interfaces.indexOf("simplegaragedoor") >= 0
|
||||||
|| thing.thingClass.interfaces.indexOf("statefulgaragedoor") >= 0
|
|| thing.thingClass.interfaces.indexOf("statefulgaragedoor") >= 0
|
||||||
|| thing.thingClass.interfaces.indexOf("extendedstatefulgaragedoor") >= 0
|
|| thing.thingClass.interfaces.indexOf("extendedstatefulgaragedoor") >= 0
|
||||||
|| thing.thingClass.interfaces.indexOf("garagegate") >= 0) {
|
|| thing.thingClass.interfaces.indexOf("garagegate") >= 0) {
|
||||||
|
|
||||||
var actionType = thing.thingClass.actionTypes.findByName("close");
|
var actionType = thing.thingClass.actionTypes.findByName("close");
|
||||||
engine.deviceManager.executeAction(thing.id, actionType.id)
|
engine.thingManager.executeAction(thing.id, actionType.id)
|
||||||
}
|
}
|
||||||
if (thing.thingClass.interfaces.indexOf("impulsegaragedoor") >= 0) {
|
if (thing.thingClass.interfaces.indexOf("impulsegaragedoor") >= 0) {
|
||||||
var actionType = thing.thingClass.actionTypes.findByName("triggerImpulse");
|
var actionType = thing.thingClass.actionTypes.findByName("triggerImpulse");
|
||||||
engine.deviceManager.executeAction(thing.id, actionType.id)
|
engine.thingManager.executeAction(thing.id, actionType.id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -569,11 +561,10 @@ MainPageTile {
|
|||||||
case "awning":
|
case "awning":
|
||||||
case "extendedawning":
|
case "extendedawning":
|
||||||
case "simpleclosable":
|
case "simpleclosable":
|
||||||
for (var i = 0; i < devicesProxy.count; i++) {
|
for (var i = 0; i < thingsProxy.count; i++) {
|
||||||
var device = devicesProxy.get(i);
|
var thing = thingsProxy.get(i);
|
||||||
var deviceClass = engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId);
|
var actionType = thing.thingClass.actionTypes.findByName("close");
|
||||||
var actionType = deviceClass.actionTypes.findByName("close");
|
engine.thingManager.executeAction(thing.id, actionType.id)
|
||||||
engine.deviceManager.executeAction(device.id, actionType.id)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -591,11 +582,10 @@ MainPageTile {
|
|||||||
ColumnLayout {
|
ColumnLayout {
|
||||||
spacing: 0
|
spacing: 0
|
||||||
|
|
||||||
property var device: devicesProxy.get(0)
|
property Thing thing: thingsProxy.get(0)
|
||||||
property var deviceClass: device ? engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId) : null
|
|
||||||
|
|
||||||
Label {
|
Label {
|
||||||
text: parent.device.name
|
text: parent.thing.name
|
||||||
font.pixelSize: app.smallFont
|
font.pixelSize: app.smallFont
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
elide: Text.ElideRight
|
elide: Text.ElideRight
|
||||||
@ -609,10 +599,9 @@ MainPageTile {
|
|||||||
id: sensorsRoot
|
id: sensorsRoot
|
||||||
property int currentDevice: 0
|
property int currentDevice: 0
|
||||||
|
|
||||||
property Device device: devicesProxy.get(currentDevice)
|
property Thing thing: thingsProxy.get(currentDevice)
|
||||||
property DeviceClass deviceClass: device ? device.deviceClass : null
|
|
||||||
|
|
||||||
property var shownSensors: findSensors(deviceClass)
|
property var shownSensors: findSensors(thing.thingClass)
|
||||||
property int currentSensor: 0
|
property int currentSensor: 0
|
||||||
|
|
||||||
ListModel {
|
ListModel {
|
||||||
@ -636,10 +625,10 @@ MainPageTile {
|
|||||||
ListElement { ifaceName: "heating"; stateName: "power" }
|
ListElement { ifaceName: "heating"; stateName: "power" }
|
||||||
ListElement { ifaceName: "extendedHeating"; stateName: "percentage" }
|
ListElement { ifaceName: "extendedHeating"; stateName: "percentage" }
|
||||||
}
|
}
|
||||||
function findSensors(deviceClass) {
|
function findSensors(thingClass) {
|
||||||
var ret = []
|
var ret = []
|
||||||
for (var i = 0; i < supportedSensors.count; i++) {
|
for (var i = 0; i < supportedSensors.count; i++) {
|
||||||
if (deviceClass.interfaces.indexOf(supportedSensors.get(i).ifaceName) >= 0) {
|
if (thingClass.interfaces.indexOf(supportedSensors.get(i).ifaceName) >= 0) {
|
||||||
ret.push({ifaceName: supportedSensors.get(i).ifaceName, stateName: supportedSensors.get(i).stateName})
|
ret.push({ifaceName: supportedSensors.get(i).ifaceName, stateName: supportedSensors.get(i).stateName})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -647,13 +636,13 @@ MainPageTile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
property StateType shownStateType: shownSensors.length > currentSensor && currentSensor >= 0
|
property StateType shownStateType: shownSensors.length > currentSensor && currentSensor >= 0
|
||||||
? deviceClass.stateTypes.findByName(shownSensors[currentSensor].stateName)
|
? thing.thingClass.stateTypes.findByName(shownSensors[currentSensor].stateName)
|
||||||
: null
|
: null
|
||||||
|
|
||||||
function nextSensor() {
|
function nextSensor() {
|
||||||
var newSensorIndex = sensorsRoot.currentSensor + 1;
|
var newSensorIndex = sensorsRoot.currentSensor + 1;
|
||||||
if (newSensorIndex > sensorsRoot.shownSensors.length - 1) {
|
if (newSensorIndex > sensorsRoot.shownSensors.length - 1) {
|
||||||
var newDeviceIndex = (sensorsRoot.currentDevice + 1) % devicesProxy.count;
|
var newDeviceIndex = (sensorsRoot.currentDevice + 1) % thingsProxy.count;
|
||||||
newSensorIndex = 0;
|
newSensorIndex = 0;
|
||||||
sensorsRoot.currentDevice = newDeviceIndex;
|
sensorsRoot.currentDevice = newDeviceIndex;
|
||||||
}
|
}
|
||||||
@ -675,7 +664,7 @@ MainPageTile {
|
|||||||
id: timer
|
id: timer
|
||||||
interval: 10000
|
interval: 10000
|
||||||
repeat: true
|
repeat: true
|
||||||
running: sensorsRoot.shownSensors.length > 1 || devicesProxy.count > 1
|
running: sensorsRoot.shownSensors.length > 1 || thingsProxy.count > 1
|
||||||
onTriggered: nextSensorAnimation.start()
|
onTriggered: nextSensorAnimation.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -693,7 +682,7 @@ MainPageTile {
|
|||||||
|
|
||||||
ColumnLayout {
|
ColumnLayout {
|
||||||
Label {
|
Label {
|
||||||
text: sensorsRoot.device.name
|
text: sensorsRoot.thing.name
|
||||||
font.pixelSize: app.smallFont
|
font.pixelSize: app.smallFont
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
elide: Text.ElideRight
|
elide: Text.ElideRight
|
||||||
@ -701,7 +690,7 @@ MainPageTile {
|
|||||||
|
|
||||||
Label {
|
Label {
|
||||||
text: sensorsRoot.shownStateType
|
text: sensorsRoot.shownStateType
|
||||||
? (Math.round(Types.toUiValue(sensorsRoot.device.states.getState(sensorsRoot.shownStateType.id).value, sensorsRoot.shownStateType.unit) * 100) / 100) + " " + Types.toUiUnit(sensorsRoot.shownStateType.unit)
|
? (Math.round(Types.toUiValue(sensorsRoot.thing.states.getState(sensorsRoot.shownStateType.id).value, sensorsRoot.shownStateType.unit) * 100) / 100) + " " + Types.toUiUnit(sensorsRoot.shownStateType.unit)
|
||||||
: ""
|
: ""
|
||||||
font.pixelSize: app.smallFont
|
font.pixelSize: app.smallFont
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
@ -711,7 +700,7 @@ MainPageTile {
|
|||||||
Led {
|
Led {
|
||||||
Layout.preferredHeight: app.iconSize * .5
|
Layout.preferredHeight: app.iconSize * .5
|
||||||
Layout.preferredWidth: height
|
Layout.preferredWidth: height
|
||||||
state: visible && sensorsRoot.device.states.getState(sensorsRoot.shownStateType.id).value === true ? "on" : "off"
|
state: visible && sensorsRoot.thing.states.getState(sensorsRoot.shownStateType.id).value === true ? "on" : "off"
|
||||||
visible: sensorsRoot.shownStateType && sensorsRoot.shownStateType.type.toLowerCase() === "bool"
|
visible: sensorsRoot.shownStateType && sensorsRoot.shownStateType.type.toLowerCase() === "bool"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -70,8 +70,8 @@ NymeaSwipeDelegate {
|
|||||||
return Style.iconColor
|
return Style.iconColor
|
||||||
}
|
}
|
||||||
|
|
||||||
property Device device: null
|
property Thing thing: null
|
||||||
property Thing thing: device
|
property alias device: root.thing
|
||||||
|
|
||||||
readonly property bool hasBatteryInterface: thing && thing.thingClass.interfaces.indexOf("battery") >= 0
|
readonly property bool hasBatteryInterface: thing && thing.thingClass.interfaces.indexOf("battery") >= 0
|
||||||
readonly property StateType batteryCriticalStateType: hasBatteryInterface ? thing.thingClass.stateTypes.findByName("batteryCritical") : null
|
readonly property StateType batteryCriticalStateType: hasBatteryInterface ? thing.thingClass.stateTypes.findByName("batteryCritical") : null
|
||||||
|
|||||||
@ -37,32 +37,32 @@ import "../components"
|
|||||||
|
|
||||||
MainPageTile {
|
MainPageTile {
|
||||||
id: root
|
id: root
|
||||||
text: device.name.toUpperCase()
|
text: thing.name.toUpperCase()
|
||||||
iconName: app.interfacesToIcon(deviceClass.interfaces)
|
iconName: app.interfacesToIcon(thing.thingClass.interfaces)
|
||||||
iconColor: Style.accentColor
|
iconColor: Style.accentColor
|
||||||
isWireless: deviceClass.interfaces.indexOf("wirelessconnectable") >= 0
|
isWireless: thing.thingClass.interfaces.indexOf("wirelessconnectable") >= 0
|
||||||
batteryCritical: batteryCriticalState && batteryCriticalState.value === true
|
batteryCritical: batteryCriticalState && batteryCriticalState.value === true
|
||||||
disconnected: connectedState && connectedState.value === false
|
disconnected: connectedState && connectedState.value === false
|
||||||
signalStrength: signalStrengthState ? signalStrengthState.value : -1
|
signalStrength: signalStrengthState ? signalStrengthState.value : -1
|
||||||
setupStatus: device.setupStatus
|
setupStatus: thing.setupStatus
|
||||||
updateStatus: updateStatusState && updateStatusState.value !== "idle"
|
updateStatus: updateStatusState && updateStatusState.value !== "idle"
|
||||||
|
|
||||||
backgroundImage: artworkState && artworkState.value.length > 0 ? artworkState.value : ""
|
backgroundImage: artworkState && artworkState.value.length > 0 ? artworkState.value : ""
|
||||||
|
|
||||||
property Device device: null
|
property Thing thing: null
|
||||||
readonly property DeviceClass deviceClass: device ? engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId) : null
|
property alias device: root.thing
|
||||||
readonly property State connectedState: deviceClass.interfaces.indexOf("connectable") >= 0 ? device.states.getState(deviceClass.stateTypes.findByName("connected").id) : null
|
readonly property State connectedState: thing.stateByName("connected")
|
||||||
readonly property State signalStrengthState: device.stateByName("signalStrength")
|
readonly property State signalStrengthState: thing.stateByName("signalStrength")
|
||||||
readonly property State batteryCriticalState: deviceClass.interfaces.indexOf("battery") >= 0 ? device.states.getState(deviceClass.stateTypes.findByName("batteryCritical").id) : null
|
readonly property State batteryCriticalState: thing.stateByName("batteryCritical")
|
||||||
readonly property State artworkState: deviceClass.interfaces.indexOf("mediametadataprovider") >= 0 ? device.states.getState(deviceClass.stateTypes.findByName("artwork").id) : null
|
readonly property State artworkState: thing.stateByName("artwork")
|
||||||
readonly property State updateStatusState: device.stateByName("updateStatus")
|
readonly property State updateStatusState: thing.stateByName("updateStatus")
|
||||||
|
|
||||||
contentItem: Loader {
|
contentItem: Loader {
|
||||||
id: loader
|
id: loader
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
sourceComponent: {
|
sourceComponent: {
|
||||||
for (var i = 0; i < root.deviceClass.interfaces.length; i++) {
|
for (var i = 0; i < root.thing.thingClass.interfaces.length; i++) {
|
||||||
switch (root.deviceClass.interfaces[i]) {
|
switch (root.thing.thingClass.interfaces[i]) {
|
||||||
case "closable":
|
case "closable":
|
||||||
return closableComponent;
|
return closableComponent;
|
||||||
case "mediacontroller":
|
case "mediacontroller":
|
||||||
@ -78,40 +78,33 @@ MainPageTile {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Binding { target: loader.item ? loader.item : null; property: "deviceClass"; value: root.deviceClass }
|
Binding { target: loader.item ? loader.item : null; property: "thing"; value: root.thing }
|
||||||
Binding { target: loader.item ? loader.item : null; property: "device"; value: root.device }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Component {
|
Component {
|
||||||
id: lightsComponent
|
id: lightsComponent
|
||||||
RowLayout {
|
RowLayout {
|
||||||
property var device: null
|
property Thing thing: null
|
||||||
property var deviceClass: null
|
readonly property State powerState: thing.stateByName("power")
|
||||||
|
readonly property State brightnessState: thing.stateByName("brightness")
|
||||||
readonly property var powerStateType: deviceClass.stateTypes.findByName("power");
|
|
||||||
readonly property var powerState: device.states.getState(powerStateType.id)
|
|
||||||
|
|
||||||
readonly property var brightnessStateType: deviceClass.stateTypes.findByName("brightness");
|
|
||||||
readonly property var brightnessState: brightnessStateType ? device.states.getState(brightnessStateType.id) : null
|
|
||||||
|
|
||||||
ThrottledSlider {
|
ThrottledSlider {
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Layout.leftMargin: app.margins / 2
|
Layout.leftMargin: app.margins / 2
|
||||||
Layout.alignment: Qt.AlignVCenter
|
Layout.alignment: Qt.AlignVCenter
|
||||||
opacity: deviceClass.interfaces.indexOf("dimmablelight") >= 0 ? 1 : 0
|
opacity: thing.thingClass.interfaces.indexOf("dimmablelight") >= 0 ? 1 : 0
|
||||||
enabled: opacity > 0
|
enabled: opacity > 0
|
||||||
from: 0
|
from: 0
|
||||||
to: 100
|
to: 100
|
||||||
value: brightnessState ? brightnessState.value : 0
|
value: brightnessState ? brightnessState.value : 0
|
||||||
onMoved: {
|
onMoved: {
|
||||||
var deviceClass = engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId);
|
var actionType = thing.thingClass.actionTypes.findByName("brightness");
|
||||||
var actionType = deviceClass.actionTypes.findByName("brightness");
|
|
||||||
var params = [];
|
var params = [];
|
||||||
var powerParam = {}
|
var powerParam = {}
|
||||||
powerParam["paramTypeId"] = actionType.paramTypes.get(0).id;
|
powerParam["paramTypeId"] = actionType.paramTypes.get(0).id;
|
||||||
powerParam["value"] = value;
|
powerParam["value"] = value;
|
||||||
params.push(powerParam)
|
params.push(powerParam)
|
||||||
engine.deviceManager.executeAction(device.id, actionType.id, params);
|
engine.thingManager.executeAction(thing.id, actionType.id, params);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,20 +116,19 @@ MainPageTile {
|
|||||||
padding: 0; topPadding: 0; bottomPadding: 0
|
padding: 0; topPadding: 0; bottomPadding: 0
|
||||||
|
|
||||||
contentItem: ColorIcon {
|
contentItem: ColorIcon {
|
||||||
name: deviceClass.interfaces.indexOf("light") >= 0
|
name: thing.thingClass.interfaces.indexOf("light") >= 0
|
||||||
? (powerState.value === true ? "../images/light-on.svg" : "../images/light-off.svg")
|
? (powerState.value === true ? "../images/light-on.svg" : "../images/light-off.svg")
|
||||||
: app.interfacesToIcon(deviceClass.interfaces)
|
: app.interfacesToIcon(thing.thingClass.interfaces)
|
||||||
color: powerState.value === true ? Style.accentColor : Style.iconColor
|
color: powerState.value === true ? Style.accentColor : Style.iconColor
|
||||||
}
|
}
|
||||||
onClicked: {
|
onClicked: {
|
||||||
var deviceClass = engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId);
|
var actionType = thing.thingClass.actionTypes.findByName("power");
|
||||||
var actionType = deviceClass.actionTypes.findByName("power");
|
|
||||||
var params = [];
|
var params = [];
|
||||||
var powerParam = {}
|
var powerParam = {}
|
||||||
powerParam["paramTypeId"] = actionType.paramTypes.get(0).id;
|
powerParam["paramTypeId"] = actionType.paramTypes.get(0).id;
|
||||||
powerParam["value"] = !powerState.value;
|
powerParam["value"] = !powerState.value;
|
||||||
params.push(powerParam)
|
params.push(powerParam)
|
||||||
engine.deviceManager.executeAction(device.id, actionType.id, params);
|
engine.thingManager.executeAction(thing.id, actionType.id, params);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -146,59 +138,58 @@ MainPageTile {
|
|||||||
id: sensorsComponent
|
id: sensorsComponent
|
||||||
RowLayout {
|
RowLayout {
|
||||||
id: sensorsRoot
|
id: sensorsRoot
|
||||||
property var device: null
|
property Thing thing: null
|
||||||
property var deviceClass: null
|
|
||||||
spacing: 0
|
spacing: 0
|
||||||
|
|
||||||
property var shownInterfaces: []
|
property var shownInterfaces: []
|
||||||
property int currentStateIndex: -1
|
property int currentStateIndex: -1
|
||||||
property var currentStateType: deviceClass ? deviceClass.stateTypes.findByName(shownInterfaces[currentStateIndex].state) : null
|
property StateType currentStateType: thing ? thing.thingClass.stateTypes.findByName(shownInterfaces[currentStateIndex].state) : null
|
||||||
property var currentState: currentStateType ? device.states.getState(currentStateType.id) : null
|
property State currentState: currentStateType ? thing.states.getState(currentStateType.id) : null
|
||||||
|
|
||||||
onDeviceClassChanged: {
|
onThingChanged: {
|
||||||
if (deviceClass == null) {
|
if (thing == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var tmp = []
|
var tmp = []
|
||||||
if (deviceClass.interfaces.indexOf("temperaturesensor") >= 0) {
|
if (thing.thingClass.interfaces.indexOf("temperaturesensor") >= 0) {
|
||||||
tmp.push({iface: "temperaturesensor", state: "temperature"});
|
tmp.push({iface: "temperaturesensor", state: "temperature"});
|
||||||
}
|
}
|
||||||
if (deviceClass.interfaces.indexOf("humiditysensor") >= 0) {
|
if (thing.thingClass.interfaces.indexOf("humiditysensor") >= 0) {
|
||||||
tmp.push({iface: "humiditysensor", state: "humidity"});
|
tmp.push({iface: "humiditysensor", state: "humidity"});
|
||||||
}
|
}
|
||||||
if (deviceClass.interfaces.indexOf("moisturesensor") >= 0) {
|
if (thing.thingClass.interfaces.indexOf("moisturesensor") >= 0) {
|
||||||
tmp.push({iface: "moisturesensor", state: "moisture"});
|
tmp.push({iface: "moisturesensor", state: "moisture"});
|
||||||
}
|
}
|
||||||
if (deviceClass.interfaces.indexOf("pressuresensor") >= 0) {
|
if (thing.thingClass.interfaces.indexOf("pressuresensor") >= 0) {
|
||||||
tmp.push({iface: "pressuresensor", state: "pressure"});
|
tmp.push({iface: "pressuresensor", state: "pressure"});
|
||||||
}
|
}
|
||||||
if (deviceClass.interfaces.indexOf("lightsensor") >= 0) {
|
if (thing.thingClass.interfaces.indexOf("lightsensor") >= 0) {
|
||||||
tmp.push({iface: "lightsensor", state: "lightIntensity"});
|
tmp.push({iface: "lightsensor", state: "lightIntensity"});
|
||||||
}
|
}
|
||||||
if (deviceClass.interfaces.indexOf("conductivitysensor") >= 0) {
|
if (thing.thingClass.interfaces.indexOf("conductivitysensor") >= 0) {
|
||||||
tmp.push({iface: "conductivitysensor", state: "conductivity"});
|
tmp.push({iface: "conductivitysensor", state: "conductivity"});
|
||||||
}
|
}
|
||||||
if (deviceClass.interfaces.indexOf("noisesensor") >= 0) {
|
if (thing.thingClass.interfaces.indexOf("noisesensor") >= 0) {
|
||||||
tmp.push({iface: "noisesensor", state: "noise"});
|
tmp.push({iface: "noisesensor", state: "noise"});
|
||||||
}
|
}
|
||||||
if (deviceClass.interfaces.indexOf("co2sensor") >= 0) {
|
if (thing.thingClass.interfaces.indexOf("co2sensor") >= 0) {
|
||||||
tmp.push({iface: "co2sensor", state: "co2"});
|
tmp.push({iface: "co2sensor", state: "co2"});
|
||||||
}
|
}
|
||||||
if (deviceClass.interfaces.indexOf("smartmeterconsumer") >= 0) {
|
if (thing.thingClass.interfaces.indexOf("smartmeterconsumer") >= 0) {
|
||||||
tmp.push({iface: "smartmeterconsumer", state: "totalEnergyConsumed"});
|
tmp.push({iface: "smartmeterconsumer", state: "totalEnergyConsumed"});
|
||||||
}
|
}
|
||||||
if (deviceClass.interfaces.indexOf("smartmeterproducer") >= 0) {
|
if (thing.thingClass.interfaces.indexOf("smartmeterproducer") >= 0) {
|
||||||
tmp.push({iface: "smartmeterproducer", state: "totalEnergyProduced"});
|
tmp.push({iface: "smartmeterproducer", state: "totalEnergyProduced"});
|
||||||
}
|
}
|
||||||
if (deviceClass.interfaces.indexOf("daylightsensor") >= 0) {
|
if (thing.thingClass.interfaces.indexOf("daylightsensor") >= 0) {
|
||||||
tmp.push({iface: "daylightsensor", state: "daylight"});
|
tmp.push({iface: "daylightsensor", state: "daylight"});
|
||||||
}
|
}
|
||||||
if (deviceClass.interfaces.indexOf("presencesensor") >= 0) {
|
if (thing.thingClass.interfaces.indexOf("presencesensor") >= 0) {
|
||||||
tmp.push({iface: "presencesensor", state: "isPresent"});
|
tmp.push({iface: "presencesensor", state: "isPresent"});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (deviceClass.interfaces.indexOf("weather") >= 0) {
|
if (thing.thingClass.interfaces.indexOf("weather") >= 0) {
|
||||||
tmp.push({iface: "temperaturesensor", state: "temperature"});
|
tmp.push({iface: "temperaturesensor", state: "temperature"});
|
||||||
tmp.push({iface: "humiditysensor", state: "humidity"});
|
tmp.push({iface: "humiditysensor", state: "humidity"});
|
||||||
tmp.push({iface: "pressuresensor", state: "pressure"});
|
tmp.push({iface: "pressuresensor", state: "pressure"});
|
||||||
@ -271,18 +262,11 @@ MainPageTile {
|
|||||||
|
|
||||||
Component {
|
Component {
|
||||||
id: closableComponent
|
id: closableComponent
|
||||||
|
ShutterControls {}
|
||||||
ShutterControls {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Component {
|
Component {
|
||||||
id: mediaComponent
|
id: mediaComponent
|
||||||
|
MediaControls {}
|
||||||
MediaControls {
|
|
||||||
property Device device: null
|
|
||||||
thing: device
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user