diff --git a/libnymea-app-core/configuration/mqttpolicies.cpp b/libnymea-app/configuration/mqttpolicies.cpp similarity index 100% rename from libnymea-app-core/configuration/mqttpolicies.cpp rename to libnymea-app/configuration/mqttpolicies.cpp diff --git a/libnymea-app-core/configuration/mqttpolicies.h b/libnymea-app/configuration/mqttpolicies.h similarity index 100% rename from libnymea-app-core/configuration/mqttpolicies.h rename to libnymea-app/configuration/mqttpolicies.h diff --git a/libnymea-app-core/configuration/mqttpolicy.cpp b/libnymea-app/configuration/mqttpolicy.cpp similarity index 100% rename from libnymea-app-core/configuration/mqttpolicy.cpp rename to libnymea-app/configuration/mqttpolicy.cpp diff --git a/libnymea-app-core/configuration/mqttpolicy.h b/libnymea-app/configuration/mqttpolicy.h similarity index 100% rename from libnymea-app-core/configuration/mqttpolicy.h rename to libnymea-app/configuration/mqttpolicy.h diff --git a/libnymea-app-core/configuration/networkmanager.cpp b/libnymea-app/configuration/networkmanager.cpp similarity index 100% rename from libnymea-app-core/configuration/networkmanager.cpp rename to libnymea-app/configuration/networkmanager.cpp diff --git a/libnymea-app-core/configuration/networkmanager.h b/libnymea-app/configuration/networkmanager.h similarity index 100% rename from libnymea-app-core/configuration/networkmanager.h rename to libnymea-app/configuration/networkmanager.h diff --git a/libnymea-app-core/configuration/nymeaconfiguration.cpp b/libnymea-app/configuration/nymeaconfiguration.cpp similarity index 100% rename from libnymea-app-core/configuration/nymeaconfiguration.cpp rename to libnymea-app/configuration/nymeaconfiguration.cpp diff --git a/libnymea-app-core/configuration/nymeaconfiguration.h b/libnymea-app/configuration/nymeaconfiguration.h similarity index 100% rename from libnymea-app-core/configuration/nymeaconfiguration.h rename to libnymea-app/configuration/nymeaconfiguration.h diff --git a/libnymea-app-core/configuration/serverconfiguration.cpp b/libnymea-app/configuration/serverconfiguration.cpp similarity index 100% rename from libnymea-app-core/configuration/serverconfiguration.cpp rename to libnymea-app/configuration/serverconfiguration.cpp diff --git a/libnymea-app-core/configuration/serverconfiguration.h b/libnymea-app/configuration/serverconfiguration.h similarity index 100% rename from libnymea-app-core/configuration/serverconfiguration.h rename to libnymea-app/configuration/serverconfiguration.h diff --git a/libnymea-app-core/configuration/serverconfigurations.cpp b/libnymea-app/configuration/serverconfigurations.cpp similarity index 100% rename from libnymea-app-core/configuration/serverconfigurations.cpp rename to libnymea-app/configuration/serverconfigurations.cpp diff --git a/libnymea-app-core/configuration/serverconfigurations.h b/libnymea-app/configuration/serverconfigurations.h similarity index 100% rename from libnymea-app-core/configuration/serverconfigurations.h rename to libnymea-app/configuration/serverconfigurations.h diff --git a/libnymea-app-core/connection/awsclient.cpp b/libnymea-app/connection/awsclient.cpp similarity index 100% rename from libnymea-app-core/connection/awsclient.cpp rename to libnymea-app/connection/awsclient.cpp diff --git a/libnymea-app-core/connection/awsclient.h b/libnymea-app/connection/awsclient.h similarity index 100% rename from libnymea-app-core/connection/awsclient.h rename to libnymea-app/connection/awsclient.h diff --git a/libnymea-app-core/connection/bluetoothtransport.cpp b/libnymea-app/connection/bluetoothtransport.cpp similarity index 100% rename from libnymea-app-core/connection/bluetoothtransport.cpp rename to libnymea-app/connection/bluetoothtransport.cpp diff --git a/libnymea-app-core/connection/bluetoothtransport.h b/libnymea-app/connection/bluetoothtransport.h similarity index 100% rename from libnymea-app-core/connection/bluetoothtransport.h rename to libnymea-app/connection/bluetoothtransport.h diff --git a/libnymea-app-core/connection/cloudtransport.cpp b/libnymea-app/connection/cloudtransport.cpp similarity index 100% rename from libnymea-app-core/connection/cloudtransport.cpp rename to libnymea-app/connection/cloudtransport.cpp diff --git a/libnymea-app-core/connection/cloudtransport.h b/libnymea-app/connection/cloudtransport.h similarity index 100% rename from libnymea-app-core/connection/cloudtransport.h rename to libnymea-app/connection/cloudtransport.h diff --git a/libnymea-app-core/connection/discovery/bluetoothservicediscovery.cpp b/libnymea-app/connection/discovery/bluetoothservicediscovery.cpp similarity index 100% rename from libnymea-app-core/connection/discovery/bluetoothservicediscovery.cpp rename to libnymea-app/connection/discovery/bluetoothservicediscovery.cpp diff --git a/libnymea-app-core/connection/discovery/bluetoothservicediscovery.h b/libnymea-app/connection/discovery/bluetoothservicediscovery.h similarity index 100% rename from libnymea-app-core/connection/discovery/bluetoothservicediscovery.h rename to libnymea-app/connection/discovery/bluetoothservicediscovery.h diff --git a/libnymea-app-core/connection/discovery/nymeadiscovery.cpp b/libnymea-app/connection/discovery/nymeadiscovery.cpp similarity index 100% rename from libnymea-app-core/connection/discovery/nymeadiscovery.cpp rename to libnymea-app/connection/discovery/nymeadiscovery.cpp diff --git a/libnymea-app-core/connection/discovery/nymeadiscovery.h b/libnymea-app/connection/discovery/nymeadiscovery.h similarity index 100% rename from libnymea-app-core/connection/discovery/nymeadiscovery.h rename to libnymea-app/connection/discovery/nymeadiscovery.h diff --git a/libnymea-app-core/connection/discovery/upnpdiscovery.cpp b/libnymea-app/connection/discovery/upnpdiscovery.cpp similarity index 100% rename from libnymea-app-core/connection/discovery/upnpdiscovery.cpp rename to libnymea-app/connection/discovery/upnpdiscovery.cpp diff --git a/libnymea-app-core/connection/discovery/upnpdiscovery.h b/libnymea-app/connection/discovery/upnpdiscovery.h similarity index 100% rename from libnymea-app-core/connection/discovery/upnpdiscovery.h rename to libnymea-app/connection/discovery/upnpdiscovery.h diff --git a/libnymea-app-core/connection/discovery/zeroconfdiscovery.cpp b/libnymea-app/connection/discovery/zeroconfdiscovery.cpp similarity index 100% rename from libnymea-app-core/connection/discovery/zeroconfdiscovery.cpp rename to libnymea-app/connection/discovery/zeroconfdiscovery.cpp diff --git a/libnymea-app-core/connection/discovery/zeroconfdiscovery.h b/libnymea-app/connection/discovery/zeroconfdiscovery.h similarity index 100% rename from libnymea-app-core/connection/discovery/zeroconfdiscovery.h rename to libnymea-app/connection/discovery/zeroconfdiscovery.h diff --git a/libnymea-app-core/connection/nymeaconnection.cpp b/libnymea-app/connection/nymeaconnection.cpp similarity index 100% rename from libnymea-app-core/connection/nymeaconnection.cpp rename to libnymea-app/connection/nymeaconnection.cpp diff --git a/libnymea-app-core/connection/nymeaconnection.h b/libnymea-app/connection/nymeaconnection.h similarity index 100% rename from libnymea-app-core/connection/nymeaconnection.h rename to libnymea-app/connection/nymeaconnection.h diff --git a/libnymea-app-core/connection/nymeahost.cpp b/libnymea-app/connection/nymeahost.cpp similarity index 100% rename from libnymea-app-core/connection/nymeahost.cpp rename to libnymea-app/connection/nymeahost.cpp diff --git a/libnymea-app-core/connection/nymeahost.h b/libnymea-app/connection/nymeahost.h similarity index 100% rename from libnymea-app-core/connection/nymeahost.h rename to libnymea-app/connection/nymeahost.h diff --git a/libnymea-app-core/connection/nymeahosts.cpp b/libnymea-app/connection/nymeahosts.cpp similarity index 100% rename from libnymea-app-core/connection/nymeahosts.cpp rename to libnymea-app/connection/nymeahosts.cpp diff --git a/libnymea-app-core/connection/nymeahosts.h b/libnymea-app/connection/nymeahosts.h similarity index 100% rename from libnymea-app-core/connection/nymeahosts.h rename to libnymea-app/connection/nymeahosts.h diff --git a/libnymea-app-core/connection/nymeatransportinterface.cpp b/libnymea-app/connection/nymeatransportinterface.cpp similarity index 100% rename from libnymea-app-core/connection/nymeatransportinterface.cpp rename to libnymea-app/connection/nymeatransportinterface.cpp diff --git a/libnymea-app-core/connection/nymeatransportinterface.h b/libnymea-app/connection/nymeatransportinterface.h similarity index 100% rename from libnymea-app-core/connection/nymeatransportinterface.h rename to libnymea-app/connection/nymeatransportinterface.h diff --git a/libnymea-app-core/connection/sigv4utils.cpp b/libnymea-app/connection/sigv4utils.cpp similarity index 100% rename from libnymea-app-core/connection/sigv4utils.cpp rename to libnymea-app/connection/sigv4utils.cpp diff --git a/libnymea-app-core/connection/sigv4utils.h b/libnymea-app/connection/sigv4utils.h similarity index 100% rename from libnymea-app-core/connection/sigv4utils.h rename to libnymea-app/connection/sigv4utils.h diff --git a/libnymea-app-core/connection/srp.c b/libnymea-app/connection/srp.c similarity index 100% rename from libnymea-app-core/connection/srp.c rename to libnymea-app/connection/srp.c diff --git a/libnymea-app-core/connection/srp.h b/libnymea-app/connection/srp.h similarity index 100% rename from libnymea-app-core/connection/srp.h rename to libnymea-app/connection/srp.h diff --git a/libnymea-app-core/connection/tcpsockettransport.cpp b/libnymea-app/connection/tcpsockettransport.cpp similarity index 100% rename from libnymea-app-core/connection/tcpsockettransport.cpp rename to libnymea-app/connection/tcpsockettransport.cpp diff --git a/libnymea-app-core/connection/tcpsockettransport.h b/libnymea-app/connection/tcpsockettransport.h similarity index 100% rename from libnymea-app-core/connection/tcpsockettransport.h rename to libnymea-app/connection/tcpsockettransport.h diff --git a/libnymea-app-core/connection/websockettransport.cpp b/libnymea-app/connection/websockettransport.cpp similarity index 100% rename from libnymea-app-core/connection/websockettransport.cpp rename to libnymea-app/connection/websockettransport.cpp diff --git a/libnymea-app-core/connection/websockettransport.h b/libnymea-app/connection/websockettransport.h similarity index 100% rename from libnymea-app-core/connection/websockettransport.h rename to libnymea-app/connection/websockettransport.h diff --git a/libnymea-app-core/deviceclasses.cpp b/libnymea-app/deviceclasses.cpp similarity index 100% rename from libnymea-app-core/deviceclasses.cpp rename to libnymea-app/deviceclasses.cpp diff --git a/libnymea-app-core/deviceclasses.h b/libnymea-app/deviceclasses.h similarity index 100% rename from libnymea-app-core/deviceclasses.h rename to libnymea-app/deviceclasses.h diff --git a/libnymea-app-core/deviceclassesproxy.cpp b/libnymea-app/deviceclassesproxy.cpp similarity index 100% rename from libnymea-app-core/deviceclassesproxy.cpp rename to libnymea-app/deviceclassesproxy.cpp diff --git a/libnymea-app-core/deviceclassesproxy.h b/libnymea-app/deviceclassesproxy.h similarity index 100% rename from libnymea-app-core/deviceclassesproxy.h rename to libnymea-app/deviceclassesproxy.h diff --git a/libnymea-app-core/devicediscovery.cpp b/libnymea-app/devicediscovery.cpp similarity index 100% rename from libnymea-app-core/devicediscovery.cpp rename to libnymea-app/devicediscovery.cpp diff --git a/libnymea-app-core/devicediscovery.h b/libnymea-app/devicediscovery.h similarity index 100% rename from libnymea-app-core/devicediscovery.h rename to libnymea-app/devicediscovery.h diff --git a/libnymea-app-core/devicemanager.cpp b/libnymea-app/devicemanager.cpp similarity index 96% rename from libnymea-app-core/devicemanager.cpp rename to libnymea-app/devicemanager.cpp index e0f87c28..5dff3ed2 100644 --- a/libnymea-app-core/devicemanager.cpp +++ b/libnymea-app/devicemanager.cpp @@ -33,6 +33,8 @@ #include "jsonrpc/jsontypes.h" #include "types/browseritems.h" #include "types/browseritem.h" +#include "thinggroup.h" +#include "types/interface.h" #include DeviceManager::DeviceManager(JsonRpcClient* jsonclient, QObject *parent) : @@ -133,6 +135,7 @@ void DeviceManager::addDevice(const QUuid &deviceClassId, const QString &name, c void DeviceManager::notificationReceived(const QVariantMap &data) { QString notification = data.value("notification").toString(); + qDebug() << "*** Notification received:" << notification; if (notification == "Devices.StateChanged") { // qDebug() << "Device state changed" << data.value("params"); Device *dev = m_devices->getDevice(data.value("params").toMap().value("deviceId").toUuid()); @@ -142,7 +145,7 @@ void DeviceManager::notificationReceived(const QVariantMap &data) } dev->setStateValue(data.value("params").toMap().value("stateTypeId").toUuid(), data.value("params").toMap().value("value")); } else if (notification == "Devices.DeviceAdded") { - Device *dev = JsonTypes::unpackDevice(data.value("params").toMap().value("device").toMap(), m_deviceClasses); + Device *dev = JsonTypes::unpackDevice(this, data.value("params").toMap().value("device").toMap(), m_deviceClasses); if (!dev) { qWarning() << "Cannot parse json device:" << data; return; @@ -158,6 +161,10 @@ void DeviceManager::notificationReceived(const QVariantMap &data) QUuid deviceId = data.value("params").toMap().value("deviceId").toUuid(); qDebug() << "JsonRpc: Notification: Device removed" << deviceId.toString(); Device *device = m_devices->getDevice(deviceId); + if (!device) { + qWarning() << "Received a DeviceRemoved notification for a device we don't know!"; + return; + } m_devices->removeDevice(device); device->deleteLater(); } else if (notification == "Devices.DeviceChanged") { @@ -168,7 +175,7 @@ void DeviceManager::notificationReceived(const QVariantMap &data) qWarning() << "Received a device changed notification for a device we don't know"; return; } - if (!JsonTypes::unpackDevice(data.value("params").toMap().value("device").toMap(), m_deviceClasses, oldDevice)) { + if (!JsonTypes::unpackDevice(this, data.value("params").toMap().value("device").toMap(), m_deviceClasses, oldDevice)) { qWarning() << "Error parsing device changed notification"; return; } @@ -282,7 +289,7 @@ void DeviceManager::getConfiguredDevicesResponse(const QVariantMap ¶ms) if (params.value("params").toMap().keys().contains("devices")) { QVariantList deviceList = params.value("params").toMap().value("devices").toList(); foreach (QVariant deviceVariant, deviceList) { - Device *device = JsonTypes::unpackDevice(deviceVariant.toMap(), m_deviceClasses); + Device *device = JsonTypes::unpackDevice(this, deviceVariant.toMap(), m_deviceClasses); if (!device) { qWarning() << "Error unpacking device" << deviceVariant.toMap().value("name").toString(); continue; @@ -323,7 +330,7 @@ void DeviceManager::addDeviceResponse(const QVariantMap ¶ms) qWarning() << "Failed to add the device:" << params.value("params").toMap().value("deviceError").toString(); } else if (params.value("params").toMap().keys().contains("device")) { QVariantMap deviceVariant = params.value("params").toMap().value("device").toMap(); - Device *device = JsonTypes::unpackDevice(deviceVariant, m_deviceClasses); + Device *device = JsonTypes::unpackDevice(this, deviceVariant, m_deviceClasses); if (!device) { qWarning() << "Couldn't parse json in addDeviceResponse"; return; @@ -394,6 +401,13 @@ void DeviceManager::savePluginConfig(const QUuid &pluginId) 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::DeviceSetupStatusComplete, QString()); + return group; +} + void DeviceManager::addDiscoveredDevice(const QUuid &deviceClassId, const QUuid &deviceDescriptorId, const QString &name, const QVariantList &deviceParams) { qDebug() << "JsonRpc: add discovered device " << deviceClassId.toString(); diff --git a/libnymea-app-core/devicemanager.h b/libnymea-app/devicemanager.h similarity index 98% rename from libnymea-app-core/devicemanager.h rename to libnymea-app/devicemanager.h index ff1e52e2..67582f2c 100644 --- a/libnymea-app-core/devicemanager.h +++ b/libnymea-app/devicemanager.h @@ -44,6 +44,8 @@ class BrowserItem; class BrowserItems; class EventHandler; +class ThingGroup; +class Interface; class DeviceManager : public JsonHandler { @@ -120,6 +122,8 @@ private: public slots: void savePluginConfig(const QUuid &pluginId); + ThingGroup* createGroup(Interface *interface, DevicesProxy *things); + signals: void pairDeviceReply(const QVariantMap ¶ms); void confirmPairingReply(const QVariantMap ¶ms); diff --git a/libnymea-app-core/devices.cpp b/libnymea-app/devices.cpp similarity index 100% rename from libnymea-app-core/devices.cpp rename to libnymea-app/devices.cpp diff --git a/libnymea-app-core/devices.h b/libnymea-app/devices.h similarity index 100% rename from libnymea-app-core/devices.h rename to libnymea-app/devices.h diff --git a/libnymea-app-core/devicesproxy.cpp b/libnymea-app/devicesproxy.cpp similarity index 99% rename from libnymea-app-core/devicesproxy.cpp rename to libnymea-app/devicesproxy.cpp index 56b64000..e7deb91c 100644 --- a/libnymea-app-core/devicesproxy.cpp +++ b/libnymea-app/devicesproxy.cpp @@ -76,6 +76,9 @@ void DevicesProxy::setParentProxy(DevicesProxy *parentProxy) m_parentProxy = parentProxy; setSourceModel(parentProxy); + if (!m_engine) { + return; + } setSortRole(Devices::RoleName); sort(0); connect(m_parentProxy, SIGNAL(countChanged()), this, SIGNAL(countChanged())); diff --git a/libnymea-app-core/devicesproxy.h b/libnymea-app/devicesproxy.h similarity index 100% rename from libnymea-app-core/devicesproxy.h rename to libnymea-app/devicesproxy.h diff --git a/libnymea-app-core/engine.cpp b/libnymea-app/engine.cpp similarity index 100% rename from libnymea-app-core/engine.cpp rename to libnymea-app/engine.cpp diff --git a/libnymea-app-core/engine.h b/libnymea-app/engine.h similarity index 100% rename from libnymea-app-core/engine.h rename to libnymea-app/engine.h diff --git a/libnymea-app-core/interfacesmodel.cpp b/libnymea-app/interfacesmodel.cpp similarity index 81% rename from libnymea-app-core/interfacesmodel.cpp rename to libnymea-app/interfacesmodel.cpp index 8291a0cf..5aac5972 100644 --- a/libnymea-app-core/interfacesmodel.cpp +++ b/libnymea-app/interfacesmodel.cpp @@ -31,6 +31,7 @@ #include "interfacesmodel.h" #include "engine.h" +#include "devicesproxy.h" InterfacesModel::InterfacesModel(QObject *parent): QAbstractListModel(parent) @@ -60,20 +61,49 @@ QHash InterfacesModel::roleNames() const return roles; } -DeviceManager *InterfacesModel::deviceManager() const +Engine *InterfacesModel::engine() const { - return m_deviceManager; + return m_engine; } -void InterfacesModel::setDeviceManager(DeviceManager *deviceManager) +void InterfacesModel::setEngine(Engine *engine) { - if (m_deviceManager != deviceManager) { - m_deviceManager = deviceManager; - emit deviceManagerChanged(); - connect(m_deviceManager->devices(), &Devices::countChanged, this, [this]() { + if (m_engine != engine) { + static QMetaObject::Connection countChangedConnection; + + if (m_engine) { + disconnect(countChangedConnection); + } + + m_engine = engine; + emit engineChanged(); + + countChangedConnection = connect(engine->deviceManager()->deviceClasses(), &DeviceClasses::countChanged, this, [this]() { syncInterfaces(); }); - connect(m_deviceManager->deviceClasses(), &DeviceClasses::countChanged, this, [this]() { + + syncInterfaces(); + } +} + +DevicesProxy *InterfacesModel::devices() const +{ + return m_devicesProxy; +} + +void InterfacesModel::setDevices(DevicesProxy *devices) +{ + if (m_devicesProxy != devices) { + static QMetaObject::Connection countChangedConnection; + + if (m_devicesProxy) { + disconnect(countChangedConnection); + } + + m_devicesProxy = devices; + emit devicesChanged(); + + countChangedConnection = connect(devices, &DevicesProxy::countChanged, this, [this]() { syncInterfaces(); }); syncInterfaces(); @@ -95,20 +125,6 @@ void InterfacesModel::setShownInterfaces(const QStringList &shownInterfaces) } } -bool InterfacesModel::onlyConfiguredDevices() const -{ - return m_onlyConfiguredDevices; -} - -void InterfacesModel::setOnlyConfiguredDevices(bool onlyConfigured) -{ - if (m_onlyConfiguredDevices != onlyConfigured) { - m_onlyConfiguredDevices = onlyConfigured; - emit onlyConfiguredDevicesChanged(); - syncInterfaces(); - } -} - bool InterfacesModel::showUncategorized() const { return m_showUncategorized; @@ -133,17 +149,17 @@ QString InterfacesModel::get(int index) const void InterfacesModel::syncInterfaces() { - if (!m_deviceManager) { + if (!m_engine) { return; } QList deviceClasses; - if (m_onlyConfiguredDevices) { - for (int i = 0; i < m_deviceManager->devices()->rowCount(); i++) { - deviceClasses << m_deviceManager->deviceClasses()->getDeviceClass(m_deviceManager->devices()->get(i)->deviceClassId()); + if (m_devicesProxy) { + for (int i = 0; i < m_devicesProxy->rowCount(); i++) { + deviceClasses << m_engine->deviceManager()->deviceClasses()->getDeviceClass(m_devicesProxy->get(i)->deviceClassId()); } } else { - for (int i = 0; i < m_deviceManager->deviceClasses()->rowCount(); i++) { - deviceClasses << m_deviceManager->deviceClasses()->get(i); + for (int i = 0; i < m_engine->deviceManager()->deviceClasses()->rowCount(); i++) { + deviceClasses << m_engine->deviceManager()->deviceClasses()->get(i); } } diff --git a/libnymea-app-core/interfacesmodel.h b/libnymea-app/interfacesmodel.h similarity index 87% rename from libnymea-app-core/interfacesmodel.h rename to libnymea-app/interfacesmodel.h index 3c645455..28714c00 100644 --- a/libnymea-app-core/interfacesmodel.h +++ b/libnymea-app/interfacesmodel.h @@ -36,16 +36,20 @@ #include "devices.h" -class DeviceManager; +class Engine; +class DevicesProxy; class InterfacesModel : public QAbstractListModel { Q_OBJECT Q_PROPERTY(int count READ rowCount NOTIFY countChanged) - Q_PROPERTY(DeviceManager* deviceManager READ deviceManager WRITE setDeviceManager NOTIFY deviceManagerChanged) - Q_PROPERTY(QStringList shownInterfaces READ shownInterfaces WRITE setShownInterfaces NOTIFY shownInterfacesChanged) - Q_PROPERTY(bool onlyConfiguredDevices READ onlyConfiguredDevices WRITE setOnlyConfiguredDevices NOTIFY onlyConfiguredDevicesChanged) + // Required + Q_PROPERTY(Engine* engine READ engine WRITE setEngine NOTIFY engineChanged) + + // Optional filters + Q_PROPERTY(DevicesProxy* devices READ devices WRITE setDevices NOTIFY devicesChanged) + Q_PROPERTY(QStringList shownInterfaces READ shownInterfaces WRITE setShownInterfaces NOTIFY shownInterfacesChanged) Q_PROPERTY(bool showUncategorized READ showUncategorized WRITE setShowUncategorized NOTIFY showUncategorizedChanged) public: @@ -60,8 +64,11 @@ public: QVariant data(const QModelIndex &index, int role) const override; QHash roleNames() const override; - DeviceManager* deviceManager() const; - void setDeviceManager(DeviceManager *deviceManager); + Engine* engine() const; + void setEngine(Engine *engine); + + DevicesProxy* devices() const; + void setDevices(DevicesProxy *devices); QStringList shownInterfaces() const; void setShownInterfaces(const QStringList &shownInterfaces); @@ -76,7 +83,8 @@ public: signals: void countChanged(); - void deviceManagerChanged(); + void engineChanged(); + void devicesChanged(); void shownInterfacesChanged(); bool onlyConfiguredDevicesChanged(); void showUncategorizedChanged(); @@ -86,11 +94,11 @@ private slots: void rowsChanged(const QModelIndex &index, int first, int last); private: - DeviceManager *m_deviceManager = nullptr; + Engine *m_engine = nullptr; QStringList m_interfaces; + DevicesProxy *m_devicesProxy = nullptr; QStringList m_shownInterfaces; - bool m_onlyConfiguredDevices = true; bool m_showUncategorized = false; }; diff --git a/libnymea-app-core/jsonrpc/actionhandler.cpp b/libnymea-app/jsonrpc/actionhandler.cpp similarity index 100% rename from libnymea-app-core/jsonrpc/actionhandler.cpp rename to libnymea-app/jsonrpc/actionhandler.cpp diff --git a/libnymea-app-core/jsonrpc/jsonhandler.cpp b/libnymea-app/jsonrpc/jsonhandler.cpp similarity index 100% rename from libnymea-app-core/jsonrpc/jsonhandler.cpp rename to libnymea-app/jsonrpc/jsonhandler.cpp diff --git a/libnymea-app-core/jsonrpc/jsonhandler.h b/libnymea-app/jsonrpc/jsonhandler.h similarity index 100% rename from libnymea-app-core/jsonrpc/jsonhandler.h rename to libnymea-app/jsonrpc/jsonhandler.h diff --git a/libnymea-app-core/jsonrpc/jsonrpcclient.cpp b/libnymea-app/jsonrpc/jsonrpcclient.cpp similarity index 100% rename from libnymea-app-core/jsonrpc/jsonrpcclient.cpp rename to libnymea-app/jsonrpc/jsonrpcclient.cpp diff --git a/libnymea-app-core/jsonrpc/jsonrpcclient.h b/libnymea-app/jsonrpc/jsonrpcclient.h similarity index 100% rename from libnymea-app-core/jsonrpc/jsonrpcclient.h rename to libnymea-app/jsonrpc/jsonrpcclient.h diff --git a/libnymea-app-core/jsonrpc/jsontypes.cpp b/libnymea-app/jsonrpc/jsontypes.cpp similarity index 96% rename from libnymea-app-core/jsonrpc/jsontypes.cpp rename to libnymea-app/jsonrpc/jsontypes.cpp index d27b9386..b7021070 100644 --- a/libnymea-app-core/jsonrpc/jsontypes.cpp +++ b/libnymea-app/jsonrpc/jsontypes.cpp @@ -222,7 +222,7 @@ ActionType *JsonTypes::unpackActionType(const QVariantMap &actionTypeMap, QObjec return actionType; } -Device* JsonTypes::unpackDevice(const QVariantMap &deviceMap, DeviceClasses *deviceClasses, Device *oldDevice) +Device* JsonTypes::unpackDevice(DeviceManager *deviceManager, const QVariantMap &deviceMap, DeviceClasses *deviceClasses, Device *oldDevice) { QUuid deviceClassId = deviceMap.value("deviceClassId").toUuid(); DeviceClass *deviceClass = deviceClasses->getDeviceClass(deviceClassId); @@ -236,15 +236,23 @@ Device* JsonTypes::unpackDevice(const QVariantMap &deviceMap, DeviceClasses *dev if (oldDevice) { device = oldDevice; } else { - device = new Device(deviceClass, parentDeviceId); + 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")) { - QMetaEnum setupStatusEnum = QMetaEnum::fromType(); - device->setSetupStatus(static_cast(setupStatusEnum.keyToValue(deviceMap.value("setupStatus").toByteArray().data())), - deviceMap.value("setupDisplayMessage").toString()); + QString setupStatus = deviceMap.value("setupStatus").toString(); + QString setupDisplayMessage = deviceMap.value("setupDisplayMessage").toString(); + if (setupStatus == "DeviceSetupStatusNone" || setupStatus == "ThingSetupStatusNone") { + device->setSetupStatus(Device::DeviceSetupStatusNone, setupDisplayMessage); + } else if (setupStatus == "DeviceSetupStatusInProgress" || setupStatus == "ThingSetupStatusInProgress") { + device->setSetupStatus(Device::DeviceSetupStatusInProgress, setupDisplayMessage); + } else if (setupStatus == "DeviceSetupStatusComplete" || setupStatus == "ThingSetupStatusComplete") { + device->setSetupStatus(Device::DeviceSetupStatusComplete, setupDisplayMessage); + } else if (setupStatus == "DeviceSetupStatusFailed" || setupStatus == "ThingSetupStatusFailed") { + device->setSetupStatus(Device::DeviceSetupStatusFailed, setupDisplayMessage); + } } else { device->setSetupStatus(deviceMap.value("setupComplete").toBool() ? Device::DeviceSetupStatusComplete : Device::DeviceSetupStatusNone, QString()); } diff --git a/libnymea-app-core/jsonrpc/jsontypes.h b/libnymea-app/jsonrpc/jsontypes.h similarity index 95% rename from libnymea-app-core/jsonrpc/jsontypes.h rename to libnymea-app/jsonrpc/jsontypes.h index 63aaf898..c963ad84 100644 --- a/libnymea-app-core/jsonrpc/jsontypes.h +++ b/libnymea-app/jsonrpc/jsontypes.h @@ -47,6 +47,7 @@ class EventType; class ActionType; class ParamType; +class DeviceManager; class Device; class DeviceClasses; class Param; @@ -73,7 +74,7 @@ public: 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(const QVariantMap &deviceMap, DeviceClasses *deviceClasses, Device *oldDevice = nullptr); + static Device *unpackDevice(DeviceManager *deviceManager, const QVariantMap &deviceMap, DeviceClasses *deviceClasses, Device *oldDevice = nullptr); static QVariantMap packRule(Rule* rule); static QVariantList packRuleActions(RuleActions* ruleActions); diff --git a/libnymea-app-core/libnymea-app-core.h b/libnymea-app/libnymea-app-core.h similarity index 99% rename from libnymea-app-core/libnymea-app-core.h rename to libnymea-app/libnymea-app-core.h index bb98dc68..00d0a4fe 100644 --- a/libnymea-app-core/libnymea-app-core.h +++ b/libnymea-app/libnymea-app-core.h @@ -109,6 +109,7 @@ #include "types/tokeninfos.h" #include "types/tokeninfo.h" #include "types/userinfo.h" +#include "thinggroup.h" #include @@ -211,6 +212,8 @@ void registerQmlTypes() { qmlRegisterSingletonType(uri, 1, 0, "Interfaces", interfacesModel_provider); qmlRegisterType(uri, 1, 0, "InterfacesProxy"); + qmlRegisterUncreatableType(uri, 1, 0, "ThingGroup", "Uncreatable"); + qmlRegisterUncreatableType(uri, 1, 0, "Plugin", "Can't create this in QML. Get it from the Plugins."); qmlRegisterUncreatableType(uri, 1, 0, "Plugins", "Can't create this in QML. Get it from the DeviceManager."); qmlRegisterType(uri, 1, 0, "PluginsProxy"); diff --git a/libnymea-app-core/libnymea-app-core.pro b/libnymea-app/libnymea-app.pro similarity index 61% rename from libnymea-app-core/libnymea-app-core.pro rename to libnymea-app/libnymea-app.pro index 663b8bd1..766c0b41 100644 --- a/libnymea-app-core/libnymea-app-core.pro +++ b/libnymea-app/libnymea-app.pro @@ -1,4 +1,4 @@ -TARGET = nymea-app-core +TARGET = nymea-app TEMPLATE = lib CONFIG += staticlib @@ -22,12 +22,70 @@ QT += network websockets bluetooth charts quick LIBS += -lssl -lcrypto -INCLUDEPATH += $$top_srcdir/libnymea-common \ - $$top_srcdir/QtZeroConf +INCLUDEPATH += $$top_srcdir/QtZeroConf SOURCES += \ configuration/networkmanager.cpp \ engine.cpp \ + types/browseritem.cpp \ + types/browseritems.cpp \ + types/networkdevice.cpp \ + types/networkdevices.cpp \ + types/package.cpp \ + types/packages.cpp \ + types/repositories.cpp \ + types/repository.cpp \ + types/script.cpp \ + types/scripts.cpp \ + types/types.cpp \ + types/vendor.cpp \ + types/vendors.cpp \ + types/deviceclass.cpp \ + types/device.cpp \ + types/param.cpp \ + types/params.cpp \ + types/paramtype.cpp \ + types/paramtypes.cpp \ + types/statetype.cpp \ + types/statetypes.cpp \ + types/eventtype.cpp \ + types/eventtypes.cpp \ + types/actiontype.cpp \ + types/actiontypes.cpp \ + types/state.cpp \ + types/states.cpp \ + types/statesproxy.cpp \ + types/plugin.cpp \ + types/plugins.cpp \ + types/rules.cpp \ + types/rule.cpp \ + types/eventdescriptor.cpp \ + types/eventdescriptors.cpp \ + types/ruleaction.cpp \ + types/ruleactions.cpp \ + types/ruleactionparams.cpp \ + types/ruleactionparam.cpp \ + types/logentry.cpp \ + types/stateevaluators.cpp \ + types/stateevaluator.cpp \ + types/statedescriptor.cpp \ + types/paramdescriptor.cpp \ + types/paramdescriptors.cpp \ + types/interface.cpp \ + types/interfaces.cpp \ + types/timedescriptor.cpp \ + types/timeeventitem.cpp \ + types/calendaritem.cpp \ + types/timeeventitems.cpp \ + types/calendaritems.cpp \ + types/repeatingoption.cpp \ + types/tag.cpp \ + types/tags.cpp \ + types/wirelessaccesspoint.cpp \ + types/wirelessaccesspoints.cpp \ + types/tokeninfo.cpp \ + types/tokeninfos.cpp \ + types/userinfo.cpp \ connection/nymeahost.cpp \ connection/nymeahosts.cpp \ connection/nymeaconnection.cpp \ @@ -91,11 +149,71 @@ SOURCES += \ configuration/mqttpolicies.cpp \ models/devicemodel.cpp \ system/systemcontroller.cpp \ + thinggroup.cpp \ HEADERS += \ configuration/networkmanager.h \ engine.h \ + types/browseritem.h \ + types/browseritems.h \ + types/networkdevice.h \ + types/networkdevices.h \ + types/package.h \ + types/packages.h \ + types/repositories.h \ + types/repository.h \ + types/script.h \ + types/scripts.h \ + types/types.h \ + types/vendor.h \ + types/vendors.h \ + types/deviceclass.h \ + types/device.h \ + types/param.h \ + types/params.h \ + types/paramtype.h \ + types/paramtypes.h \ + types/statetype.h \ + types/statetypes.h \ + types/eventtype.h \ + types/eventtypes.h \ + types/actiontype.h \ + types/actiontypes.h \ + types/state.h \ + types/states.h \ + types/statesproxy.h \ + types/plugin.h \ + types/plugins.h \ + types/rules.h \ + types/rule.h \ + types/eventdescriptor.h \ + types/eventdescriptors.h \ + types/ruleaction.h \ + types/ruleactions.h \ + types/ruleactionparams.h \ + types/ruleactionparam.h \ + types/logentry.h \ + types/stateevaluators.h \ + types/stateevaluator.h \ + types/statedescriptor.h \ + types/paramdescriptor.h \ + types/paramdescriptors.h \ + types/interface.h \ + types/interfaces.h \ + types/timedescriptor.h \ + types/timeeventitem.h \ + types/calendaritem.h \ + types/timeeventitems.h \ + types/calendaritems.h \ + types/repeatingoption.h \ + types/tag.h \ + types/tags.h \ + types/wirelessaccesspoint.h \ + types/wirelessaccesspoints.h \ + types/tokeninfo.h \ + types/tokeninfos.h \ + types/userinfo.h \ connection/nymeahost.h \ connection/nymeahosts.h \ connection/nymeaconnection.h \ @@ -160,6 +278,7 @@ HEADERS += \ configuration/mqttpolicies.h \ models/devicemodel.h \ system/systemcontroller.h \ + thinggroup.h \ ubports: { DEFINES += UBPORTS diff --git a/libnymea-app-core/logmanager.cpp b/libnymea-app/logmanager.cpp similarity index 100% rename from libnymea-app-core/logmanager.cpp rename to libnymea-app/logmanager.cpp diff --git a/libnymea-app-core/logmanager.h b/libnymea-app/logmanager.h similarity index 100% rename from libnymea-app-core/logmanager.h rename to libnymea-app/logmanager.h diff --git a/libnymea-app-core/models/devicemodel.cpp b/libnymea-app/models/devicemodel.cpp similarity index 100% rename from libnymea-app-core/models/devicemodel.cpp rename to libnymea-app/models/devicemodel.cpp diff --git a/libnymea-app-core/models/devicemodel.h b/libnymea-app/models/devicemodel.h similarity index 100% rename from libnymea-app-core/models/devicemodel.h rename to libnymea-app/models/devicemodel.h diff --git a/libnymea-app-core/models/interfacesproxy.cpp b/libnymea-app/models/interfacesproxy.cpp similarity index 94% rename from libnymea-app-core/models/interfacesproxy.cpp rename to libnymea-app/models/interfacesproxy.cpp index 1fae117f..e1980fc8 100644 --- a/libnymea-app-core/models/interfacesproxy.cpp +++ b/libnymea-app/models/interfacesproxy.cpp @@ -160,3 +160,15 @@ Interface *InterfacesProxy::get(int index) const { return m_interfaces->get(mapToSource(this->index(index, 0)).row()); } + +Interface *InterfacesProxy::getInterface(const QString &name) const +{ + qDebug() << "Getting iface" << name; + for (int i = 0; i < rowCount(); i++) { + if (get(i)->name() == name) { + qDebug() << "checking" << get(i)->name(); + return get(i); + } + } + return nullptr; +} diff --git a/libnymea-app-core/models/interfacesproxy.h b/libnymea-app/models/interfacesproxy.h similarity index 98% rename from libnymea-app-core/models/interfacesproxy.h rename to libnymea-app/models/interfacesproxy.h index 0d7c4da7..30f0049b 100644 --- a/libnymea-app-core/models/interfacesproxy.h +++ b/libnymea-app/models/interfacesproxy.h @@ -74,6 +74,7 @@ public: bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override; Q_INVOKABLE Interface* get(int index) const; + Q_INVOKABLE Interface* getInterface(const QString &name) const; signals: void shownInterfacesChanged(); diff --git a/libnymea-app-core/models/logsmodel.cpp b/libnymea-app/models/logsmodel.cpp similarity index 100% rename from libnymea-app-core/models/logsmodel.cpp rename to libnymea-app/models/logsmodel.cpp diff --git a/libnymea-app-core/models/logsmodel.h b/libnymea-app/models/logsmodel.h similarity index 100% rename from libnymea-app-core/models/logsmodel.h rename to libnymea-app/models/logsmodel.h diff --git a/libnymea-app-core/models/logsmodelng.cpp b/libnymea-app/models/logsmodelng.cpp similarity index 99% rename from libnymea-app-core/models/logsmodelng.cpp rename to libnymea-app/models/logsmodelng.cpp index e7f63bbd..1c032f5f 100644 --- a/libnymea-app-core/models/logsmodelng.cpp +++ b/libnymea-app/models/logsmodelng.cpp @@ -406,6 +406,7 @@ bool LogsModelNg::canFetchMore(const QModelIndex &parent) const void LogsModelNg::newLogEntryReceived(const QVariantMap &data) { + qDebug() << "***** model NG" << data << m_live; if (!m_live) { return; } @@ -421,6 +422,7 @@ void LogsModelNg::newLogEntryReceived(const QVariantMap &data) return; } + qDebug() << "Adding entry!!!!!!"; beginInsertRows(QModelIndex(), 0, 0); QDateTime timeStamp = QDateTime::fromMSecsSinceEpoch(entryMap.value("timestamp").toLongLong()); QMetaEnum sourceEnum = QMetaEnum::fromType(); diff --git a/libnymea-app-core/models/logsmodelng.h b/libnymea-app/models/logsmodelng.h similarity index 100% rename from libnymea-app-core/models/logsmodelng.h rename to libnymea-app/models/logsmodelng.h diff --git a/libnymea-app-core/models/packagesfiltermodel.cpp b/libnymea-app/models/packagesfiltermodel.cpp similarity index 100% rename from libnymea-app-core/models/packagesfiltermodel.cpp rename to libnymea-app/models/packagesfiltermodel.cpp diff --git a/libnymea-app-core/models/packagesfiltermodel.h b/libnymea-app/models/packagesfiltermodel.h similarity index 100% rename from libnymea-app-core/models/packagesfiltermodel.h rename to libnymea-app/models/packagesfiltermodel.h diff --git a/libnymea-app-core/models/rulesfiltermodel.cpp b/libnymea-app/models/rulesfiltermodel.cpp similarity index 100% rename from libnymea-app-core/models/rulesfiltermodel.cpp rename to libnymea-app/models/rulesfiltermodel.cpp diff --git a/libnymea-app-core/models/rulesfiltermodel.h b/libnymea-app/models/rulesfiltermodel.h similarity index 100% rename from libnymea-app-core/models/rulesfiltermodel.h rename to libnymea-app/models/rulesfiltermodel.h diff --git a/libnymea-app-core/models/taglistmodel.cpp b/libnymea-app/models/taglistmodel.cpp similarity index 100% rename from libnymea-app-core/models/taglistmodel.cpp rename to libnymea-app/models/taglistmodel.cpp diff --git a/libnymea-app-core/models/taglistmodel.h b/libnymea-app/models/taglistmodel.h similarity index 100% rename from libnymea-app-core/models/taglistmodel.h rename to libnymea-app/models/taglistmodel.h diff --git a/libnymea-app-core/models/tagsproxymodel.cpp b/libnymea-app/models/tagsproxymodel.cpp similarity index 100% rename from libnymea-app-core/models/tagsproxymodel.cpp rename to libnymea-app/models/tagsproxymodel.cpp diff --git a/libnymea-app-core/models/tagsproxymodel.h b/libnymea-app/models/tagsproxymodel.h similarity index 100% rename from libnymea-app-core/models/tagsproxymodel.h rename to libnymea-app/models/tagsproxymodel.h diff --git a/libnymea-app-core/models/valuelogsproxymodel.cpp b/libnymea-app/models/valuelogsproxymodel.cpp similarity index 100% rename from libnymea-app-core/models/valuelogsproxymodel.cpp rename to libnymea-app/models/valuelogsproxymodel.cpp diff --git a/libnymea-app-core/models/valuelogsproxymodel.h b/libnymea-app/models/valuelogsproxymodel.h similarity index 100% rename from libnymea-app-core/models/valuelogsproxymodel.h rename to libnymea-app/models/valuelogsproxymodel.h diff --git a/libnymea-app-core/models/wirelessaccesspointsproxy.cpp b/libnymea-app/models/wirelessaccesspointsproxy.cpp similarity index 100% rename from libnymea-app-core/models/wirelessaccesspointsproxy.cpp rename to libnymea-app/models/wirelessaccesspointsproxy.cpp diff --git a/libnymea-app-core/models/wirelessaccesspointsproxy.h b/libnymea-app/models/wirelessaccesspointsproxy.h similarity index 100% rename from libnymea-app-core/models/wirelessaccesspointsproxy.h rename to libnymea-app/models/wirelessaccesspointsproxy.h diff --git a/libnymea-app-core/pluginsproxy.cpp b/libnymea-app/pluginsproxy.cpp similarity index 100% rename from libnymea-app-core/pluginsproxy.cpp rename to libnymea-app/pluginsproxy.cpp diff --git a/libnymea-app-core/pluginsproxy.h b/libnymea-app/pluginsproxy.h similarity index 100% rename from libnymea-app-core/pluginsproxy.h rename to libnymea-app/pluginsproxy.h diff --git a/libnymea-app-core/rulemanager.cpp b/libnymea-app/rulemanager.cpp similarity index 100% rename from libnymea-app-core/rulemanager.cpp rename to libnymea-app/rulemanager.cpp diff --git a/libnymea-app-core/rulemanager.h b/libnymea-app/rulemanager.h similarity index 100% rename from libnymea-app-core/rulemanager.h rename to libnymea-app/rulemanager.h diff --git a/libnymea-app-core/ruletemplates/eventdescriptortemplate.cpp b/libnymea-app/ruletemplates/eventdescriptortemplate.cpp similarity index 100% rename from libnymea-app-core/ruletemplates/eventdescriptortemplate.cpp rename to libnymea-app/ruletemplates/eventdescriptortemplate.cpp diff --git a/libnymea-app-core/ruletemplates/eventdescriptortemplate.h b/libnymea-app/ruletemplates/eventdescriptortemplate.h similarity index 100% rename from libnymea-app-core/ruletemplates/eventdescriptortemplate.h rename to libnymea-app/ruletemplates/eventdescriptortemplate.h diff --git a/libnymea-app-core/ruletemplates/ruleactionparamtemplate.cpp b/libnymea-app/ruletemplates/ruleactionparamtemplate.cpp similarity index 100% rename from libnymea-app-core/ruletemplates/ruleactionparamtemplate.cpp rename to libnymea-app/ruletemplates/ruleactionparamtemplate.cpp diff --git a/libnymea-app-core/ruletemplates/ruleactionparamtemplate.h b/libnymea-app/ruletemplates/ruleactionparamtemplate.h similarity index 100% rename from libnymea-app-core/ruletemplates/ruleactionparamtemplate.h rename to libnymea-app/ruletemplates/ruleactionparamtemplate.h diff --git a/libnymea-app-core/ruletemplates/ruleactiontemplate.cpp b/libnymea-app/ruletemplates/ruleactiontemplate.cpp similarity index 100% rename from libnymea-app-core/ruletemplates/ruleactiontemplate.cpp rename to libnymea-app/ruletemplates/ruleactiontemplate.cpp diff --git a/libnymea-app-core/ruletemplates/ruleactiontemplate.h b/libnymea-app/ruletemplates/ruleactiontemplate.h similarity index 100% rename from libnymea-app-core/ruletemplates/ruleactiontemplate.h rename to libnymea-app/ruletemplates/ruleactiontemplate.h diff --git a/libnymea-app-core/ruletemplates/ruletemplate.cpp b/libnymea-app/ruletemplates/ruletemplate.cpp similarity index 100% rename from libnymea-app-core/ruletemplates/ruletemplate.cpp rename to libnymea-app/ruletemplates/ruletemplate.cpp diff --git a/libnymea-app-core/ruletemplates/ruletemplate.h b/libnymea-app/ruletemplates/ruletemplate.h similarity index 100% rename from libnymea-app-core/ruletemplates/ruletemplate.h rename to libnymea-app/ruletemplates/ruletemplate.h diff --git a/libnymea-app-core/ruletemplates/ruletemplates.cpp b/libnymea-app/ruletemplates/ruletemplates.cpp similarity index 100% rename from libnymea-app-core/ruletemplates/ruletemplates.cpp rename to libnymea-app/ruletemplates/ruletemplates.cpp diff --git a/libnymea-app-core/ruletemplates/ruletemplates.h b/libnymea-app/ruletemplates/ruletemplates.h similarity index 100% rename from libnymea-app-core/ruletemplates/ruletemplates.h rename to libnymea-app/ruletemplates/ruletemplates.h diff --git a/libnymea-app-core/ruletemplates/statedescriptortemplate.cpp b/libnymea-app/ruletemplates/statedescriptortemplate.cpp similarity index 100% rename from libnymea-app-core/ruletemplates/statedescriptortemplate.cpp rename to libnymea-app/ruletemplates/statedescriptortemplate.cpp diff --git a/libnymea-app-core/ruletemplates/statedescriptortemplate.h b/libnymea-app/ruletemplates/statedescriptortemplate.h similarity index 100% rename from libnymea-app-core/ruletemplates/statedescriptortemplate.h rename to libnymea-app/ruletemplates/statedescriptortemplate.h diff --git a/libnymea-app-core/ruletemplates/stateevaluatortemplate.cpp b/libnymea-app/ruletemplates/stateevaluatortemplate.cpp similarity index 100% rename from libnymea-app-core/ruletemplates/stateevaluatortemplate.cpp rename to libnymea-app/ruletemplates/stateevaluatortemplate.cpp diff --git a/libnymea-app-core/ruletemplates/stateevaluatortemplate.h b/libnymea-app/ruletemplates/stateevaluatortemplate.h similarity index 100% rename from libnymea-app-core/ruletemplates/stateevaluatortemplate.h rename to libnymea-app/ruletemplates/stateevaluatortemplate.h diff --git a/libnymea-app-core/scripting/codecompletion.cpp b/libnymea-app/scripting/codecompletion.cpp similarity index 100% rename from libnymea-app-core/scripting/codecompletion.cpp rename to libnymea-app/scripting/codecompletion.cpp diff --git a/libnymea-app-core/scripting/codecompletion.h b/libnymea-app/scripting/codecompletion.h similarity index 100% rename from libnymea-app-core/scripting/codecompletion.h rename to libnymea-app/scripting/codecompletion.h diff --git a/libnymea-app-core/scripting/completionmodel.cpp b/libnymea-app/scripting/completionmodel.cpp similarity index 100% rename from libnymea-app-core/scripting/completionmodel.cpp rename to libnymea-app/scripting/completionmodel.cpp diff --git a/libnymea-app-core/scripting/completionmodel.h b/libnymea-app/scripting/completionmodel.h similarity index 100% rename from libnymea-app-core/scripting/completionmodel.h rename to libnymea-app/scripting/completionmodel.h diff --git a/libnymea-app-core/scriptmanager.cpp b/libnymea-app/scriptmanager.cpp similarity index 100% rename from libnymea-app-core/scriptmanager.cpp rename to libnymea-app/scriptmanager.cpp diff --git a/libnymea-app-core/scriptmanager.h b/libnymea-app/scriptmanager.h similarity index 100% rename from libnymea-app-core/scriptmanager.h rename to libnymea-app/scriptmanager.h diff --git a/libnymea-app-core/scriptsyntaxhighlighter.cpp b/libnymea-app/scriptsyntaxhighlighter.cpp similarity index 100% rename from libnymea-app-core/scriptsyntaxhighlighter.cpp rename to libnymea-app/scriptsyntaxhighlighter.cpp diff --git a/libnymea-app-core/scriptsyntaxhighlighter.h b/libnymea-app/scriptsyntaxhighlighter.h similarity index 100% rename from libnymea-app-core/scriptsyntaxhighlighter.h rename to libnymea-app/scriptsyntaxhighlighter.h diff --git a/libnymea-app-core/system/systemcontroller.cpp b/libnymea-app/system/systemcontroller.cpp similarity index 100% rename from libnymea-app-core/system/systemcontroller.cpp rename to libnymea-app/system/systemcontroller.cpp diff --git a/libnymea-app-core/system/systemcontroller.h b/libnymea-app/system/systemcontroller.h similarity index 100% rename from libnymea-app-core/system/systemcontroller.h rename to libnymea-app/system/systemcontroller.h diff --git a/libnymea-app-core/tagsmanager.cpp b/libnymea-app/tagsmanager.cpp similarity index 100% rename from libnymea-app-core/tagsmanager.cpp rename to libnymea-app/tagsmanager.cpp diff --git a/libnymea-app-core/tagsmanager.h b/libnymea-app/tagsmanager.h similarity index 100% rename from libnymea-app-core/tagsmanager.h rename to libnymea-app/tagsmanager.h diff --git a/libnymea-app/thinggroup.cpp b/libnymea-app/thinggroup.cpp new file mode 100644 index 00000000..e0f2a84e --- /dev/null +++ b/libnymea-app/thinggroup.cpp @@ -0,0 +1,152 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +* +* 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 . +* +* 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 "thinggroup.h" +#include "devicemanager.h" +#include "devicesproxy.h" +#include "types/statetypes.h" +#include "types/actiontype.h" + +ThingGroup::ThingGroup(DeviceManager *deviceManager, DeviceClass *deviceClass, DevicesProxy *devices, QObject *parent): + Device(deviceManager, deviceClass, QUuid::createUuid(), parent), + m_deviceManager(deviceManager), + m_devices(devices) +{ + deviceClass->setParent(this); + + States *states = new States(this); + for (int i = 0; i < deviceClass->stateTypes()->rowCount(); i++) { + StateType *st = deviceClass->stateTypes()->get(i); + State *state = new State(id(), st->id(), QVariant(), this); + qDebug() << "Adding state" << st->name(); + states->addState(state); + } + setStates(states); + syncStates(); + setName(deviceClass->displayName()); + + connect(devices, &DevicesProxy::dataChanged, this, [this](const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector &roles){ + syncStates(); + }); + + connect(m_deviceManager, &DeviceManager::executeActionReply, this, [this](const QVariantMap ¶ms){ + int returningId = params.value("id").toInt(); + foreach (int id, m_pendingActions.keys()) { + if (m_pendingActions.value(id).contains(returningId)) { + m_pendingActions[id].removeAll(returningId); + if (m_pendingActions[id].isEmpty()) { + m_pendingActions.remove(id); + emit actionExecutionFinished(id, "DeviceErrorNoError"); + } + return; + } + } + }); + +} + +int ThingGroup::executeAction(const QString &actionName, const QVariantList ¶ms) +{ + QList pendingIds; + + qDebug() << "Execute action for group:" << this; + for (int i = 0; i < m_devices->rowCount(); i++) { + Device *device = m_devices->get(i); + if (device->setupStatus() != Device::DeviceSetupStatusComplete) { + continue; + } + ActionType *actionType = device->deviceClass()->actionTypes()->findByName(actionName); + if (!actionType) { + continue; + } + + + QVariantList finalParams; + foreach (const QVariant ¶mVariant, params) { + ParamType *paramType = actionType->paramTypes()->findByName(paramVariant.toMap().value("paramName").toString()); + if (paramType) { + QVariantMap finalParam; + finalParam.insert("paramTypeId", paramType->id()); + finalParam.insert("value", paramVariant.toMap().value("value")); + finalParams.append(finalParam); + } + } + + qDebug() << "Initial params" << params; + qDebug() << "Executing" << device->id() << actionType->name() << finalParams; + int id = m_deviceManager->executeAction(device->id(), actionType->id(), finalParams); + pendingIds.append(id); + } + m_pendingActions.insert(++m_idCounter, pendingIds); + return m_idCounter; +} + +void ThingGroup::syncStates() +{ + for (int i = 0; i < deviceClass()->stateTypes()->rowCount(); i++) { + StateType *stateType = deviceClass()->stateTypes()->get(i); + State *state = states()->getState(stateType->id()); + + qDebug() << "syncing state" << stateType->name(); + + QVariant value; + int count = 0; + for (int j = 0; j < m_devices->rowCount(); j++) { + Device *d = m_devices->get(j); + // Skip things that don't have the required state + StateType *ds = d->deviceClass()->stateTypes()->findByName(stateType->name()); + if (!ds) { + continue; + } + + // Skip disconnected things + StateType *connectedStateType = d->deviceClass()->stateTypes()->findByName("connected"); + if (connectedStateType) { + if (!d->stateValue(connectedStateType->id()).toBool()) { + continue; + } + } + + if (stateType->type().toLower() == "bool") { + if (d->stateValue(ds->id()).toBool()) { + value = true; + break; + } + } else if (stateType->type().toLower() == "int") { + value = value.toInt() + d->stateValue(ds->id()).toInt(); + count++; + } + } + if (count > 0) { + value = value.toDouble() / count; + } + state->setValue(value); + } +} diff --git a/libnymea-app/thinggroup.h b/libnymea-app/thinggroup.h new file mode 100644 index 00000000..f076d513 --- /dev/null +++ b/libnymea-app/thinggroup.h @@ -0,0 +1,63 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +* +* 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 . +* +* 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 THINGGROUP_H +#define THINGGROUP_H + +#include + +#include "types/device.h" + +class DevicesProxy; +class DeviceManager; + +class ThingGroup : public Device +{ + Q_OBJECT +public: + explicit ThingGroup(DeviceManager *deviceManager, DeviceClass *deviceClass, DevicesProxy *devices, QObject *parent = nullptr); + + Q_INVOKABLE int executeAction(const QString &actionName, const QVariantList ¶ms) override; + +private: + void syncStates(); + +signals: + void actionExecutionFinished(int id, const QString &status); + +private: + DeviceManager* m_deviceManager = nullptr; + DevicesProxy* m_devices = nullptr; + + int m_idCounter = 0; + QHash> m_pendingActions; +}; + +#endif // THINGGROUP_H diff --git a/libnymea-common/types/actiontype.cpp b/libnymea-app/types/actiontype.cpp similarity index 100% rename from libnymea-common/types/actiontype.cpp rename to libnymea-app/types/actiontype.cpp diff --git a/libnymea-common/types/actiontype.h b/libnymea-app/types/actiontype.h similarity index 100% rename from libnymea-common/types/actiontype.h rename to libnymea-app/types/actiontype.h diff --git a/libnymea-common/types/actiontypes.cpp b/libnymea-app/types/actiontypes.cpp similarity index 100% rename from libnymea-common/types/actiontypes.cpp rename to libnymea-app/types/actiontypes.cpp diff --git a/libnymea-common/types/actiontypes.h b/libnymea-app/types/actiontypes.h similarity index 100% rename from libnymea-common/types/actiontypes.h rename to libnymea-app/types/actiontypes.h diff --git a/libnymea-common/types/browseritem.cpp b/libnymea-app/types/browseritem.cpp similarity index 100% rename from libnymea-common/types/browseritem.cpp rename to libnymea-app/types/browseritem.cpp diff --git a/libnymea-common/types/browseritem.h b/libnymea-app/types/browseritem.h similarity index 100% rename from libnymea-common/types/browseritem.h rename to libnymea-app/types/browseritem.h diff --git a/libnymea-common/types/browseritems.cpp b/libnymea-app/types/browseritems.cpp similarity index 100% rename from libnymea-common/types/browseritems.cpp rename to libnymea-app/types/browseritems.cpp diff --git a/libnymea-common/types/browseritems.h b/libnymea-app/types/browseritems.h similarity index 100% rename from libnymea-common/types/browseritems.h rename to libnymea-app/types/browseritems.h diff --git a/libnymea-common/types/calendaritem.cpp b/libnymea-app/types/calendaritem.cpp similarity index 100% rename from libnymea-common/types/calendaritem.cpp rename to libnymea-app/types/calendaritem.cpp diff --git a/libnymea-common/types/calendaritem.h b/libnymea-app/types/calendaritem.h similarity index 100% rename from libnymea-common/types/calendaritem.h rename to libnymea-app/types/calendaritem.h diff --git a/libnymea-common/types/calendaritems.cpp b/libnymea-app/types/calendaritems.cpp similarity index 100% rename from libnymea-common/types/calendaritems.cpp rename to libnymea-app/types/calendaritems.cpp diff --git a/libnymea-common/types/calendaritems.h b/libnymea-app/types/calendaritems.h similarity index 100% rename from libnymea-common/types/calendaritems.h rename to libnymea-app/types/calendaritems.h diff --git a/libnymea-common/types/device.cpp b/libnymea-app/types/device.cpp similarity index 87% rename from libnymea-common/types/device.cpp rename to libnymea-app/types/device.cpp index c8cd9a4d..13b4de90 100644 --- a/libnymea-common/types/device.cpp +++ b/libnymea-app/types/device.cpp @@ -30,11 +30,13 @@ #include "device.h" #include "deviceclass.h" +#include "devicemanager.h" #include -Device::Device(DeviceClass *deviceClass, const QUuid &parentDeviceId, QObject *parent) : +Device::Device(DeviceManager *deviceManager, DeviceClass *deviceClass, const QUuid &parentDeviceId, QObject *parent) : QObject(parent), + m_deviceManager(deviceManager), m_parentDeviceId(parentDeviceId), m_deviceClass(deviceClass) { @@ -181,6 +183,22 @@ void Device::setStateValue(const QUuid &stateTypeId, const QVariant &value) } } +int Device::executeAction(const QString &actionName, const QVariantList ¶ms) +{ + ActionType *actionType = m_deviceClass->actionTypes()->findByName(actionName); + + QVariantList finalParams; + foreach (const QVariant ¶mVariant, params) { + QVariantMap param = paramVariant.toMap(); + if (!param.contains("paramTypeId") && param.contains("paramName")) { + ParamType *paramType = actionType->paramTypes()->findByName(param.take("paramName").toString()); + param.insert("paramTypeId", paramType->id()); + } + finalParams.append(param); + } + return m_deviceManager->executeAction(m_id, actionType->id(), finalParams); +} + QDebug operator<<(QDebug &dbg, Device *device) { dbg.nospace() << "Device: " << device->name() << " (" << device->id().toString() << ") Class:" << device->deviceClass()->name() << " (" << device->deviceClassId().toString() << ")" << endl; diff --git a/libnymea-common/types/device.h b/libnymea-app/types/device.h similarity index 91% rename from libnymea-common/types/device.h rename to libnymea-app/types/device.h index 51cfa23e..cfd6b333 100644 --- a/libnymea-common/types/device.h +++ b/libnymea-app/types/device.h @@ -39,6 +39,7 @@ #include "statesproxy.h" class DeviceClass; +class DeviceManager; class Device : public QObject { @@ -64,7 +65,7 @@ public: }; Q_ENUM(DeviceSetupStatus) - explicit Device(DeviceClass *deviceClass, const QUuid &parentDeviceId = QUuid(), QObject *parent = nullptr); + explicit Device(DeviceManager *deviceManager, DeviceClass *deviceClass, const QUuid &parentDeviceId = QUuid(), QObject *parent = nullptr); QUuid id() const; void setId(const QUuid &id); @@ -96,6 +97,8 @@ public: Q_INVOKABLE QVariant stateValue(const QUuid &stateTypeId); void setStateValue(const QUuid &stateTypeId, const QVariant &value); + Q_INVOKABLE virtual int executeAction(const QString &actionName, const QVariantList ¶ms); + signals: void nameChanged(); void setupStatusChanged(); @@ -106,11 +109,12 @@ signals: private: -private: +protected: + DeviceManager *m_deviceManager = nullptr; QString m_name; QUuid m_id; QUuid m_parentDeviceId; - DeviceSetupStatus m_setupStatus; + DeviceSetupStatus m_setupStatus = DeviceSetupStatusNone; QString m_setupDisplayMessage; Params *m_params = nullptr; Params *m_settings = nullptr; diff --git a/libnymea-common/types/deviceclass.cpp b/libnymea-app/types/deviceclass.cpp similarity index 100% rename from libnymea-common/types/deviceclass.cpp rename to libnymea-app/types/deviceclass.cpp diff --git a/libnymea-common/types/deviceclass.h b/libnymea-app/types/deviceclass.h similarity index 100% rename from libnymea-common/types/deviceclass.h rename to libnymea-app/types/deviceclass.h diff --git a/libnymea-common/types/eventdescriptor.cpp b/libnymea-app/types/eventdescriptor.cpp similarity index 100% rename from libnymea-common/types/eventdescriptor.cpp rename to libnymea-app/types/eventdescriptor.cpp diff --git a/libnymea-common/types/eventdescriptor.h b/libnymea-app/types/eventdescriptor.h similarity index 100% rename from libnymea-common/types/eventdescriptor.h rename to libnymea-app/types/eventdescriptor.h diff --git a/libnymea-common/types/eventdescriptors.cpp b/libnymea-app/types/eventdescriptors.cpp similarity index 100% rename from libnymea-common/types/eventdescriptors.cpp rename to libnymea-app/types/eventdescriptors.cpp diff --git a/libnymea-common/types/eventdescriptors.h b/libnymea-app/types/eventdescriptors.h similarity index 100% rename from libnymea-common/types/eventdescriptors.h rename to libnymea-app/types/eventdescriptors.h diff --git a/libnymea-common/types/eventtype.cpp b/libnymea-app/types/eventtype.cpp similarity index 100% rename from libnymea-common/types/eventtype.cpp rename to libnymea-app/types/eventtype.cpp diff --git a/libnymea-common/types/eventtype.h b/libnymea-app/types/eventtype.h similarity index 100% rename from libnymea-common/types/eventtype.h rename to libnymea-app/types/eventtype.h diff --git a/libnymea-common/types/eventtypes.cpp b/libnymea-app/types/eventtypes.cpp similarity index 100% rename from libnymea-common/types/eventtypes.cpp rename to libnymea-app/types/eventtypes.cpp diff --git a/libnymea-common/types/eventtypes.h b/libnymea-app/types/eventtypes.h similarity index 100% rename from libnymea-common/types/eventtypes.h rename to libnymea-app/types/eventtypes.h diff --git a/libnymea-common/types/interface.cpp b/libnymea-app/types/interface.cpp similarity index 84% rename from libnymea-common/types/interface.cpp rename to libnymea-app/types/interface.cpp index a2d8d8ff..55ecd526 100644 --- a/libnymea-common/types/interface.cpp +++ b/libnymea-app/types/interface.cpp @@ -33,6 +33,7 @@ #include "eventtypes.h" #include "statetypes.h" #include "actiontypes.h" +#include "deviceclass.h" Interface::Interface(const QString &name, const QString &displayName, QObject *parent) : QObject(parent), @@ -69,3 +70,16 @@ ActionTypes* Interface::actionTypes() const { return m_actionTypes; } + +DeviceClass *Interface::createDeviceClass() +{ + DeviceClass* dc = new DeviceClass(); + dc->setName(m_name); + dc->setParamTypes(new ParamTypes(dc)); + dc->setSettingsTypes(new ParamTypes(dc)); + dc->setDisplayName(m_displayName); + dc->setEventTypes(m_eventTypes); + dc->setStateTypes(m_stateTypes); + dc->setActionTypes(m_actionTypes); + return dc; +} diff --git a/libnymea-common/types/interface.h b/libnymea-app/types/interface.h similarity index 97% rename from libnymea-common/types/interface.h rename to libnymea-app/types/interface.h index 98798c82..58f32fe3 100644 --- a/libnymea-common/types/interface.h +++ b/libnymea-app/types/interface.h @@ -36,6 +36,7 @@ class EventTypes; class StateTypes; class ActionTypes; +class DeviceClass; class Interface : public QObject { @@ -55,6 +56,8 @@ public: StateTypes* stateTypes() const; ActionTypes* actionTypes() const; + DeviceClass* createDeviceClass(); + private: QString m_name; QString m_displayName; diff --git a/libnymea-common/types/interfaces.cpp b/libnymea-app/types/interfaces.cpp similarity index 74% rename from libnymea-common/types/interfaces.cpp rename to libnymea-app/types/interfaces.cpp index 9693dbed..b469ec20 100644 --- a/libnymea-common/types/interfaces.cpp +++ b/libnymea-app/types/interfaces.cpp @@ -69,11 +69,23 @@ Interfaces::Interfaces(QObject *parent) : QAbstractListModel(parent) tr("A light is turned on or off"), tr("Turn lights on or off")); - addInterface("dimmablelight", tr("Dimmable lights")); + addInterface("dimmablelight", tr("Dimmable lights"), {"light"}); addStateType("dimmablelight", "brightness", QVariant::Int, true, tr("Light's brightness is"), tr("A light's brightness has changed"), - tr("Set lights brightness")); + tr("Set lights brightness"), 0, 100); + + addInterface("colortemperaturelight", tr("Color temperature light"), {"light", "dimmablelight"}); + addStateType("colortemperaturelight", "colorTemperature", QVariant::Int, true, + tr("Lights color temperature is"), + tr("A lights color temperature has changed"), + tr("Set lights color temperature"), 0, 100); + + addInterface("colorlight", tr("Color lights"), {"light", "dimmablelight", "colortemperaturelight"}); + addStateType("colorlight", "color", QVariant::Color, true, + tr("Light's color is"), + tr("A light's color has changed"), + tr("Set lights color")); addInterface("temperaturesensor", tr("Temperature sensors")); addStateType("temperaturesensor", "temperature", QVariant::Double, false, @@ -157,6 +169,49 @@ Interfaces::Interfaces(QObject *parent) : QAbstractListModel(parent) addActionType("mediacontroller", "pause", tr("Pause playback"), new ParamTypes()); addActionType("mediacontroller", "skipBack", tr("Skip back"), new ParamTypes()); addActionType("mediacontroller", "skipNext", tr("Skip next"), new ParamTypes()); + + addInterface("powersocket", tr("Power sockets")); + addStateType("powersocket", "power", QVariant::Bool, true, + tr("Powered"), + tr("Turned on/off"), + tr("Turn on/off")); + + addInterface("weather", tr("Weather")); + addStateType("weather", "weatherCondition", QVariant::String, false, + tr("Weather description"), + tr("Weather description changed")); + addStateType("weather", "weatherDescription", QVariant::String, false, + tr("Weather condition"), + tr("Weather condition changed")); + addStateType("weather", "temperature", QVariant::Double, false, + tr("Temperature"), + tr("Temperature changed")); + addStateType("weather", "humidity", QVariant::Double, false, + tr("Humidity"), + tr("Humidity changed")); + addStateType("weather", "humidity", QVariant::Double, false, + tr("Pressure"), + tr("Pressure changed")); + addStateType("weather", "windSpeed", QVariant::Double, false, + tr("Wind seed"), + tr("Wind speed changed")); + addStateType("weather", "windDirection", QVariant::Int, false, + tr("Wind direction"), + tr("Wind direction changed")); + + addInterface("media", tr("Media")); + + addInterface("sensor", tr("Sensor")); + + addInterface("smartmeter", tr("Smart meter")); + + addInterface("button", tr("Button")); + addEventType("button", "pressed", tr("Button pressed"), new ParamTypes()); + + addInterface("account", tr("Accounts"), {"gateway"}); + addStateType("account", "loggedIn", QVariant::Bool, false, + tr("User is logged in"), + tr("User login changed")); } int Interfaces::rowCount(const QModelIndex &parent) const @@ -202,10 +257,23 @@ Interface *Interfaces::findByName(const QString &name) const return nullptr; } -void Interfaces::addInterface(const QString &name, const QString &displayName) +void Interfaces::addInterface(const QString &name, const QString &displayName, const QStringList &extends) { - Interface *iface = new Interface(name, displayName, this); - m_list.append(iface); + Interface *newIface = new Interface(name, displayName, this); + foreach (const QString &extend, extends) { + Interface *extendIface = m_hash.value(extend); + for (int i = 0; i < extendIface->stateTypes()->rowCount(); i++) { + newIface->stateTypes()->addStateType(extendIface->stateTypes()->get(i)); + } + for (int i = 0; i < extendIface->actionTypes()->rowCount(); i++) { + newIface->actionTypes()->addActionType(extendIface->actionTypes()->get(i)); + } + for (int i = 0; i < extendIface->eventTypes()->rowCount(); i++) { + newIface->eventTypes()->addEventType(extendIface->eventTypes()->get(i)); + } + } + m_list.append(newIface); + m_hash.insert(name, newIface); } void Interfaces::addEventType(const QString &interfaceName, const QString &name, const QString &displayName, ParamTypes *paramTypes) @@ -219,6 +287,7 @@ void Interfaces::addEventType(const QString &interfaceName, const QString &name, } Q_ASSERT_X(iface != nullptr, "Interfaces", "Interface not found"); EventType *et = new EventType(); + et->setId(QUuid::createUuid()); et->setName(name); et->setDisplayName(displayName); et->setParamTypes(paramTypes); @@ -236,13 +305,14 @@ void Interfaces::addActionType(const QString &interfaceName, const QString &name } Q_ASSERT_X(iface != nullptr, "Interfaces", "Interface not found"); ActionType *at = new ActionType(); + at->setId(QUuid::createUuid()); at->setName(name); at->setDisplayName(displayName); at->setParamTypes(paramTypes); iface->actionTypes()->addActionType(at); } -void Interfaces::addStateType(const QString &interfaceName, const QString &name, QVariant::Type type, bool writable, const QString &displayName, const QString &displayNameEvent, const QString &displayNameAction) +void Interfaces::addStateType(const QString &interfaceName, const QString &name, QVariant::Type type, bool writable, const QString &displayName, const QString &displayNameEvent, const QString &displayNameAction, const QVariant &min, const QVariant &max) { Interface *iface = nullptr; foreach (Interface* i, m_list) { @@ -253,9 +323,12 @@ void Interfaces::addStateType(const QString &interfaceName, const QString &name, } Q_ASSERT_X(iface != nullptr, "Interfaces", "Interface not found"); StateType *st = new StateType(); + st->setId(QUuid::createUuid()); st->setName(name); st->setDisplayName(displayName); st->setType(type); + st->setMinValue(min); + st->setMaxValue(max); iface->stateTypes()->addStateType(st); ParamTypes *pts = createParamTypes(name, displayName, type); addEventType(interfaceName, name, displayNameEvent, pts); diff --git a/libnymea-common/types/interfaces.h b/libnymea-app/types/interfaces.h similarity index 94% rename from libnymea-common/types/interfaces.h rename to libnymea-app/types/interfaces.h index c5104987..14c05f14 100644 --- a/libnymea-common/types/interfaces.h +++ b/libnymea-app/types/interfaces.h @@ -61,12 +61,13 @@ public: private: QList m_list; + QHash m_hash; // helpers to populate the model - void addInterface(const QString &name, const QString &displayName); + void addInterface(const QString &name, const QString &displayName, const QStringList &extends = QStringList()); void addEventType(const QString &interfaceName, const QString &name, const QString &displayName, ParamTypes *paramTypes); void addActionType(const QString &interfaceName, const QString &name, const QString &displayName, ParamTypes *paramTypes); - void addStateType(const QString &interfaceName, const QString &name, QVariant::Type type, bool writable, const QString &displayName, const QString &displayNameEvent, const QString &displayNameAction = QString()); + void addStateType(const QString &interfaceName, const QString &name, QVariant::Type type, bool writable, const QString &displayName, const QString &displayNameEvent, const QString &displayNameAction = QString(), const QVariant &min = QVariant(), const QVariant &max = QVariant()); ParamTypes* createParamTypes(const QString &name, const QString &displayName, QVariant::Type type, const QVariant &defaultValue = QVariant(), const QVariant &minValue = QVariant(), const QVariant &maxValue = QVariant()); void addParamType(ParamTypes* paramTypes, const QString &name, const QString &displayName, QVariant::Type type, const QVariant &defaultValue = QVariant(), const QVariant &minValue = QVariant(), const QVariant &maxValue = QVariant()); diff --git a/libnymea-common/types/logentry.cpp b/libnymea-app/types/logentry.cpp similarity index 100% rename from libnymea-common/types/logentry.cpp rename to libnymea-app/types/logentry.cpp diff --git a/libnymea-common/types/logentry.h b/libnymea-app/types/logentry.h similarity index 100% rename from libnymea-common/types/logentry.h rename to libnymea-app/types/logentry.h diff --git a/libnymea-common/types/networkdevice.cpp b/libnymea-app/types/networkdevice.cpp similarity index 100% rename from libnymea-common/types/networkdevice.cpp rename to libnymea-app/types/networkdevice.cpp diff --git a/libnymea-common/types/networkdevice.h b/libnymea-app/types/networkdevice.h similarity index 100% rename from libnymea-common/types/networkdevice.h rename to libnymea-app/types/networkdevice.h diff --git a/libnymea-common/types/networkdevices.cpp b/libnymea-app/types/networkdevices.cpp similarity index 100% rename from libnymea-common/types/networkdevices.cpp rename to libnymea-app/types/networkdevices.cpp diff --git a/libnymea-common/types/networkdevices.h b/libnymea-app/types/networkdevices.h similarity index 100% rename from libnymea-common/types/networkdevices.h rename to libnymea-app/types/networkdevices.h diff --git a/libnymea-common/types/package.cpp b/libnymea-app/types/package.cpp similarity index 100% rename from libnymea-common/types/package.cpp rename to libnymea-app/types/package.cpp diff --git a/libnymea-common/types/package.h b/libnymea-app/types/package.h similarity index 100% rename from libnymea-common/types/package.h rename to libnymea-app/types/package.h diff --git a/libnymea-common/types/packages.cpp b/libnymea-app/types/packages.cpp similarity index 100% rename from libnymea-common/types/packages.cpp rename to libnymea-app/types/packages.cpp diff --git a/libnymea-common/types/packages.h b/libnymea-app/types/packages.h similarity index 100% rename from libnymea-common/types/packages.h rename to libnymea-app/types/packages.h diff --git a/libnymea-common/types/param.cpp b/libnymea-app/types/param.cpp similarity index 100% rename from libnymea-common/types/param.cpp rename to libnymea-app/types/param.cpp diff --git a/libnymea-common/types/param.h b/libnymea-app/types/param.h similarity index 100% rename from libnymea-common/types/param.h rename to libnymea-app/types/param.h diff --git a/libnymea-common/types/paramdescriptor.cpp b/libnymea-app/types/paramdescriptor.cpp similarity index 100% rename from libnymea-common/types/paramdescriptor.cpp rename to libnymea-app/types/paramdescriptor.cpp diff --git a/libnymea-common/types/paramdescriptor.h b/libnymea-app/types/paramdescriptor.h similarity index 100% rename from libnymea-common/types/paramdescriptor.h rename to libnymea-app/types/paramdescriptor.h diff --git a/libnymea-common/types/paramdescriptors.cpp b/libnymea-app/types/paramdescriptors.cpp similarity index 100% rename from libnymea-common/types/paramdescriptors.cpp rename to libnymea-app/types/paramdescriptors.cpp diff --git a/libnymea-common/types/paramdescriptors.h b/libnymea-app/types/paramdescriptors.h similarity index 100% rename from libnymea-common/types/paramdescriptors.h rename to libnymea-app/types/paramdescriptors.h diff --git a/libnymea-common/types/params.cpp b/libnymea-app/types/params.cpp similarity index 100% rename from libnymea-common/types/params.cpp rename to libnymea-app/types/params.cpp diff --git a/libnymea-common/types/params.h b/libnymea-app/types/params.h similarity index 100% rename from libnymea-common/types/params.h rename to libnymea-app/types/params.h diff --git a/libnymea-common/types/paramtype.cpp b/libnymea-app/types/paramtype.cpp similarity index 100% rename from libnymea-common/types/paramtype.cpp rename to libnymea-app/types/paramtype.cpp diff --git a/libnymea-common/types/paramtype.h b/libnymea-app/types/paramtype.h similarity index 100% rename from libnymea-common/types/paramtype.h rename to libnymea-app/types/paramtype.h diff --git a/libnymea-common/types/paramtypes.cpp b/libnymea-app/types/paramtypes.cpp similarity index 100% rename from libnymea-common/types/paramtypes.cpp rename to libnymea-app/types/paramtypes.cpp diff --git a/libnymea-common/types/paramtypes.h b/libnymea-app/types/paramtypes.h similarity index 100% rename from libnymea-common/types/paramtypes.h rename to libnymea-app/types/paramtypes.h diff --git a/libnymea-common/types/plugin.cpp b/libnymea-app/types/plugin.cpp similarity index 100% rename from libnymea-common/types/plugin.cpp rename to libnymea-app/types/plugin.cpp diff --git a/libnymea-common/types/plugin.h b/libnymea-app/types/plugin.h similarity index 100% rename from libnymea-common/types/plugin.h rename to libnymea-app/types/plugin.h diff --git a/libnymea-common/types/plugins.cpp b/libnymea-app/types/plugins.cpp similarity index 100% rename from libnymea-common/types/plugins.cpp rename to libnymea-app/types/plugins.cpp diff --git a/libnymea-common/types/plugins.h b/libnymea-app/types/plugins.h similarity index 100% rename from libnymea-common/types/plugins.h rename to libnymea-app/types/plugins.h diff --git a/libnymea-common/types/repeatingoption.cpp b/libnymea-app/types/repeatingoption.cpp similarity index 100% rename from libnymea-common/types/repeatingoption.cpp rename to libnymea-app/types/repeatingoption.cpp diff --git a/libnymea-common/types/repeatingoption.h b/libnymea-app/types/repeatingoption.h similarity index 100% rename from libnymea-common/types/repeatingoption.h rename to libnymea-app/types/repeatingoption.h diff --git a/libnymea-common/types/repositories.cpp b/libnymea-app/types/repositories.cpp similarity index 100% rename from libnymea-common/types/repositories.cpp rename to libnymea-app/types/repositories.cpp diff --git a/libnymea-common/types/repositories.h b/libnymea-app/types/repositories.h similarity index 100% rename from libnymea-common/types/repositories.h rename to libnymea-app/types/repositories.h diff --git a/libnymea-common/types/repository.cpp b/libnymea-app/types/repository.cpp similarity index 100% rename from libnymea-common/types/repository.cpp rename to libnymea-app/types/repository.cpp diff --git a/libnymea-common/types/repository.h b/libnymea-app/types/repository.h similarity index 100% rename from libnymea-common/types/repository.h rename to libnymea-app/types/repository.h diff --git a/libnymea-common/types/rule.cpp b/libnymea-app/types/rule.cpp similarity index 100% rename from libnymea-common/types/rule.cpp rename to libnymea-app/types/rule.cpp diff --git a/libnymea-common/types/rule.h b/libnymea-app/types/rule.h similarity index 100% rename from libnymea-common/types/rule.h rename to libnymea-app/types/rule.h diff --git a/libnymea-common/types/ruleaction.cpp b/libnymea-app/types/ruleaction.cpp similarity index 100% rename from libnymea-common/types/ruleaction.cpp rename to libnymea-app/types/ruleaction.cpp diff --git a/libnymea-common/types/ruleaction.h b/libnymea-app/types/ruleaction.h similarity index 100% rename from libnymea-common/types/ruleaction.h rename to libnymea-app/types/ruleaction.h diff --git a/libnymea-common/types/ruleactionparam.cpp b/libnymea-app/types/ruleactionparam.cpp similarity index 100% rename from libnymea-common/types/ruleactionparam.cpp rename to libnymea-app/types/ruleactionparam.cpp diff --git a/libnymea-common/types/ruleactionparam.h b/libnymea-app/types/ruleactionparam.h similarity index 100% rename from libnymea-common/types/ruleactionparam.h rename to libnymea-app/types/ruleactionparam.h diff --git a/libnymea-common/types/ruleactionparams.cpp b/libnymea-app/types/ruleactionparams.cpp similarity index 100% rename from libnymea-common/types/ruleactionparams.cpp rename to libnymea-app/types/ruleactionparams.cpp diff --git a/libnymea-common/types/ruleactionparams.h b/libnymea-app/types/ruleactionparams.h similarity index 100% rename from libnymea-common/types/ruleactionparams.h rename to libnymea-app/types/ruleactionparams.h diff --git a/libnymea-common/types/ruleactions.cpp b/libnymea-app/types/ruleactions.cpp similarity index 100% rename from libnymea-common/types/ruleactions.cpp rename to libnymea-app/types/ruleactions.cpp diff --git a/libnymea-common/types/ruleactions.h b/libnymea-app/types/ruleactions.h similarity index 100% rename from libnymea-common/types/ruleactions.h rename to libnymea-app/types/ruleactions.h diff --git a/libnymea-common/types/rules.cpp b/libnymea-app/types/rules.cpp similarity index 100% rename from libnymea-common/types/rules.cpp rename to libnymea-app/types/rules.cpp diff --git a/libnymea-common/types/rules.h b/libnymea-app/types/rules.h similarity index 100% rename from libnymea-common/types/rules.h rename to libnymea-app/types/rules.h diff --git a/libnymea-common/types/script.cpp b/libnymea-app/types/script.cpp similarity index 100% rename from libnymea-common/types/script.cpp rename to libnymea-app/types/script.cpp diff --git a/libnymea-common/types/script.h b/libnymea-app/types/script.h similarity index 100% rename from libnymea-common/types/script.h rename to libnymea-app/types/script.h diff --git a/libnymea-common/types/scripts.cpp b/libnymea-app/types/scripts.cpp similarity index 100% rename from libnymea-common/types/scripts.cpp rename to libnymea-app/types/scripts.cpp diff --git a/libnymea-common/types/scripts.h b/libnymea-app/types/scripts.h similarity index 100% rename from libnymea-common/types/scripts.h rename to libnymea-app/types/scripts.h diff --git a/libnymea-common/types/state.cpp b/libnymea-app/types/state.cpp similarity index 100% rename from libnymea-common/types/state.cpp rename to libnymea-app/types/state.cpp diff --git a/libnymea-common/types/state.h b/libnymea-app/types/state.h similarity index 100% rename from libnymea-common/types/state.h rename to libnymea-app/types/state.h diff --git a/libnymea-common/types/statedescriptor.cpp b/libnymea-app/types/statedescriptor.cpp similarity index 100% rename from libnymea-common/types/statedescriptor.cpp rename to libnymea-app/types/statedescriptor.cpp diff --git a/libnymea-common/types/statedescriptor.h b/libnymea-app/types/statedescriptor.h similarity index 100% rename from libnymea-common/types/statedescriptor.h rename to libnymea-app/types/statedescriptor.h diff --git a/libnymea-common/types/stateevaluator.cpp b/libnymea-app/types/stateevaluator.cpp similarity index 100% rename from libnymea-common/types/stateevaluator.cpp rename to libnymea-app/types/stateevaluator.cpp diff --git a/libnymea-common/types/stateevaluator.h b/libnymea-app/types/stateevaluator.h similarity index 100% rename from libnymea-common/types/stateevaluator.h rename to libnymea-app/types/stateevaluator.h diff --git a/libnymea-common/types/stateevaluators.cpp b/libnymea-app/types/stateevaluators.cpp similarity index 100% rename from libnymea-common/types/stateevaluators.cpp rename to libnymea-app/types/stateevaluators.cpp diff --git a/libnymea-common/types/stateevaluators.h b/libnymea-app/types/stateevaluators.h similarity index 100% rename from libnymea-common/types/stateevaluators.h rename to libnymea-app/types/stateevaluators.h diff --git a/libnymea-common/types/states.cpp b/libnymea-app/types/states.cpp similarity index 100% rename from libnymea-common/types/states.cpp rename to libnymea-app/types/states.cpp diff --git a/libnymea-common/types/states.h b/libnymea-app/types/states.h similarity index 100% rename from libnymea-common/types/states.h rename to libnymea-app/types/states.h diff --git a/libnymea-common/types/statesproxy.cpp b/libnymea-app/types/statesproxy.cpp similarity index 100% rename from libnymea-common/types/statesproxy.cpp rename to libnymea-app/types/statesproxy.cpp diff --git a/libnymea-common/types/statesproxy.h b/libnymea-app/types/statesproxy.h similarity index 100% rename from libnymea-common/types/statesproxy.h rename to libnymea-app/types/statesproxy.h diff --git a/libnymea-common/types/statetype.cpp b/libnymea-app/types/statetype.cpp similarity index 100% rename from libnymea-common/types/statetype.cpp rename to libnymea-app/types/statetype.cpp diff --git a/libnymea-common/types/statetype.h b/libnymea-app/types/statetype.h similarity index 100% rename from libnymea-common/types/statetype.h rename to libnymea-app/types/statetype.h diff --git a/libnymea-common/types/statetypes.cpp b/libnymea-app/types/statetypes.cpp similarity index 100% rename from libnymea-common/types/statetypes.cpp rename to libnymea-app/types/statetypes.cpp diff --git a/libnymea-common/types/statetypes.h b/libnymea-app/types/statetypes.h similarity index 100% rename from libnymea-common/types/statetypes.h rename to libnymea-app/types/statetypes.h diff --git a/libnymea-common/types/tag.cpp b/libnymea-app/types/tag.cpp similarity index 100% rename from libnymea-common/types/tag.cpp rename to libnymea-app/types/tag.cpp diff --git a/libnymea-common/types/tag.h b/libnymea-app/types/tag.h similarity index 100% rename from libnymea-common/types/tag.h rename to libnymea-app/types/tag.h diff --git a/libnymea-common/types/tags.cpp b/libnymea-app/types/tags.cpp similarity index 100% rename from libnymea-common/types/tags.cpp rename to libnymea-app/types/tags.cpp diff --git a/libnymea-common/types/tags.h b/libnymea-app/types/tags.h similarity index 100% rename from libnymea-common/types/tags.h rename to libnymea-app/types/tags.h diff --git a/libnymea-common/types/timedescriptor.cpp b/libnymea-app/types/timedescriptor.cpp similarity index 100% rename from libnymea-common/types/timedescriptor.cpp rename to libnymea-app/types/timedescriptor.cpp diff --git a/libnymea-common/types/timedescriptor.h b/libnymea-app/types/timedescriptor.h similarity index 100% rename from libnymea-common/types/timedescriptor.h rename to libnymea-app/types/timedescriptor.h diff --git a/libnymea-common/types/timeeventitem.cpp b/libnymea-app/types/timeeventitem.cpp similarity index 100% rename from libnymea-common/types/timeeventitem.cpp rename to libnymea-app/types/timeeventitem.cpp diff --git a/libnymea-common/types/timeeventitem.h b/libnymea-app/types/timeeventitem.h similarity index 100% rename from libnymea-common/types/timeeventitem.h rename to libnymea-app/types/timeeventitem.h diff --git a/libnymea-common/types/timeeventitems.cpp b/libnymea-app/types/timeeventitems.cpp similarity index 100% rename from libnymea-common/types/timeeventitems.cpp rename to libnymea-app/types/timeeventitems.cpp diff --git a/libnymea-common/types/timeeventitems.h b/libnymea-app/types/timeeventitems.h similarity index 100% rename from libnymea-common/types/timeeventitems.h rename to libnymea-app/types/timeeventitems.h diff --git a/libnymea-common/types/tokeninfo.cpp b/libnymea-app/types/tokeninfo.cpp similarity index 100% rename from libnymea-common/types/tokeninfo.cpp rename to libnymea-app/types/tokeninfo.cpp diff --git a/libnymea-common/types/tokeninfo.h b/libnymea-app/types/tokeninfo.h similarity index 100% rename from libnymea-common/types/tokeninfo.h rename to libnymea-app/types/tokeninfo.h diff --git a/libnymea-common/types/tokeninfos.cpp b/libnymea-app/types/tokeninfos.cpp similarity index 100% rename from libnymea-common/types/tokeninfos.cpp rename to libnymea-app/types/tokeninfos.cpp diff --git a/libnymea-common/types/tokeninfos.h b/libnymea-app/types/tokeninfos.h similarity index 100% rename from libnymea-common/types/tokeninfos.h rename to libnymea-app/types/tokeninfos.h diff --git a/libnymea-common/types/types.cpp b/libnymea-app/types/types.cpp similarity index 100% rename from libnymea-common/types/types.cpp rename to libnymea-app/types/types.cpp diff --git a/libnymea-common/types/types.h b/libnymea-app/types/types.h similarity index 100% rename from libnymea-common/types/types.h rename to libnymea-app/types/types.h diff --git a/libnymea-common/types/userinfo.cpp b/libnymea-app/types/userinfo.cpp similarity index 100% rename from libnymea-common/types/userinfo.cpp rename to libnymea-app/types/userinfo.cpp diff --git a/libnymea-common/types/userinfo.h b/libnymea-app/types/userinfo.h similarity index 100% rename from libnymea-common/types/userinfo.h rename to libnymea-app/types/userinfo.h diff --git a/libnymea-common/types/vendor.cpp b/libnymea-app/types/vendor.cpp similarity index 100% rename from libnymea-common/types/vendor.cpp rename to libnymea-app/types/vendor.cpp diff --git a/libnymea-common/types/vendor.h b/libnymea-app/types/vendor.h similarity index 100% rename from libnymea-common/types/vendor.h rename to libnymea-app/types/vendor.h diff --git a/libnymea-common/types/vendors.cpp b/libnymea-app/types/vendors.cpp similarity index 100% rename from libnymea-common/types/vendors.cpp rename to libnymea-app/types/vendors.cpp diff --git a/libnymea-common/types/vendors.h b/libnymea-app/types/vendors.h similarity index 100% rename from libnymea-common/types/vendors.h rename to libnymea-app/types/vendors.h diff --git a/libnymea-common/types/wirelessaccesspoint.cpp b/libnymea-app/types/wirelessaccesspoint.cpp similarity index 100% rename from libnymea-common/types/wirelessaccesspoint.cpp rename to libnymea-app/types/wirelessaccesspoint.cpp diff --git a/libnymea-common/types/wirelessaccesspoint.h b/libnymea-app/types/wirelessaccesspoint.h similarity index 100% rename from libnymea-common/types/wirelessaccesspoint.h rename to libnymea-app/types/wirelessaccesspoint.h diff --git a/libnymea-common/types/wirelessaccesspoints.cpp b/libnymea-app/types/wirelessaccesspoints.cpp similarity index 100% rename from libnymea-common/types/wirelessaccesspoints.cpp rename to libnymea-app/types/wirelessaccesspoints.cpp diff --git a/libnymea-common/types/wirelessaccesspoints.h b/libnymea-app/types/wirelessaccesspoints.h similarity index 100% rename from libnymea-common/types/wirelessaccesspoints.h rename to libnymea-app/types/wirelessaccesspoints.h diff --git a/libnymea-app-core/usermanager.cpp b/libnymea-app/usermanager.cpp similarity index 100% rename from libnymea-app-core/usermanager.cpp rename to libnymea-app/usermanager.cpp diff --git a/libnymea-app-core/usermanager.h b/libnymea-app/usermanager.h similarity index 100% rename from libnymea-app-core/usermanager.h rename to libnymea-app/usermanager.h diff --git a/libnymea-app-core/vendorsproxy.cpp b/libnymea-app/vendorsproxy.cpp similarity index 100% rename from libnymea-app-core/vendorsproxy.cpp rename to libnymea-app/vendorsproxy.cpp diff --git a/libnymea-app-core/vendorsproxy.h b/libnymea-app/vendorsproxy.h similarity index 100% rename from libnymea-app-core/vendorsproxy.h rename to libnymea-app/vendorsproxy.h diff --git a/libnymea-app-core/wifisetup/bluetoothdevice.cpp b/libnymea-app/wifisetup/bluetoothdevice.cpp similarity index 100% rename from libnymea-app-core/wifisetup/bluetoothdevice.cpp rename to libnymea-app/wifisetup/bluetoothdevice.cpp diff --git a/libnymea-app-core/wifisetup/bluetoothdevice.h b/libnymea-app/wifisetup/bluetoothdevice.h similarity index 100% rename from libnymea-app-core/wifisetup/bluetoothdevice.h rename to libnymea-app/wifisetup/bluetoothdevice.h diff --git a/libnymea-app-core/wifisetup/bluetoothdeviceinfo.cpp b/libnymea-app/wifisetup/bluetoothdeviceinfo.cpp similarity index 100% rename from libnymea-app-core/wifisetup/bluetoothdeviceinfo.cpp rename to libnymea-app/wifisetup/bluetoothdeviceinfo.cpp diff --git a/libnymea-app-core/wifisetup/bluetoothdeviceinfo.h b/libnymea-app/wifisetup/bluetoothdeviceinfo.h similarity index 100% rename from libnymea-app-core/wifisetup/bluetoothdeviceinfo.h rename to libnymea-app/wifisetup/bluetoothdeviceinfo.h diff --git a/libnymea-app-core/wifisetup/bluetoothdeviceinfos.cpp b/libnymea-app/wifisetup/bluetoothdeviceinfos.cpp similarity index 100% rename from libnymea-app-core/wifisetup/bluetoothdeviceinfos.cpp rename to libnymea-app/wifisetup/bluetoothdeviceinfos.cpp diff --git a/libnymea-app-core/wifisetup/bluetoothdeviceinfos.h b/libnymea-app/wifisetup/bluetoothdeviceinfos.h similarity index 100% rename from libnymea-app-core/wifisetup/bluetoothdeviceinfos.h rename to libnymea-app/wifisetup/bluetoothdeviceinfos.h diff --git a/libnymea-app-core/wifisetup/bluetoothdiscovery.cpp b/libnymea-app/wifisetup/bluetoothdiscovery.cpp similarity index 100% rename from libnymea-app-core/wifisetup/bluetoothdiscovery.cpp rename to libnymea-app/wifisetup/bluetoothdiscovery.cpp diff --git a/libnymea-app-core/wifisetup/bluetoothdiscovery.h b/libnymea-app/wifisetup/bluetoothdiscovery.h similarity index 100% rename from libnymea-app-core/wifisetup/bluetoothdiscovery.h rename to libnymea-app/wifisetup/bluetoothdiscovery.h diff --git a/libnymea-app-core/wifisetup/networkmanagercontroller.cpp b/libnymea-app/wifisetup/networkmanagercontroller.cpp similarity index 100% rename from libnymea-app-core/wifisetup/networkmanagercontroller.cpp rename to libnymea-app/wifisetup/networkmanagercontroller.cpp diff --git a/libnymea-app-core/wifisetup/networkmanagercontroller.h b/libnymea-app/wifisetup/networkmanagercontroller.h similarity index 100% rename from libnymea-app-core/wifisetup/networkmanagercontroller.h rename to libnymea-app/wifisetup/networkmanagercontroller.h diff --git a/libnymea-app-core/wifisetup/wirelesssetupmanager.cpp b/libnymea-app/wifisetup/wirelesssetupmanager.cpp similarity index 100% rename from libnymea-app-core/wifisetup/wirelesssetupmanager.cpp rename to libnymea-app/wifisetup/wirelesssetupmanager.cpp diff --git a/libnymea-app-core/wifisetup/wirelesssetupmanager.h b/libnymea-app/wifisetup/wirelesssetupmanager.h similarity index 100% rename from libnymea-app-core/wifisetup/wirelesssetupmanager.h rename to libnymea-app/wifisetup/wirelesssetupmanager.h diff --git a/libnymea-common/libnymea-common.pro b/libnymea-common/libnymea-common.pro index 1d5745ff..a7e17797 100644 --- a/libnymea-common/libnymea-common.pro +++ b/libnymea-common/libnymea-common.pro @@ -8,126 +8,8 @@ QT -= gui QT += network HEADERS += \ - types/browseritem.h \ - types/browseritems.h \ - types/networkdevice.h \ - types/networkdevices.h \ - types/package.h \ - types/packages.h \ - types/repositories.h \ - types/repository.h \ - types/script.h \ - types/scripts.h \ - types/types.h \ - types/vendor.h \ - types/vendors.h \ - types/deviceclass.h \ - types/device.h \ - types/param.h \ - types/params.h \ - types/paramtype.h \ - types/paramtypes.h \ - types/statetype.h \ - types/statetypes.h \ - types/eventtype.h \ - types/eventtypes.h \ - types/actiontype.h \ - types/actiontypes.h \ - types/state.h \ - types/states.h \ - types/statesproxy.h \ - types/plugin.h \ - types/plugins.h \ - types/rules.h \ - types/rule.h \ - types/eventdescriptor.h \ - types/eventdescriptors.h \ - types/ruleaction.h \ - types/ruleactions.h \ - types/ruleactionparams.h \ - types/ruleactionparam.h \ - types/logentry.h \ - types/stateevaluators.h \ - types/stateevaluator.h \ - types/statedescriptor.h \ - types/paramdescriptor.h \ - types/paramdescriptors.h \ - types/interface.h \ - types/interfaces.h \ - types/timedescriptor.h \ - types/timeeventitem.h \ - types/calendaritem.h \ - types/timeeventitems.h \ - types/calendaritems.h \ - types/repeatingoption.h \ - types/tag.h \ - types/tags.h \ - types/wirelessaccesspoint.h \ - types/wirelessaccesspoints.h \ - types/tokeninfo.h \ - types/tokeninfos.h \ - types/userinfo.h \ SOURCES += \ - types/browseritem.cpp \ - types/browseritems.cpp \ - types/networkdevice.cpp \ - types/networkdevices.cpp \ - types/package.cpp \ - types/packages.cpp \ - types/repositories.cpp \ - types/repository.cpp \ - types/script.cpp \ - types/scripts.cpp \ - types/types.cpp \ - types/vendor.cpp \ - types/vendors.cpp \ - types/deviceclass.cpp \ - types/device.cpp \ - types/param.cpp \ - types/params.cpp \ - types/paramtype.cpp \ - types/paramtypes.cpp \ - types/statetype.cpp \ - types/statetypes.cpp \ - types/eventtype.cpp \ - types/eventtypes.cpp \ - types/actiontype.cpp \ - types/actiontypes.cpp \ - types/state.cpp \ - types/states.cpp \ - types/statesproxy.cpp \ - types/plugin.cpp \ - types/plugins.cpp \ - types/rules.cpp \ - types/rule.cpp \ - types/eventdescriptor.cpp \ - types/eventdescriptors.cpp \ - types/ruleaction.cpp \ - types/ruleactions.cpp \ - types/ruleactionparams.cpp \ - types/ruleactionparam.cpp \ - types/logentry.cpp \ - types/stateevaluators.cpp \ - types/stateevaluator.cpp \ - types/statedescriptor.cpp \ - types/paramdescriptor.cpp \ - types/paramdescriptors.cpp \ - types/interface.cpp \ - types/interfaces.cpp \ - types/timedescriptor.cpp \ - types/timeeventitem.cpp \ - types/calendaritem.cpp \ - types/timeeventitems.cpp \ - types/calendaritems.cpp \ - types/repeatingoption.cpp \ - types/tag.cpp \ - types/tags.cpp \ - types/wirelessaccesspoint.cpp \ - types/wirelessaccesspoints.cpp \ - types/tokeninfo.cpp \ - types/tokeninfos.cpp \ - types/userinfo.cpp \ diff --git a/nymea-app.pro b/nymea-app.pro index 4069141d..eda42125 100644 --- a/nymea-app.pro +++ b/nymea-app.pro @@ -2,15 +2,14 @@ include(config.pri) message("APP_VERSION: $${APP_VERSION} ($${APP_REVISION})") TEMPLATE=subdirs -SUBDIRS = libnymea-common libnymea-app-core nymea-app -libnymea-app-core.depends = libnymea-common -nymea-app.depends = libnymea-app-core +SUBDIRS = libnymea-app nymea-app +nymea-app.depends = libnymea-app #QML_IMPORT_PATH=/home/micha/Develop/Qt/5.11.0/gcc_64/qml/ withtests: { SUBDIRS += tests - tests.depends = libnymea-app-core + tests.depends = libnymea-app } # Building a Windows installer: diff --git a/nymea-app/nymea-app.pro b/nymea-app/nymea-app.pro index 4404c5fa..67bc711a 100644 --- a/nymea-app/nymea-app.pro +++ b/nymea-app/nymea-app.pro @@ -4,17 +4,13 @@ include(../config.pri) QT += network qml quick quickcontrols2 svg websockets bluetooth charts gui-private -INCLUDEPATH += $$top_srcdir/libnymea-common \ - $$top_srcdir/libnymea-app-core -LIBS += -L$$top_builddir/libnymea-app-core/ -lnymea-app-core \ - -L$$top_builddir/libnymea-common/ -lnymea-common \ +INCLUDEPATH += $$top_srcdir/libnymea-app +LIBS += -L$$top_builddir/libnymea-app/ -lnymea-app -win32:Debug:LIBS += -L$$top_builddir/libnymea-app-core/debug \ - -L$$top_builddir/libnymea-common/debug -win32:Release:LIBS += -L$$top_builddir/libnymea-app-core/release \ - -L$$top_builddir/libnymea-common/release +win32:Debug:LIBS += -L$$top_builddir/libnymea-app/debug +win32:Release:LIBS += -L$$top_builddir/libnymea-app/release linux:!android:LIBS += -lavahi-client -lavahi-common -PRE_TARGETDEPS += ../libnymea-app-core ../libnymea-common +PRE_TARGETDEPS += ../libnymea-app HEADERS += \ platformintegration/generic/raspberrypihelper.h \ diff --git a/nymea-app/resources.qrc b/nymea-app/resources.qrc index 47c5d301..245fca5d 100644 --- a/nymea-app/resources.qrc +++ b/nymea-app/resources.qrc @@ -199,7 +199,7 @@ ui/components/WebViewWrapper.qml ui/magic/NewScenePage.qml ui/mainviews/GroupsView.qml - ui/grouping/GroupPage.qml + ui/grouping/GroupThingsPage.qml ui/delegates/ThingTile.qml ui/components/TimePicker.qml ui/components/DatePicker.qml @@ -211,5 +211,6 @@ ui/system/UsersSettingsPage.qml ui/components/SettingsPageBase.qml ui/components/SettingsPageSectionHeader.qml + ui/grouping/GroupInterfacesPage.qml diff --git a/nymea-app/ui/MainPage.qml b/nymea-app/ui/MainPage.qml index 448c8c8d..d87f31b5 100644 --- a/nymea-app/ui/MainPage.qml +++ b/nymea-app/ui/MainPage.qml @@ -284,7 +284,10 @@ Page { height: swipeView.height model: InterfacesSortModel { interfacesModel: InterfacesModel { - deviceManager: engine.deviceManager + engine: _engine + devices: DevicesProxy { + engine: _engine + } shownInterfaces: app.supportedInterfaces showUncategorized: true } diff --git a/nymea-app/ui/components/Dial.qml b/nymea-app/ui/components/Dial.qml index b708e0f1..ed5649c0 100644 --- a/nymea-app/ui/components/Dial.qml +++ b/nymea-app/ui/components/Dial.qml @@ -90,10 +90,10 @@ ColumnLayout { function executeAction(value) { var params = [] var param = {} - param["paramTypeId"] = dial.stateType.id + param["paramName"] = dial.stateType.name param["value"] = value params.push(param) - d.pendingActionId = engine.deviceManager.executeAction(dial.device.id, dial.stateType.id, params) + d.pendingActionId = dial.device.executeAction(dial.stateType.name, params) } } Connections { @@ -106,6 +106,18 @@ ColumnLayout { } } } + Connections { + target: dial.device + onActionExecutionFinished: { + if (id == d.pendingActionId) { + d.pendingActionId = -1; + if (d.valueCacheDirty) { + d.executeAction(d.valueCache) + d.valueCacheDirty = false; + } + } + } + } Component.onCompleted: rotationButton.rotation = dial.valueToAngle(dial.deviceState.value) Connections { @@ -268,10 +280,10 @@ ColumnLayout { if (dial.powerStateType && !dragging) { var params = [] var param = {} - param["paramTypeId"] = dial.powerStateType.id + param["paramName"] = "power" param["value"] = !dial.powerState.value params.push(param) - engine.deviceManager.executeAction(dial.device.id, dial.powerStateType.id, params) + dial.device.executeAction("power", params) } dragging = false; } @@ -312,6 +324,7 @@ ColumnLayout { } lastVibration = new Date() } + d.enqueueSetValue(newValue); } } diff --git a/nymea-app/ui/devicelistpages/DeviceListPageBase.qml b/nymea-app/ui/devicelistpages/DeviceListPageBase.qml index de1401b4..edde3bb6 100644 --- a/nymea-app/ui/devicelistpages/DeviceListPageBase.qml +++ b/nymea-app/ui/devicelistpages/DeviceListPageBase.qml @@ -40,6 +40,7 @@ Page { property alias shownInterfaces: devicesProxyInternal.shownInterfaces property alias hiddenInterfaces: devicesProxyInternal.hiddenInterfaces + property alias filterTagId: devicesProxyInternal.filterTagId Component.onCompleted: { if (devicesProxyInternal.count === 1) { diff --git a/nymea-app/ui/devicepages/DevicePageBase.qml b/nymea-app/ui/devicepages/DevicePageBase.qml index e6c60d44..95b10c97 100644 --- a/nymea-app/ui/devicepages/DevicePageBase.qml +++ b/nymea-app/ui/devicepages/DevicePageBase.qml @@ -37,7 +37,7 @@ import "../components" Page { id: root property Device device: null - readonly property DeviceClass deviceClass: engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId) + readonly property DeviceClass deviceClass: device.deviceClass property bool showLogsButton: true property bool showDetailsButton: true diff --git a/nymea-app/ui/devicepages/PowersocketDevicePage.qml b/nymea-app/ui/devicepages/PowersocketDevicePage.qml index 6442d25e..11e8af3f 100644 --- a/nymea-app/ui/devicepages/PowersocketDevicePage.qml +++ b/nymea-app/ui/devicepages/PowersocketDevicePage.qml @@ -51,7 +51,7 @@ DevicePageBase { Layout.alignment: Qt.AlignCenter Item { - Layout.preferredWidth: Math.max(app.iconSize * 4, parent.width / 5) + Layout.preferredWidth: Math.max(app.iconSize * 6, parent.width / 5) Layout.preferredHeight: width Layout.topMargin: app.margins Layout.bottomMargin: app.landscape ? app.margins : 0 @@ -65,7 +65,7 @@ DevicePageBase { anchors.centerIn: parent Rectangle { anchors.fill: parent - color: "white" + color: "transparent" border.color: root.powerState.value === true ? app.accentColor : bulbIcon.keyColor border.width: 4 radius: width / 2 diff --git a/nymea-app/ui/grouping/GroupPage.qml b/nymea-app/ui/grouping/GroupInterfacesPage.qml similarity index 72% rename from nymea-app/ui/grouping/GroupPage.qml rename to nymea-app/ui/grouping/GroupInterfacesPage.qml index ab252f45..87f158e9 100644 --- a/nymea-app/ui/grouping/GroupPage.qml +++ b/nymea-app/ui/grouping/GroupInterfacesPage.qml @@ -35,6 +35,7 @@ import QtQuick.Layouts 1.1 import Nymea 1.0 import "../components" import "../delegates" +import "../mainviews" Page { id: root @@ -45,41 +46,41 @@ Page { property string groupTag - DevicesProxy { id: devicesInGroup engine: _engine filterTagId: root.groupTag } - InterfacesProxy { - id: interfacesInGroup - devicesProxyFilter: devicesInGroup - showStates: true - } - GridView { - id: gridView + id: interfacesGridView anchors.fill: parent anchors.margins: app.margins / 2 - model: devicesInGroup + model: InterfacesSortModel { + interfacesModel: InterfacesModel { + engine: _engine + devices: devicesInGroup + shownInterfaces: app.supportedInterfaces + showUncategorized: true + } + } - readonly property int minTileWidth: 180 - readonly property int minTileHeight: 240 + readonly property int minTileWidth: 172 readonly property int tilesPerRow: root.width / minTileWidth - cellWidth: gridView.width / tilesPerRow + cellWidth: width / tilesPerRow cellHeight: cellWidth +// delegate: DevicesPageDelegate { +// width: interfacesGridView.cellWidth +// height: interfacesGridView.cellHeight +// } - delegate: ThingTile { - width: gridView.cellWidth - height: gridView.cellHeight - - device: devicesInGroup.get(index) - - onClicked: pageStack.push(Qt.resolvedUrl("../devicepages/" + app.interfaceListToDevicePage(deviceClass.interfaces)), {device: device}) - + delegate: DevicesPageDelegate { + width: interfacesGridView.cellWidth + height: interfacesGridView.cellHeight + iface: Interfaces.findByName(model.name) + filterTagId: root.groupTag } } diff --git a/nymea-app/ui/grouping/GroupThingsPage.qml b/nymea-app/ui/grouping/GroupThingsPage.qml new file mode 100644 index 00000000..b5ea065c --- /dev/null +++ b/nymea-app/ui/grouping/GroupThingsPage.qml @@ -0,0 +1,139 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +* +* 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 . +* +* 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 +* +* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +import QtQuick 2.5 +import QtQuick.Controls 2.1 +import QtQuick.Controls.Material 2.1 +import QtQuick.Layouts 1.1 +import Nymea 1.0 +import "../components" +import "../delegates" + +Page { + id: root + header: NymeaHeader { + text: root.groupTag.substring(6) + onBackPressed: pageStack.pop() + } + + property string groupTag + + + DevicesProxy { + id: devicesInGroup + engine: _engine + filterTagId: root.groupTag + } + + InterfacesProxy { + id: interfacesInGroup + devicesProxyFilter: devicesInGroup + showStates: true + } + + DevicesProxy { + id: lightsInGroup + engine: _engine + sourceModel: devicesInGroup + filterTagId: root.groupTag + shownInterfaces: "light" + } + DevicesProxy { + id: dimmableLightsInGroup + engine: _engine + sourceModel: devicesInGroup + filterTagId: root.groupTag + shownInterfaces: "dimmablelight" + } + DevicesProxy { + id: colorLightsInGroup + engine: _engine + sourceModel: devicesInGroup + filterTagId: root.groupTag + shownInterfaces: "colorlight" + } + DevicesProxy { + id: socketsInGroup + engine: _engine + sourceModel: devicesInGroup + filterTagId: root.groupTag + shownInterfaces: "powersocket" + } + + ColumnLayout { + anchors.fill: parent + + Pane { + Layout.fillWidth: true + Material.elevation: 1 + RowLayout { + HeaderButton { + imageSource: "../images/powersocket.svg" + visible: socketsInGroup.count > 0 + } + HeaderButton { + imageSource: "../images/light-on.svg" + visible: lightsInGroup.count > 0 + } + HeaderButton { + imageSource: "../images/radiator.svg" + } + } + } + + GridView { + id: gridView + Layout.fillWidth: true + Layout.fillHeight: true + clip: true + + model: devicesInGroup + + readonly property int minTileWidth: 180 + readonly property int minTileHeight: 240 + readonly property int tilesPerRow: root.width / minTileWidth + + cellWidth: gridView.width / tilesPerRow + cellHeight: cellWidth + + delegate: ThingTile { + width: gridView.cellWidth + height: gridView.cellHeight + + device: devicesInGroup.get(index) + + onClicked: pageStack.push(Qt.resolvedUrl("../devicepages/" + app.interfaceListToDevicePage(deviceClass.interfaces)), {device: device}) + + } + } + } + + +} diff --git a/nymea-app/ui/mainviews/DevicesPage.qml b/nymea-app/ui/mainviews/DevicesPage.qml index 41db9198..1cc17923 100644 --- a/nymea-app/ui/mainviews/DevicesPage.qml +++ b/nymea-app/ui/mainviews/DevicesPage.qml @@ -57,6 +57,7 @@ MouseArea { delegate: DevicesPageDelegate { width: interfacesGridView.cellWidth height: interfacesGridView.cellHeight + iface: Interfaces.findByName(model.name) } } } diff --git a/nymea-app/ui/mainviews/DevicesPageDelegate.qml b/nymea-app/ui/mainviews/DevicesPageDelegate.qml index 36694788..95764ad3 100644 --- a/nymea-app/ui/mainviews/DevicesPageDelegate.qml +++ b/nymea-app/ui/mainviews/DevicesPageDelegate.qml @@ -37,17 +37,20 @@ import "../components" MainPageTile { id: root - text: interfaceToString(model.name).toUpperCase() - iconName: interfaceToIcon(model.name) + text: interfaceToString(iface.name).toUpperCase() + iconName: interfaceToIcon(iface.name) iconColor: app.accentColor disconnected: devicesSubProxyConnectables.count > 0 batteryCritical: devicesSubProxyBattery.count > 0 + property Interface iface: null + property alias filterTagId: devicesProxy.filterTagId + backgroundImage: inlineControlLoader.item && inlineControlLoader.item.hasOwnProperty("backgroundImage") ? inlineControlLoader.item.backgroundImage : "" onClicked: { var page; - switch (model.name) { + switch (iface.name) { case "heating": case "sensor": page = "SensorsDeviceListPage.qml" @@ -85,18 +88,18 @@ MainPageTile { default: page = "GenericDeviceListPage.qml" } - if (model.name === "uncategorized") { - pageStack.push(Qt.resolvedUrl("../devicelistpages/" + page), {hiddenInterfaces: app.supportedInterfaces}) + if (iface.name === "uncategorized") { + pageStack.push(Qt.resolvedUrl("../devicelistpages/" + page), {hiddenInterfaces: app.supportedInterfaces, filterTagId: root.filterTagId}) } else { - print("= 0 +// state: { +// var stateName = null +// switch (model.name) { +// case "presencesensor": +// stateName = "isPresent" +// break; +// } +// if (!stateName) { +// return "off"; +// } +// var ret = false; +// for (var i = 0; i < innerProxy.count; i++) { +// ret |= innerProxy.get(i).states.getState(innerProxy.get(i).deviceClass.stateTypes.findByName(stateName).id).value +// } +// return ret ? "on" : "off"; +// } +// } + +// Label { +// height: parent.height +// verticalAlignment: Text.AlignVCenter +// text: { +// var stateName = null; +// switch (model.name) { +// case "temperaturesensor": +// stateName = "temperature"; +// break; +// case "lightsensor": +// stateName = "lightIntensity" +// break; +// } +// if (!stateName) { +// return ""; +// } + +// var ret = 0 +// for (var i = 0; i < innerProxy.count; i++) { +// ret += innerProxy.get(i).states.getState(innerProxy.get(i).deviceClass.stateTypes.findByName(stateName).id).value +// } +// return (ret / innerProxy.count).toFixed(1) +// } +// } +// } +// } +// } +// } +// } +// } +// } + } + } + + Component { + id: powerSocketDelegate + RowLayout { + property var devices + + Layout.alignment: Layout.Right + + DevicesProxy { + id: sockets + engine: _engine + parentProxy: devices + shownInterfaces: ["powersocket"] + } + + ColorIcon { + Layout.preferredHeight: app.iconSize + Layout.preferredWidth: app.iconSize + name: "../images/powersocket.svg" + color: isOn ? app.accentColor : keyColor + + property bool isOn: { + for (var i = 0; i < sockets.count; i++) { + var device = sockets.get(i) + var powerId = device.deviceClass.stateTypes.findByName("power").id + if (device.states.getState(powerId).value === true) { + return true + } } + return false; + } - contentItem: ColumnLayout { - Rectangle { - Layout.fillWidth: true - Layout.preferredHeight: 30 - color: Qt.rgba(app.foregroundColor.r, app.foregroundColor.g, app.foregroundColor.b, .05) - Label { - anchors.fill: parent - verticalAlignment: Text.AlignVCenter - anchors { leftMargin: app.margins; rightMargin: app.margins } - text: model.tagId.substring(6) - elide: Text.ElideRight - } - } - Item { - Layout.fillHeight: true - Layout.fillWidth: true - - ColorIcon { - anchors.centerIn: parent - height: app.iconSize * 2 - width: height - visible: controlsInGroup.count == 0 - color: app.accentColor - name: "../images/view-grid-symbolic.svg" - } - - ColumnLayout { - anchors.fill: parent - - Repeater { - model: Math.min(controlsInGroup.count, parent.height / 50) - delegate: Loader { - id: controlLoader - Layout.fillWidth: true - Layout.leftMargin: app.margins / 2 - Layout.rightMargin: app.margins / 2 - property string interfaceName: controlsInGroup.get(index).name - sourceComponent: { - switch (interfaceName) { - case "simpleclosable": - return closableDelegate - case "light": - return lightDelegate - case "mediacontroller": - return mediaControllerDelegate - } - } - Binding { - target: controlLoader.item - property: "devices" - value: devicesInGroup - } - } - } - Item { - Layout.fillHeight: true - Layout.fillWidth: true - } - } - - } - Rectangle { - Layout.fillWidth: true - Layout.preferredHeight: app.iconSize * 1.2 - color: Qt.rgba(app.foregroundColor.r, app.foregroundColor.g, app.foregroundColor.b, 0.05) - - RowLayout { - anchors.fill: parent - - Repeater { - model: sensorsInGroup - delegate: Row { - height: parent.height - - ColorIcon { - height: app.iconSize * .8 - width: height - name: app.interfaceToIcon(model.name) - color: app.interfaceToColor(model.name) - } - DevicesProxy { - id: innerProxy - engine: _engine - parentProxy: devicesInGroup - shownInterfaces: [model.name] - } - - Led { - visible: ["presencesensor"].indexOf(model.name) >= 0 - state: { - var stateName = null - switch (model.name) { - case "presencesensor": - stateName = "isPresent" - break; - } - if (!stateName) { - return "off"; - } - var ret = false; - for (var i = 0; i < innerProxy.count; i++) { - ret |= innerProxy.get(i).states.getState(innerProxy.get(i).deviceClass.stateTypes.findByName(stateName).id).value - } - return ret ? "on" : "off"; - } - } - - Label { - height: parent.height - verticalAlignment: Text.AlignVCenter - text: { - var stateName = null; - switch (model.name) { - case "temperaturesensor": - stateName = "temperature"; - break; - case "lightsensor": - stateName = "lightIntensity" - break; - } - if (!stateName) { - return ""; - } - - var ret = 0 - for (var i = 0; i < innerProxy.count; i++) { - ret += innerProxy.get(i).states.getState(innerProxy.get(i).deviceClass.stateTypes.findByName(stateName).id).value - } - return (ret / innerProxy.count).toFixed(1) - } - } - } - } - } + MouseArea { + anchors.fill: parent + onClicked: { + for (var i = 0; i < sockets.count; i++) { + var device = sockets.get(i) + var powerId = device.deviceClass.stateTypes.findByName("power").id + engine.deviceManager.executeAction(device.id, powerId, [{paramTypeId: powerId, value: !parent.isOn}]) } } } diff --git a/nymea-app/ui/thingconfiguration/NewThingPage.qml b/nymea-app/ui/thingconfiguration/NewThingPage.qml index 73020cd3..0a6c120d 100644 --- a/nymea-app/ui/thingconfiguration/NewThingPage.qml +++ b/nymea-app/ui/thingconfiguration/NewThingPage.qml @@ -104,9 +104,8 @@ Page { InterfacesSortModel { id: interfacesSortModel interfacesModel: InterfacesModel { - deviceManager: engine.deviceManager + engine: _engine shownInterfaces: app.supportedInterfaces - onlyConfiguredDevices: false showUncategorized: false } } diff --git a/tests/testrunner/testrunner.pro b/tests/testrunner/testrunner.pro index 7004fa5f..e8a804a5 100644 --- a/tests/testrunner/testrunner.pro +++ b/tests/testrunner/testrunner.pro @@ -7,16 +7,12 @@ QT += core gui testlib bluetooth websockets CONFIG += qmltestcase INCLUDEPATH += ../../nymea-app/ \ - ../../libnymea-common/ \ - ../../libnymea-app-core/ + ../../libnymea-app -LIBS += -L$$top_builddir/libnymea-app-core/ -lnymea-app-core \ - -L$$top_builddir/libnymea-common/ -lnymea-common \ +LIBS += -L$$top_builddir/libnymea-app/ -lnymea-app \ -lavahi-common -lavahi-client -win32:Debug:LIBS += -L$$top_builddir/libmea-core/debug \ - -L$$top_builddir/libnymea-common/debug -win32:Release:LIBS += -L$$top_builddir/libmea-core/release \ - -L$$top_builddir/libnymea-common/release +win32:Debug:LIBS += -L$$top_builddir/libnymea-app/debug +win32:Release:LIBS += -L$$top_builddir/libnymea-app/release SOURCES += testrunner.cpp