From 67aa7ae17225e30434b95de22a2fc555f8e96d21 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Sat, 20 Feb 2021 23:25:01 +0100 Subject: [PATCH 1/5] Drop checks for version less than 1.10 as we won't connect to that anyways any more --- libnymea-app/engine.cpp | 5 +--- nymea-app/ui/SettingsPage.qml | 1 - nymea-app/ui/components/ThingContextMenu.qml | 26 +++++++++---------- .../ui/customviews/GenericTypeLogView.qml | 6 ++--- nymea-app/ui/devicepages/DeviceLogPage.qml | 3 +-- nymea-app/ui/devicepages/StateLogPage.qml | 11 +++----- nymea-app/ui/magic/EditRulePage.qml | 4 +-- 7 files changed, 21 insertions(+), 35 deletions(-) diff --git a/libnymea-app/engine.cpp b/libnymea-app/engine.cpp index 235e02bc..771e2cf1 100644 --- a/libnymea-app/engine.cpp +++ b/libnymea-app/engine.cpp @@ -150,13 +150,10 @@ void Engine::onConnectedChanged() void Engine::onDeviceManagerFetchingChanged() { if (!m_thingManager->fetchingData()) { + m_tagsManager->init(); m_ruleManager->init(); m_scriptManager->init(); m_nymeaConfiguration->init(); m_systemController->init(); - - if (m_jsonRpcClient->ensureServerVersion("1.7")) { - m_tagsManager->init(); - } } } diff --git a/nymea-app/ui/SettingsPage.qml b/nymea-app/ui/SettingsPage.qml index f1137d3f..f9a387ff 100644 --- a/nymea-app/ui/SettingsPage.qml +++ b/nymea-app/ui/SettingsPage.qml @@ -106,7 +106,6 @@ Page { Pane { Layout.fillWidth: true Material.elevation: layout.isGrid ? 1 : 0 - visible: engine.jsonRpcClient.ensureServerVersion("1.9") padding: 0 NymeaSwipeDelegate { diff --git a/nymea-app/ui/components/ThingContextMenu.qml b/nymea-app/ui/components/ThingContextMenu.qml index 34cae6ed..cd5ace82 100644 --- a/nymea-app/ui/components/ThingContextMenu.qml +++ b/nymea-app/ui/components/ThingContextMenu.qml @@ -22,21 +22,19 @@ AutoSizeMenu { root.addItem(menuEntryComponent.createObject(root, {text: qsTr("Logs"), iconSource: "../images/logs.svg", functionName: "openThingLogPage"})) } - if (engine.jsonRpcClient.ensureServerVersion("1.6")) { - root.addItem(menuEntryComponent.createObject(root, - { - text: Qt.binding(function() { return favoritesProxy.count === 0 ? qsTr("Mark as favorite") : qsTr("Remove from favorites")}), - iconSource: Qt.binding(function() { return favoritesProxy.count === 0 ? "../images/starred.svg" : "../images/non-starred.svg"}), - functionName: "toggleFavorite" - })) + root.addItem(menuEntryComponent.createObject(root, + { + text: Qt.binding(function() { return favoritesProxy.count === 0 ? qsTr("Mark as favorite") : qsTr("Remove from favorites")}), + iconSource: Qt.binding(function() { return favoritesProxy.count === 0 ? "../images/starred.svg" : "../images/non-starred.svg"}), + functionName: "toggleFavorite" + })) - root.addItem(menuEntryComponent.createObject(root, - { - text: qsTr("Grouping"), - iconSource: "../images/view-grid-symbolic.svg", - functionName: "addToGroup" - })) - } + root.addItem(menuEntryComponent.createObject(root, + { + text: qsTr("Grouping"), + iconSource: "../images/view-grid-symbolic.svg", + functionName: "addToGroup" + })) print("*** creating menu") print("NFC", NfcHelper.isAvailable) diff --git a/nymea-app/ui/customviews/GenericTypeLogView.qml b/nymea-app/ui/customviews/GenericTypeLogView.qml index 5a418766..d99e8ea3 100644 --- a/nymea-app/ui/customviews/GenericTypeLogView.qml +++ b/nymea-app/ui/customviews/GenericTypeLogView.qml @@ -54,10 +54,8 @@ Item { SwipeDelegateGroup {} onContentYChanged: { - if (!engine.jsonRpcClient.ensureServerVersion("1.10")) { - if (!logsModel.busy && contentY - originY < 5 * height) { - logsModel.fetchEarlier(24) - } + if (!logsModel.busy && contentY - originY < 5 * height) { + logsModel.fetchEarlier(24) } } diff --git a/nymea-app/ui/devicepages/DeviceLogPage.qml b/nymea-app/ui/devicepages/DeviceLogPage.qml index 6c5d612d..c1ae039d 100644 --- a/nymea-app/ui/devicepages/DeviceLogPage.qml +++ b/nymea-app/ui/devicepages/DeviceLogPage.qml @@ -126,9 +126,8 @@ Page { case "uint": case "int": case "double": - return true; case "bool": - return engine.jsonRpcClient.ensureServerVersion("1.10") + return true; } print("not showing graph for", stateType.type) return false; diff --git a/nymea-app/ui/devicepages/StateLogPage.qml b/nymea-app/ui/devicepages/StateLogPage.qml index a442afb2..f3c40c39 100644 --- a/nymea-app/ui/devicepages/StateLogPage.qml +++ b/nymea-app/ui/devicepages/StateLogPage.qml @@ -46,9 +46,8 @@ Page { switch (root.stateType.type) { case "Int": case "Double": - return true; case "Bool": - return engine.jsonRpcClient.ensureServerVersion("1.10") + return true; } print("not showing graph for", root.stateType.type) return false; @@ -94,7 +93,7 @@ Page { width: swipeView.width height: swipeView.height - logsModel: engine.jsonRpcClient.ensureServerVersion("1.10") ? logsModelNg : logsModel + logsModel: logsModelNg onAddRuleClicked: { var value = logView.logsModel.get(index).value @@ -119,11 +118,7 @@ Page { height: swipeView.height Component.onCompleted: { var source; - if (engine.jsonRpcClient.ensureServerVersion("1.10")) { - source = Qt.resolvedUrl("../customviews/GenericTypeGraph.qml"); - } else { - source = Qt.resolvedUrl("../customviews/GenericTypeGraphPre110.qml"); - } + source = Qt.resolvedUrl("../customviews/GenericTypeGraph.qml"); setSource(source, {device: root.device, stateType: root.stateType}) } } diff --git a/nymea-app/ui/magic/EditRulePage.qml b/nymea-app/ui/magic/EditRulePage.qml index 54e0a2ac..0f3f219d 100644 --- a/nymea-app/ui/magic/EditRulePage.qml +++ b/nymea-app/ui/magic/EditRulePage.qml @@ -45,7 +45,7 @@ Page { readonly property bool isEventBased: rule.eventDescriptors.count > 0 || rule.timeDescriptor.timeEventItems.count > 0 readonly property bool isStateBased: (rule.stateEvaluator !== null || rule.timeDescriptor.calendarItems.count > 0) readonly property bool actionsVisible: true - readonly property bool exitActionsVisible: engine.jsonRpcClient.ensureServerVersion("1.7") && isStateBased + readonly property bool exitActionsVisible: isStateBased readonly property bool hasActions: rule.actions.count > 0 readonly property bool hasExitActions: rule.exitActions.count > 0 readonly property bool isEmpty: !isEventBased && !isStateBased && !hasActions @@ -380,7 +380,7 @@ Page { columnSpacing: app.margins rowSpacing: app.margins Layout.preferredHeight: opacity > 0 ? implicitHeight : 0 - opacity: engine.jsonRpcClient.ensureServerVersion(1.6) && ruleSettings.showDetails && root.rule.executable ? 1 : 0 + opacity: ruleSettings.showDetails && root.rule.executable ? 1 : 0 Behavior on Layout.preferredHeight { NumberAnimation { duration: 200; easing.type: Easing.InOutQuad} } Behavior on opacity { NumberAnimation {duration: 200; easing.type: Easing.InOutQuad } } From 24d5d8fa29432bee02b23af2a02f4c696064b6b6 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Wed, 24 Feb 2021 12:28:35 +0100 Subject: [PATCH 2/5] No more devices! --- androidservice/controlviews/Main.qml | 2 +- .../nymeaappservice/androidbinder.cpp | 2 +- libnymea-app/devicemanager.cpp | 786 ----------- libnymea-app/engine.cpp | 13 +- libnymea-app/engine.h | 12 +- libnymea-app/interfacesmodel.cpp | 24 +- libnymea-app/interfacesmodel.h | 16 +- libnymea-app/jsonrpc/jsontypes.cpp | 477 ------- libnymea-app/jsonrpc/jsontypes.h | 80 -- libnymea-app/libnymea-app-core.h | 49 +- libnymea-app/libnymea-app.pri | 34 +- libnymea-app/models/interfacesproxy.cpp | 12 +- libnymea-app/models/interfacesproxy.h | 20 +- libnymea-app/models/logsmodel.cpp | 22 +- libnymea-app/models/logsmodel.h | 4 +- libnymea-app/models/logsmodelng.cpp | 32 +- libnymea-app/models/logsmodelng.h | 2 - libnymea-app/models/rulesfiltermodel.cpp | 6 +- libnymea-app/models/rulesfiltermodel.h | 1 - libnymea-app/models/tagsproxymodel.h | 1 - .../{devicemodel.cpp => thingmodel.cpp} | 32 +- .../models/{devicemodel.h => thingmodel.h} | 24 +- libnymea-app/rulemanager.cpp | 44 +- libnymea-app/ruletemplates/ruletemplates.cpp | 18 +- libnymea-app/ruletemplates/ruletemplates.h | 18 +- libnymea-app/scripting/codecompletion.cpp | 46 +- libnymea-app/scriptsyntaxhighlighter.cpp | 10 +- libnymea-app/tagsmanager.cpp | 27 +- .../{deviceclasses.cpp => thingclasses.cpp} | 71 +- .../{deviceclasses.h => thingclasses.h} | 23 +- ...classesproxy.cpp => thingclassesproxy.cpp} | 76 +- ...viceclassesproxy.h => thingclassesproxy.h} | 18 +- libnymea-app/thingdiscovery.cpp | 34 +- libnymea-app/thingdiscovery.h | 6 +- libnymea-app/thinggroup.cpp | 30 +- libnymea-app/thinggroup.h | 12 +- libnymea-app/thingmanager.cpp | 1158 +++++++++++++++++ .../{devicemanager.h => thingmanager.h} | 120 +- libnymea-app/{devices.cpp => things.cpp} | 56 +- libnymea-app/{devices.h => things.h} | 39 +- .../{devicesproxy.cpp => thingsproxy.cpp} | 195 ++- .../{devicesproxy.h => thingsproxy.h} | 47 +- libnymea-app/types/browseritems.cpp | 8 +- libnymea-app/types/browseritems.h | 6 +- libnymea-app/types/eventdescriptor.h | 1 - libnymea-app/types/eventdescriptors.cpp | 2 - libnymea-app/types/eventdescriptors.h | 1 - libnymea-app/types/interface.cpp | 6 +- libnymea-app/types/interface.h | 4 +- libnymea-app/types/interfaces.cpp | 2 +- libnymea-app/types/interfaces.h | 2 +- libnymea-app/types/logentry.h | 1 - libnymea-app/types/rule.cpp | 12 +- libnymea-app/types/ruleaction.cpp | 16 +- libnymea-app/types/ruleaction.h | 11 +- libnymea-app/types/ruleactionparam.cpp | 18 +- libnymea-app/types/ruleactionparam.h | 10 +- libnymea-app/types/ruleactionparams.cpp | 12 +- libnymea-app/types/ruleactionparams.h | 4 +- libnymea-app/types/state.cpp | 8 +- libnymea-app/types/state.h | 8 +- libnymea-app/types/statedescriptor.cpp | 20 +- libnymea-app/types/statedescriptor.h | 12 +- libnymea-app/types/stateevaluator.cpp | 8 +- libnymea-app/types/stateevaluator.h | 2 +- libnymea-app/types/tag.h | 1 - libnymea-app/types/tags.cpp | 7 - libnymea-app/types/tags.h | 2 - libnymea-app/types/{device.cpp => thing.cpp} | 66 +- libnymea-app/types/{device.h => thing.h} | 68 +- .../types/{deviceclass.cpp => thingclass.cpp} | 72 +- .../types/{deviceclass.h => thingclass.h} | 10 +- nymea-app/nfcthingactionwriter.cpp | 6 +- nymea-app/nfcthingactionwriter.h | 10 +- nymea-app/resources.qrc | 22 +- nymea-app/ui/MagicPage.qml | 4 +- nymea-app/ui/MainPage.qml | 2 +- .../ui/components/BrowserContextMenu.qml | 4 +- .../ui/components/ClosablesControlLarge.qml | 8 +- nymea-app/ui/components/ErrorDialog.qml | 6 +- nymea-app/ui/components/Graph.qml | 6 +- nymea-app/ui/components/MediaBrowser.qml | 8 +- nymea-app/ui/components/MediaPlayer.qml | 10 +- nymea-app/ui/components/NavigationPad.qml | 14 +- .../ui/components/RemoveThingMethodDialog.qml | 6 +- nymea-app/ui/components/ShutterControls.qml | 14 +- nymea-app/ui/components/SmartMeterChart.qml | 2 +- nymea-app/ui/components/ThingContextMenu.qml | 6 +- nymea-app/ui/customviews/GenericTypeGraph.qml | 13 +- .../ui/customviews/GenericTypeLogView.qml | 6 +- .../ui/delegates/BrowserItemDelegate.qml | 5 +- nymea-app/ui/delegates/InterfaceTile.qml | 171 ++- nymea-app/ui/delegates/ThingDelegate.qml | 4 +- nymea-app/ui/delegates/ThingTile.qml | 104 +- ...eListPage.qml => AwningThingsListPage.qml} | 2 +- ...ceListPage.qml => BlindThingsListPage.qml} | 2 +- ...stPage.qml => ClosablesThingsListPage.qml} | 31 +- ...gListPage.qml => GarageThingsListPage.qml} | 4 +- ...ListPage.qml => GenericThingsListPage.qml} | 2 +- ...ceListPage.qml => LightThingsListPage.qml} | 19 +- .../devicelistpages/MediaDeviceListPage.qml | 2 +- .../PowerSocketsDeviceListPage.qml | 4 +- .../devicelistpages/SensorsDeviceListPage.qml | 2 +- .../devicelistpages/ShutterDeviceListPage.qml | 2 +- .../SmartMeterDeviceListPage.qml | 2 +- ...istPageBase.qml => ThingsListPageBase.qml} | 5 +- .../devicelistpages/WeatherDeviceListPage.qml | 2 +- ...ningDevicePage.qml => AwningThingPage.qml} | 15 +- .../devicepages/BarcodeScannerThingPage.qml | 12 +- ...ttonDevicePage.qml => ButtonThingPage.qml} | 6 +- .../ui/devicepages/DeviceBrowserPage.qml | 33 +- nymea-app/ui/devicepages/DeviceLogPage.qml | 10 +- .../ui/devicepages/DoorbellDevicePage.qml | 8 +- .../FingerprintReaderDevicePage.qml | 24 +- nymea-app/ui/devicepages/GarageThingPage.qml | 2 +- .../ui/devicepages/GenericDevicePage.qml | 54 +- .../ui/devicepages/HeatingDevicePage.qml | 9 +- .../ui/devicepages/InputTriggerDevicePage.qml | 14 +- .../ui/devicepages/IrrigationDevicePage.qml | 4 +- nymea-app/ui/devicepages/LightDevicePage.qml | 21 +- nymea-app/ui/devicepages/MediaThingPage.qml | 2 +- .../devicepages/NotificationsDevicePage.qml | 10 +- .../ui/devicepages/PowersocketDevicePage.qml | 9 +- nymea-app/ui/devicepages/SensorDevicePage.qml | 26 +- .../ui/devicepages/ShutterDevicePage.qml | 23 +- .../ui/devicepages/SmartMeterDevicePage.qml | 6 +- nymea-app/ui/devicepages/StateLogPage.qml | 14 +- .../ui/devicepages/ThermostatDevicePage.qml | 2 +- .../{DevicePageBase.qml => ThingPageBase.qml} | 11 +- .../ui/devicepages/VentilationDevicePage.qml | 9 +- .../ui/devicepages/WeatherDevicePage.qml | 18 +- nymea-app/ui/experiences/heating/Main.qml | 22 +- nymea-app/ui/grouping/GroupInterfacesPage.qml | 6 +- nymea-app/ui/grouping/GroupThingsPage.qml | 15 +- nymea-app/ui/magic/EditRulePage.qml | 26 +- .../ui/magic/EventDescriptorDelegate.qml | 10 +- nymea-app/ui/magic/NewScenePage.qml | 2 +- nymea-app/ui/magic/NewThingMagicPage.qml | 175 ++- nymea-app/ui/magic/RuleActionDelegate.qml | 21 +- .../ui/magic/SelectBrowserItemActionPage.qml | 8 +- .../ui/magic/SelectEventDescriptorPage.qml | 27 +- .../magic/SelectEventDescriptorParamsPage.qml | 9 +- nymea-app/ui/magic/SelectRuleActionPage.qml | 37 +- .../ui/magic/SelectRuleActionParamsPage.qml | 55 +- .../ui/magic/SelectStateDescriptorPage.qml | 29 +- .../magic/SelectStateDescriptorParamsPage.qml | 6 +- nymea-app/ui/magic/SelectStatePage.qml | 6 +- nymea-app/ui/magic/SelectThingPage.qml | 44 +- .../ui/magic/SimpleStateEvaluatorDelegate.qml | 16 +- nymea-app/ui/magic/StateEvaluatorDelegate.qml | 11 +- ...DeviceRulesPage.qml => ThingRulesPage.qml} | 23 +- nymea-app/ui/mainviews/FavoritesView.qml | 22 +- nymea-app/ui/mainviews/GaragesView.qml | 2 +- nymea-app/ui/mainviews/GroupsView.qml | 225 +--- nymea-app/ui/mainviews/ScenesView.qml | 9 +- nymea-app/ui/mainviews/ThingsView.qml | 4 +- nymea-app/ui/system/LogViewerPage.qml | 11 +- nymea-app/ui/system/PluginParamsPage.qml | 10 +- nymea-app/ui/system/PluginsPage.qml | 2 +- .../thingconfiguration/ConfigureThingPage.qml | 96 +- .../ui/thingconfiguration/EditThingsPage.qml | 28 +- .../ui/thingconfiguration/NewThingPage.qml | 16 +- .../ui/thingconfiguration/SetupWizard.qml | 134 +- .../ThingClassDetailsPage.qml | 4 +- nymea-app/ui/utils/NymeaUtils.qml | 6 +- 165 files changed, 2764 insertions(+), 3304 deletions(-) delete mode 100644 libnymea-app/devicemanager.cpp delete mode 100644 libnymea-app/jsonrpc/jsontypes.cpp delete mode 100644 libnymea-app/jsonrpc/jsontypes.h rename libnymea-app/models/{devicemodel.cpp => thingmodel.cpp} (87%) rename libnymea-app/models/{devicemodel.h => thingmodel.h} (86%) rename libnymea-app/{deviceclasses.cpp => thingclasses.cpp} (58%) rename libnymea-app/{deviceclasses.h => thingclasses.h} (79%) rename libnymea-app/{deviceclassesproxy.cpp => thingclassesproxy.cpp} (59%) rename libnymea-app/{deviceclassesproxy.h => thingclassesproxy.h} (90%) create mode 100644 libnymea-app/thingmanager.cpp rename libnymea-app/{devicemanager.h => thingmanager.h} (53%) rename libnymea-app/{devices.cpp => things.cpp} (74%) rename libnymea-app/{devices.h => things.h} (74%) rename libnymea-app/{devicesproxy.cpp => thingsproxy.cpp} (61%) rename libnymea-app/{devicesproxy.h => thingsproxy.h} (85%) rename libnymea-app/types/{device.cpp => thing.cpp} (79%) rename libnymea-app/types/{device.h => thing.h} (67%) rename libnymea-app/types/{deviceclass.cpp => thingclass.cpp} (74%) rename libnymea-app/types/{deviceclass.h => thingclass.h} (97%) rename nymea-app/ui/devicelistpages/{AwningDeviceListPage.qml => AwningThingsListPage.qml} (98%) rename nymea-app/ui/devicelistpages/{BlindDeviceListPage.qml => BlindThingsListPage.qml} (98%) rename nymea-app/ui/devicelistpages/{ClosablesDeviceListPage.qml => ClosablesThingsListPage.qml} (80%) rename nymea-app/ui/devicelistpages/{GarageThingListPage.qml => GarageThingsListPage.qml} (98%) rename nymea-app/ui/devicelistpages/{GenericDeviceListPage.qml => GenericThingsListPage.qml} (99%) rename nymea-app/ui/devicelistpages/{LightsDeviceListPage.qml => LightThingsListPage.qml} (95%) rename nymea-app/ui/devicelistpages/{DeviceListPageBase.qml => ThingsListPageBase.qml} (94%) rename nymea-app/ui/devicepages/{AwningDevicePage.qml => AwningThingPage.qml} (87%) rename nymea-app/ui/devicepages/{ButtonDevicePage.qml => ButtonThingPage.qml} (96%) rename nymea-app/ui/devicepages/{DevicePageBase.qml => ThingPageBase.qml} (92%) rename nymea-app/ui/magic/{DeviceRulesPage.qml => ThingRulesPage.qml} (89%) diff --git a/androidservice/controlviews/Main.qml b/androidservice/controlviews/Main.qml index ff445f9f..31b032a3 100644 --- a/androidservice/controlviews/Main.qml +++ b/androidservice/controlviews/Main.qml @@ -47,7 +47,7 @@ ApplicationWindow { ThingsProxy { id: thingProxy engine: _engine - filterDeviceId: controlledThingId + filterThingId: controlledThingId } property Thing controlledThing: engine.thingManager.fetchingData ? null : engine.thingManager.things.getThing(controlledThingId) diff --git a/androidservice/nymeaappservice/androidbinder.cpp b/androidservice/nymeaappservice/androidbinder.cpp index b0213fc5..cb81a8cb 100644 --- a/androidservice/nymeaappservice/androidbinder.cpp +++ b/androidservice/nymeaappservice/androidbinder.cpp @@ -1,6 +1,6 @@ #include "androidbinder.h" #include "engine.h" -#include "types/device.h" +#include "types/thing.h" #include #include diff --git a/libnymea-app/devicemanager.cpp b/libnymea-app/devicemanager.cpp deleted file mode 100644 index 10ec3910..00000000 --- a/libnymea-app/devicemanager.cpp +++ /dev/null @@ -1,786 +0,0 @@ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -* -* Copyright 2013 - 2020, nymea GmbH -* Contact: contact@nymea.io -* -* This file is part of nymea. -* This project including source code and documentation is protected by -* copyright law, and remains the property of nymea GmbH. All rights, including -* reproduction, publication, editing and translation, are reserved. The use of -* this project is subject to the terms of a license agreement to be concluded -* with nymea GmbH in accordance with the terms of use of nymea GmbH, available -* under https://nymea.io/license -* -* GNU General Public License Usage -* Alternatively, this project may be redistributed and/or modified under the -* terms of the GNU General Public License as published by the Free Software -* Foundation, GNU version 3. This project is distributed in the hope that it -* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty -* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General -* Public License for more details. -* -* You should have received a copy of the GNU General Public License along with -* this project. If not, see . -* -* For any further details and any questions please contact us under -* contact@nymea.io or see our FAQ/Licensing Information on -* https://nymea.io/license/faq -* -* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - -#include "devicemanager.h" -#include "engine.h" -#include "jsonrpc/jsontypes.h" -#include "types/browseritems.h" -#include "types/browseritem.h" -#include "thinggroup.h" -#include "types/interface.h" -#include "types/ioconnections.h" - -#include -#include -#include - -DeviceManager::DeviceManager(JsonRpcClient* jsonclient, QObject *parent) : - JsonHandler(parent), - m_vendors(new Vendors(this)), - m_plugins(new Plugins(this)), - m_devices(new Devices(this)), - m_thingClasses(new DeviceClasses(this)), - m_ioConnections(new IOConnections(this)), - m_jsonClient(jsonclient) -{ - m_jsonClient->registerNotificationHandler(this, "notificationReceived"); -} - -void DeviceManager::clear() -{ - m_devices->clearModel(); - m_thingClasses->clearModel(); - m_vendors->clearModel(); - m_plugins->clearModel(); - m_ioConnections->clearModel(); -} - -void DeviceManager::init() -{ - m_connectionBenchmark = QDateTime::currentDateTime(); - - // For old nymea setups we need to register to Events.Notifications. - // Deprecated since JSONRPC 4.0/nymea 0.17 - if (!m_jsonClient->ensureServerVersion("4.0")) { - if (!m_eventHandler) { - m_eventHandler = new EventHandler(this); - m_jsonClient->registerNotificationHandler(m_eventHandler, "notificationReceived"); - connect(m_eventHandler, &EventHandler::eventReceived, this, [this](const QVariantMap event) { - QUuid deviceId = event.value("deviceId").toUuid(); - QUuid eventTypeId = event.value("eventTypeId").toUuid(); - - Device *dev = m_devices->getDevice(deviceId); - if (!dev) { - qWarning() << "received an event from a device we don't know..." << deviceId << event; - return; - } -// qDebug() << "Event received" << deviceId.toString() << eventTypeId.toString() << qUtf8Printable(QJsonDocument::fromVariant(event).toJson()); - dev->eventTriggered(eventTypeId.toString(), event.value("params").toMap()); - emit eventTriggered(deviceId.toString(), eventTypeId.toString(), event.value("params").toMap()); - }); - } - } else { - if (m_eventHandler) { - m_jsonClient->unregisterNotificationHandler(m_eventHandler); - m_eventHandler->deleteLater(); - m_eventHandler = nullptr; - } - } - - // Register a custom notification handler for the Integrations namespace for now. - if (m_jsonClient->ensureServerVersion("5.1")) { - if (!m_integrationsHandler) { - m_integrationsHandler = new IntegrationsHandler(this); - m_jsonClient->registerNotificationHandler(m_integrationsHandler, "notificationReceived"); - connect(m_integrationsHandler, &IntegrationsHandler::onNotificationReceived, this, [this](const QVariantMap ¶ms){ - notificationReceived(params); - }); - } - } - - m_fetchingData = true; - emit fetchingDataChanged(); - - m_jsonClient->sendCommand("Devices.GetSupportedDevices", this, "getSupportedDevicesResponse"); -} - -QString DeviceManager::nameSpace() const -{ - return "Devices"; -} - -Vendors *DeviceManager::vendors() const -{ - return m_vendors; -} - -Plugins *DeviceManager::plugins() const -{ - return m_plugins; -} - -Devices *DeviceManager::devices() const -{ - return m_devices; -} - -Devices *DeviceManager::things() const -{ - return m_devices; -} - -DeviceClasses *DeviceManager::deviceClasses() const -{ - return m_thingClasses; -} - -DeviceClasses *DeviceManager::thingClasses() const -{ - return m_thingClasses; -} - -IOConnections *DeviceManager::ioConnections() const -{ - return m_ioConnections; -} - -bool DeviceManager::fetchingData() const -{ - return m_fetchingData; -} - -int DeviceManager::addDevice(const QUuid &deviceClassId, const QString &name, const QVariantList &deviceParams) -{ - qDebug() << "add device " << deviceClassId.toString(); - QVariantMap params; - params.insert("deviceClassId", deviceClassId.toString()); - params.insert("name", name); - params.insert("deviceParams", deviceParams); - return m_jsonClient->sendCommand("Devices.AddConfiguredDevice", params, this, "addDeviceResponse"); -} - -void DeviceManager::notificationReceived(const QVariantMap &data) -{ - QString notification = data.value("notification").toString(); - if (notification == "Devices.StateChanged") { - Device *dev = m_devices->getDevice(data.value("params").toMap().value("deviceId").toUuid()); - if (!dev) { - qWarning() << "Device state change notification received for an unknown device"; - return; - } - QUuid stateTypeId = data.value("params").toMap().value("stateTypeId").toUuid(); - QVariant value = data.value("params").toMap().value("value"); -// qDebug() << "Device state changed for:" << dev->name() << "State name:" << dev->thingClass()->stateTypes()->getStateType(stateTypeId) << "value:" << value; - dev->setStateValue(stateTypeId, value); - emit thingStateChanged(dev->id(), stateTypeId, value); - } else if (notification == "Devices.DeviceAdded") { - Device *dev = JsonTypes::unpackDevice(this, data.value("params").toMap().value("device").toMap(), m_thingClasses); - if (!dev) { - qWarning() << "Cannot parse json device:" << data; - return; - } - DeviceClass *dc = deviceClasses()->getDeviceClass(dev->deviceClassId()); - if (!dc) { - qWarning() << "Skipping invalid device. Don't have a device class for it"; - delete dev; - return; - } - m_devices->addDevice(dev); - } else if (notification == "Devices.DeviceRemoved") { - QUuid deviceId = data.value("params").toMap().value("deviceId").toUuid(); -// qDebug() << "JsonRpc: Notification: Device removed" << deviceId.toString(); - Device *thing = m_devices->getDevice(deviceId); - if (!thing) { - qWarning() << "Received a DeviceRemoved notification for a device we don't know!"; - return; - } - m_devices->removeThing(thing); - thing->deleteLater(); - } else if (notification == "Devices.DeviceChanged") { - QUuid deviceId = data.value("params").toMap().value("device").toMap().value("id").toUuid(); -// qDebug() << "Device changed notification" << deviceId << data.value("params").toMap(); - Device *oldDevice = m_devices->getDevice(deviceId); - if (!oldDevice) { - qWarning() << "Received a device changed notification for a device we don't know"; - return; - } - if (!JsonTypes::unpackDevice(this, data.value("params").toMap().value("device").toMap(), m_thingClasses, oldDevice)) { - qWarning() << "Error parsing device changed notification"; - return; - } - } else if (notification == "Devices.DeviceSettingChanged") { - QUuid deviceId = data.value("params").toMap().value("deviceId").toUuid(); - QString paramTypeId = data.value("params").toMap().value("paramTypeId").toString(); - QVariant value = data.value("params").toMap().value("value"); -// qDebug() << "Device settings changed notification for device" << deviceId << data.value("params").toMap().value("settings").toList(); - Device *dev = m_devices->getDevice(deviceId); - if (!dev) { - qWarning() << "Device settings changed notification for a device we don't know" << deviceId.toString(); - return; - } - Param *p = dev->settings()->getParam(paramTypeId); - if (!p) { - qWarning() << "Device" << dev->name() << dev->id().toString() << "does not have a setting of id" << paramTypeId; - return; - } - p->setValue(value); - } else if (notification == "Devices.EventTriggered") { - QVariantMap event = data.value("params").toMap().value("event").toMap(); - QUuid deviceId = event.value("deviceId").toUuid(); - QUuid eventTypeId = event.value("eventTypeId").toUuid(); - - Device *dev = m_devices->getDevice(deviceId); - if (!dev) { - qWarning() << "received an event from a device we don't know..." << deviceId << qUtf8Printable(QJsonDocument::fromVariant(data).toJson()); - return; - } -// qDebug() << "Event received" << deviceId.toString() << eventTypeId.toString() << qUtf8Printable(QJsonDocument::fromVariant(event).toJson()); - dev->eventTriggered(eventTypeId.toString(), event.value("params").toMap()); - } else if (notification == "Integrations.IOConnectionAdded") { - QVariantMap connectionMap = data.value("params").toMap().value("ioConnection").toMap(); - QUuid id = connectionMap.value("id").toUuid(); - QUuid inputThingId = connectionMap.value("inputThingId").toUuid(); - QUuid inputStateTypeId = connectionMap.value("inputStateTypeId").toUuid(); - QUuid outputThingId = connectionMap.value("outputThingId").toUuid(); - QUuid outputStateTypeId = connectionMap.value("outputStateTypeId").toUuid(); - bool inverted = connectionMap.value("inverted").toBool(); - IOConnection *ioConnection = new IOConnection(id, inputThingId, inputStateTypeId, outputThingId, outputStateTypeId, inverted); - m_ioConnections->addIOConnection(ioConnection); - } else if (notification == "Integrations.IOConnectionRemoved") { - QUuid connectionId = data.value("params").toMap().value("ioConnectionId").toUuid(); - if (!m_ioConnections->getIOConnection(connectionId)) { - qWarning() << "Received an IO connection removed event for an IO connection we don't know."; - return; - } - m_ioConnections->removeIOConnection(connectionId); - } else if (notification == "Integrations.EventTriggered") { - // Still using Devices.EventTriggered - } else if (notification == "Integrations.StateChanged") { - // Still using Devies.StateChanged - } else { - qWarning() << "DeviceManager unhandled device notification received" << notification; - } -} - -void DeviceManager::getVendorsResponse(int /*commandId*/, const QVariantMap ¶ms) -{ -// qDebug() << "Got GetSupportedVendors response" << params; - if (params.keys().contains("vendors")) { - QVariantList vendorList = params.value("vendors").toList(); - foreach (QVariant vendorVariant, vendorList) { - Vendor *vendor = JsonTypes::unpackVendor(vendorVariant.toMap()); - m_vendors->addVendor(vendor); -// qDebug() << "Added Vendor:" << vendor->name(); - } - } -} - -void DeviceManager::getSupportedDevicesResponse(int /*commandId*/, const QVariantMap ¶ms) -{ -// qDebug() << "DeviceClasses received:" << qUtf8Printable(QJsonDocument::fromVariant(params).toJson(QJsonDocument::Indented)); - if (params.keys().contains("deviceClasses")) { - QVariantList deviceClassList = params.value("deviceClasses").toList(); - foreach (QVariant deviceClassVariant, deviceClassList) { - DeviceClass *deviceClass = JsonTypes::unpackDeviceClass(deviceClassVariant.toMap(), deviceClasses()); - m_thingClasses->addDeviceClass(deviceClass); - } - } - m_jsonClient->sendCommand("Devices.GetConfiguredDevices", this, "getConfiguredDevicesResponse"); -} - -void DeviceManager::getPluginsResponse(int /*commandId*/, const QVariantMap ¶ms) -{ -// qDebug() << "received plugins"; - if (params.keys().contains("plugins")) { - QVariantList pluginList = params.value("plugins").toList(); - foreach (QVariant pluginVariant, pluginList) { - Plugin *plugin = JsonTypes::unpackPlugin(pluginVariant.toMap(), plugins()); - m_plugins->addPlugin(plugin); - } - } - m_jsonClient->sendCommand("Devices.GetSupportedVendors", this, "getVendorsResponse"); - - if (m_plugins->count() > 0) { - m_currentGetConfigIndex = 0; - QVariantMap configRequestParams; - configRequestParams.insert("pluginId", m_plugins->get(m_currentGetConfigIndex)->pluginId()); - m_jsonClient->sendCommand("Devices.GetPluginConfiguration", configRequestParams, this, "getPluginConfigResponse"); - } -} - -void DeviceManager::getPluginConfigResponse(int /*commandId*/, const QVariantMap ¶ms) -{ -// qDebug() << "plugin config response" << params; - Plugin *p = m_plugins->get(m_currentGetConfigIndex); - if (!p) { - qDebug() << "Received a plugin config for a plugin we don't know"; - return; - } - QVariantList pluginParams = params.value("configuration").toList(); - foreach (const QVariant ¶mVariant, pluginParams) { - Param* param = new Param(); - JsonTypes::unpackParam(paramVariant.toMap(), param); - p->params()->addParam(param); - } - - m_currentGetConfigIndex++; - if (m_plugins->count() > m_currentGetConfigIndex) { - QVariantMap configRequestParams; - configRequestParams.insert("pluginId", m_plugins->get(m_currentGetConfigIndex)->pluginId()); - m_jsonClient->sendCommand("Devices.GetPluginConfiguration", configRequestParams, this, "getPluginConfigResponse"); - } -} - -void DeviceManager::getConfiguredDevicesResponse(int /*commandId*/, const QVariantMap ¶ms) -{ - if (params.keys().contains("devices")) { - QVariantList deviceList = params.value("devices").toList(); - foreach (QVariant deviceVariant, deviceList) { - Device *device = JsonTypes::unpackDevice(this, deviceVariant.toMap(), m_thingClasses); - if (!device) { - qWarning() << "Error unpacking device" << deviceVariant.toMap().value("name").toString(); - continue; - } - - // set initial state values - QVariantList stateVariantList = deviceVariant.toMap().value("states").toList(); - foreach (const QVariant &stateMap, stateVariantList) { - QString stateTypeId = stateMap.toMap().value("stateTypeId").toString(); - StateType *st = device->thingClass()->stateTypes()->getStateType(stateTypeId); - if (!st) { - qWarning() << "Can't find a statetype for this state"; - continue; - } - QVariant value = stateMap.toMap().value("value"); - if (st->type() == "Bool") { - value.convert(QVariant::Bool); - } else if (st->type() == "Double") { - value.convert(QVariant::Double); - } else if (st->type() == "Int") { - value.convert(QVariant::Int); - } - device->setStateValue(stateTypeId, value); -// qDebug() << "Set device state value:" << device->stateValue(stateTypeId) << value; - } -// qDebug() << "Configured Device JSON:" << qUtf8Printable(QJsonDocument::fromVariant(deviceVariant).toJson(QJsonDocument::Indented)); - devices()->addDevice(device); -// qDebug() << "*** Added device:" << endl << device; - } - } - qDebug() << "Initializing thing manager took" << m_connectionBenchmark.msecsTo(QDateTime::currentDateTime()) << "ms"; - m_fetchingData = false; - emit fetchingDataChanged(); - - m_jsonClient->sendCommand("Integrations.GetIOConnections", this, "getIOConnectionsResponse"); - - m_jsonClient->sendCommand("Devices.GetPlugins", this, "getPluginsResponse"); -} - -void DeviceManager::addDeviceResponse(int commandId, const QVariantMap ¶ms) -{ - if (params.value("deviceError").toString() != "DeviceErrorNoError") { - qWarning() << "Failed to add the device:" << params.value("deviceError").toString(); - } else if (params.keys().contains("device")) { - QVariantMap deviceVariant = params.value("device").toMap(); - Device *device = JsonTypes::unpackDevice(this, deviceVariant, m_thingClasses); - if (!device) { - qWarning() << "Couldn't parse json in addDeviceResponse"; - return; - } - - qDebug() << "Device added" << device->id().toString(); - m_devices->addDevice(device); - } - emit addDeviceReply(commandId, params); -} - -void DeviceManager::removeThingResponse(int commandId, const QVariantMap ¶ms) -{ - qDebug() << "Thing removed response" << params; - emit removeThingReply(commandId, params); -} - -void DeviceManager::pairDeviceResponse(int commandId, const QVariantMap ¶ms) -{ - qDebug() << "Pair device response:" << params; - emit pairDeviceReply(commandId, params); -} - -void DeviceManager::confirmPairingResponse(int commandId, const QVariantMap ¶ms) -{ - qDebug() << "ConfirmPairingResponse" << params; - emit confirmPairingReply(commandId, params); -} - -void DeviceManager::setPluginConfigResponse(int commandId, const QVariantMap ¶ms) -{ - qDebug() << "set plugin config response" << params; - emit savePluginConfigReply(commandId, params); -} - -void DeviceManager::editThingResponse(int commandId, const QVariantMap ¶ms) -{ - qDebug() << "Edit thing response" << params; - emit editThingReply(commandId, params); -} - -void DeviceManager::executeActionResponse(int commandId, const QVariantMap ¶ms) -{ - qDebug() << "Execute Action response" << params; - emit executeActionReply(commandId, params); -} - -void DeviceManager::reconfigureDeviceResponse(int commandId, const QVariantMap ¶ms) -{ - qDebug() << "Reconfigure device response" << params; - emit reconfigureDeviceReply(commandId, params); -} - -int DeviceManager::savePluginConfig(const QUuid &pluginId) -{ - Plugin *p = m_plugins->getPlugin(pluginId); - if (!p) { - qWarning()<< "Error: can't find plugin with id" << pluginId; - return -1; - } - QVariantMap params; - params.insert("pluginId", pluginId); - QVariantList pluginParams; - for (int i = 0; i < p->params()->rowCount(); i++) { - pluginParams.append(JsonTypes::packParam(p->params()->get(i))); - } - params.insert("configuration", pluginParams); - return m_jsonClient->sendCommand("Devices.SetPluginConfiguration", params, this, "setPluginConfigResponse"); -} - -ThingGroup *DeviceManager::createGroup(Interface *interface, DevicesProxy *things) -{ - ThingGroup* group = new ThingGroup(this, interface->createDeviceClass(), things, this); - group->setSetupStatus(Device::ThingSetupStatusComplete, QString()); - return group; -} - -int DeviceManager::addDiscoveredDevice(const QUuid &deviceClassId, const QUuid &deviceDescriptorId, const QString &name, const QVariantList &deviceParams) -{ - qDebug() << "JsonRpc: add discovered device " << deviceClassId.toString(); - QVariantMap params; - params.insert("deviceClassId", deviceClassId.toString()); - params.insert("name", name); - params.insert("deviceDescriptorId", deviceDescriptorId.toString()); - params.insert("deviceParams", deviceParams); - return m_jsonClient->sendCommand("Devices.AddConfiguredDevice", params, this, "addDeviceResponse"); -} - -int DeviceManager::pairDiscoveredDevice(const QUuid &deviceClassId, const QUuid &deviceDescriptorId, const QVariantList &deviceParams, const QString &name) -{ - qDebug() << "JsonRpc: pair discovered device " << deviceDescriptorId.toString(); - QVariantMap params; - params.insert("deviceDescriptorId", deviceDescriptorId.toString()); - params.insert("deviceParams", deviceParams); - params.insert("name", name); - - if (!m_jsonClient->ensureServerVersion("3.2")) { - params.insert("deviceClassId", deviceClassId); - } - - return m_jsonClient->sendCommand("Devices.PairDevice", params, this, "pairDeviceResponse"); -} - -int DeviceManager::pairDevice(const QUuid &deviceClassId, const QVariantList &deviceParams, const QString &name) -{ - qDebug() << "JsonRpc: pair device " << deviceClassId.toString(); - QVariantMap params; - params.insert("deviceClassId", deviceClassId.toString()); - params.insert("deviceParams", deviceParams); - params.insert("name", name); - return m_jsonClient->sendCommand("Devices.PairDevice", params, this, "pairDeviceResponse"); -} - -int DeviceManager::rePairDevice(const QUuid &deviceId, const QVariantList &deviceParams, const QString &name) -{ - qDebug() << "JsonRpc: pair device (reconfigure)" << deviceId; - QVariantMap params; - params.insert("deviceId", deviceId.toString()); - params.insert("deviceParams", deviceParams); - if (!name.isEmpty()) { - params.insert("name", name); - } - return m_jsonClient->sendCommand("Devices.PairDevice", params, this, "pairDeviceResponse"); -} - -int DeviceManager::confirmPairing(const QUuid &pairingTransactionId, const QString &secret, const QString &username) -{ - qDebug() << "JsonRpc: confirm pairing" << pairingTransactionId.toString(); - QVariantMap params; - params.insert("pairingTransactionId", pairingTransactionId.toString()); - params.insert("secret", secret); - if (!username.isEmpty()) { - params.insert("username", username); - } - return m_jsonClient->sendCommand("Devices.ConfirmPairing", params, this, "confirmPairingResponse"); -} - -int DeviceManager::removeThing(const QUuid &thingId, DeviceManager::RemovePolicy policy) -{ - qDebug() << "JsonRpc: delete device" << thingId.toString(); - QVariantMap params; - params.insert("deviceId", thingId.toString()); - if (policy != RemovePolicyNone) { - QMetaEnum policyEnum = QMetaEnum::fromType(); - params.insert("removePolicy", policyEnum.valueToKey(policy)); - } - return m_jsonClient->sendCommand("Devices.RemoveConfiguredDevice", params, this, "removeThingResponse"); -} - -int DeviceManager::editThing(const QUuid &thingId, const QString &name) -{ - QVariantMap params; - params.insert("deviceId", thingId.toString()); - params.insert("name", name); - return m_jsonClient->sendCommand("Devices.EditDevice", params, this, "editThingResponse"); -} - -int DeviceManager::setDeviceSettings(const QUuid &deviceId, const QVariantList &settings) -{ - QVariantMap params; - params.insert("deviceId", deviceId); - params.insert("settings", settings); - return m_jsonClient->sendCommand("Devices.SetDeviceSettings", params); -} - -int DeviceManager::reconfigureDevice(const QUuid &deviceId, const QVariantList &deviceParams) -{ - QVariantMap params; - params.insert("deviceId", deviceId.toString()); - params.insert("deviceParams", deviceParams); - return m_jsonClient->sendCommand("Devices.ReconfigureDevice", params, this, "reconfigureDeviceResponse"); -} - -int DeviceManager::reconfigureDiscoveredDevice(const QUuid &deviceId, const QUuid &deviceDescriptorId, const QVariantList ¶mOverride) -{ - QVariantMap params; - params.insert("deviceId", deviceId.toString()); - params.insert("deviceDescriptorId", deviceDescriptorId); - if (!paramOverride.isEmpty()) { - params.insert("deviceParams", paramOverride); - } - qDebug() << "Calling ReconfigureDevice" << qUtf8Printable(QJsonDocument::fromVariant(params).toJson()); - return m_jsonClient->sendCommand("Devices.ReconfigureDevice", params, this, "reconfigureDeviceResponse"); -} - -int DeviceManager::executeAction(const QUuid &deviceId, const QUuid &actionTypeId, const QVariantList ¶ms) -{ -// qDebug() << "JsonRpc: execute action " << deviceId.toString() << actionTypeId.toString() << params; - QVariantMap p; - p.insert("deviceId", deviceId.toString()); - p.insert("actionTypeId", actionTypeId.toString()); - if (!params.isEmpty()) { - p.insert("params", params); - } - QString method = m_jsonClient->ensureServerVersion("4.0") ? "Devices.ExecuteAction" : "Actions.ExecuteAction"; - - return m_jsonClient->sendCommand(method, p, this, "executeActionResponse"); -} - -BrowserItems *DeviceManager::browseDevice(const QUuid &deviceId, const QString &itemId) -{ - QVariantMap params; - params.insert("deviceId", deviceId.toString()); - params.insert("itemId", itemId); - int id = m_jsonClient->sendCommand("Devices.BrowseDevice", params, this, "browseDeviceResponse"); - - // Intentionally not parented. The caller takes ownership and needs to destroy when not needed any more. - BrowserItems *itemModel = new BrowserItems(deviceId, itemId); - itemModel->setBusy(true); - QPointer itemModelPtr(itemModel); - m_browsingRequests.insert(id, itemModelPtr); - - return itemModel; -} - -void DeviceManager::refreshBrowserItems(BrowserItems *browserItems) -{ - QVariantMap params; - params.insert("deviceId", browserItems->deviceId().toString()); - params.insert("itemId", browserItems->itemId()); - int id = m_jsonClient->sendCommand("Devices.BrowseDevice", params, this, "browseDeviceResponse"); - - // Intentionally not parented. The caller takes ownership and needs to destroy when not needed any more. - browserItems->setBusy(true); - QPointer itemModelPtr(browserItems); - m_browsingRequests.insert(id, browserItems); -} - -BrowserItem *DeviceManager::browserItem(const QUuid &deviceId, const QString &itemId) -{ - QVariantMap params; - params.insert("deviceId", deviceId.toString()); - params.insert("itemId", itemId); - int id = m_jsonClient->sendCommand("Devices.GetBrowserItem", params, this, "browserItemResponse"); - - // Intentionally not parented. The caller takes ownership and needs to destroy when not needed any more. - BrowserItem *item = new BrowserItem(itemId); - QPointer itemPtr(item); - m_browserDetailsRequests.insert(id, itemPtr); - - return item; -} - -void DeviceManager::browseDeviceResponse(int commandId, const QVariantMap ¶ms) -{ -// qDebug() << "Browsing response:" << qUtf8Printable(QJsonDocument::fromVariant(params).toJson(QJsonDocument::Indented)); - if (!m_browsingRequests.contains(commandId)) { - qWarning() << "Received a browsing reply for an id we don't know."; - return; - } - - QPointer itemModel = m_browsingRequests.take(commandId); - if (!itemModel) { - qDebug() << "BrowserItems model seems to have disappeared. Discarding browsing result."; - return; - } - - QList itemsToRemove = itemModel->list(); - - foreach (const QVariant &itemVariant, params.value("items").toList()) { - QVariantMap itemMap = itemVariant.toMap(); - QString itemId = itemMap.value("id").toString(); - BrowserItem *item = itemModel->getBrowserItem(itemId); - if (!item) { - item = new BrowserItem(itemId, this); - itemModel->addBrowserItem(item); - } - item->setDisplayName(itemMap.value("displayName").toString()); - item->setDescription(itemMap.value("description").toString()); - item->setIcon(itemMap.value("icon").toString()); - item->setThumbnail(itemMap.value("thumbnail").toString()); - item->setExecutable(itemMap.value("executable").toBool()); - item->setBrowsable(itemMap.value("browsable").toBool()); - item->setDisabled(itemMap.value("disabled").toBool()); - item->setActionTypeIds(itemMap.value("actionTypeIds").toStringList()); - - item->setMediaIcon(itemMap.value("mediaIcon").toString()); - - if (itemsToRemove.contains(item)) { - itemsToRemove.removeAll(item); - } - } - - while (!itemsToRemove.isEmpty()) { - BrowserItem *item = itemsToRemove.takeFirst(); - itemModel->removeItem(item); - } - - itemModel->setBusy(false); -} - -void DeviceManager::browserItemResponse(int commandId, const QVariantMap ¶ms) -{ - qDebug() << "Browser item details response:" << qUtf8Printable(QJsonDocument::fromVariant(params).toJson(QJsonDocument::Indented)); - if (!m_browserDetailsRequests.contains(commandId)) { - qWarning() << "Received a browser item details reply for an id we don't know."; - return; - } - - QPointer item = m_browserDetailsRequests.take(commandId); - if (!item) { - qDebug() << "BrowserItem seems to have disappeared. Discarding browser item details result."; - return; - } - - QVariantMap itemMap = params.value("item").toMap(); - item->setDisplayName(itemMap.value("displayName").toString()); - item->setDescription(itemMap.value("description").toString()); - item->setIcon(itemMap.value("icon").toString()); - item->setThumbnail(itemMap.value("thumbnail").toString()); - item->setExecutable(itemMap.value("executable").toBool()); - item->setBrowsable(itemMap.value("browsable").toBool()); - item->setDisabled(itemMap.value("disabled").toBool()); - item->setActionTypeIds(itemMap.value("actionTypeIds").toStringList()); - - item->setMediaIcon(itemMap.value("mediaIcon").toString()); -} - -int DeviceManager::executeBrowserItem(const QUuid &deviceId, const QString &itemId) -{ - QVariantMap params; - params.insert("thingId", deviceId); - params.insert("itemId", itemId); - return m_jsonClient->sendCommand("Integrations.ExecuteBrowserItem", params, this, "executeBrowserItemResponse"); -} - -void DeviceManager::executeBrowserItemResponse(int commandId, const QVariantMap ¶ms) -{ - qDebug() << "Execute Browser Item finished" << params; - emit executeBrowserItemReply(commandId, params); -} - -int DeviceManager::executeBrowserItemAction(const QUuid &deviceId, const QString &itemId, const QUuid &actionTypeId, const QVariantList ¶ms) -{ - QVariantMap data; - data.insert("thingId", deviceId); - data.insert("itemId", itemId); - data.insert("actionTypeId", actionTypeId); - data.insert("params", params); - qDebug() << "params:" << params; - return m_jsonClient->sendCommand("Integrations.ExecuteBrowserItemAction", data, this, "executeBrowserItemActionResponse"); -} - -int DeviceManager::connectIO(const QUuid &inputThingId, const QUuid &inputStateTypeId, const QUuid &outputThingId, const QUuid &outputStateTypeId, bool inverted) -{ - QVariantMap data; - data.insert("inputThingId", inputThingId); - data.insert("inputStateTypeId", inputStateTypeId); - data.insert("outputThingId", outputThingId); - data.insert("outputStateTypeId", outputStateTypeId); - data.insert("inverted", inverted); - return m_jsonClient->sendCommand("Integrations.ConnectIO", data, this, "connectIOResponse"); -} - -int DeviceManager::disconnectIO(const QUuid &ioConnectionId) -{ - QVariantMap data; - data.insert("ioConnectionId", ioConnectionId); - return m_jsonClient->sendCommand("Integrations.DisconnectIO", data, this, "disconnectIOResponse"); -} - -void DeviceManager::executeBrowserItemActionResponse(int commandId, const QVariantMap ¶ms) -{ - qDebug() << "Execute Browser Item Action finished" << params; - emit executeBrowserItemActionReply(commandId, params); -} - -void DeviceManager::getIOConnectionsResponse(int /*commandId*/, const QVariantMap ¶ms) -{ -// qDebug() << "Get IO connections response" << qUtf8Printable(QJsonDocument::fromVariant(params).toJson()); - - foreach (const QVariant &connectionVariant, params.value("ioConnections").toList()) { - QVariantMap connectionMap = connectionVariant.toMap(); - QUuid id = connectionMap.value("id").toUuid(); - QUuid inputThingId = connectionMap.value("inputThingId").toUuid(); - QUuid inputStateTypeId = connectionMap.value("inputStateTypeId").toUuid(); - QUuid outputThingId = connectionMap.value("outputThingId").toUuid(); - QUuid outputStateTypeId = connectionMap.value("outputStateTypeId").toUuid(); - bool inverted = connectionMap.value("inverted").toBool(); - IOConnection *ioConnection = new IOConnection(id, inputThingId, inputStateTypeId, outputThingId, outputStateTypeId, inverted); - m_ioConnections->addIOConnection(ioConnection); - } -} - -void DeviceManager::connectIOResponse(int commandId, const QVariantMap ¶ms) -{ - qDebug() << "ConnectIO response" << commandId << qUtf8Printable(QJsonDocument::fromVariant(params).toJson()); -} - -void DeviceManager::disconnectIOResponse(int commandId, const QVariantMap ¶ms) -{ - qDebug() << "DisconnectIO response" << commandId << qUtf8Printable(QJsonDocument::fromVariant(params).toJson()); -} - diff --git a/libnymea-app/engine.cpp b/libnymea-app/engine.cpp index 771e2cf1..db5f73c1 100644 --- a/libnymea-app/engine.cpp +++ b/libnymea-app/engine.cpp @@ -42,7 +42,7 @@ Engine::Engine(QObject *parent) : QObject(parent), m_jsonRpcClient(new JsonRpcClient(this)), - m_thingManager(new DeviceManager(m_jsonRpcClient, this)), + m_thingManager(new ThingManager(m_jsonRpcClient, this)), m_ruleManager(new RuleManager(m_jsonRpcClient, this)), m_scriptManager(new ScriptManager(m_jsonRpcClient, this)), m_logManager(new LogManager(m_jsonRpcClient, this)), @@ -53,7 +53,7 @@ Engine::Engine(QObject *parent) : connect(m_jsonRpcClient, &JsonRpcClient::connectedChanged, this, &Engine::onConnectedChanged); - connect(m_thingManager, &DeviceManager::fetchingDataChanged, this, &Engine::onDeviceManagerFetchingChanged); + connect(m_thingManager, &ThingManager::fetchingDataChanged, this, &Engine::onThingManagerFetchingChanged); connect(m_jsonRpcClient, &JsonRpcClient::connectedChanged, this, [this]() { qDebug() << "JSONRpc connected changed:" << m_jsonRpcClient->connected() << "AWS status:" << AWSClient::instance()->awsDevices()->rowCount(); @@ -72,12 +72,7 @@ Engine::Engine(QObject *parent) : }); } -DeviceManager *Engine::deviceManager() const -{ - return m_thingManager; -} - -DeviceManager *Engine::thingManager() const +ThingManager *Engine::thingManager() const { return m_thingManager; } @@ -147,7 +142,7 @@ void Engine::onConnectedChanged() } } -void Engine::onDeviceManagerFetchingChanged() +void Engine::onThingManagerFetchingChanged() { if (!m_thingManager->fetchingData()) { m_tagsManager->init(); diff --git a/libnymea-app/engine.h b/libnymea-app/engine.h index 07b38c6a..2c884994 100644 --- a/libnymea-app/engine.h +++ b/libnymea-app/engine.h @@ -33,7 +33,7 @@ #include -#include "devicemanager.h" +#include "thingmanager.h" #include "connection/nymeatransportinterface.h" #include "jsonrpc/jsonrpcclient.h" #include "wifisetup/bluetoothdiscovery.h" @@ -49,8 +49,7 @@ class NetworkManager; class Engine : public QObject { Q_OBJECT - Q_PROPERTY(DeviceManager* deviceManager READ deviceManager CONSTANT) - Q_PROPERTY(DeviceManager* thingManager READ thingManager CONSTANT) + Q_PROPERTY(ThingManager* thingManager READ thingManager CONSTANT) Q_PROPERTY(RuleManager* ruleManager READ ruleManager CONSTANT) Q_PROPERTY(ScriptManager* scriptManager READ scriptManager CONSTANT) Q_PROPERTY(TagsManager* tagsManager READ tagsManager CONSTANT) @@ -61,8 +60,7 @@ class Engine : public QObject public: explicit Engine(QObject *parent = nullptr); - DeviceManager *deviceManager() const; - DeviceManager *thingManager() const; + ThingManager *thingManager() const; RuleManager *ruleManager() const; ScriptManager *scriptManager() const; TagsManager *tagsManager() const; @@ -75,7 +73,7 @@ public: private: JsonRpcClient *m_jsonRpcClient; - DeviceManager *m_thingManager; + ThingManager *m_thingManager; RuleManager *m_ruleManager; ScriptManager *m_scriptManager; LogManager *m_logManager; @@ -85,7 +83,7 @@ private: private slots: void onConnectedChanged(); - void onDeviceManagerFetchingChanged(); + void onThingManagerFetchingChanged(); }; diff --git a/libnymea-app/interfacesmodel.cpp b/libnymea-app/interfacesmodel.cpp index f73faa13..87bc49b1 100644 --- a/libnymea-app/interfacesmodel.cpp +++ b/libnymea-app/interfacesmodel.cpp @@ -31,7 +31,7 @@ #include "interfacesmodel.h" #include "engine.h" -#include "devicesproxy.h" +#include "thingsproxy.h" InterfacesModel::InterfacesModel(QObject *parent): QAbstractListModel(parent) @@ -77,7 +77,7 @@ void InterfacesModel::setEngine(Engine *engine) m_engine = engine; emit engineChanged(); - m_thingClassesCountChangedConnection = connect(engine->deviceManager()->deviceClasses(), &DeviceClasses::countChanged, this, [this]() { + m_thingClassesCountChangedConnection = connect(engine->thingManager()->thingClasses(), &ThingClasses::countChanged, this, [this]() { syncInterfaces(); }); @@ -85,12 +85,12 @@ void InterfacesModel::setEngine(Engine *engine) } } -DevicesProxy *InterfacesModel::things() const +ThingsProxy *InterfacesModel::things() const { return m_thingsProxy; } -void InterfacesModel::setThings(DevicesProxy *things) +void InterfacesModel::setThings(ThingsProxy *things) { if (m_thingsProxy != things) { if (m_thingsProxy) { @@ -100,7 +100,7 @@ void InterfacesModel::setThings(DevicesProxy *things) m_thingsProxy = things; emit thingsChanged(); - m_thingsCountChangedConnection = connect(things, &DevicesProxy::countChanged, this, [this]() { + m_thingsCountChangedConnection = connect(things, &ThingsProxy::countChanged, this, [this]() { syncInterfaces(); }); syncInterfaces(); @@ -149,20 +149,20 @@ void InterfacesModel::syncInterfaces() if (!m_engine) { return; } - QList deviceClasses; + QList thingClasses; if (m_thingsProxy) { for (int i = 0; i < m_thingsProxy->rowCount(); i++) { - deviceClasses << m_engine->deviceManager()->deviceClasses()->getDeviceClass(m_thingsProxy->get(i)->deviceClassId()); + thingClasses << m_engine->thingManager()->thingClasses()->getThingClass(m_thingsProxy->get(i)->thingClassId()); } } else { - for (int i = 0; i < m_engine->deviceManager()->deviceClasses()->rowCount(); i++) { - deviceClasses << m_engine->deviceManager()->deviceClasses()->get(i); + for (int i = 0; i < m_engine->thingManager()->thingClasses()->rowCount(); i++) { + thingClasses << m_engine->thingManager()->thingClasses()->get(i); } } QStringList interfacesInSource; - foreach (DeviceClass *dc, deviceClasses) { -// qDebug() << "device" <name() << "has interfaces" << dc->interfaces(); + foreach (ThingClass *dc, thingClasses) { +// qDebug() << "thing" <name() << "has interfaces" << dc->interfaces(); bool isInShownIfaces = false; foreach (const QString &interface, dc->interfaces()) { @@ -227,7 +227,7 @@ void InterfacesSortModel::setInterfacesModel(InterfacesModel *interfacesModel) m_interfacesModel = interfacesModel; setSourceModel(interfacesModel); connect(interfacesModel, &InterfacesModel::countChanged, this, &InterfacesSortModel::countChanged); - setSortRole(Devices::RoleName); + setSortRole(Things::RoleName); sort(0); emit interfacesModelChanged(); } diff --git a/libnymea-app/interfacesmodel.h b/libnymea-app/interfacesmodel.h index e6fca2e9..1c236404 100644 --- a/libnymea-app/interfacesmodel.h +++ b/libnymea-app/interfacesmodel.h @@ -34,10 +34,10 @@ #include #include -#include "devices.h" +#include "things.h" class Engine; -class DevicesProxy; +class ThingsProxy; class InterfacesModel : public QAbstractListModel { @@ -48,7 +48,7 @@ class InterfacesModel : public QAbstractListModel Q_PROPERTY(Engine* engine READ engine WRITE setEngine NOTIFY engineChanged) // Optional filters - Q_PROPERTY(DevicesProxy* things READ things WRITE setThings NOTIFY thingsChanged) + Q_PROPERTY(ThingsProxy* things READ things WRITE setThings NOTIFY thingsChanged) Q_PROPERTY(QStringList shownInterfaces READ shownInterfaces WRITE setShownInterfaces NOTIFY shownInterfacesChanged) Q_PROPERTY(bool showUncategorized READ showUncategorized WRITE setShowUncategorized NOTIFY showUncategorizedChanged) @@ -67,15 +67,12 @@ public: Engine* engine() const; void setEngine(Engine *engine); - DevicesProxy* things() const; - void setThings(DevicesProxy *things); + ThingsProxy* things() const; + void setThings(ThingsProxy *things); QStringList shownInterfaces() const; void setShownInterfaces(const QStringList &shownInterfaces); - bool onlyConfiguredDevices() const; - void setOnlyConfiguredDevices(bool onlyConfigured); - bool showUncategorized() const; void setShowUncategorized(bool showUncategorized); @@ -86,7 +83,6 @@ signals: void engineChanged(); void thingsChanged(); void shownInterfacesChanged(); - bool onlyConfiguredDevicesChanged(); void showUncategorizedChanged(); private slots: @@ -99,7 +95,7 @@ private: QStringList m_interfaces; - DevicesProxy *m_thingsProxy = nullptr; + ThingsProxy *m_thingsProxy = nullptr; QMetaObject::Connection m_thingsCountChangedConnection; QStringList m_shownInterfaces; diff --git a/libnymea-app/jsonrpc/jsontypes.cpp b/libnymea-app/jsonrpc/jsontypes.cpp deleted file mode 100644 index c825b2cc..00000000 --- a/libnymea-app/jsonrpc/jsontypes.cpp +++ /dev/null @@ -1,477 +0,0 @@ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -* -* Copyright 2013 - 2020, nymea GmbH -* Contact: contact@nymea.io -* -* This file is part of nymea. -* This project including source code and documentation is protected by -* copyright law, and remains the property of nymea GmbH. All rights, including -* reproduction, publication, editing and translation, are reserved. The use of -* this project is subject to the terms of a license agreement to be concluded -* with nymea GmbH in accordance with the terms of use of nymea GmbH, available -* under https://nymea.io/license -* -* GNU General Public License Usage -* Alternatively, this project may be redistributed and/or modified under the -* terms of the GNU General Public License as published by the Free Software -* Foundation, GNU version 3. This project is distributed in the hope that it -* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty -* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General -* Public License for more details. -* -* You should have received a copy of the GNU General Public License along with -* this project. If not, see . -* -* For any further details and any questions please contact us under -* contact@nymea.io or see our FAQ/Licensing Information on -* https://nymea.io/license/faq -* -* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - -#include "jsontypes.h" -#include "engine.h" -#include "types/vendors.h" -#include "deviceclasses.h" -#include "types/params.h" -#include "types/paramtypes.h" -#include "types/rule.h" -#include "types/ruleaction.h" -#include "types/ruleactions.h" -#include "types/eventdescriptor.h" -#include "types/eventdescriptors.h" -#include "types/ruleactionparam.h" -#include "types/ruleactionparams.h" -#include "types/stateevaluator.h" -#include "types/stateevaluators.h" -#include "types/statedescriptor.h" -#include "types/timeeventitem.h" -#include "types/timeeventitems.h" -#include "types/timedescriptor.h" -#include "types/repeatingoption.h" -#include "types/calendaritems.h" -#include "types/calendaritem.h" - -#include - -JsonTypes::JsonTypes(QObject *parent) : - QObject(parent) -{ -} - -Vendor *JsonTypes::unpackVendor(const QVariantMap &vendorMap) -{ - Vendor *v = new Vendor(vendorMap.value("id").toString(), vendorMap.value("name").toString()); - v->setDisplayName(vendorMap.value("displayName").toString()); - return v; -} - -Plugin *JsonTypes::unpackPlugin(const QVariantMap &pluginMap, QObject *parent) -{ - Plugin *plugin = new Plugin(parent); - plugin->setName(pluginMap.value("name").toString()); - plugin->setPluginId(pluginMap.value("id").toUuid()); - ParamTypes *paramTypes = new ParamTypes(plugin); - foreach (QVariant paramType, pluginMap.value("paramTypes").toList()) { - paramTypes->addParamType(JsonTypes::unpackParamType(paramType.toMap(), paramTypes)); - } - plugin->setParamTypes(paramTypes); - return plugin; -} - -DeviceClass *JsonTypes::unpackDeviceClass(const QVariantMap &deviceClassMap, QObject *parent) -{ - DeviceClass *deviceClass = new DeviceClass(parent); - deviceClass->setName(deviceClassMap.value("name").toString()); - deviceClass->setDisplayName(deviceClassMap.value("displayName").toString()); - deviceClass->setId(deviceClassMap.value("id").toUuid()); - deviceClass->setVendorId(deviceClassMap.value("vendorId").toUuid()); - deviceClass->setBrowsable(deviceClassMap.value("browsable").toBool()); - QVariantList createMethodsList = deviceClassMap.value("createMethods").toList(); - QStringList createMethods; - foreach (QVariant method, createMethodsList) { - createMethods.append(method.toString()); - } - deviceClass->setCreateMethods(createMethods); - deviceClass->setSetupMethod(stringToSetupMethod(deviceClassMap.value("setupMethod").toString())); - deviceClass->setInterfaces(deviceClassMap.value("interfaces").toStringList()); - - // ParamTypes - ParamTypes *paramTypes = new ParamTypes(deviceClass); - foreach (QVariant paramType, deviceClassMap.value("paramTypes").toList()) { - paramTypes->addParamType(JsonTypes::unpackParamType(paramType.toMap(), paramTypes)); - } - deviceClass->setParamTypes(paramTypes); - - // SettingsTypes - ParamTypes *settingsTypes = new ParamTypes(deviceClass); - foreach (QVariant settingsType, deviceClassMap.value("settingsTypes").toList()) { - settingsTypes->addParamType(JsonTypes::unpackParamType(settingsType.toMap(), settingsTypes)); - } - deviceClass->setSettingsTypes(settingsTypes); - - // discovery ParamTypes - ParamTypes *discoveryParamTypes = new ParamTypes(deviceClass); - foreach (QVariant paramType, deviceClassMap.value("discoveryParamTypes").toList()) { - discoveryParamTypes->addParamType(JsonTypes::unpackParamType(paramType.toMap(), discoveryParamTypes)); - } - deviceClass->setDiscoveryParamTypes(discoveryParamTypes); - - // StateTypes - StateTypes *stateTypes = new StateTypes(deviceClass); - foreach (QVariant stateType, deviceClassMap.value("stateTypes").toList()) { - stateTypes->addStateType(JsonTypes::unpackStateType(stateType.toMap(), stateTypes)); - } - deviceClass->setStateTypes(stateTypes); - - // EventTypes - EventTypes *eventTypes = new EventTypes(deviceClass); - foreach (QVariant eventType, deviceClassMap.value("eventTypes").toList()) { - eventTypes->addEventType(JsonTypes::unpackEventType(eventType.toMap(), eventTypes)); - } - deviceClass->setEventTypes(eventTypes); - - // ActionTypes - ActionTypes *actionTypes = new ActionTypes(deviceClass); - foreach (QVariant actionType, deviceClassMap.value("actionTypes").toList()) { - actionTypes->addActionType(JsonTypes::unpackActionType(actionType.toMap(), actionTypes)); - } - deviceClass->setActionTypes(actionTypes); - - // BrowserItemActionTypes - ActionTypes *browserItemActionTypes = new ActionTypes(deviceClass); - foreach (QVariant actionType, deviceClassMap.value("browserItemActionTypes").toList()) { - browserItemActionTypes->addActionType(JsonTypes::unpackActionType(actionType.toMap(), actionTypes)); - } - deviceClass->setBrowserItemActionTypes(browserItemActionTypes); - - return deviceClass; -} - -void JsonTypes::unpackParam(const QVariantMap ¶mMap, Param *param) -{ - param->setParamTypeId(paramMap.value("paramTypeId").toString()); - param->setValue(paramMap.value("value")); -} - -ParamType *JsonTypes::unpackParamType(const QVariantMap ¶mTypeMap, QObject *parent) -{ - ParamType *paramType = new ParamType(parent); - paramType->setId(paramTypeMap.value("id").toString()); - paramType->setName(paramTypeMap.value("name").toString()); - paramType->setDisplayName(paramTypeMap.value("displayName").toString()); - paramType->setType(paramTypeMap.value("type").toString()); - paramType->setIndex(paramTypeMap.value("index").toInt()); - paramType->setDefaultValue(paramTypeMap.value("defaultValue")); - paramType->setMinValue(paramTypeMap.value("minValue")); - paramType->setMaxValue(paramTypeMap.value("maxValue")); - paramType->setAllowedValues(paramTypeMap.value("allowedValues").toList()); - paramType->setInputType(stringToInputType(paramTypeMap.value("inputType").toString())); - paramType->setReadOnly(paramTypeMap.value("readOnly").toBool()); - QPair unit = stringToUnit(paramTypeMap.value("unit").toString()); - paramType->setUnit(unit.first); - paramType->setUnitString(unit.second); - return paramType; -} - -StateType *JsonTypes::unpackStateType(const QVariantMap &stateTypeMap, QObject *parent) -{ - StateType *stateType = new StateType(parent); - stateType->setId(stateTypeMap.value("id").toString()); - stateType->setName(stateTypeMap.value("name").toString()); - stateType->setDisplayName(stateTypeMap.value("displayName").toString()); - stateType->setIndex(stateTypeMap.value("index").toInt()); - stateType->setDefaultValue(stateTypeMap.value("defaultValue")); - stateType->setAllowedValues(stateTypeMap.value("possibleValues").toList()); - stateType->setType(stateTypeMap.value("type").toString()); - stateType->setMinValue(stateTypeMap.value("minValue")); - stateType->setMaxValue(stateTypeMap.value("maxValue")); - - QPair unit = stringToUnit(stateTypeMap.value("unit").toString()); - stateType->setUnit(unit.first); - stateType->setUnitString(unit.second); - - QMetaEnum metaEnum = QMetaEnum::fromType(); - Types::IOType ioType = static_cast(metaEnum.keyToValue(stateTypeMap.value("ioType").toByteArray())); - stateType->setIOType(ioType); - - return stateType; -} - -EventType *JsonTypes::unpackEventType(const QVariantMap &eventTypeMap, QObject *parent) -{ - EventType *eventType = new EventType(parent); - eventType->setId(eventTypeMap.value("id").toString()); - eventType->setName(eventTypeMap.value("name").toString()); - eventType->setDisplayName(eventTypeMap.value("displayName").toString()); - eventType->setIndex(eventTypeMap.value("index").toInt()); - ParamTypes *paramTypes = new ParamTypes(eventType); - foreach (QVariant paramType, eventTypeMap.value("paramTypes").toList()) { - paramTypes->addParamType(JsonTypes::unpackParamType(paramType.toMap(), paramTypes)); - } - eventType->setParamTypes(paramTypes); - return eventType; -} - -ActionType *JsonTypes::unpackActionType(const QVariantMap &actionTypeMap, QObject *parent) -{ - ActionType *actionType = new ActionType(parent); - actionType->setId(actionTypeMap.value("id").toString()); - actionType->setName(actionTypeMap.value("name").toString()); - actionType->setDisplayName(actionTypeMap.value("displayName").toString()); - actionType->setIndex(actionTypeMap.value("index").toInt()); - ParamTypes *paramTypes = new ParamTypes(actionType); - foreach (QVariant paramType, actionTypeMap.value("paramTypes").toList()) { - paramTypes->addParamType(JsonTypes::unpackParamType(paramType.toMap(), paramTypes)); - } - actionType->setParamTypes(paramTypes); - return actionType; -} - -Device* JsonTypes::unpackDevice(DeviceManager *deviceManager, const QVariantMap &deviceMap, DeviceClasses *deviceClasses, Device *oldDevice) -{ - QUuid deviceClassId = deviceMap.value("deviceClassId").toUuid(); - DeviceClass *deviceClass = deviceClasses->getDeviceClass(deviceClassId); - if (!deviceClass) { - qWarning() << "Cannot find a device class for this device"; - return nullptr; - } - - QUuid parentDeviceId = deviceMap.value("parentId").toUuid(); - Device *device = nullptr; - if (oldDevice) { - device = oldDevice; - } else { - device = new Device(deviceManager, deviceClass, parentDeviceId); - } - device->setName(deviceMap.value("name").toString()); - device->setId(deviceMap.value("id").toUuid()); - // As of JSONRPC 4.2 setupComplete is deprecated and setupStatus is new - if (deviceMap.contains("setupStatus")) { - QString setupStatus = deviceMap.value("setupStatus").toString(); - QString setupDisplayMessage = deviceMap.value("setupDisplayMessage").toString(); - if (setupStatus == "DeviceSetupStatusNone" || setupStatus == "ThingSetupStatusNone") { - device->setSetupStatus(Device::ThingSetupStatusNone, setupDisplayMessage); - } else if (setupStatus == "DeviceSetupStatusInProgress" || setupStatus == "ThingSetupStatusInProgress") { - device->setSetupStatus(Device::ThingSetupStatusInProgress, setupDisplayMessage); - } else if (setupStatus == "DeviceSetupStatusComplete" || setupStatus == "ThingSetupStatusComplete") { - device->setSetupStatus(Device::ThingSetupStatusComplete, setupDisplayMessage); - } else if (setupStatus == "DeviceSetupStatusFailed" || setupStatus == "ThingSetupStatusFailed") { - device->setSetupStatus(Device::ThingSetupStatusFailed, setupDisplayMessage); - } - } else { - device->setSetupStatus(deviceMap.value("setupComplete").toBool() ? Device::ThingSetupStatusComplete : Device::ThingSetupStatusNone, QString()); - } - - Params *params = device->params(); - if (!params) { - params = new Params(device); - } - foreach (QVariant param, deviceMap.value("params").toList()) { - Param *p = params->getParam(param.toMap().value("paramTypeId").toString()); - if (!p) { - p = new Param(); - params->addParam(p); - } - JsonTypes::unpackParam(param.toMap(), p); - } - device->setParams(params); - - Params *settings = device->settings(); - if (!settings) { - settings = new Params(device); - } - foreach (QVariant setting, deviceMap.value("settings").toList()) { - Param *p = settings->getParam(setting.toMap().value("paramTypeId").toString()); - if (!p) { - p = new Param(); - settings->addParam(p); - } - JsonTypes::unpackParam(setting.toMap(), p); - } - device->setSettings(settings); - - States *states = device->states(); - if (!states) { - states = new States(device); - } - foreach (const QVariant &stateVariant, deviceMap.value("states").toList()) { - State *state = states->getState(stateVariant.toMap().value("stateTypeId").toUuid()); - if (!state) { - state = new State(device->id(), stateVariant.toMap().value("stateTypeId").toUuid(), stateVariant.toMap().value("value"), states); - states->addState(state); - } else { - state->setValue(stateVariant.toMap().value("value")); - } - } - device->setStates(states); - - return device; -} - - - - -QVariantMap JsonTypes::packParam(Param *param) -{ - QVariantMap ret; - ret.insert("paramTypeId", param->paramTypeId()); - ret.insert("value", param->value()); - return ret; -} - -DeviceClass::SetupMethod JsonTypes::stringToSetupMethod(const QString &setupMethodString) -{ - if (setupMethodString == "SetupMethodJustAdd") { - return DeviceClass::SetupMethodJustAdd; - } else if (setupMethodString == "SetupMethodDisplayPin") { - return DeviceClass::SetupMethodDisplayPin; - } else if (setupMethodString == "SetupMethodEnterPin") { - return DeviceClass::SetupMethodEnterPin; - } else if (setupMethodString == "SetupMethodPushButton") { - return DeviceClass::SetupMethodPushButton; - } else if (setupMethodString == "SetupMethodOAuth") { - return DeviceClass::SetupMethodOAuth; - } else if (setupMethodString == "SetupMethodUserAndPassword") { - return DeviceClass::SetupMethodUserAndPassword; - } - return DeviceClass::SetupMethodJustAdd; -} - -QPair JsonTypes::stringToUnit(const QString &unitString) -{ - if (unitString == "UnitNone") { - return QPair(Types::UnitNone, ""); - } else if (unitString == "UnitSeconds") { - return QPair(Types::UnitSeconds, "s"); - } else if (unitString == "UnitMinutes") { - return QPair(Types::UnitMinutes, "m"); - } else if (unitString == "UnitHours") { - return QPair(Types::UnitHours, "h"); - } else if (unitString == "UnitUnixTime") { - return QPair(Types::UnitUnixTime, "datetime"); - } else if (unitString == "UnitMeterPerSecond") { - return QPair(Types::UnitMeterPerSecond, "m/s"); - } else if (unitString == "UnitKiloMeterPerHour") { - return QPair(Types::UnitKiloMeterPerHour, "km/h"); - } else if (unitString == "UnitDegree") { - return QPair(Types::UnitDegree, "°"); - } else if (unitString == "UnitRadiant") { - return QPair(Types::UnitRadiant, "rad"); - } else if (unitString == "UnitDegreeCelsius") { - return QPair(Types::UnitDegreeCelsius, "°C"); - } else if (unitString == "UnitDegreeKelvin") { - return QPair(Types::UnitDegreeKelvin, "°K"); - } else if (unitString == "UnitMired") { - return QPair(Types::UnitMired, "mir"); - } else if (unitString == "UnitMilliBar") { - return QPair(Types::UnitMilliBar, "mbar"); - } else if (unitString == "UnitBar") { - return QPair(Types::UnitBar, "bar"); - } else if (unitString == "UnitPascal") { - return QPair(Types::UnitPascal, "Pa"); - } else if (unitString == "UnitHectoPascal") { - return QPair(Types::UnitHectoPascal, "hPa"); - } else if (unitString == "UnitAtmosphere") { - return QPair(Types::UnitAtmosphere, "atm"); - } else if (unitString == "UnitLumen") { - return QPair(Types::UnitLumen, "lm"); - } else if (unitString == "UnitLux") { - return QPair(Types::UnitLux, "lx"); - } else if (unitString == "UnitCandela") { - return QPair(Types::UnitCandela, "cd"); - } else if (unitString == "UnitMilliMeter") { - return QPair(Types::UnitMilliMeter, "mm"); - } else if (unitString == "UnitCentiMeter") { - return QPair(Types::UnitCentiMeter, "cm"); - } else if (unitString == "UnitMeter") { - return QPair(Types::UnitMeter, "m"); - } else if (unitString == "UnitKiloMeter") { - return QPair(Types::UnitKiloMeter, "km"); - } else if (unitString == "UnitGram") { - return QPair(Types::UnitGram, "g"); - } else if (unitString == "UnitKiloGram") { - return QPair(Types::UnitKiloGram, "kg"); - } else if (unitString == "UnitDezibel") { - return QPair(Types::UnitDezibel, "db"); - } else if (unitString == "UnitBpm") { - return QPair(Types::UnitBpm, "bpm"); - } else if (unitString == "UnitKiloByte") { - return QPair(Types::UnitKiloByte, "kB"); - } else if (unitString == "UnitMegaByte") { - return QPair(Types::UnitMegaByte, "MB"); - } else if (unitString == "UnitGigaByte") { - return QPair(Types::UnitGigaByte, "GB"); - } else if (unitString == "UnitTeraByte") { - return QPair(Types::UnitTeraByte, "TB"); - } else if (unitString == "UnitMilliWatt") { - return QPair(Types::UnitMilliWatt, "mW"); - } else if (unitString == "UnitWatt") { - return QPair(Types::UnitWatt, "W"); - } else if (unitString == "UnitKiloWatt") { - return QPair(Types::UnitKiloWatt, "kW"); - } else if (unitString == "UnitKiloWattHour") { - return QPair(Types::UnitKiloWattHour, "kWh"); - } else if (unitString == "UnitEuroPerMegaWattHour") { - return QPair(Types::UnitEuroPerMegaWattHour, "€/MWh"); - } else if (unitString == "UnitEuroCentPerKiloWattHour") { - return QPair(Types::UnitEuroCentPerKiloWattHour, "ct/kWh"); - } else if (unitString == "UnitPercentage") { - return QPair(Types::UnitPercentage, "%"); - } else if (unitString == "UnitPartsPerMillion") { - return QPair(Types::UnitPartsPerMillion, "ppm"); - } else if (unitString == "UnitEuro") { - return QPair(Types::UnitEuro, "€"); - } else if (unitString == "UnitDollar") { - return QPair(Types::UnitDollar, "$"); - } else if (unitString == "UnitHerz") { // legacy - return QPair(Types::UnitHertz, "Hz"); - } else if (unitString == "UnitHertz") { - return QPair(Types::UnitHertz, "Hz"); - } else if (unitString == "UnitAmpere") { - return QPair(Types::UnitAmpere, "A"); - } else if (unitString == "UnitMilliAmpere") { - return QPair(Types::UnitMilliAmpere, "mA"); - } else if (unitString == "UnitVolt") { - return QPair(Types::UnitVolt, "V"); - } else if (unitString == "UnitMilliVolt") { - return QPair(Types::UnitMilliVolt, "mV"); - } else if (unitString == "UnitVoltAmpere") { - return QPair(Types::UnitVoltAmpere, "VA"); - } else if (unitString == "UnitVoltAmpereReactive") { - return QPair(Types::UnitVoltAmpereReactive, "VAR"); - } else if (unitString == "UnitAmpereHour") { - return QPair(Types::UnitAmpereHour, "Ah"); - } else if (unitString == "UnitMicroSiemensPerCentimeter") { - return QPair(Types::UnitMicroSiemensPerCentimeter, "µS/cm"); - } else if (unitString == "UnitDuration") { - return QPair(Types::UnitDuration, "s"); - } - - return QPair(Types::UnitNone, ""); -} - -Types::InputType JsonTypes::stringToInputType(const QString &inputTypeString) -{ - if (inputTypeString == "InputTypeNone") { - return Types::InputTypeNone; - } else if (inputTypeString == "InputTypeTextLine") { - return Types::InputTypeTextLine; - } else if (inputTypeString == "InputTypeTextArea") { - return Types::InputTypeTextArea; - } else if (inputTypeString == "InputTypePassword") { - return Types::InputTypePassword; - } else if (inputTypeString == "InputTypeSearch") { - return Types::InputTypeSearch; - } else if (inputTypeString == "InputTypeMail") { - return Types::InputTypeMail; - } else if (inputTypeString == "InputTypeIPv4Address") { - return Types::InputTypeIPv4Address; - } else if (inputTypeString == "InputTypeIPv6Address") { - return Types::InputTypeIPv6Address; - } else if (inputTypeString == "InputTypeUrl") { - return Types::InputTypeUrl; - } else if (inputTypeString == "InputTypeMacAddress") { - return Types::InputTypeMacAddress; - } - return Types::InputTypeNone; -} diff --git a/libnymea-app/jsonrpc/jsontypes.h b/libnymea-app/jsonrpc/jsontypes.h deleted file mode 100644 index 736fac32..00000000 --- a/libnymea-app/jsonrpc/jsontypes.h +++ /dev/null @@ -1,80 +0,0 @@ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -* -* Copyright 2013 - 2020, nymea GmbH -* Contact: contact@nymea.io -* -* This file is part of nymea. -* This project including source code and documentation is protected by -* copyright law, and remains the property of nymea GmbH. All rights, including -* reproduction, publication, editing and translation, are reserved. The use of -* this project is subject to the terms of a license agreement to be concluded -* with nymea GmbH in accordance with the terms of use of nymea GmbH, available -* under https://nymea.io/license -* -* GNU General Public License Usage -* Alternatively, this project may be redistributed and/or modified under the -* terms of the GNU General Public License as published by the Free Software -* Foundation, GNU version 3. This project is distributed in the hope that it -* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty -* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General -* Public License for more details. -* -* You should have received a copy of the GNU General Public License along with -* this project. If not, see . -* -* For any further details and any questions please contact us under -* contact@nymea.io or see our FAQ/Licensing Information on -* https://nymea.io/license/faq -* -* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - -#ifndef JSONTYPES_H -#define JSONTYPES_H - -#include -#include -#include -#include - -#include "types/types.h" -#include "types/deviceclass.h" - -class Plugin; -class Vendor; - -class StateType; -class EventType; -class ActionType; -class ParamType; - -class DeviceManager; -class Device; -class DeviceClasses; -class Param; - -class JsonTypes : public QObject -{ - Q_OBJECT -public: - explicit JsonTypes(QObject *parent = nullptr); - - static Vendor *unpackVendor(const QVariantMap &vendorMap); - static Plugin *unpackPlugin(const QVariantMap &pluginMap, QObject *parent); - static DeviceClass *unpackDeviceClass(const QVariantMap &deviceClassMap, QObject *parent); - static void unpackParam(const QVariantMap ¶mMap, Param *param); - static ParamType *unpackParamType(const QVariantMap ¶mTypeMap, QObject *parent); - static StateType *unpackStateType(const QVariantMap &stateTypeMap, QObject *parent); - static EventType *unpackEventType(const QVariantMap &eventTypeMap, QObject *parent); - static ActionType *unpackActionType(const QVariantMap &actionTypeMap, QObject *parent); - static Device *unpackDevice(DeviceManager *deviceManager, const QVariantMap &deviceMap, DeviceClasses *deviceClasses, Device *oldDevice = nullptr); - - static QVariantMap packParam(Param *param); - -private: - static DeviceClass::SetupMethod stringToSetupMethod(const QString &setupMethodString); - static QPair stringToUnit(const QString &unitString); - static Types::InputType stringToInputType(const QString &inputTypeString); - -}; - -#endif // JSONTYPES_H diff --git a/libnymea-app/libnymea-app-core.h b/libnymea-app/libnymea-app-core.h index 80f08d6f..8de2204d 100644 --- a/libnymea-app/libnymea-app-core.h +++ b/libnymea-app/libnymea-app-core.h @@ -36,8 +36,8 @@ #include "connection/nymeahost.h" #include "connection/discovery/nymeadiscovery.h" #include "vendorsproxy.h" -#include "deviceclassesproxy.h" -#include "devicesproxy.h" +#include "thingclassesproxy.h" +#include "thingsproxy.h" #include "pluginsproxy.h" #include "thingdiscovery.h" #include "interfacesmodel.h" @@ -92,7 +92,7 @@ #include "ruletemplates/ruleactiontemplate.h" #include "ruletemplates/ruleactionparamtemplate.h" #include "connection/awsclient.h" -#include "models/devicemodel.h" +#include "models/thingmodel.h" #include "models/sortfilterproxymodel.h" #include "system/systemcontroller.h" #include "types/package.h" @@ -158,8 +158,7 @@ void registerQmlTypes() { qmlRegisterType(uri, 1, 0, "Engine"); - qmlRegisterUncreatableType(uri, 1, 0, "ThingManager", "Can't create this in QML. Get it from the Engine."); - qmlRegisterUncreatableType(uri, 1, 0, "DeviceManager", "Can't create this in QML. Get it from the Engine."); + qmlRegisterUncreatableType(uri, 1, 0, "ThingManager", "Can't create this in QML. Get it from the Engine."); qmlRegisterUncreatableType(uri, 1, 0, "JsonRpcClient", "Can't create this in QML. Get it from the Engine."); qmlRegisterUncreatableType(uri, 1, 0, "NymeaConnection", "Can't create this in QML. Get it from the Engine."); @@ -167,45 +166,39 @@ void registerQmlTypes() { qmlRegisterSingletonType(uri, 1, 0, "Types", typesProvider); qmlRegisterUncreatableType(uri, 1, 0, "ParamType", "Can't create this in QML. Get it from the ParamTypes."); - qmlRegisterUncreatableType(uri, 1, 0, "ParamTypes", "Can't create this in QML. Get it from the DeviceClass."); + qmlRegisterUncreatableType(uri, 1, 0, "ParamTypes", "Can't create this in QML. Get it from the ThingClass."); qmlRegisterUncreatableType(uri, 1, 0, "EventType", "Can't create this in QML. Get it from the EventTypes."); - qmlRegisterUncreatableType(uri, 1, 0, "EventTypes", "Can't create this in QML. Get it from the DeviceClass."); + qmlRegisterUncreatableType(uri, 1, 0, "EventTypes", "Can't create this in QML. Get it from the ThingClass."); qmlRegisterUncreatableType(uri, 1, 0, "StateType", "Can't create this in QML. Get it from the StateTypes."); - qmlRegisterUncreatableType(uri, 1, 0, "StateTypes", "Can't create this in QML. Get it from the DeviceClass."); + qmlRegisterUncreatableType(uri, 1, 0, "StateTypes", "Can't create this in QML. Get it from the ThingClass."); qmlRegisterUncreatableType(uri, 1, 0, "ActionType", "Can't create this in QML. Get it from the ActionTypes."); - qmlRegisterUncreatableType(uri, 1, 0, "ActionTypes", "Can't create this in QML. Get it from the DeviceClass."); + qmlRegisterUncreatableType(uri, 1, 0, "ActionTypes", "Can't create this in QML. Get it from the ThingClass."); qmlRegisterType(uri, 1, 0, "StateTypesProxy"); qmlRegisterUncreatableType(uri, 1, 0, "State", "Can't create this in QML. Get it from the States."); - qmlRegisterUncreatableType(uri, 1, 0, "States", "Can't create this in QML. Get it from the Device."); + qmlRegisterUncreatableType(uri, 1, 0, "States", "Can't create this in QML. Get it from the Thing."); - qmlRegisterUncreatableType(uri, 1, 0, "BrowserItems", "Can't create this in QML. Get it from DeviceManager."); - qmlRegisterUncreatableType(uri, 1, 0, "BrowserItem", "Can't create this in QML. Get it from BroweserItems."); + qmlRegisterUncreatableType(uri, 1, 0, "BrowserItems", "Can't create this in QML. Get it from ThingManager."); + qmlRegisterUncreatableType(uri, 1, 0, "BrowserItem", "Can't create this in QML. Get it from BrowserItems."); qmlRegisterUncreatableType(uri, 1, 0, "Vendor", "Can't create this in QML. Get it from the Vendors."); - qmlRegisterUncreatableType(uri, 1, 0, "Vendors", "Can't create this in QML. Get it from the DeviceManager."); + qmlRegisterUncreatableType(uri, 1, 0, "Vendors", "Can't create this in QML. Get it from the ThingManager."); qmlRegisterType(uri, 1, 0, "VendorsProxy"); - qmlRegisterUncreatableType(uri, 1, 0, "Device", "Can't create this in QML. Get it from the Devices."); - qmlRegisterUncreatableType(uri, 1, 0, "Thing", "Can't create this in QML. Get it from the Things."); - qmlRegisterUncreatableType(uri, 1, 0, "Devices", "Can't create this in QML. Get it from the DeviceManager."); - qmlRegisterUncreatableType(uri, 1, 0, "Things", "Can't create this in QML. Get it from the ThingManager."); - qmlRegisterType(uri, 1, 0, "DevicesProxy"); - qmlRegisterType(uri, 1, 0, "ThingsProxy"); + qmlRegisterUncreatableType(uri, 1, 0, "Thing", "Can't create this in QML. Get it from the Things."); + qmlRegisterUncreatableType(uri, 1, 0, "Things", "Can't create this in QML. Get it from the ThingManager."); + qmlRegisterType(uri, 1, 0, "ThingsProxy"); qmlRegisterType(uri, 1, 0, "InterfacesModel"); qmlRegisterType(uri, 1, 0, "InterfacesSortModel"); - qmlRegisterUncreatableType(uri, 1, 0, "ThingClass", "Can't create this in QML. Get it from the ThingClasses."); - qmlRegisterUncreatableType(uri, 1, 0, "ThingClasses", "Can't create this in QML. Get it from the ThingManager."); - qmlRegisterUncreatableType(uri, 1, 0, "DeviceClass", "Can't create this in QML. Get it from the DeviceClasses."); - qmlRegisterUncreatableType(uri, 1, 0, "DeviceClasses", "Can't create this in QML. Get it from the DeviceManager."); - qmlRegisterType(uri, 1, 0, "DeviceClassesProxy"); + qmlRegisterUncreatableType(uri, 1, 0, "ThingClass", "Can't create this in QML. Get it from the ThingClasses."); + qmlRegisterUncreatableType(uri, 1, 0, "ThingClasses", "Can't create this in QML. Get it from the ThingManager."); + qmlRegisterType(uri, 1, 0, "ThingClassesProxy"); qmlRegisterType(uri, 1, 0, "ThingDiscovery"); qmlRegisterType(uri, 1, 0, "ThingDiscoveryProxy"); - qmlRegisterUncreatableType(uri, 1, 0, "DeviceDescriptor", "Get it from DeviceDiscovery"); qmlRegisterUncreatableType(uri, 1, 0, "ThingDescriptor", "Get it from ThingDiscovery"); - qmlRegisterType(uri, 1, 0, "DeviceModel"); + qmlRegisterType(uri, 1, 0, "ThingModel"); qmlRegisterUncreatableType(uri, 1, 0, "RuleManager", "Get it from the Engine"); qmlRegisterUncreatableType(uri, 1, 0, "Rules", "Get it from RuleManager"); @@ -239,7 +232,7 @@ void registerQmlTypes() { 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."); + qmlRegisterUncreatableType(uri, 1, 0, "Plugins", "Can't create this in QML. Get it from the ThingManager."); qmlRegisterType(uri, 1, 0, "PluginsProxy"); qmlRegisterUncreatableType(uri, 1, 0, "NymeaConfiguration", "Get it from Engine"); @@ -332,7 +325,7 @@ void registerQmlTypes() { qmlRegisterUncreatableType(uri, 1, 0, "TokenInfo", "Get it from TokenInfos"); qmlRegisterUncreatableType(uri, 1, 0, "TokenInfos", "Get it from UserManager"); - qmlRegisterUncreatableType(uri, 1, 0, "IOConnections", "Get it from DeviceManager"); + qmlRegisterUncreatableType(uri, 1, 0, "IOConnections", "Get it from ThingManager"); qmlRegisterUncreatableType(uri, 1, 0, "IOConnection", "Get it from IOConnections"); qmlRegisterType(uri, 1, 0, "IOInputConnectionWatcher"); qmlRegisterType(uri, 1, 0, "IOOutputConnectionWatcher"); diff --git a/libnymea-app/libnymea-app.pri b/libnymea-app/libnymea-app.pri index 19ee02e4..5b867965 100644 --- a/libnymea-app/libnymea-app.pri +++ b/libnymea-app/libnymea-app.pri @@ -43,8 +43,8 @@ SOURCES += \ $${PWD}/types/types.cpp \ $${PWD}/types/vendor.cpp \ $${PWD}/types/vendors.cpp \ - $${PWD}/types/deviceclass.cpp \ - $${PWD}/types/device.cpp \ + $${PWD}/types/thingclass.cpp \ + $${PWD}/types/thing.cpp \ $${PWD}/types/param.cpp \ $${PWD}/types/params.cpp \ $${PWD}/types/paramtype.cpp \ @@ -105,14 +105,13 @@ SOURCES += \ $${PWD}/connection/discovery/upnpdiscovery.cpp \ $${PWD}/connection/discovery/zeroconfdiscovery.cpp \ $${PWD}/connection/discovery/bluetoothservicediscovery.cpp \ - $${PWD}/devicemanager.cpp \ - $${PWD}/jsonrpc/jsontypes.cpp \ + $${PWD}/thingmanager.cpp \ $${PWD}/jsonrpc/jsonrpcclient.cpp \ $${PWD}/jsonrpc/jsonhandler.cpp \ - $${PWD}/devices.cpp \ - $${PWD}/devicesproxy.cpp \ - $${PWD}/deviceclasses.cpp \ - $${PWD}/deviceclassesproxy.cpp \ + $${PWD}/things.cpp \ + $${PWD}/thingsproxy.cpp \ + $${PWD}/thingclasses.cpp \ + $${PWD}/thingclassesproxy.cpp \ $${PWD}/thingdiscovery.cpp \ $${PWD}/models/packagesfiltermodel.cpp \ $${PWD}/models/taglistmodel.cpp \ @@ -151,7 +150,7 @@ SOURCES += \ $${PWD}/configuration/nymeaconfiguration.cpp \ $${PWD}/configuration/mqttpolicy.cpp \ $${PWD}/configuration/mqttpolicies.cpp \ - $${PWD}/models/devicemodel.cpp \ + $${PWD}/models/thingmodel.cpp \ $${PWD}/system/systemcontroller.cpp \ $${PWD}/thinggroup.cpp \ $${PWD}/zigbee/zigbeeadapters.cpp \ @@ -187,8 +186,8 @@ HEADERS += \ $${PWD}/types/types.h \ $${PWD}/types/vendor.h \ $${PWD}/types/vendors.h \ - $${PWD}/types/deviceclass.h \ - $${PWD}/types/device.h \ + $${PWD}/types/thingclass.h \ + $${PWD}/types/thing.h \ $${PWD}/types/param.h \ $${PWD}/types/params.h \ $${PWD}/types/paramtype.h \ @@ -250,14 +249,13 @@ HEADERS += \ $${PWD}/connection/discovery/upnpdiscovery.h \ $${PWD}/connection/discovery/zeroconfdiscovery.h \ $${PWD}/connection/discovery/bluetoothservicediscovery.h \ - $${PWD}/devicemanager.h \ - $${PWD}/jsonrpc/jsontypes.h \ + $${PWD}/thingmanager.h \ $${PWD}/jsonrpc/jsonrpcclient.h \ $${PWD}/jsonrpc/jsonhandler.h \ - $${PWD}/devices.h \ - $${PWD}/devicesproxy.h \ - $${PWD}/deviceclasses.h \ - $${PWD}/deviceclassesproxy.h \ + $${PWD}/things.h \ + $${PWD}/thingsproxy.h \ + $${PWD}/thingclasses.h \ + $${PWD}/thingclassesproxy.h \ $${PWD}/thingdiscovery.h \ $${PWD}/models/packagesfiltermodel.h \ $${PWD}/models/taglistmodel.h \ @@ -296,7 +294,7 @@ HEADERS += \ $${PWD}/configuration/nymeaconfiguration.h \ $${PWD}/configuration/mqttpolicy.h \ $${PWD}/configuration/mqttpolicies.h \ - $${PWD}/models/devicemodel.h \ + $${PWD}/models/thingmodel.h \ $${PWD}/system/systemcontroller.h \ $${PWD}/thinggroup.h \ $${PWD}/zigbee/zigbeeadapters.h \ diff --git a/libnymea-app/models/interfacesproxy.cpp b/libnymea-app/models/interfacesproxy.cpp index 059e92d6..a4857c1e 100644 --- a/libnymea-app/models/interfacesproxy.cpp +++ b/libnymea-app/models/interfacesproxy.cpp @@ -32,10 +32,10 @@ #include "types/interface.h" #include "types/interfaces.h" -#include "types/device.h" +#include "types/thing.h" -#include "devices.h" -#include "devicesproxy.h" +#include "things.h" +#include "thingsproxy.h" InterfacesProxy::InterfacesProxy(QObject *parent): QSortFilterProxyModel(parent) { @@ -102,9 +102,9 @@ bool InterfacesProxy::filterAcceptsRow(int source_row, const QModelIndex &source // TODO: This could be improved *a lot* by caching interfaces in the devices model... bool found = false; for (int i = 0; i < m_thingsFilter->rowCount(); i++) { - Device *d = m_thingsFilter->get(i); + Thing *d = m_thingsFilter->get(i); if (!d->thingClass()) { - qWarning() << "Cannot find DeviceClass for device:" << d->id() << d->name(); + qWarning() << "Cannot find ThingClass for thing:" << d->id() << d->name(); return false; } if (d->thingClass()->interfaces().contains(interfaceName)) { @@ -120,7 +120,7 @@ bool InterfacesProxy::filterAcceptsRow(int source_row, const QModelIndex &source // TODO: This could be improved *a lot* by caching interfaces in the devices model... bool found = false; for (int i = 0; i < m_thingsProxyFilter->rowCount(); i++) { - Device *d = m_thingsProxyFilter->get(i); + Thing *d = m_thingsProxyFilter->get(i); if (!d->thingClass()) { qWarning() << "Cannot find ThingClass for thing:" << d->id() << d->name(); return false; diff --git a/libnymea-app/models/interfacesproxy.h b/libnymea-app/models/interfacesproxy.h index 271c681c..a433f79c 100644 --- a/libnymea-app/models/interfacesproxy.h +++ b/libnymea-app/models/interfacesproxy.h @@ -33,8 +33,8 @@ #include -class Devices; -class DevicesProxy; +class Things; +class ThingsProxy; class Interface; class Interfaces; @@ -44,8 +44,8 @@ class InterfacesProxy: public QSortFilterProxyModel Q_PROPERTY(int count READ rowCount NOTIFY countChanged) Q_PROPERTY(QStringList shownInterfaces READ shownInterfaces WRITE setShownInterfaces NOTIFY shownInterfacesChanged) - Q_PROPERTY(Devices* thingsFilter READ thingsFilter WRITE setThingsFilter NOTIFY thingsFilterChanged) - Q_PROPERTY(DevicesProxy* thingsProxyFilter READ thingsProxyFilter WRITE setThingsProxyFilter NOTIFY thingsProxyFilterChanged) + Q_PROPERTY(Things* thingsFilter READ thingsFilter WRITE setThingsFilter NOTIFY thingsFilterChanged) + Q_PROPERTY(ThingsProxy* thingsProxyFilter READ thingsProxyFilter WRITE setThingsProxyFilter NOTIFY thingsProxyFilterChanged) Q_PROPERTY(bool showEvents READ showEvents WRITE setShowEvents NOTIFY showEventsChanged) Q_PROPERTY(bool showActions READ showActions WRITE setShowActions NOTIFY showActionsChanged) Q_PROPERTY(bool showStates READ showStates WRITE setShowStates NOTIFY showStatesChanged) @@ -56,11 +56,11 @@ public: QStringList shownInterfaces() const { return m_shownInterfaces; } void setShownInterfaces(const QStringList &shownInterfaces) { m_shownInterfaces = shownInterfaces; emit shownInterfacesChanged(); invalidateFilter(); } - Devices* thingsFilter() const { return m_thingsFilter; } - void setThingsFilter(Devices *things) { m_thingsFilter = things; emit thingsFilterChanged(); invalidateFilter(); } + Things* thingsFilter() const { return m_thingsFilter; } + void setThingsFilter(Things *things) { m_thingsFilter = things; emit thingsFilterChanged(); invalidateFilter(); } - DevicesProxy* thingsProxyFilter() const { return m_thingsProxyFilter; } - void setThingsProxyFilter(DevicesProxy *thingsProxy) { m_thingsProxyFilter = thingsProxy; emit thingsProxyFilterChanged(); invalidateFilter(); } + ThingsProxy* thingsProxyFilter() const { return m_thingsProxyFilter; } + void setThingsProxyFilter(ThingsProxy *thingsProxy) { m_thingsProxyFilter = thingsProxy; emit thingsProxyFilterChanged(); invalidateFilter(); } bool showEvents() const; void setShowEvents(bool showEvents); @@ -89,8 +89,8 @@ signals: private: Interfaces *m_interfaces = nullptr; QStringList m_shownInterfaces; - Devices* m_thingsFilter = nullptr; - DevicesProxy* m_thingsProxyFilter = nullptr; + Things* m_thingsFilter = nullptr; + ThingsProxy* m_thingsProxyFilter = nullptr; bool m_showEvents = false; bool m_showActions = false; bool m_showStates = false; diff --git a/libnymea-app/models/logsmodel.cpp b/libnymea-app/models/logsmodel.cpp index 13857c80..2eb30c58 100644 --- a/libnymea-app/models/logsmodel.cpp +++ b/libnymea-app/models/logsmodel.cpp @@ -71,7 +71,6 @@ QVariant LogsModel::data(const QModelIndex &index, int role) const case RoleValue: return m_list.at(index.row())->value(); case RoleThingId: - case RoleDeviceId: return m_list.at(index.row())->thingId(); case RoleTypeId: return m_list.at(index.row())->typeId(); @@ -91,7 +90,6 @@ QHash LogsModel::roleNames() const roles.insert(RoleTimestamp, "timestamp"); roles.insert(RoleValue, "value"); roles.insert(RoleThingId, "thingId"); - roles.insert(RoleDeviceId, "deviceId"); roles.insert(RoleTypeId, "typeId"); roles.insert(RoleSource, "source"); roles.insert(RoleLoggingEventType, "loggingEventType"); @@ -220,12 +218,7 @@ void LogsModel::logsReply(int /*commandId*/, const QVariantMap &data) foreach (const QVariant &logEntryVariant, logEntries) { QVariantMap entryMap = logEntryVariant.toMap(); QDateTime timeStamp = QDateTime::fromMSecsSinceEpoch(entryMap.value("timestamp").toLongLong()); - QString thingId; - if (m_engine->jsonRpcClient()->ensureServerVersion("5.0")) { - thingId = entryMap.value("thingId").toString(); - } else { - thingId = entryMap.value("deviceId").toString(); - } + QString thingId = entryMap.value("thingId").toString(); QString typeId = entryMap.value("typeId").toString(); QMetaEnum sourceEnum = QMetaEnum::fromType(); LogEntry::LoggingSource loggingSource = static_cast(sourceEnum.keyToValue(entryMap.value("source").toByteArray())); @@ -298,11 +291,7 @@ void LogsModel::fetchMore(const QModelIndex &parent) if (!m_thingId.isNull()) { QVariantList thingIds; thingIds.append(m_thingId); - if (m_engine->jsonRpcClient()->ensureServerVersion("5.0")) { - params.insert("thingIds", thingIds); - } else { - params.insert("deviceIds", thingIds); - } + params.insert("thingIds", thingIds); } if (!m_typeIds.isEmpty()) { QVariantList typeIds; @@ -354,12 +343,7 @@ void LogsModel::newLogEntryReceived(const QVariantMap &data) } QVariantMap entryMap = data; - QUuid thingId; - if (m_engine->jsonRpcClient()->ensureServerVersion("5.0")) { - thingId = entryMap.value("deviceId").toUuid(); - } else { - thingId = entryMap.value("thingId").toUuid(); - } + QUuid thingId = entryMap.value("thingId").toUuid(); if (!m_thingId.isNull() && thingId != m_thingId) { return; } diff --git a/libnymea-app/models/logsmodel.h b/libnymea-app/models/logsmodel.h index 98388b5d..aebf4ef4 100644 --- a/libnymea-app/models/logsmodel.h +++ b/libnymea-app/models/logsmodel.h @@ -43,6 +43,7 @@ class LogsModel : public QAbstractListModel, public QQmlParserStatus { Q_OBJECT Q_PROPERTY(Engine* engine READ engine WRITE setEngine NOTIFY engineChanged) + Q_INTERFACES(QQmlParserStatus) Q_PROPERTY(int count READ rowCount NOTIFY countChanged) Q_PROPERTY(bool busy READ busy NOTIFY busyChanged) @@ -58,7 +59,6 @@ public: RoleTimestamp, RoleValue, RoleThingId, - RoleDeviceId, // < JSONRPC 5.0 RoleTypeId, RoleSource, RoleLoggingEventType, @@ -82,7 +82,7 @@ public: void setLive(bool live); QUuid thingId() const; - void setThingId(const QUuid &deviceId); + void setThingId(const QUuid &thingId); QStringList typeIds() const; void setTypeIds(const QStringList &typeIds); diff --git a/libnymea-app/models/logsmodelng.cpp b/libnymea-app/models/logsmodelng.cpp index 037d0c66..2a9c921f 100644 --- a/libnymea-app/models/logsmodelng.cpp +++ b/libnymea-app/models/logsmodelng.cpp @@ -71,7 +71,6 @@ QVariant LogsModelNg::data(const QModelIndex &index, int role) const case RoleValue: return m_list.at(index.row())->value(); case RoleThingId: - case RoleDeviceId: return m_list.at(index.row())->thingId(); case RoleTypeId: return m_list.at(index.row())->typeId(); @@ -89,7 +88,6 @@ QHash LogsModelNg::roleNames() const roles.insert(RoleTimestamp, "timestamp"); roles.insert(RoleValue, "value"); roles.insert(RoleThingId, "thingId"); - roles.insert(RoleDeviceId, "deviceId"); roles.insert(RoleTypeId, "typeId"); roles.insert(RoleSource, "source"); roles.insert(RoleLoggingEventType, "loggingEventType"); @@ -250,12 +248,7 @@ void LogsModelNg::logsReply(int commandId, const QVariantMap &data) foreach (const QVariant &logEntryVariant, logEntries) { QVariantMap entryMap = logEntryVariant.toMap(); QDateTime timeStamp = QDateTime::fromMSecsSinceEpoch(entryMap.value("timestamp").toLongLong()); - QString thingId; - if (m_engine->jsonRpcClient()->ensureServerVersion("5.0")) { - thingId = entryMap.value("thingId").toString(); - } else { - thingId = entryMap.value("deviceId").toString(); - } + QString thingId = entryMap.value("thingId").toString(); QString typeId = entryMap.value("typeId").toString(); QMetaEnum sourceEnum = QMetaEnum::fromType(); LogEntry::LoggingSource loggingSource = static_cast(sourceEnum.keyToValue(entryMap.value("source").toByteArray())); @@ -284,13 +277,13 @@ void LogsModelNg::logsReply(int commandId, const QVariantMap &data) for (int i = 0; i < newBlock.count(); i++) { LogEntry *entry = newBlock.at(i); m_list.insert(offset + i, entry); - Device *dev = m_engine->deviceManager()->devices()->getDevice(entry->thingId()); - if (!dev) { - qWarning() << "Device not found in system. Cannot add item to graph series."; + Thing *thing = m_engine->thingManager()->things()->getThing(entry->thingId()); + if (!thing) { + qWarning() << "Thing not found in system. Cannot add item to graph series."; continue; } - StateType *entryStateType = dev->thingClass()->stateTypes()->getStateType(entry->typeId()); + StateType *entryStateType = thing->thingClass()->stateTypes()->getStateType(entry->typeId()); if (m_graphSeries) { if (entryStateType->type().toLower() == "bool") { @@ -394,11 +387,7 @@ void LogsModelNg::fetchMore(const QModelIndex &parent) if (!m_thingId.isNull()) { QVariantList thingIds; thingIds.append(m_thingId); - if (m_engine->jsonRpcClient()->ensureServerVersion("5.0")) { - params.insert("thingIds", thingIds); - } else { - params.insert("deviceIds", thingIds); - } + params.insert("thingIds", thingIds); } if (!m_typeIds.isEmpty()) { QVariantList typeIds; @@ -440,12 +429,7 @@ void LogsModelNg::newLogEntryReceived(const QVariantMap &data) } QVariantMap entryMap = data; - QUuid thingId; - if (m_engine->jsonRpcClient()->ensureServerVersion("5.0")) { - thingId = entryMap.value("deviceId").toUuid(); - } else { - thingId = entryMap.value("thingId").toUuid(); - } + QUuid thingId = entryMap.value("thingId").toUuid(); if (!m_thingId.isNull() && thingId != m_thingId) { return; } @@ -466,7 +450,7 @@ void LogsModelNg::newLogEntryReceived(const QVariantMap &data) m_list.prepend(entry); if (m_graphSeries) { - Device *dev = m_engine->thingManager()->devices()->getDevice(entry->thingId()); + Thing *dev = m_engine->thingManager()->devices()->getThing(entry->thingId()); StateType *entryStateType = dev->thingClass()->stateTypes()->getStateType(entry->typeId()); diff --git a/libnymea-app/models/logsmodelng.h b/libnymea-app/models/logsmodelng.h index 4908cf58..f9b58998 100644 --- a/libnymea-app/models/logsmodelng.h +++ b/libnymea-app/models/logsmodelng.h @@ -49,7 +49,6 @@ class LogsModelNg : public QAbstractListModel, public QQmlParserStatus Q_PROPERTY(bool live READ live WRITE setLive NOTIFY liveChanged) Q_PROPERTY(int count READ rowCount NOTIFY countChanged) Q_PROPERTY(QUuid thingId READ thingId WRITE setThingId NOTIFY thingIdChanged) - Q_PROPERTY(QUuid deviceId READ thingId WRITE setThingId NOTIFY thingIdChanged) Q_PROPERTY(QStringList typeIds READ typeIds WRITE setTypeIds NOTIFY typeIdsChanged) Q_PROPERTY(QDateTime startTime READ startTime WRITE setStartTime NOTIFY startTimeChanged) Q_PROPERTY(QDateTime endTime READ endTime WRITE setEndTime NOTIFY endTimeChanged) @@ -64,7 +63,6 @@ public: RoleTimestamp, RoleValue, RoleThingId, - RoleDeviceId, // < JSONRPC 5.0 RoleTypeId, RoleSource, RoleLoggingEventType diff --git a/libnymea-app/models/rulesfiltermodel.cpp b/libnymea-app/models/rulesfiltermodel.cpp index 3331ef19..07a098c6 100644 --- a/libnymea-app/models/rulesfiltermodel.cpp +++ b/libnymea-app/models/rulesfiltermodel.cpp @@ -113,13 +113,13 @@ bool RulesFilterModel::filterAcceptsRow(int source_row, const QModelIndex &sourc break; } } - if (!found && rule->stateEvaluator() && rule->stateEvaluator()->containsDevice(m_filterThingId)) { + if (!found && rule->stateEvaluator() && rule->stateEvaluator()->containsThing(m_filterThingId)) { found = true; } if (!found) { for (int i = 0; i < rule->actions()->rowCount(); i++) { RuleAction *ra = rule->actions()->get(i); - if (ra->deviceId() == m_filterThingId) { + if (ra->thingId() == m_filterThingId) { found = true; break; } @@ -128,7 +128,7 @@ bool RulesFilterModel::filterAcceptsRow(int source_row, const QModelIndex &sourc if (!found) { for (int i = 0; i < rule->exitActions()->rowCount(); i++) { RuleAction *ra = rule->exitActions()->get(i); - if (ra->deviceId() == m_filterThingId) { + if (ra->thingId() == m_filterThingId) { found = true; break; } diff --git a/libnymea-app/models/rulesfiltermodel.h b/libnymea-app/models/rulesfiltermodel.h index 7c081066..fd1ffd8c 100644 --- a/libnymea-app/models/rulesfiltermodel.h +++ b/libnymea-app/models/rulesfiltermodel.h @@ -43,7 +43,6 @@ class RulesFilterModel : public QSortFilterProxyModel Q_PROPERTY(int count READ rowCount NOTIFY countChanged) Q_PROPERTY(Rules* rules READ rules WRITE setRules NOTIFY rulesChanged) Q_PROPERTY(QUuid filterThingId READ filterThingId WRITE setFilterThingId NOTIFY filterThingIdChanged) - Q_PROPERTY(QUuid filterDeviceId READ filterThingId WRITE setFilterThingId NOTIFY filterThingIdChanged) Q_PROPERTY(bool filterExecutable READ filterExecutable WRITE setFilterExecutable NOTIFY filterExecutableChanged) public: diff --git a/libnymea-app/models/tagsproxymodel.h b/libnymea-app/models/tagsproxymodel.h index f0ca7b1d..f9fcd626 100644 --- a/libnymea-app/models/tagsproxymodel.h +++ b/libnymea-app/models/tagsproxymodel.h @@ -44,7 +44,6 @@ class TagsProxyModel : public QSortFilterProxyModel Q_PROPERTY(int count READ rowCount NOTIFY countChanged) Q_PROPERTY(QString filterTagId READ filterTagId WRITE setFilterTagId NOTIFY filterTagIdChanged) Q_PROPERTY(QUuid filterThingId READ filterThingId WRITE setFilterThingId NOTIFY filterThingIdChanged) - Q_PROPERTY(QUuid filterDeviceId READ filterThingId WRITE setFilterThingId NOTIFY filterThingIdChanged) Q_PROPERTY(QUuid filterRuleId READ filterRuleId WRITE setFilterRuleId NOTIFY filterRuleIdChanged) Q_PROPERTY(QString filterValue READ filterValue WRITE setFilterValue NOTIFY filterValueChanged) diff --git a/libnymea-app/models/devicemodel.cpp b/libnymea-app/models/thingmodel.cpp similarity index 87% rename from libnymea-app/models/devicemodel.cpp rename to libnymea-app/models/thingmodel.cpp index ee105f8f..c792175f 100644 --- a/libnymea-app/models/devicemodel.cpp +++ b/libnymea-app/models/thingmodel.cpp @@ -28,22 +28,22 @@ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -#include "devicemodel.h" +#include "thingmodel.h" #include "types/statetype.h" -DeviceModel::DeviceModel(QObject *parent) : QAbstractListModel(parent) +ThingModel::ThingModel(QObject *parent) : QAbstractListModel(parent) { } -int DeviceModel::rowCount(const QModelIndex &parent) const +int ThingModel::rowCount(const QModelIndex &parent) const { Q_UNUSED(parent) return m_list.count(); } -QVariant DeviceModel::data(const QModelIndex &index, int role) const +QVariant ThingModel::data(const QModelIndex &index, int role) const { if (role == RoleId) { return m_list.at(index.row()); @@ -83,7 +83,7 @@ QVariant DeviceModel::data(const QModelIndex &index, int role) const return QVariant(); } -QHash DeviceModel::roleNames() const +QHash ThingModel::roleNames() const { QHash roles; roles.insert(RoleId, "id"); @@ -93,7 +93,7 @@ QHash DeviceModel::roleNames() const return roles; } -QVariant DeviceModel::getData(int index, int role) const +QVariant ThingModel::getData(int index, int role) const { if (index < 0 || index >= m_list.count()) { return QVariant(); @@ -101,26 +101,26 @@ QVariant DeviceModel::getData(int index, int role) const return data(this->index(index), role); } -Device *DeviceModel::device() const +Thing *ThingModel::thing() const { return m_device; } -void DeviceModel::setDevice(Device *device) +void ThingModel::setThing(Thing *device) { if (m_device != device) { m_device = device; - emit deviceChanged(); + emit thingChanged(); updateList(); } } -bool DeviceModel::showStates() const +bool ThingModel::showStates() const { return m_showStates; } -void DeviceModel::setShowStates(bool showStates) +void ThingModel::setShowStates(bool showStates) { if (m_showStates != showStates) { m_showStates = showStates; @@ -129,12 +129,12 @@ void DeviceModel::setShowStates(bool showStates) } } -bool DeviceModel::showActions() const +bool ThingModel::showActions() const { return m_showActions; } -void DeviceModel::setShowActions(bool showActions) +void ThingModel::setShowActions(bool showActions) { if (m_showActions != showActions) { m_showActions = showActions; @@ -143,12 +143,12 @@ void DeviceModel::setShowActions(bool showActions) } } -bool DeviceModel::showEvents() const +bool ThingModel::showEvents() const { return m_showEvents; } -void DeviceModel::setShowEvents(bool showEvents) +void ThingModel::setShowEvents(bool showEvents) { if (m_showEvents != showEvents) { m_showEvents = showEvents; @@ -157,7 +157,7 @@ void DeviceModel::setShowEvents(bool showEvents) } } -void DeviceModel::updateList() +void ThingModel::updateList() { if (!m_device) { beginResetModel(); diff --git a/libnymea-app/models/devicemodel.h b/libnymea-app/models/thingmodel.h similarity index 86% rename from libnymea-app/models/devicemodel.h rename to libnymea-app/models/thingmodel.h index 24fa442e..7a5ce700 100644 --- a/libnymea-app/models/devicemodel.h +++ b/libnymea-app/models/thingmodel.h @@ -28,21 +28,21 @@ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -#ifndef DEVICEMODEL_H -#define DEVICEMODEL_H +#ifndef THINGMODEL_H +#define THINGMODEL_H #include -#include "types/device.h" -#include "types/deviceclass.h" +#include "types/thing.h" +#include "types/thingclass.h" -class DeviceModel : public QAbstractListModel +class ThingModel : public QAbstractListModel { Q_OBJECT Q_PROPERTY(int count READ rowCount NOTIFY countChanged) - Q_PROPERTY(Device* device READ device WRITE setDevice NOTIFY deviceChanged) + Q_PROPERTY(Thing* thing READ thing WRITE setThing NOTIFY thingChanged) Q_PROPERTY(bool showStates READ showStates WRITE setShowStates NOTIFY showStatesChanged) Q_PROPERTY(bool showActions READ showActions WRITE setShowActions NOTIFY showActionsChanged) @@ -63,15 +63,15 @@ public: }; Q_ENUM(Type) - explicit DeviceModel(QObject *parent = nullptr); + explicit ThingModel(QObject *parent = nullptr); int rowCount(const QModelIndex &parent = QModelIndex()) const override; QVariant data(const QModelIndex &index, int role) const override; QHash roleNames() const override; Q_INVOKABLE QVariant getData(int index, int role) const; - Device* device() const; - void setDevice(Device *device); + Thing* thing() const; + void setThing(Thing *device); bool showStates() const; void setShowStates(bool showStates); @@ -83,7 +83,7 @@ public: void setShowEvents(bool showEvents); signals: - void deviceChanged(); + void thingChanged(); void countChanged(); @@ -95,7 +95,7 @@ private: void updateList(); private: - Device *m_device = nullptr; + Thing *m_device = nullptr; bool m_showStates = true; bool m_showActions = true; @@ -104,4 +104,4 @@ private: QList m_list; }; -#endif // DEVICEMODEL_H +#endif // THINGMODEL_H diff --git a/libnymea-app/rulemanager.cpp b/libnymea-app/rulemanager.cpp index ce9f66b0..4ebf6c7c 100644 --- a/libnymea-app/rulemanager.cpp +++ b/libnymea-app/rulemanager.cpp @@ -31,7 +31,6 @@ #include "rulemanager.h" #include "jsonrpc/jsonrpcclient.h" -#include "jsonrpc/jsontypes.h" #include "types/rule.h" #include "types/eventdescriptor.h" #include "types/eventdescriptors.h" @@ -50,6 +49,7 @@ #include "types/calendaritem.h" #include +#include RuleManager::RuleManager(JsonRpcClient* jsonClient, QObject *parent) : JsonHandler(parent), @@ -246,11 +246,7 @@ void RuleManager::parseEventDescriptors(const QVariantList &eventDescriptorList, { foreach (const QVariant &eventDescriptorVariant, eventDescriptorList) { EventDescriptor *eventDescriptor = new EventDescriptor(rule); - if (m_jsonClient->ensureServerVersion("5.0")) { - eventDescriptor->setThingId(eventDescriptorVariant.toMap().value("thingId").toString()); - } else { - eventDescriptor->setThingId(eventDescriptorVariant.toMap().value("deviceId").toString()); - } + eventDescriptor->setThingId(eventDescriptorVariant.toMap().value("thingId").toString()); eventDescriptor->setEventTypeId(eventDescriptorVariant.toMap().value("eventTypeId").toString()); eventDescriptor->setInterfaceName(eventDescriptorVariant.toMap().value("interface").toString()); eventDescriptor->setInterfaceEvent(eventDescriptorVariant.toMap().value("interfaceEvent").toString()); @@ -263,7 +259,7 @@ void RuleManager::parseEventDescriptors(const QVariantList &eventDescriptorList, paramDescriptor->setOperatorType((ParamDescriptor::ValueOperator)operatorEnum.keyToValue(paramDescriptorVariant.toMap().value("operator").toString().toLocal8Bit())); eventDescriptor->paramDescriptors()->addParamDescriptor(paramDescriptor); } - // qDebug() << "Adding eventdescriptor" << eventDescriptor->deviceId() << eventDescriptor->eventTypeId(); + // qDebug() << "Adding eventdescriptor" << eventDescriptor->thingId() << eventDescriptor->eventTypeId(); rule->eventDescriptors()->addEventDescriptor(eventDescriptor); } } @@ -280,8 +276,8 @@ StateEvaluator *RuleManager::parseStateEvaluator(const QVariantMap &stateEvaluat StateDescriptor::ValueOperator op = (StateDescriptor::ValueOperator)operatorEnum.keyToValue(sdMap.value("operator").toByteArray()); StateDescriptor *sd = nullptr; - if (sdMap.contains("deviceId") && sdMap.contains("stateTypeId")) { - sd = new StateDescriptor(sdMap.value("deviceId").toUuid(), sdMap.value("stateTypeId").toUuid(), op, sdMap.value("value"), stateEvaluator); + if (sdMap.contains("thingId") && sdMap.contains("stateTypeId")) { + sd = new StateDescriptor(sdMap.value("thingId").toUuid(), sdMap.value("stateTypeId").toUuid(), op, sdMap.value("value"), stateEvaluator); } else { sd = new StateDescriptor(sdMap.value("interface").toString(), sdMap.value("interfaceState").toString(), op, sdMap.value("value"), stateEvaluator); } @@ -315,11 +311,11 @@ void RuleManager::parseRuleExitActions(const QVariantList &ruleActions, Rule *ru RuleAction *RuleManager::parseRuleAction(const QVariantMap &ruleAction) { RuleAction *ret = new RuleAction(); - if (ruleAction.contains("deviceId") && ruleAction.contains("actionTypeId")) { - ret->setDeviceId(ruleAction.value("deviceId").toUuid()); + if (ruleAction.contains("thingId") && ruleAction.contains("actionTypeId")) { + ret->setThingId(ruleAction.value("thingId").toUuid()); ret->setActionTypeId(ruleAction.value("actionTypeId").toUuid()); - } else if (ruleAction.contains("deviceId") && ruleAction.contains("browserItemId")) { - ret->setDeviceId(ruleAction.value("deviceId").toUuid()); + } else if (ruleAction.contains("thingId") && ruleAction.contains("browserItemId")) { + ret->setThingId(ruleAction.value("thingId").toUuid()); ret->setBrowserItemId(ruleAction.value("browserItemId").toString()); } else { ret->setInterfaceName(ruleAction.value("interface").toString()); @@ -332,7 +328,7 @@ RuleAction *RuleManager::parseRuleAction(const QVariantMap &ruleAction) param->setValue(ruleActionParamVariant.toMap().value("value")); param->setEventTypeId(ruleActionParamVariant.toMap().value("eventTypeId").toString()); param->setEventParamTypeId(ruleActionParamVariant.toMap().value("eventParamTypeId").toString()); - param->setStateDeviceId(ruleActionParamVariant.toMap().value("stateDeviceId").toString()); + param->setStateThingId(ruleActionParamVariant.toMap().value("stateThingId").toString()); param->setStateTypeId(ruleActionParamVariant.toMap().value("stateTypeId").toString()); ret->ruleActionParams()->addRuleActionParam(param); } @@ -415,11 +411,7 @@ QVariantList RuleManager::packEventDescriptors(EventDescriptors *eventDescriptor EventDescriptor* eventDescriptor = eventDescriptors->get(i); if (!eventDescriptor->thingId().isNull() && !eventDescriptor->eventTypeId().isNull()) { eventDescriptorMap.insert("eventTypeId", eventDescriptor->eventTypeId()); - if (m_jsonClient->ensureServerVersion("5.0")) { - eventDescriptorMap.insert("thingId", eventDescriptor->thingId()); - } else { - eventDescriptorMap.insert("deviceId", eventDescriptor->thingId()); - } + eventDescriptorMap.insert("thingId", eventDescriptor->thingId()); } else { eventDescriptorMap.insert("interface", eventDescriptor->interfaceName()); eventDescriptorMap.insert("interfaceEvent", eventDescriptor->interfaceEvent()); @@ -512,11 +504,11 @@ QVariantList RuleManager::packRuleActions(RuleActions *ruleActions) for (int i = 0; i < ruleActions->rowCount(); i++) { QVariantMap ruleAction; RuleAction *ra = ruleActions->get(i); - if (!ra->actionTypeId().isNull() && !ra->deviceId().isNull()) { - ruleAction.insert("deviceId", ra->deviceId()); + if (!ra->actionTypeId().isNull() && !ra->thingId().isNull()) { + ruleAction.insert("thingId", ra->thingId()); ruleAction.insert("actionTypeId", ra->actionTypeId()); - } else if (!ra->deviceId().isNull() && !ra->browserItemId().isEmpty()) { - ruleAction.insert("deviceId", ra->deviceId()); + } else if (!ra->thingId().isNull() && !ra->browserItemId().isEmpty()) { + ruleAction.insert("thingId", ra->thingId()); ruleAction.insert("browserItemId", ra->browserItemId()); } else { ruleAction.insert("interface", ra->interfaceName()); @@ -538,7 +530,7 @@ QVariantList RuleManager::packRuleActions(RuleActions *ruleActions) ruleActionParam.insert("eventTypeId", rap->eventTypeId()); ruleActionParam.insert("eventParamTypeId", rap->eventParamTypeId()); } else { - ruleActionParam.insert("stateDeviceId", rap->stateDeviceId()); + ruleActionParam.insert("stateThingId", rap->stateThingId()); ruleActionParam.insert("stateTypeId", rap->stateTypeId()); } ruleActionParams.append(ruleActionParam); @@ -557,8 +549,8 @@ QVariantMap RuleManager::packStateEvaluator(StateEvaluator *stateEvaluator) QMetaEnum stateOperatorEnum = QMetaEnum::fromType(); ret.insert("operator", stateOperatorEnum.valueToKey(stateEvaluator->stateOperator())); QVariantMap stateDescriptor; - if (!stateEvaluator->stateDescriptor()->deviceId().isNull() && !stateEvaluator->stateDescriptor()->stateTypeId().isNull()) { - stateDescriptor.insert("deviceId", stateEvaluator->stateDescriptor()->deviceId()); + if (!stateEvaluator->stateDescriptor()->thingId().isNull() && !stateEvaluator->stateDescriptor()->stateTypeId().isNull()) { + stateDescriptor.insert("thingId", stateEvaluator->stateDescriptor()->thingId()); stateDescriptor.insert("stateTypeId", stateEvaluator->stateDescriptor()->stateTypeId()); } else { stateDescriptor.insert("interface", stateEvaluator->stateDescriptor()->interfaceName()); diff --git a/libnymea-app/ruletemplates/ruletemplates.cpp b/libnymea-app/ruletemplates/ruletemplates.cpp index 6bd94378..ee2b9d42 100644 --- a/libnymea-app/ruletemplates/ruletemplates.cpp +++ b/libnymea-app/ruletemplates/ruletemplates.cpp @@ -42,7 +42,7 @@ #include "types/ruleactionparam.h" #include "types/ruleactionparams.h" #include "types/repeatingoption.h" -#include "devicesproxy.h" +#include "thingsproxy.h" #include #include @@ -297,7 +297,7 @@ bool RuleTemplatesFilterModel::filterAcceptsRow(int source_row, const QModelInde // Make sure we have all the things to satisfy all of the templates events/states/actions - if (m_filterDevicesProxy && !thingsSatisfyRuleTemplate(t, m_filterDevicesProxy)) { + if (m_filterThingsProxy && !thingsSatisfyRuleTemplate(t, m_filterThingsProxy)) { qDebug() << "Filtering out" << t->description() << "because required no thing in the provided filter proxy satisfies definitions"; return false; } @@ -330,7 +330,7 @@ bool RuleTemplatesFilterModel::stateEvaluatorTemplateContainsInterface(StateEval return false; } -bool RuleTemplatesFilterModel::thingsSatisfyRuleTemplate(RuleTemplate *ruleTemplate, DevicesProxy *things) const +bool RuleTemplatesFilterModel::thingsSatisfyRuleTemplate(RuleTemplate *ruleTemplate, ThingsProxy *things) const { // For improved performance it would be better to just cycle things once and flag satisfied states/events/actions // instead of looping over all things for every entry, but for the amount of templates we have right now @@ -340,7 +340,7 @@ bool RuleTemplatesFilterModel::thingsSatisfyRuleTemplate(RuleTemplate *ruleTempl foreach (const QString &interfaceName, ruleTemplate->interfaces()) { bool haveThing = false; for (int i = 0; i < things->rowCount(); i++) { - Device *thing = things->get(i); + Thing *thing = things->get(i); if (thing->thingClass()->interfaces().contains(interfaceName)) { haveThing = true; break; @@ -357,7 +357,7 @@ bool RuleTemplatesFilterModel::thingsSatisfyRuleTemplate(RuleTemplate *ruleTempl EventDescriptorTemplate *eventDescriptorTemplate = ruleTemplate->eventDescriptorTemplates()->get(i); bool haveThing = false; for (int j = 0; j < things->rowCount(); j++) { - Device *thing = things->get(j); + Thing *thing = things->get(j); if (thing->thingClass()->eventTypes()->findByName(eventDescriptorTemplate->eventName())) { haveThing = true; break; @@ -378,7 +378,7 @@ bool RuleTemplatesFilterModel::thingsSatisfyRuleTemplate(RuleTemplate *ruleTempl RuleActionTemplate *ruleActionTemplate = ruleTemplate->ruleActionTemplates()->get(i); bool haveThing = false; for (int j = 0; j < things->rowCount(); j++) { - Device *thing = things->get(j); + Thing *thing = things->get(j); if (thing->thingClass()->actionTypes()->findByName(ruleActionTemplate->actionName())) { haveThing = true; break; @@ -394,7 +394,7 @@ bool RuleTemplatesFilterModel::thingsSatisfyRuleTemplate(RuleTemplate *ruleTempl RuleActionTemplate *ruleExitActionTemplate = ruleTemplate->ruleExitActionTemplates()->get(i); bool haveThing = false; for (int j = 0; j < things->rowCount(); j++) { - Device *thing = things->get(j); + Thing *thing = things->get(j); if (thing->thingClass()->actionTypes()->findByName(ruleExitActionTemplate->actionName())) { haveThing = true; break; @@ -409,12 +409,12 @@ bool RuleTemplatesFilterModel::thingsSatisfyRuleTemplate(RuleTemplate *ruleTempl return true; } -bool RuleTemplatesFilterModel::thingsSatisfyStateEvaluatorTemplate(StateEvaluatorTemplate *stateEvaluatorTemplate, DevicesProxy *things) const +bool RuleTemplatesFilterModel::thingsSatisfyStateEvaluatorTemplate(StateEvaluatorTemplate *stateEvaluatorTemplate, ThingsProxy *things) const { if (stateEvaluatorTemplate->stateDescriptorTemplate()) { bool haveThing = false; for (int i = 0; i < things->rowCount(); i++) { - Device *thing = things->get(i); + Thing *thing = things->get(i); if (thing->thingClass()->stateTypes()->findByName(stateEvaluatorTemplate->stateDescriptorTemplate()->stateName())) { haveThing = true; break; diff --git a/libnymea-app/ruletemplates/ruletemplates.h b/libnymea-app/ruletemplates/ruletemplates.h index 1be08f79..291bee6a 100644 --- a/libnymea-app/ruletemplates/ruletemplates.h +++ b/libnymea-app/ruletemplates/ruletemplates.h @@ -37,8 +37,8 @@ class RuleTemplate; class StateEvaluatorTemplate; class TimeDescriptorTemplate; class RepeatingOption; -class DevicesProxy; -class Device; +class ThingsProxy; +class Thing; class RuleTemplates : public QAbstractListModel { @@ -79,7 +79,7 @@ class RuleTemplatesFilterModel: public QSortFilterProxyModel Q_PROPERTY(int count READ rowCount NOTIFY countChanged) Q_PROPERTY(RuleTemplates* ruleTemplates READ ruleTemplates WRITE setRuleTemplates NOTIFY ruleTemplatesChanged) Q_PROPERTY(QStringList filterInterfaceNames READ filterInterfaceNames WRITE setFilterInterfaceNames NOTIFY filterInterfaceNamesChanged) - Q_PROPERTY(DevicesProxy* filterByDevices READ filterByDevices WRITE setFilterByDevices NOTIFY filterByDevicesChanged) + Q_PROPERTY(ThingsProxy* filterByThings READ filterByThings WRITE setFilterByThings NOTIFY filterByThingsChanged) public: RuleTemplatesFilterModel(QObject *parent = nullptr): QSortFilterProxyModel(parent) {} @@ -87,8 +87,8 @@ public: void setRuleTemplates(RuleTemplates* ruleTemplates) { if (m_ruleTemplates != ruleTemplates) { m_ruleTemplates = ruleTemplates; setSourceModel(ruleTemplates); emit ruleTemplatesChanged(); invalidateFilter(); emit countChanged();}} QStringList filterInterfaceNames() const { return m_filterInterfaceNames; } void setFilterInterfaceNames(const QStringList &filterInterfaceNames) { if (m_filterInterfaceNames != filterInterfaceNames) { m_filterInterfaceNames = filterInterfaceNames; emit filterInterfaceNamesChanged(); invalidateFilter(); emit countChanged(); }} - DevicesProxy* filterByDevices() const { return m_filterDevicesProxy; } - void setFilterByDevices(DevicesProxy* filterDevicesProxy) {if (m_filterDevicesProxy != filterDevicesProxy) { m_filterDevicesProxy = filterDevicesProxy; emit filterByDevicesChanged(); invalidateFilter(); }} + ThingsProxy* filterByThings() const { return m_filterThingsProxy; } + void setFilterByThings(ThingsProxy* filterThingsProxy) {if (m_filterThingsProxy != filterThingsProxy) { m_filterThingsProxy = filterThingsProxy; emit filterByThingsChanged(); invalidateFilter(); }} Q_INVOKABLE RuleTemplate* get(int index) { if (index < 0 || index >= rowCount()) { return nullptr; @@ -101,18 +101,18 @@ protected: signals: void ruleTemplatesChanged(); void filterInterfaceNamesChanged(); - void filterByDevicesChanged(); + void filterByThingsChanged(); void countChanged(); private: - bool thingsSatisfyRuleTemplate(RuleTemplate *ruleTemplate, DevicesProxy *things) const; - bool thingsSatisfyStateEvaluatorTemplate(StateEvaluatorTemplate *stateEvaluatorTemplate, DevicesProxy *things) const; + bool thingsSatisfyRuleTemplate(RuleTemplate *ruleTemplate, ThingsProxy *things) const; + bool thingsSatisfyStateEvaluatorTemplate(StateEvaluatorTemplate *stateEvaluatorTemplate, ThingsProxy *things) const; private: RuleTemplates* m_ruleTemplates = nullptr; QStringList m_filterInterfaceNames; - DevicesProxy* m_filterDevicesProxy = nullptr; + ThingsProxy* m_filterThingsProxy = nullptr; }; #endif // RULETEMPLATES_H diff --git a/libnymea-app/scripting/codecompletion.cpp b/libnymea-app/scripting/codecompletion.cpp index 17b0e308..10ea38cd 100644 --- a/libnymea-app/scripting/codecompletion.cpp +++ b/libnymea-app/scripting/codecompletion.cpp @@ -168,9 +168,9 @@ void CodeCompletion::update() QRegExp thingIdExp(".*thingId: \"[a-zA-ZÀ-ž0-9- ]*"); if (thingIdExp.exactMatch(blockText)) { - for (int i = 0; i < m_engine->deviceManager()->devices()->rowCount(); i++) { - Device *dev = m_engine->deviceManager()->devices()->get(i); - entries.append(CompletionModel::Entry(dev->id().toString() + "\" // " + dev->name(), dev->name(), "thing", dev->thingClass()->interfaces().join(","))); + for (int i = 0; i < m_engine->thingManager()->things()->rowCount(); i++) { + Thing *thing = m_engine->thingManager()->things()->get(i); + entries.append(CompletionModel::Entry(thing->id().toString() + "\" // " + thing->name(), thing->name(), "thing", thing->thingClass()->interfaces().join(","))); } blockText.remove(QRegExp(".*thingId: \"")); m_model->update(entries); @@ -189,13 +189,13 @@ void CodeCompletion::update() thingId = info.properties.value("thingId"); qDebug() << "selected thingId" << thingId; - Device *device = m_engine->deviceManager()->devices()->getDevice(thingId); - if (!device) { + Thing *thing = m_engine->thingManager()->things()->getThing(thingId); + if (!thing) { return; } - for (int i = 0; i < device->thingClass()->stateTypes()->rowCount(); i++) { - StateType *stateType = device->thingClass()->stateTypes()->get(i); + for (int i = 0; i < thing->thingClass()->stateTypes()->rowCount(); i++) { + StateType *stateType = thing->thingClass()->stateTypes()->get(i); entries.append(CompletionModel::Entry(stateType->id().toString() + "\" // " + stateType->name(), stateType->name(), "stateType")); } blockText.remove(QRegExp(".*stateTypeId: \"")); @@ -217,14 +217,14 @@ void CodeCompletion::update() thingId = info.properties.value("thingId"); qDebug() << "selected thingId" << thingId; - Device *device = m_engine->deviceManager()->devices()->getDevice(thingId); - if (!device) { + Thing *thing = m_engine->thingManager()->things()->getThing(thingId); + if (!thing) { return; } - qDebug() << "Device is" << device->name(); + qDebug() << "Thing is" << thing->name(); - for (int i = 0; i < device->thingClass()->stateTypes()->rowCount(); i++) { - StateType *stateType = device->thingClass()->stateTypes()->get(i); + for (int i = 0; i < thing->thingClass()->stateTypes()->rowCount(); i++) { + StateType *stateType = thing->thingClass()->stateTypes()->get(i); entries.append(CompletionModel::Entry(stateType->name() + "\"", stateType->name(), "stateType")); } blockText.remove(QRegExp(".*stateName: \"")); @@ -244,13 +244,13 @@ void CodeCompletion::update() thingId = info.properties.value("thingId"); qDebug() << "selected thingId" << thingId; - Device *device = m_engine->deviceManager()->devices()->getDevice(thingId); - if (!device) { + Thing *thing = m_engine->thingManager()->things()->getThing(thingId); + if (!thing) { return; } - for (int i = 0; i < device->thingClass()->actionTypes()->rowCount(); i++) { - ActionType *actionType = device->thingClass()->actionTypes()->get(i); + for (int i = 0; i < thing->thingClass()->actionTypes()->rowCount(); i++) { + ActionType *actionType = thing->thingClass()->actionTypes()->get(i); entries.append(CompletionModel::Entry(actionType->id().toString() + "\" // " + actionType->name(), actionType->name(), "actionType")); } blockText.remove(QRegExp(".*actionTypeId: \"")); @@ -270,7 +270,7 @@ void CodeCompletion::update() if (info.properties.contains("thingId")) { QString thingId = info.properties.value("thingId"); qDebug() << "selected thingId" << thingId; - Device *thing = m_engine->thingManager()->things()->getThing(thingId); + Thing *thing = m_engine->thingManager()->things()->getThing(thingId); if (!thing) { return; } @@ -308,13 +308,13 @@ void CodeCompletion::update() thingId = info.properties.value("thingId"); qDebug() << "selected thingId" << thingId; - Device *device = m_engine->deviceManager()->devices()->getDevice(thingId); - if (!device) { + Thing *thing= m_engine->thingManager()->things()->getThing(thingId); + if (!thing) { return; } - for (int i = 0; i < device->thingClass()->eventTypes()->rowCount(); i++) { - EventType *eventType = device->thingClass()->eventTypes()->get(i); + for (int i = 0; i < thing->thingClass()->eventTypes()->rowCount(); i++) { + EventType *eventType = thing->thingClass()->eventTypes()->get(i); entries.append(CompletionModel::Entry(eventType->id().toString() + "\" // " + eventType->name(), eventType->name(), "eventType")); } blockText.remove(QRegExp(".*eventTypeId: \"")); @@ -331,7 +331,7 @@ void CodeCompletion::update() EventTypes *eventTypes = nullptr; if (info.properties.contains("thingId")) { QString thingId = info.properties.value("thingId"); - Device *thing = m_engine->thingManager()->things()->getThing(thingId); + Thing *thing = m_engine->thingManager()->things()->getThing(thingId); if (!thing) { return; } @@ -454,7 +454,7 @@ void CodeCompletion::update() if (blockPosition >= 0) { if (blockInfo.valid) { QString thingId = blockInfo.properties.value("thingId"); - Device *d = m_engine->thingManager()->things()->getDevice(QUuid(thingId)); + Thing *d = m_engine->thingManager()->things()->getThing(QUuid(thingId)); if (d) { ActionType *at = nullptr; if (blockInfo.properties.contains("actionTypeId")) { diff --git a/libnymea-app/scriptsyntaxhighlighter.cpp b/libnymea-app/scriptsyntaxhighlighter.cpp index c355e8ee..a7e57fb5 100644 --- a/libnymea-app/scriptsyntaxhighlighter.cpp +++ b/libnymea-app/scriptsyntaxhighlighter.cpp @@ -31,8 +31,8 @@ #include "scriptsyntaxhighlighter.h" #include "engine.h" -#include "devicemanager.h" -#include "devices.h" +#include "thingmanager.h" +#include "things.h" #include #include @@ -59,7 +59,7 @@ private: BlockStateNone = 0, BlockStateImport = 1, BlockStateAction, - BlockstateDeviceId, + BlockstateThingId, }; struct HighlightingRule { @@ -202,8 +202,8 @@ void ScriptSyntaxHighlighterPrivate::highlightBlock(const QString &text) setCurrentBlockState(BlockStateImport); } else if (text.trimmed().startsWith("Action")) { setCurrentBlockState(BlockStateAction); - } else if (text.trimmed().startsWith("deviceId:")) { - setCurrentBlockState(BlockstateDeviceId); + } else if (text.trimmed().startsWith("thingId:")) { + setCurrentBlockState(BlockstateThingId); } else { setCurrentBlockState(0); } diff --git a/libnymea-app/tagsmanager.cpp b/libnymea-app/tagsmanager.cpp index 54f892a9..c7383408 100644 --- a/libnymea-app/tagsmanager.cpp +++ b/libnymea-app/tagsmanager.cpp @@ -72,7 +72,7 @@ int TagsManager::tagThing(const QString &thingId, const QString &tagId, const QS { QVariantMap params; QVariantMap tag; - tag.insert("deviceId", thingId); + tag.insert("thingId", thingId); tag.insert("appId", "nymea:app"); tag.insert("tagId", tagId); tag.insert("value", value); @@ -84,7 +84,7 @@ int TagsManager::untagThing(const QString &thingId, const QString &tagId) { QVariantMap params; QVariantMap tag; - tag.insert("deviceId", thingId); + tag.insert("thingId", thingId); tag.insert("appId", "nymea:app"); tag.insert("tagId", tagId); params.insert("tag", tag); @@ -133,12 +133,7 @@ void TagsManager::handleTagsNotification(const QVariantMap ¶ms) } else if (notification == "Tags.TagRemoved") { for (int i = 0; i < m_tags->rowCount(); i++) { Tag* tag = m_tags->get(i); - QUuid thingId; - if (m_jsonClient->ensureServerVersion("5.0")) { - thingId = tagMap.value("thingId").toUuid(); - } else { - thingId = tagMap.value("deviceId").toUuid(); - } + QUuid thingId = tagMap.value("thingId").toUuid(); QUuid ruleId = tagMap.value("ruleId").toUuid(); QString tagId = tagMap.value("tagId").toString(); if (thingId == tag->thingId() && ruleId == tag->ruleId() && tagId == tag->tagId()) { @@ -149,12 +144,7 @@ void TagsManager::handleTagsNotification(const QVariantMap ¶ms) } else if (notification == "Tags.TagValueChanged") { for (int i = 0; i < m_tags->rowCount(); i++) { Tag* tag = m_tags->get(i); - QUuid thingId; - if (m_jsonClient->ensureServerVersion("5.0")) { - thingId = tagMap.value("thingId").toUuid(); - } else { - thingId = tagMap.value("deviceId").toUuid(); - } + QUuid thingId = tagMap.value("thingId").toUuid(); QUuid ruleId = tagMap.value("ruleId").toUuid(); QString tagId = tagMap.value("tagId").toString(); if (thingId == tag->thingId() && ruleId == tag->ruleId() && tagId == tag->tagId()) { @@ -191,12 +181,7 @@ void TagsManager::removeTagReply(int commandId, const QVariantMap ¶ms) Tag* TagsManager::unpackTag(const QVariantMap &tagMap) { - QString thingId; - if (m_jsonClient->ensureServerVersion("5.0")) { - thingId = tagMap.value("thingId").toString(); - } else { - thingId = tagMap.value("deviceId").toString(); - } + QString thingId = tagMap.value("thingId").toString(); QString ruleId = tagMap.value("ruleId").toString(); QString tagId = tagMap.value("tagId").toString(); QString value = tagMap.value("value").toString(); @@ -208,7 +193,7 @@ Tag* TagsManager::unpackTag(const QVariantMap &tagMap) tag = new Tag(tagId, value); tag->setRuleId(ruleId); } else { - qWarning() << "Invalid tag. Neither deviceId nor ruleId are set. Skipping..."; + qWarning() << "Invalid tag. Neither thingId nor ruleId are set. Skipping..."; tag->deleteLater(); return nullptr; } diff --git a/libnymea-app/deviceclasses.cpp b/libnymea-app/thingclasses.cpp similarity index 58% rename from libnymea-app/deviceclasses.cpp rename to libnymea-app/thingclasses.cpp index 24938f13..cf6c36b8 100644 --- a/libnymea-app/deviceclasses.cpp +++ b/libnymea-app/thingclasses.cpp @@ -28,93 +28,98 @@ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -#include "deviceclasses.h" +#include "thingclasses.h" #include -DeviceClasses::DeviceClasses(QObject *parent) : +ThingClasses::ThingClasses(QObject *parent) : QAbstractListModel(parent) { } -QList DeviceClasses::deviceClasses() +QList ThingClasses::thingClasses() { - return m_deviceClasses; + return m_thingClasses; } -int DeviceClasses::rowCount(const QModelIndex &parent) const +int ThingClasses::rowCount(const QModelIndex &parent) const { Q_UNUSED(parent) - return m_deviceClasses.count(); + return m_thingClasses.count(); } -QVariant DeviceClasses::data(const QModelIndex &index, int role) const +QVariant ThingClasses::data(const QModelIndex &index, int role) const { - if (index.row() < 0 || index.row() >= m_deviceClasses.count()) + if (index.row() < 0 || index.row() >= m_thingClasses.count()) return QVariant(); - DeviceClass *deviceClass = m_deviceClasses.at(index.row()); + ThingClass *thingClass = m_thingClasses.at(index.row()); switch (role) { case RoleId: - return deviceClass->id().toString(); + return thingClass->id().toString(); case RoleName: - return deviceClass->name(); + return thingClass->name(); case RoleDisplayName: - return deviceClass->displayName(); + return thingClass->displayName(); case RolePluginId: - return deviceClass->pluginId().toString(); + return thingClass->pluginId().toString(); case RoleVendorId: - return deviceClass->vendorId().toString(); + return thingClass->vendorId().toString(); case RoleInterfaces: - return deviceClass->interfaces(); + return thingClass->interfaces(); case RoleBaseInterface: - return deviceClass->baseInterface(); + return thingClass->baseInterface(); } return QVariant(); } -int DeviceClasses::count() const +int ThingClasses::count() const { - return m_deviceClasses.count(); + return m_thingClasses.count(); } -DeviceClass *DeviceClasses::get(int index) const +ThingClass *ThingClasses::get(int index) const { - if (index < 0 || index >= m_deviceClasses.count()) { + if (index < 0 || index >= m_thingClasses.count()) { return nullptr; } - return m_deviceClasses.at(index); + return m_thingClasses.at(index); } -DeviceClass *DeviceClasses::getDeviceClass(QUuid deviceClassId) const +ThingClass *ThingClasses::getThingClass(QUuid thingClassId) const { - foreach (DeviceClass *deviceClass, m_deviceClasses) { - if (deviceClass->id() == deviceClassId) { - return deviceClass; + foreach (ThingClass *thingClass, m_thingClasses) { + if (thingClass->id() == thingClassId) { + return thingClass; } } return nullptr; } -void DeviceClasses::addDeviceClass(DeviceClass *deviceClass) +ThingClass *ThingClasses::getDeviceClass(QUuid thingClassId) const { - beginInsertRows(QModelIndex(), m_deviceClasses.count(), m_deviceClasses.count()); - //qDebug() << "DeviceClasses: loaded deviceClass" << deviceClass->name(); - m_deviceClasses.append(deviceClass); + return getThingClass(thingClassId); +} + +void ThingClasses::addThingClass(ThingClass *thingClass) +{ + thingClass->setParent(this); + beginInsertRows(QModelIndex(), m_thingClasses.count(), m_thingClasses.count()); + m_thingClasses.append(thingClass); endInsertRows(); emit countChanged(); } -void DeviceClasses::clearModel() +void ThingClasses::clearModel() { beginResetModel(); - qDeleteAll(m_deviceClasses); - m_deviceClasses.clear(); + qDeleteAll(m_thingClasses); + m_thingClasses.clear(); endResetModel(); emit countChanged(); } -QHash DeviceClasses::roleNames() const +QHash ThingClasses::roleNames() const { QHash roles; roles[RoleId] = "id"; diff --git a/libnymea-app/deviceclasses.h b/libnymea-app/thingclasses.h similarity index 79% rename from libnymea-app/deviceclasses.h rename to libnymea-app/thingclasses.h index 0313b164..9f3e572e 100644 --- a/libnymea-app/deviceclasses.h +++ b/libnymea-app/thingclasses.h @@ -33,9 +33,9 @@ #include -#include "types/deviceclass.h" +#include "types/thingclass.h" -class DeviceClasses : public QAbstractListModel +class ThingClasses : public QAbstractListModel { Q_OBJECT Q_PROPERTY(int count READ rowCount NOTIFY countChanged) @@ -50,18 +50,19 @@ public: RoleBaseInterface }; - explicit DeviceClasses(QObject *parent = nullptr); + explicit ThingClasses(QObject *parent = nullptr); - QList deviceClasses(); + QList thingClasses(); - int rowCount(const QModelIndex & parent = QModelIndex()) const; - QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const; + int rowCount(const QModelIndex & parent = QModelIndex()) const override; + QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const override; Q_INVOKABLE int count() const; - Q_INVOKABLE DeviceClass *get(int index) const; - Q_INVOKABLE DeviceClass *getDeviceClass(QUuid deviceClassId) const; + Q_INVOKABLE ThingClass *get(int index) const; + Q_INVOKABLE ThingClass *getThingClass(QUuid thingClassId) const; + Q_INVOKABLE ThingClass *getDeviceClass(QUuid thingClassId) const; - void addDeviceClass(DeviceClass *deviceClass); + void addThingClass(ThingClass *thingClass); void clearModel(); @@ -69,10 +70,10 @@ signals: void countChanged(); protected: - QHash roleNames() const; + QHash roleNames() const override; private: - QList m_deviceClasses; + QList m_thingClasses; }; diff --git a/libnymea-app/deviceclassesproxy.cpp b/libnymea-app/thingclassesproxy.cpp similarity index 59% rename from libnymea-app/deviceclassesproxy.cpp rename to libnymea-app/thingclassesproxy.cpp index ae0a8885..bc3a3478 100644 --- a/libnymea-app/deviceclassesproxy.cpp +++ b/libnymea-app/thingclassesproxy.cpp @@ -28,26 +28,26 @@ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -#include "deviceclassesproxy.h" +#include "thingclassesproxy.h" #include -DeviceClassesProxy::DeviceClassesProxy(QObject *parent) : +ThingClassesProxy::ThingClassesProxy(QObject *parent) : QSortFilterProxyModel(parent) { - setSortRole(DeviceClasses::RoleDisplayName); + setSortRole(ThingClasses::RoleDisplayName); } -Engine *DeviceClassesProxy::engine() const +Engine *ThingClassesProxy::engine() const { return m_engine; } -void DeviceClassesProxy::setEngine(Engine *engine) +void ThingClassesProxy::setEngine(Engine *engine) { if (m_engine != engine) { m_engine = engine; - setSourceModel(engine->deviceManager()->deviceClasses()); + setSourceModel(engine->thingManager()->thingClasses()); emit engineChanged(); emit countChanged(); sort(0); @@ -55,12 +55,12 @@ void DeviceClassesProxy::setEngine(Engine *engine) } -QString DeviceClassesProxy::filterInterface() const +QString ThingClassesProxy::filterInterface() const { return m_filterInterface; } -void DeviceClassesProxy::setFilterInterface(const QString &filterInterface) +void ThingClassesProxy::setFilterInterface(const QString &filterInterface) { if (m_filterInterface != filterInterface) { m_filterInterface = filterInterface; @@ -70,12 +70,12 @@ void DeviceClassesProxy::setFilterInterface(const QString &filterInterface) } } -QString DeviceClassesProxy::filterDisplayName() const +QString ThingClassesProxy::filterDisplayName() const { return m_filterDisplayName; } -void DeviceClassesProxy::setFilterDisplayName(const QString &filter) +void ThingClassesProxy::setFilterDisplayName(const QString &filter) { if (m_filterDisplayName != filter) { m_filterDisplayName = filter; @@ -85,12 +85,12 @@ void DeviceClassesProxy::setFilterDisplayName(const QString &filter) } } -QUuid DeviceClassesProxy::filterVendorId() const +QUuid ThingClassesProxy::filterVendorId() const { return m_filterVendorId; } -void DeviceClassesProxy::setFilterVendorId(const QUuid &filterVendorId) +void ThingClassesProxy::setFilterVendorId(const QUuid &filterVendorId) { if (m_filterVendorId != filterVendorId) { m_filterVendorId = filterVendorId; @@ -100,12 +100,12 @@ void DeviceClassesProxy::setFilterVendorId(const QUuid &filterVendorId) } } -QString DeviceClassesProxy::filterVendorName() const +QString ThingClassesProxy::filterVendorName() const { return m_filterVendorName; } -void DeviceClassesProxy::setFilterVendorName(const QString &filterVendorName) +void ThingClassesProxy::setFilterVendorName(const QString &filterVendorName) { if (m_filterVendorName != filterVendorName) { m_filterVendorName = filterVendorName; @@ -115,12 +115,12 @@ void DeviceClassesProxy::setFilterVendorName(const QString &filterVendorName) } } -QString DeviceClassesProxy::filterString() const +QString ThingClassesProxy::filterString() const { return m_filterString; } -void DeviceClassesProxy::setFilterString(const QString &filterString) +void ThingClassesProxy::setFilterString(const QString &filterString) { if (m_filterString != filterString) { m_filterString = filterString; @@ -130,12 +130,12 @@ void DeviceClassesProxy::setFilterString(const QString &filterString) } } -bool DeviceClassesProxy::groupByInterface() const +bool ThingClassesProxy::groupByInterface() const { return m_groupByInterface; } -void DeviceClassesProxy::setGroupByInterface(bool groupByInterface) +void ThingClassesProxy::setGroupByInterface(bool groupByInterface) { if (m_groupByInterface != groupByInterface) { m_groupByInterface = groupByInterface; @@ -144,13 +144,13 @@ void DeviceClassesProxy::setGroupByInterface(bool groupByInterface) } } -DeviceClass *DeviceClassesProxy::get(int index) const +ThingClass *ThingClassesProxy::get(int index) const { - return m_engine->deviceManager()->deviceClasses()->get(mapToSource(this->index(index, 0)).row()); + return m_engine->thingManager()->thingClasses()->get(mapToSource(this->index(index, 0)).row()); } -void DeviceClassesProxy::resetFilter() +void ThingClassesProxy::resetFilter() { m_filterVendorId = QUuid(); m_filterInterface.clear(); @@ -160,31 +160,31 @@ void DeviceClassesProxy::resetFilter() emit countChanged(); } -bool DeviceClassesProxy::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const +bool ThingClassesProxy::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const { Q_UNUSED(sourceParent) - DeviceClass *deviceClass = m_engine->deviceManager()->deviceClasses()->get(sourceRow); + ThingClass *thingClass = m_engine->thingManager()->thingClasses()->get(sourceRow); - // filter auto devices - if (deviceClass->createMethods().count() == 1 && deviceClass->createMethods().contains("CreateMethodAuto")) + // filter auto things + if (thingClass->createMethods().count() == 1 && thingClass->createMethods().contains("CreateMethodAuto")) return false; - if (!m_filterVendorId.isNull() && deviceClass->vendorId() != m_filterVendorId) + if (!m_filterVendorId.isNull() && thingClass->vendorId() != m_filterVendorId) return false; - if (!m_filterInterface.isEmpty() && !deviceClass->interfaces().contains(m_filterInterface)) { + if (!m_filterInterface.isEmpty() && !thingClass->interfaces().contains(m_filterInterface)) { return false; } - if (!m_filterDisplayName.isEmpty() && !deviceClass->displayName().toLower().contains(m_filterDisplayName.toLower())) { + if (!m_filterDisplayName.isEmpty() && !thingClass->displayName().toLower().contains(m_filterDisplayName.toLower())) { return false; } if (!m_filterVendorName.isEmpty()) { - Vendor *vendor = m_engine->deviceManager()->vendors()->getVendor(deviceClass->vendorId()); + Vendor *vendor = m_engine->thingManager()->vendors()->getVendor(thingClass->vendorId()); if (!vendor) { - qWarning() << "Invalid vendor for deviceClass:" << deviceClass->name() << deviceClass->vendorId(); + qWarning() << "Invalid vendor for thingClass:" << thingClass->name() << thingClass->vendorId(); return false; } if (!vendor->displayName().toLower().contains(m_filterVendorName.toLower())) { @@ -193,12 +193,12 @@ bool DeviceClassesProxy::filterAcceptsRow(int sourceRow, const QModelIndex &sour } if (!m_filterString.isEmpty()) { - Vendor *vendor = m_engine->deviceManager()->vendors()->getVendor(deviceClass->vendorId()); + Vendor *vendor = m_engine->thingManager()->vendors()->getVendor(thingClass->vendorId()); if (!vendor) { - qWarning() << "Invalid vendor for deviceClass:" << deviceClass->name() << deviceClass->vendorId(); + qWarning() << "Invalid vendor for thingClass:" << thingClass->name() << thingClass->vendorId(); return false; } - if (!vendor->displayName().toLower().contains(m_filterString.toLower()) && !deviceClass->displayName().toLower().contains(m_filterString.toLower())) { + if (!vendor->displayName().toLower().contains(m_filterString.toLower()) && !thingClass->displayName().toLower().contains(m_filterString.toLower())) { return false; } } @@ -206,17 +206,17 @@ bool DeviceClassesProxy::filterAcceptsRow(int sourceRow, const QModelIndex &sour return true; } -bool DeviceClassesProxy::lessThan(const QModelIndex &left, const QModelIndex &right) const +bool ThingClassesProxy::lessThan(const QModelIndex &left, const QModelIndex &right) const { if (m_groupByInterface) { - QString leftBaseInterface = sourceModel()->data(left, DeviceClasses::RoleBaseInterface).toString(); - QString rightBaseInterface = sourceModel()->data(right, DeviceClasses::RoleBaseInterface).toString(); + QString leftBaseInterface = sourceModel()->data(left, ThingClasses::RoleBaseInterface).toString(); + QString rightBaseInterface = sourceModel()->data(right, ThingClasses::RoleBaseInterface).toString(); if (leftBaseInterface != rightBaseInterface) { return QString::localeAwareCompare(leftBaseInterface, rightBaseInterface) < 0; } } - QString leftName = sourceModel()->data(left, DeviceClasses::RoleDisplayName).toString(); - QString rightName = sourceModel()->data(right, DeviceClasses::RoleDisplayName).toString(); + QString leftName = sourceModel()->data(left, ThingClasses::RoleDisplayName).toString(); + QString rightName = sourceModel()->data(right, ThingClasses::RoleDisplayName).toString(); return QString::localeAwareCompare(leftName, rightName) < 0; } diff --git a/libnymea-app/deviceclassesproxy.h b/libnymea-app/thingclassesproxy.h similarity index 90% rename from libnymea-app/deviceclassesproxy.h rename to libnymea-app/thingclassesproxy.h index f72ce94c..f836b7ff 100644 --- a/libnymea-app/deviceclassesproxy.h +++ b/libnymea-app/thingclassesproxy.h @@ -28,18 +28,18 @@ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -#ifndef DEVICECLASSFILERMODEL_H -#define DEVICECLASSFILERMODEL_H +#ifndef THINGCLASSESPROXY_H +#define THINGCLASSESPROXY_H #include #include #include #include "engine.h" -#include "deviceclasses.h" -#include "types/deviceclass.h" +#include "thingclasses.h" +#include "types/thingclass.h" -class DeviceClassesProxy : public QSortFilterProxyModel +class ThingClassesProxy : public QSortFilterProxyModel { Q_OBJECT Q_PROPERTY(int count READ rowCount NOTIFY countChanged) @@ -50,13 +50,13 @@ class DeviceClassesProxy : public QSortFilterProxyModel Q_PROPERTY(QUuid filterVendorId READ filterVendorId WRITE setFilterVendorId NOTIFY filterVendorIdChanged) Q_PROPERTY(QString filterVendorName READ filterVendorName WRITE setFilterVendorName NOTIFY filterVendorNameChanged) - // Filters by deviceClass' displayName or vendor's displayName + // Filters by thingClass' displayName or vendor's displayName Q_PROPERTY(QString filterString READ filterString WRITE setFilterString NOTIFY filterStringChanged) Q_PROPERTY(bool groupByInterface READ groupByInterface WRITE setGroupByInterface NOTIFY groupByInterfaceChanged) public: - explicit DeviceClassesProxy(QObject *parent = nullptr); + explicit ThingClassesProxy(QObject *parent = nullptr); Engine *engine() const; void setEngine(Engine *engine); @@ -79,7 +79,7 @@ public: bool groupByInterface() const; void setGroupByInterface(bool groupByInterface); - Q_INVOKABLE DeviceClass *get(int index) const; + Q_INVOKABLE ThingClass *get(int index) const; Q_INVOKABLE void resetFilter(); @@ -107,4 +107,4 @@ private: bool m_groupByInterface = false; }; -#endif // DEVICECLASSFILERMODEL_H +#endif // THINGCLASSESPROXY_H diff --git a/libnymea-app/thingdiscovery.cpp b/libnymea-app/thingdiscovery.cpp index e380ef9a..0bda1130 100644 --- a/libnymea-app/thingdiscovery.cpp +++ b/libnymea-app/thingdiscovery.cpp @@ -40,20 +40,20 @@ ThingDiscovery::ThingDiscovery(QObject *parent) : int ThingDiscovery::rowCount(const QModelIndex &parent) const { Q_UNUSED(parent) - return m_foundDevices.count(); + return m_foundThings.count(); } QVariant ThingDiscovery::data(const QModelIndex &index, int role) const { switch (role) { case RoleId: - return m_foundDevices.at(index.row())->id(); + return m_foundThings.at(index.row())->id(); case RoleName: - return m_foundDevices.at(index.row())->name(); + return m_foundThings.at(index.row())->name(); case RoleDescription: - return m_foundDevices.at(index.row())->description(); - case RoleDeviceId: - return m_foundDevices.at(index.row())->thingId(); + return m_foundThings.at(index.row())->description(); + case RoleThingId: + return m_foundThings.at(index.row())->thingId(); } return QVariant(); @@ -63,7 +63,7 @@ QHash ThingDiscovery::roleNames() const { QHash roles; roles.insert(RoleId, "id"); - roles.insert(RoleDeviceId, "deviceId"); + roles.insert(RoleThingId, "thingId"); roles.insert(RoleName, "name"); roles.insert(RoleDescription, "description"); return roles; @@ -76,7 +76,7 @@ void ThingDiscovery::discoverThings(const QUuid &deviceClassId, const QVariantLi return; } beginResetModel(); - m_foundDevices.clear(); + m_foundThings.clear(); endResetModel(); emit countChanged(); @@ -102,10 +102,10 @@ void ThingDiscovery::discoverThings(const QUuid &deviceClassId, const QVariantLi ThingDescriptor *ThingDiscovery::get(int index) const { - if (index < 0 || index >= m_foundDevices.count()) { + if (index < 0 || index >= m_foundThings.count()) { return nullptr; } - return m_foundDevices.at(index); + return m_foundThings.at(index); } Engine *ThingDiscovery::engine() const @@ -138,9 +138,9 @@ void ThingDiscovery::discoverThingsResponse(int /*commandId*/, const QVariantMap foreach (const QVariant &descriptorVariant, descriptors) { qDebug() << "Found device. Descriptor:" << descriptorVariant; if (!contains(descriptorVariant.toMap().value("id").toUuid())) { - beginInsertRows(QModelIndex(), m_foundDevices.count(), m_foundDevices.count()); + beginInsertRows(QModelIndex(), m_foundThings.count(), m_foundThings.count()); ThingDescriptor *descriptor = new ThingDescriptor(descriptorVariant.toMap().value("id").toUuid(), - descriptorVariant.toMap().value("deviceId").toString(), + descriptorVariant.toMap().value("thingId").toString(), descriptorVariant.toMap().value("title").toString(), descriptorVariant.toMap().value("description").toString()); foreach (const QVariant ¶mVariant, descriptorVariant.toMap().value("deviceParams").toList()) { @@ -148,7 +148,7 @@ void ThingDiscovery::discoverThingsResponse(int /*commandId*/, const QVariantMap Param* p = new Param(paramVariant.toMap().value("paramTypeId").toString(), paramVariant.toMap().value("value")); descriptor->params()->addParam(p); } - m_foundDevices.append(descriptor); + m_foundThings.append(descriptor); endInsertRows(); emit countChanged(); } @@ -161,7 +161,7 @@ void ThingDiscovery::discoverThingsResponse(int /*commandId*/, const QVariantMap bool ThingDiscovery::contains(const QUuid &deviceDescriptorId) const { - foreach (ThingDescriptor *descriptor, m_foundDevices) { + foreach (ThingDescriptor *descriptor, m_foundThings) { if (descriptor->id() == deviceDescriptorId) { return true; } @@ -263,10 +263,10 @@ QUuid ThingDiscoveryProxy::filterThingId() const return m_filterThingId; } -void ThingDiscoveryProxy::setFilterThingId(const QUuid &filterDeviceId) +void ThingDiscoveryProxy::setFilterThingId(const QUuid &filterThingId) { - if (m_filterThingId != filterDeviceId) { - m_filterThingId = filterDeviceId; + if (m_filterThingId != filterThingId) { + m_filterThingId = filterThingId; emit filterThingIdChanged(); invalidateFilter(); emit countChanged(); diff --git a/libnymea-app/thingdiscovery.h b/libnymea-app/thingdiscovery.h index 5cd4daf5..d64d63f9 100644 --- a/libnymea-app/thingdiscovery.h +++ b/libnymea-app/thingdiscovery.h @@ -70,7 +70,7 @@ class ThingDiscovery : public QAbstractListModel public: enum Roles { RoleId, - RoleDeviceId, + RoleThingId, RoleName, RoleDescription }; @@ -106,7 +106,7 @@ private: QString m_displayMessage; bool contains(const QUuid &deviceDescriptorId) const; - QList m_foundDevices; + QList m_foundThings; }; class ThingDiscoveryProxy: public QSortFilterProxyModel @@ -131,7 +131,7 @@ public: void setShowNew(bool showNew); QUuid filterThingId() const; - void setFilterThingId(const QUuid &filterDeviceId); + void setFilterThingId(const QUuid &filterThingId); Q_INVOKABLE ThingDescriptor* get(int index) const; diff --git a/libnymea-app/thinggroup.cpp b/libnymea-app/thinggroup.cpp index d74379ee..2796e99e 100644 --- a/libnymea-app/thinggroup.cpp +++ b/libnymea-app/thinggroup.cpp @@ -29,33 +29,33 @@ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ #include "thinggroup.h" -#include "devicemanager.h" -#include "devicesproxy.h" +#include "thingmanager.h" +#include "thingsproxy.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_things(devices) +ThingGroup::ThingGroup(ThingManager *thingManager, ThingClass *thingClass, ThingsProxy *things, QObject *parent): + Thing(thingManager, thingClass, QUuid::createUuid(), parent), + m_things(things) { - deviceClass->setParent(this); + thingClass->setParent(this); States *states = new States(this); - for (int i = 0; i < deviceClass->stateTypes()->rowCount(); i++) { - StateType *st = deviceClass->stateTypes()->get(i); + for (int i = 0; i < thingClass->stateTypes()->rowCount(); i++) { + StateType *st = thingClass->stateTypes()->get(i); State *state = new State(id(), st->id(), QVariant(), this); qDebug() << "Adding state" << st->name() << st->minValue() << st->maxValue(); states->addState(state); } setStates(states); syncStates(); - setName(deviceClass->displayName()); + setName(thingClass->displayName()); - connect(devices, &DevicesProxy::dataChanged, this, [this](const QModelIndex &/*topLeft*/, const QModelIndex &/*bottomRight*/, const QVector &/*roles*/){ + connect(things, &ThingsProxy::dataChanged, this, [this](const QModelIndex &/*topLeft*/, const QModelIndex &/*bottomRight*/, const QVector &/*roles*/){ syncStates(); }); - connect(m_thingManager, &DeviceManager::executeActionReply, this, [this](int commandId, const QVariantMap ¶ms){ + connect(m_thingManager, &ThingManager::executeActionReply, this, [this](int commandId, Thing::ThingError error, const QString &displayMessage){ // This should maybe check the params and create a sensible group result instead of just forwarding the result of the last reply qDebug() << "action reply:" << commandId; foreach (int id, m_pendingGroupActions.keys()) { @@ -63,7 +63,7 @@ ThingGroup::ThingGroup(DeviceManager *deviceManager, DeviceClass *deviceClass, D m_pendingGroupActions[id].removeAll(commandId); if (m_pendingGroupActions[id].isEmpty()) { m_pendingGroupActions.remove(id); - emit executeActionReply(id, params); + emit executeActionReply(id, error, displayMessage); } return; } @@ -84,8 +84,8 @@ int ThingGroup::executeAction(const QString &actionName, const QVariantList &par qDebug() << "Execute action for group:" << this; for (int i = 0; i < m_things->rowCount(); i++) { - Device *thing = m_things->get(i); - if (thing->setupStatus() != Device::ThingSetupStatusComplete) { + Thing *thing = m_things->get(i); + if (thing->setupStatus() != Thing::ThingSetupStatusComplete) { continue; } ActionType *actionType = thing->thingClass()->actionTypes()->findByName(actionName); @@ -135,7 +135,7 @@ void ThingGroup::syncStates() QVariant value; int count = 0; for (int j = 0; j < m_things->rowCount(); j++) { - Device *d = m_things->get(j); + Thing *d = m_things->get(j); // Skip things that don't have the required state StateType *ds = d->thingClass()->stateTypes()->findByName(stateType->name()); if (!ds) { diff --git a/libnymea-app/thinggroup.h b/libnymea-app/thinggroup.h index 533b8888..278329fe 100644 --- a/libnymea-app/thinggroup.h +++ b/libnymea-app/thinggroup.h @@ -33,17 +33,17 @@ #include -#include "types/device.h" +#include "types/thing.h" -class DevicesProxy; -class DeviceManager; +class ThingsProxy; +class ThingManager; class ParamType; -class ThingGroup : public Device +class ThingGroup : public Thing { Q_OBJECT public: - explicit ThingGroup(DeviceManager *deviceManager, DeviceClass *deviceClass, DevicesProxy *devices, QObject *parent = nullptr); + explicit ThingGroup(ThingManager *thingManager, ThingClass *thingClass, ThingsProxy *things, QObject *parent = nullptr); Q_INVOKABLE int executeAction(const QString &actionName, const QVariantList ¶ms) override; @@ -53,7 +53,7 @@ private: QVariant mapValue(const QVariant &value, ParamType *fromParamType, ParamType *toParamType) const; private: - DevicesProxy* m_things = nullptr; + ThingsProxy* m_things = nullptr; int m_idCounter = 0; QHash> m_pendingGroupActions; diff --git a/libnymea-app/thingmanager.cpp b/libnymea-app/thingmanager.cpp new file mode 100644 index 00000000..199128b1 --- /dev/null +++ b/libnymea-app/thingmanager.cpp @@ -0,0 +1,1158 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +* +* 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 "thingmanager.h" +#include "engine.h" +#include "types/browseritems.h" +#include "types/browseritem.h" +#include "thinggroup.h" +#include "types/interface.h" +#include "types/ioconnections.h" + +#include +#include +#include +#include + +ThingManager::ThingManager(JsonRpcClient* jsonclient, QObject *parent) : + JsonHandler(parent), + m_vendors(new Vendors(this)), + m_plugins(new Plugins(this)), + m_things(new Things(this)), + m_thingClasses(new ThingClasses(this)), + m_ioConnections(new IOConnections(this)), + m_jsonClient(jsonclient) +{ + m_jsonClient->registerNotificationHandler(this, "notificationReceived"); +} + +void ThingManager::clear() +{ + m_things->clearModel(); + m_thingClasses->clearModel(); + m_vendors->clearModel(); + m_plugins->clearModel(); + m_ioConnections->clearModel(); +} + +void ThingManager::init() +{ + m_connectionBenchmark = QDateTime::currentDateTime(); + + m_fetchingData = true; + emit fetchingDataChanged(); + + m_jsonClient->sendCommand("Integrations.GetThingClasses", this, "getThingClassesResponse"); +} + +QString ThingManager::nameSpace() const +{ + return "Integrations"; +} + +Vendors *ThingManager::vendors() const +{ + return m_vendors; +} + +Plugins *ThingManager::plugins() const +{ + return m_plugins; +} + +Things *ThingManager::devices() const +{ + return m_things; +} + +Things *ThingManager::things() const +{ + return m_things; +} + +ThingClasses *ThingManager::thingClasses() const +{ + return m_thingClasses; +} + +ThingClasses *ThingManager::deviceClasses() const +{ + return m_thingClasses; +} + +IOConnections *ThingManager::ioConnections() const +{ + return m_ioConnections; +} + +bool ThingManager::fetchingData() const +{ + return m_fetchingData; +} + +int ThingManager::addThing(const QUuid &thingClassId, const QString &name, const QVariantList &thingParams) +{ + QVariantMap params; + params.insert("thingClassId", thingClassId.toString()); + params.insert("name", name); + params.insert("thingParams", thingParams); + return m_jsonClient->sendCommand("Integrations.AddThing", params, this, "addThingResponse"); +} + +void ThingManager::notificationReceived(const QVariantMap &data) +{ + QString notification = data.value("notification").toString(); + if (notification == "Integrations.StateChanged") { + Thing *thing = m_things->getThing(data.value("params").toMap().value("thingId").toUuid()); + if (!thing) { + qWarning() << "Thing state change notification received for an unknown thing"; + return; + } + QUuid stateTypeId = data.value("params").toMap().value("stateTypeId").toUuid(); + QVariant value = data.value("params").toMap().value("value"); +// qDebug() << "Thing state changed for:" << dev->name() << "State name:" << dev->thingClass()->stateTypes()->getStateType(stateTypeId) << "value:" << value; + thing->setStateValue(stateTypeId, value); + emit thingStateChanged(thing->id(), stateTypeId, value); + } else if (notification == "Integrations.ThingAdded") { + Thing *thing = unpackThing(this, data.value("params").toMap().value("thing").toMap(), m_thingClasses); + if (!thing) { + qWarning() << "Cannot parse thing json:" << data; + return; + } + ThingClass *thingClass = thingClasses()->getThingClass(thing->thingClassId()); + if (!thingClass) { + qWarning() << "Skipping invalid thing. Don't have a thing class for it"; + delete thing; + return; + } + m_things->addThing(thing); + } else if (notification == "Integrations.ThingRemoved") { + QUuid thingId = data.value("params").toMap().value("thingId").toUuid(); +// qDebug() << "JsonRpc: Notification: Thing removed" << thingId.toString(); + Thing *thing = m_things->getThing(thingId); + if (!thing) { + qWarning() << "Received a ThingRemoved notification for a thing we don't know!"; + return; + } + m_things->removeThing(thing); + thing->deleteLater(); + } else if (notification == "Integrations.ThingChanged") { + QUuid thingId = data.value("params").toMap().value("thing").toMap().value("id").toUuid(); +// qDebug() << "Thing changed notification" << thingId << data.value("params").toMap(); + Thing *oldThing = m_things->getThing(thingId); + if (!oldThing) { + qWarning() << "Received a thing changed notification for a thing we don't know"; + return; + } + if (!unpackThing(this, data.value("params").toMap().value("thing").toMap(), m_thingClasses, oldThing)) { + qWarning() << "Error parsing thing changed notification" << data; + return; + } + } else if (notification == "Integrations.ThingSettingChanged") { + QUuid thingId = data.value("params").toMap().value("thingId").toUuid(); + QString paramTypeId = data.value("params").toMap().value("paramTypeId").toString(); + QVariant value = data.value("params").toMap().value("value"); +// qDebug() << "Thing settings changed notification for thing" << thingId << data.value("params").toMap().value("settings").toList(); + Thing *thing = m_things->getThing(thingId); + if (!thing) { + qWarning() << "Thing settings changed notification for a thing we don't know" << thingId.toString(); + return; + } + Param *p = thing->settings()->getParam(paramTypeId); + if (!p) { + qWarning() << "Thing" << thing->name() << thing->id().toString() << "does not have a setting of id" << paramTypeId; + return; + } + p->setValue(value); + } else if (notification == "Integrations.EventTriggered") { + QVariantMap event = data.value("params").toMap().value("event").toMap(); + QUuid thingId = event.value("thingId").toUuid(); + QUuid eventTypeId = event.value("eventTypeId").toUuid(); + + Thing *thing = m_things->getThing(thingId); + if (!thing) { + qWarning() << "received an event from a thing we don't know..." << thingId << qUtf8Printable(QJsonDocument::fromVariant(data).toJson()); + return; + } +// qDebug() << "Event received" << thingId.toString() << eventTypeId.toString() << qUtf8Printable(QJsonDocument::fromVariant(event).toJson()); + thing->eventTriggered(eventTypeId.toString(), event.value("params").toMap()); + } else if (notification == "Integrations.IOConnectionAdded") { + QVariantMap connectionMap = data.value("params").toMap().value("ioConnection").toMap(); + QUuid id = connectionMap.value("id").toUuid(); + QUuid inputThingId = connectionMap.value("inputThingId").toUuid(); + QUuid inputStateTypeId = connectionMap.value("inputStateTypeId").toUuid(); + QUuid outputThingId = connectionMap.value("outputThingId").toUuid(); + QUuid outputStateTypeId = connectionMap.value("outputStateTypeId").toUuid(); + bool inverted = connectionMap.value("inverted").toBool(); + IOConnection *ioConnection = new IOConnection(id, inputThingId, inputStateTypeId, outputThingId, outputStateTypeId, inverted); + m_ioConnections->addIOConnection(ioConnection); + } else if (notification == "Integrations.IOConnectionRemoved") { + QUuid connectionId = data.value("params").toMap().value("ioConnectionId").toUuid(); + if (!m_ioConnections->getIOConnection(connectionId)) { + qWarning() << "Received an IO connection removed event for an IO connection we don't know."; + return; + } + m_ioConnections->removeIOConnection(connectionId); + } else { + qWarning() << "ThingManager unhandled thing notification received" << notification; + } +} + +void ThingManager::getVendorsResponse(int /*commandId*/, const QVariantMap ¶ms) +{ +// qDebug() << "Got GetSupportedVendors response" << params; + if (params.keys().contains("vendors")) { + QVariantList vendorList = params.value("vendors").toList(); + foreach (QVariant vendorVariant, vendorList) { + Vendor *vendor = unpackVendor(vendorVariant.toMap()); + m_vendors->addVendor(vendor); +// qDebug() << "Added Vendor:" << vendor->name(); + } + } +} + +void ThingManager::getThingClassesResponse(int /*commandId*/, const QVariantMap ¶ms) +{ + if (params.keys().contains("thingClasses")) { + QVariantList deviceClassList = params.value("thingClasses").toList(); + foreach (QVariant deviceClassVariant, deviceClassList) { + ThingClass *thingClass = unpackThingClass(deviceClassVariant.toMap()); + m_thingClasses->addThingClass(thingClass); + } + } + m_jsonClient->sendCommand("Integrations.GetThings", this, "getThingsResponse"); +} + +void ThingManager::getPluginsResponse(int /*commandId*/, const QVariantMap ¶ms) +{ +// qDebug() << "received plugins"; + if (params.keys().contains("plugins")) { + QVariantList pluginList = params.value("plugins").toList(); + foreach (QVariant pluginVariant, pluginList) { + Plugin *plugin = unpackPlugin(pluginVariant.toMap(), plugins()); + m_plugins->addPlugin(plugin); + } + } + m_jsonClient->sendCommand("Integrations.GetVendors", this, "getVendorsResponse"); + + if (m_plugins->count() > 0) { + m_currentGetConfigIndex = 0; + QVariantMap configRequestParams; + configRequestParams.insert("pluginId", m_plugins->get(m_currentGetConfigIndex)->pluginId()); + m_jsonClient->sendCommand("Integrations.GetPluginConfiguration", configRequestParams, this, "getPluginConfigResponse"); + } +} + +void ThingManager::getPluginConfigResponse(int /*commandId*/, const QVariantMap ¶ms) +{ +// qDebug() << "plugin config response" << params; + Plugin *p = m_plugins->get(m_currentGetConfigIndex); + if (!p) { + qDebug() << "Received a plugin config for a plugin we don't know"; + return; + } + QVariantList pluginParams = params.value("configuration").toList(); + foreach (const QVariant ¶mVariant, pluginParams) { + Param* param = new Param(); + unpackParam(paramVariant.toMap(), param); + p->params()->addParam(param); + } + + m_currentGetConfigIndex++; + if (m_plugins->count() > m_currentGetConfigIndex) { + QVariantMap configRequestParams; + configRequestParams.insert("pluginId", m_plugins->get(m_currentGetConfigIndex)->pluginId()); + m_jsonClient->sendCommand("Integrations.GetPluginConfiguration", configRequestParams, this, "getPluginConfigResponse"); + } +} + +void ThingManager::getThingsResponse(int /*commandId*/, const QVariantMap ¶ms) +{ + qDebug() << "Things received:" << params; + if (params.keys().contains("things")) { + QVariantList thingsList = params.value("things").toList(); + foreach (QVariant thingVariant, thingsList) { + Thing *thing = unpackThing(this, thingVariant.toMap(), m_thingClasses); + if (!thing) { + qWarning() << "Error unpacking thing" << thingVariant.toMap().value("name").toString(); + continue; + } + + // set initial state values + QVariantList stateVariantList = thingVariant.toMap().value("states").toList(); + foreach (const QVariant &stateMap, stateVariantList) { + QString stateTypeId = stateMap.toMap().value("stateTypeId").toString(); + StateType *st = thing->thingClass()->stateTypes()->getStateType(stateTypeId); + if (!st) { + qWarning() << "Can't find a statetype for this state"; + continue; + } + QVariant value = stateMap.toMap().value("value"); + if (st->type() == "Bool") { + value.convert(QVariant::Bool); + } else if (st->type() == "Double") { + value.convert(QVariant::Double); + } else if (st->type() == "Int") { + value.convert(QVariant::Int); + } + thing->setStateValue(stateTypeId, value); +// qDebug() << "Set thing state value:" << thing->stateValue(stateTypeId) << value; + } + devices()->addThing(thing); + } + } + qDebug() << "Initializing thing manager took" << m_connectionBenchmark.msecsTo(QDateTime::currentDateTime()) << "ms"; + m_fetchingData = false; + emit fetchingDataChanged(); + + m_jsonClient->sendCommand("Integrations.GetIOConnections", this, "getIOConnectionsResponse"); + + m_jsonClient->sendCommand("Integrations.GetPlugins", this, "getPluginsResponse"); +} + +void ThingManager::addThingResponse(int commandId, const QVariantMap ¶ms) +{ + qDebug() << "Error from string:" << errorFromString(params.value("thingError").toByteArray()) << params.value("thingError"); + emit addThingReply(commandId, errorFromString(params.value("thingError").toByteArray()), params.value("thingId").toUuid(), params.value("displayMessage").toString()); + + if (params.value("thingError").toString() != "ThingErrorNoError") { + qWarning() << "Failed to add thing:" << params.value("thingError").toString(); + } else if (params.keys().contains("thing")) { + QVariantMap thingVariant = params.value("thing").toMap(); + Thing *thing = unpackThing(this, thingVariant, m_thingClasses); + if (!thing) { + qWarning() << "Couldn't parse json in addThingResponse"; + return; + } + + qDebug() << "Thing added" << thing->id().toString(); + m_things->addThing(thing); + } +} + +void ThingManager::removeThingResponse(int commandId, const QVariantMap ¶ms) +{ + qDebug() << "Thing removed response" << params; + emit removeThingReply(commandId, errorFromString(params.value("thingError").toByteArray()), params.value("ruleIds").toStringList()); +} + +void ThingManager::pairThingResponse(int commandId, const QVariantMap ¶ms) +{ + emit pairThingReply(commandId, + errorFromString(params.value("thingError").toByteArray()), + params.value("pairingTransactionId").toUuid(), + params.value("setupMethod").toString(), + params.value("displayMessage").toString(), + params.value("oAuthUrl").toString()); +} + +void ThingManager::confirmPairingResponse(int commandId, const QVariantMap ¶ms) +{ + qDebug() << "ConfirmPairingResponse" << params; + emit confirmPairingReply(commandId, errorFromString(params.value("thingError").toByteArray()), params.value("thingId").toUuid(), params.value("displayMessage").toString()); +} + +void ThingManager::setPluginConfigResponse(int commandId, const QVariantMap ¶ms) +{ + qDebug() << "set plugin config response" << params; + emit savePluginConfigReply(commandId, errorFromString(params.value("thingError").toByteArray())); +} + +void ThingManager::editThingResponse(int commandId, const QVariantMap ¶ms) +{ + qDebug() << "Edit thing response" << params; + emit editThingReply(commandId, errorFromString(params.value("thingError").toByteArray())); +} + +void ThingManager::executeActionResponse(int commandId, const QVariantMap ¶ms) +{ + qDebug() << "Execute Action response" << params; + emit executeActionReply(commandId, errorFromString(params.value("thingError").toByteArray()), params.value("displayMessage").toString()); +} + +void ThingManager::reconfigureThingResponse(int commandId, const QVariantMap ¶ms) +{ + qDebug() << "Reconfigure device response" << params; + emit reconfigureThingReply(commandId, errorFromString(params.value("thingError").toByteArray()), params.value("displayMessage").toString()); +} + +int ThingManager::savePluginConfig(const QUuid &pluginId) +{ + Plugin *p = m_plugins->getPlugin(pluginId); + if (!p) { + qWarning()<< "Error: can't find plugin with id" << pluginId; + return -1; + } + QVariantMap params; + params.insert("pluginId", pluginId); + QVariantList pluginParams; + for (int i = 0; i < p->params()->rowCount(); i++) { + pluginParams.append(packParam(p->params()->get(i))); + } + params.insert("configuration", pluginParams); + return m_jsonClient->sendCommand("Integrations.SetPluginConfiguration", params, this, "setPluginConfigResponse"); +} + +ThingGroup *ThingManager::createGroup(Interface *interface, ThingsProxy *things) +{ + ThingGroup* group = new ThingGroup(this, interface->createDeviceClass(), things, this); + group->setSetupStatus(Thing::ThingSetupStatusComplete, QString()); + return group; +} + +int ThingManager::addDiscoveredThing(const QUuid &thingClassId, const QUuid &thingDescriptorId, const QString &name, const QVariantList &thingParams) +{ + QVariantMap params; + params.insert("name", name); + params.insert("thingClassId", thingClassId); + params.insert("thingDescriptorId", thingDescriptorId.toString()); + params.insert("thingParams", thingParams); + return m_jsonClient->sendCommand("Integrations.AddThing", params, this, "addThingResponse"); +} + +int ThingManager::pairDiscoveredThing(const QUuid &thingDescriptorId, const QVariantList &thingParams, const QString &name) +{ + QVariantMap params; + params.insert("thingDescriptorId", thingDescriptorId.toString()); + params.insert("thingParams", thingParams); + params.insert("name", name); + + return m_jsonClient->sendCommand("Integrations.PairThing", params, this, "pairThingResponse"); +} + +int ThingManager::pairThing(const QUuid &thingClassId, const QVariantList &thingParams, const QString &name) +{ + QVariantMap params; + params.insert("thingClassId", thingClassId.toString()); + params.insert("thingParams", thingParams); + params.insert("name", name); + return m_jsonClient->sendCommand("Integrations.PairThing", params, this, "pairThingResponse"); +} + +int ThingManager::rePairThing(const QUuid &thingId, const QVariantList &thingParams, const QString &name) +{ + qDebug() << "JsonRpc: pair thing (reconfigure)" << thingId; + QVariantMap params; + params.insert("thingId", thingId.toString()); + params.insert("thingParams", thingParams); + if (!name.isEmpty()) { + params.insert("name", name); + } + return m_jsonClient->sendCommand("Things.PairThing", params, this, "pairThingResponse"); +} + +int ThingManager::confirmPairing(const QUuid &pairingTransactionId, const QString &secret, const QString &username) +{ + qDebug() << "JsonRpc: confirm pairing" << pairingTransactionId.toString(); + QVariantMap params; + params.insert("pairingTransactionId", pairingTransactionId.toString()); + params.insert("secret", secret); + if (!username.isEmpty()) { + params.insert("username", username); + } + return m_jsonClient->sendCommand("Integrations.ConfirmPairing", params, this, "confirmPairingResponse"); +} + +int ThingManager::removeThing(const QUuid &thingId, ThingManager::RemovePolicy policy) +{ + qDebug() << "JsonRpc: remove thing" << thingId.toString(); + QVariantMap params; + params.insert("thingId", thingId.toString()); + if (policy != RemovePolicyNone) { + QMetaEnum policyEnum = QMetaEnum::fromType(); + params.insert("removePolicy", policyEnum.valueToKey(policy)); + } + return m_jsonClient->sendCommand("Integrations.RemoveThing", params, this, "removeThingResponse"); +} + +int ThingManager::editThing(const QUuid &thingId, const QString &name) +{ + QVariantMap params; + params.insert("thingId", thingId.toString()); + params.insert("name", name); + return m_jsonClient->sendCommand("Integrations.EditThing", params, this, "editThingResponse"); +} + +int ThingManager::setThingSettings(const QUuid &thingId, const QVariantList &settings) +{ + QVariantMap params; + params.insert("thingId", thingId); + params.insert("settings", settings); + return m_jsonClient->sendCommand("Integrations.SetThingSettings", params); +} + +int ThingManager::reconfigureThing(const QUuid &thingId, const QVariantList &thingParams) +{ + QVariantMap params; + params.insert("thingId", thingId.toString()); + params.insert("thingParams", thingParams); + return m_jsonClient->sendCommand("Integrations.ReconfigureThing", params, this, "reconfigureThingResponse"); +} + +int ThingManager::reconfigureDiscoveredThing(const QUuid &thingDescriptorId, const QVariantList ¶mOverride) +{ + QVariantMap params; + params.insert("thingDescriptorId", thingDescriptorId); + if (!paramOverride.isEmpty()) { + params.insert("thingParams", paramOverride); + } + return m_jsonClient->sendCommand("Integrations.ReconfigureThing", params, this, "reconfigureThingResponse"); +} + +int ThingManager::executeAction(const QUuid &thingId, const QUuid &actionTypeId, const QVariantList ¶ms) +{ + QVariantMap p; + p.insert("thingId", thingId.toString()); + p.insert("actionTypeId", actionTypeId.toString()); + if (!params.isEmpty()) { + p.insert("params", params); + } + + return m_jsonClient->sendCommand("Integrations.ExecuteAction", p, this, "executeActionResponse"); +} + +BrowserItems *ThingManager::browseThing(const QUuid &thingId, const QString &itemId) +{ + QVariantMap params; + params.insert("thingId", thingId.toString()); + params.insert("itemId", itemId); + int id = m_jsonClient->sendCommand("Integrations.BrowseThing", params, this, "browseThingResponse"); + + // Intentionally not parented. The caller takes ownership and needs to destroy when not needed any more. + BrowserItems *itemModel = new BrowserItems(thingId, itemId); + itemModel->setBusy(true); + QPointer itemModelPtr(itemModel); + m_browsingRequests.insert(id, itemModelPtr); + + return itemModel; +} + +void ThingManager::refreshBrowserItems(BrowserItems *browserItems) +{ + QVariantMap params; + params.insert("thingId", browserItems->thingId().toString()); + params.insert("itemId", browserItems->itemId()); + int id = m_jsonClient->sendCommand("Integrations.BrowseThing", params, this, "browseThingResponse"); + + // Intentionally not parented. The caller takes ownership and needs to destroy when not needed any more. + browserItems->setBusy(true); + QPointer itemModelPtr(browserItems); + m_browsingRequests.insert(id, browserItems); +} + +BrowserItem *ThingManager::browserItem(const QUuid &thingId, const QString &itemId) +{ + QVariantMap params; + params.insert("thingId", thingId.toString()); + params.insert("itemId", itemId); + int id = m_jsonClient->sendCommand("Integrations.GetBrowserItem", params, this, "browserItemResponse"); + + // Intentionally not parented. The caller takes ownership and needs to destroy when not needed any more. + BrowserItem *item = new BrowserItem(itemId); + QPointer itemPtr(item); + m_browserDetailsRequests.insert(id, itemPtr); + + return item; +} + +void ThingManager::browseThingResponse(int commandId, const QVariantMap ¶ms) +{ +// qDebug() << "Browsing response:" << qUtf8Printable(QJsonDocument::fromVariant(params).toJson(QJsonDocument::Indented)); + if (!m_browsingRequests.contains(commandId)) { + qWarning() << "Received a browsing reply for an id we don't know."; + return; + } + + QPointer itemModel = m_browsingRequests.take(commandId); + if (!itemModel) { + qDebug() << "BrowserItems model seems to have disappeared. Discarding browsing result."; + return; + } + + QList itemsToRemove = itemModel->list(); + + foreach (const QVariant &itemVariant, params.value("items").toList()) { + QVariantMap itemMap = itemVariant.toMap(); + QString itemId = itemMap.value("id").toString(); + BrowserItem *item = itemModel->getBrowserItem(itemId); + if (!item) { + item = new BrowserItem(itemId, this); + itemModel->addBrowserItem(item); + } + item->setDisplayName(itemMap.value("displayName").toString()); + item->setDescription(itemMap.value("description").toString()); + item->setIcon(itemMap.value("icon").toString()); + item->setThumbnail(itemMap.value("thumbnail").toString()); + item->setExecutable(itemMap.value("executable").toBool()); + item->setBrowsable(itemMap.value("browsable").toBool()); + item->setDisabled(itemMap.value("disabled").toBool()); + item->setActionTypeIds(itemMap.value("actionTypeIds").toStringList()); + + item->setMediaIcon(itemMap.value("mediaIcon").toString()); + + if (itemsToRemove.contains(item)) { + itemsToRemove.removeAll(item); + } + } + + while (!itemsToRemove.isEmpty()) { + BrowserItem *item = itemsToRemove.takeFirst(); + itemModel->removeItem(item); + } + + itemModel->setBusy(false); +} + +void ThingManager::browserItemResponse(int commandId, const QVariantMap ¶ms) +{ + qDebug() << "Browser item details response:" << qUtf8Printable(QJsonDocument::fromVariant(params).toJson(QJsonDocument::Indented)); + if (!m_browserDetailsRequests.contains(commandId)) { + qWarning() << "Received a browser item details reply for an id we don't know."; + return; + } + + QPointer item = m_browserDetailsRequests.take(commandId); + if (!item) { + qDebug() << "BrowserItem seems to have disappeared. Discarding browser item details result."; + return; + } + + QVariantMap itemMap = params.value("item").toMap(); + item->setDisplayName(itemMap.value("displayName").toString()); + item->setDescription(itemMap.value("description").toString()); + item->setIcon(itemMap.value("icon").toString()); + item->setThumbnail(itemMap.value("thumbnail").toString()); + item->setExecutable(itemMap.value("executable").toBool()); + item->setBrowsable(itemMap.value("browsable").toBool()); + item->setDisabled(itemMap.value("disabled").toBool()); + item->setActionTypeIds(itemMap.value("actionTypeIds").toStringList()); + + item->setMediaIcon(itemMap.value("mediaIcon").toString()); +} + +int ThingManager::executeBrowserItem(const QUuid &thingId, const QString &itemId) +{ + QVariantMap params; + params.insert("thingId", thingId); + params.insert("itemId", itemId); + return m_jsonClient->sendCommand("Integrations.ExecuteBrowserItem", params, this, "executeBrowserItemResponse"); +} + +void ThingManager::executeBrowserItemResponse(int commandId, const QVariantMap ¶ms) +{ + qDebug() << "Execute Browser Item finished" << params; + emit executeBrowserItemReply(commandId, errorFromString(params.value("thingError").toByteArray()), params.value("displayMessage").toString()); +} + +int ThingManager::executeBrowserItemAction(const QUuid &thingId, const QString &itemId, const QUuid &actionTypeId, const QVariantList ¶ms) +{ + QVariantMap data; + data.insert("thingId", thingId); + data.insert("itemId", itemId); + data.insert("actionTypeId", actionTypeId); + data.insert("params", params); + qDebug() << "params:" << params; + return m_jsonClient->sendCommand("Integrations.ExecuteBrowserItemAction", data, this, "executeBrowserItemActionResponse"); +} + +int ThingManager::connectIO(const QUuid &inputThingId, const QUuid &inputStateTypeId, const QUuid &outputThingId, const QUuid &outputStateTypeId, bool inverted) +{ + QVariantMap data; + data.insert("inputThingId", inputThingId); + data.insert("inputStateTypeId", inputStateTypeId); + data.insert("outputThingId", outputThingId); + data.insert("outputStateTypeId", outputStateTypeId); + data.insert("inverted", inverted); + return m_jsonClient->sendCommand("Integrations.ConnectIO", data, this, "connectIOResponse"); +} + +int ThingManager::disconnectIO(const QUuid &ioConnectionId) +{ + QVariantMap data; + data.insert("ioConnectionId", ioConnectionId); + return m_jsonClient->sendCommand("Integrations.DisconnectIO", data, this, "disconnectIOResponse"); +} + +void ThingManager::executeBrowserItemActionResponse(int commandId, const QVariantMap ¶ms) +{ + qDebug() << "Execute Browser Item Action finished" << params; + emit executeBrowserItemActionReply(commandId, errorFromString(params.value("thingError").toByteArray()), params.value("displayMessage").toString()); +} + +void ThingManager::getIOConnectionsResponse(int /*commandId*/, const QVariantMap ¶ms) +{ +// qDebug() << "Get IO connections response" << qUtf8Printable(QJsonDocument::fromVariant(params).toJson()); + + foreach (const QVariant &connectionVariant, params.value("ioConnections").toList()) { + QVariantMap connectionMap = connectionVariant.toMap(); + QUuid id = connectionMap.value("id").toUuid(); + QUuid inputThingId = connectionMap.value("inputThingId").toUuid(); + QUuid inputStateTypeId = connectionMap.value("inputStateTypeId").toUuid(); + QUuid outputThingId = connectionMap.value("outputThingId").toUuid(); + QUuid outputStateTypeId = connectionMap.value("outputStateTypeId").toUuid(); + bool inverted = connectionMap.value("inverted").toBool(); + IOConnection *ioConnection = new IOConnection(id, inputThingId, inputStateTypeId, outputThingId, outputStateTypeId, inverted); + m_ioConnections->addIOConnection(ioConnection); + } +} + +void ThingManager::connectIOResponse(int commandId, const QVariantMap ¶ms) +{ + qDebug() << "ConnectIO response" << commandId << qUtf8Printable(QJsonDocument::fromVariant(params).toJson()); +} + +void ThingManager::disconnectIOResponse(int commandId, const QVariantMap ¶ms) +{ + qDebug() << "DisconnectIO response" << commandId << qUtf8Printable(QJsonDocument::fromVariant(params).toJson()); +} + +Vendor *ThingManager::unpackVendor(const QVariantMap &vendorMap) +{ + Vendor *v = new Vendor(vendorMap.value("id").toString(), vendorMap.value("name").toString()); + v->setDisplayName(vendorMap.value("displayName").toString()); + return v; +} + +Plugin *ThingManager::unpackPlugin(const QVariantMap &pluginMap, QObject *parent) +{ + Plugin *plugin = new Plugin(parent); + plugin->setName(pluginMap.value("name").toString()); + plugin->setPluginId(pluginMap.value("id").toUuid()); + ParamTypes *paramTypes = new ParamTypes(plugin); + foreach (QVariant paramType, pluginMap.value("paramTypes").toList()) { + paramTypes->addParamType(unpackParamType(paramType.toMap(), paramTypes)); + } + plugin->setParamTypes(paramTypes); + return plugin; +} + +ThingClass *ThingManager::unpackThingClass(const QVariantMap &thingClassMap) +{ + ThingClass *thingClass = new ThingClass(); + thingClass->setName(thingClassMap.value("name").toString()); + thingClass->setDisplayName(thingClassMap.value("displayName").toString()); + thingClass->setId(thingClassMap.value("id").toUuid()); + thingClass->setVendorId(thingClassMap.value("vendorId").toUuid()); + thingClass->setBrowsable(thingClassMap.value("browsable").toBool()); + QVariantList createMethodsList = thingClassMap.value("createMethods").toList(); + QStringList createMethods; + foreach (QVariant method, createMethodsList) { + createMethods.append(method.toString()); + } + thingClass->setCreateMethods(createMethods); + thingClass->setSetupMethod(stringToSetupMethod(thingClassMap.value("setupMethod").toString())); + thingClass->setInterfaces(thingClassMap.value("interfaces").toStringList()); + + // ParamTypes + ParamTypes *paramTypes = new ParamTypes(thingClass); + foreach (QVariant paramType, thingClassMap.value("paramTypes").toList()) { + paramTypes->addParamType(unpackParamType(paramType.toMap(), paramTypes)); + } + thingClass->setParamTypes(paramTypes); + + // SettingsTypes + ParamTypes *settingsTypes = new ParamTypes(thingClass); + foreach (QVariant settingsType, thingClassMap.value("settingsTypes").toList()) { + settingsTypes->addParamType(unpackParamType(settingsType.toMap(), settingsTypes)); + } + thingClass->setSettingsTypes(settingsTypes); + + // discovery ParamTypes + ParamTypes *discoveryParamTypes = new ParamTypes(thingClass); + foreach (QVariant paramType, thingClassMap.value("discoveryParamTypes").toList()) { + discoveryParamTypes->addParamType(unpackParamType(paramType.toMap(), discoveryParamTypes)); + } + thingClass->setDiscoveryParamTypes(discoveryParamTypes); + + // StateTypes + StateTypes *stateTypes = new StateTypes(thingClass); + foreach (QVariant stateType, thingClassMap.value("stateTypes").toList()) { + stateTypes->addStateType(unpackStateType(stateType.toMap(), stateTypes)); + } + thingClass->setStateTypes(stateTypes); + + // EventTypes + EventTypes *eventTypes = new EventTypes(thingClass); + foreach (QVariant eventType, thingClassMap.value("eventTypes").toList()) { + eventTypes->addEventType(unpackEventType(eventType.toMap(), eventTypes)); + } + thingClass->setEventTypes(eventTypes); + + // ActionTypes + ActionTypes *actionTypes = new ActionTypes(thingClass); + foreach (QVariant actionType, thingClassMap.value("actionTypes").toList()) { + actionTypes->addActionType(unpackActionType(actionType.toMap(), actionTypes)); + } + thingClass->setActionTypes(actionTypes); + + // BrowserItemActionTypes + ActionTypes *browserItemActionTypes = new ActionTypes(thingClass); + foreach (QVariant actionType, thingClassMap.value("browserItemActionTypes").toList()) { + browserItemActionTypes->addActionType(unpackActionType(actionType.toMap(), actionTypes)); + } + thingClass->setBrowserItemActionTypes(browserItemActionTypes); + + return thingClass; +} + +void ThingManager::unpackParam(const QVariantMap ¶mMap, Param *param) +{ + param->setParamTypeId(paramMap.value("paramTypeId").toString()); + param->setValue(paramMap.value("value")); +} + +ParamType *ThingManager::unpackParamType(const QVariantMap ¶mTypeMap, QObject *parent) +{ + ParamType *paramType = new ParamType(parent); + paramType->setId(paramTypeMap.value("id").toString()); + paramType->setName(paramTypeMap.value("name").toString()); + paramType->setDisplayName(paramTypeMap.value("displayName").toString()); + paramType->setType(paramTypeMap.value("type").toString()); + paramType->setIndex(paramTypeMap.value("index").toInt()); + paramType->setDefaultValue(paramTypeMap.value("defaultValue")); + paramType->setMinValue(paramTypeMap.value("minValue")); + paramType->setMaxValue(paramTypeMap.value("maxValue")); + paramType->setAllowedValues(paramTypeMap.value("allowedValues").toList()); + paramType->setInputType(stringToInputType(paramTypeMap.value("inputType").toString())); + paramType->setReadOnly(paramTypeMap.value("readOnly").toBool()); + QPair unit = stringToUnit(paramTypeMap.value("unit").toString()); + paramType->setUnit(unit.first); + paramType->setUnitString(unit.second); + return paramType; +} + +StateType *ThingManager::unpackStateType(const QVariantMap &stateTypeMap, QObject *parent) +{ + StateType *stateType = new StateType(parent); + stateType->setId(stateTypeMap.value("id").toString()); + stateType->setName(stateTypeMap.value("name").toString()); + stateType->setDisplayName(stateTypeMap.value("displayName").toString()); + stateType->setIndex(stateTypeMap.value("index").toInt()); + stateType->setDefaultValue(stateTypeMap.value("defaultValue")); + stateType->setAllowedValues(stateTypeMap.value("possibleValues").toList()); + stateType->setType(stateTypeMap.value("type").toString()); + stateType->setMinValue(stateTypeMap.value("minValue")); + stateType->setMaxValue(stateTypeMap.value("maxValue")); + + QPair unit = stringToUnit(stateTypeMap.value("unit").toString()); + stateType->setUnit(unit.first); + stateType->setUnitString(unit.second); + + QMetaEnum metaEnum = QMetaEnum::fromType(); + Types::IOType ioType = static_cast(metaEnum.keyToValue(stateTypeMap.value("ioType").toByteArray())); + stateType->setIOType(ioType); + + return stateType; +} + +EventType *ThingManager::unpackEventType(const QVariantMap &eventTypeMap, QObject *parent) +{ + EventType *eventType = new EventType(parent); + eventType->setId(eventTypeMap.value("id").toString()); + eventType->setName(eventTypeMap.value("name").toString()); + eventType->setDisplayName(eventTypeMap.value("displayName").toString()); + eventType->setIndex(eventTypeMap.value("index").toInt()); + ParamTypes *paramTypes = new ParamTypes(eventType); + foreach (QVariant paramType, eventTypeMap.value("paramTypes").toList()) { + paramTypes->addParamType(unpackParamType(paramType.toMap(), paramTypes)); + } + eventType->setParamTypes(paramTypes); + return eventType; +} + +ActionType *ThingManager::unpackActionType(const QVariantMap &actionTypeMap, QObject *parent) +{ + ActionType *actionType = new ActionType(parent); + actionType->setId(actionTypeMap.value("id").toString()); + actionType->setName(actionTypeMap.value("name").toString()); + actionType->setDisplayName(actionTypeMap.value("displayName").toString()); + actionType->setIndex(actionTypeMap.value("index").toInt()); + ParamTypes *paramTypes = new ParamTypes(actionType); + foreach (QVariant paramType, actionTypeMap.value("paramTypes").toList()) { + paramTypes->addParamType(unpackParamType(paramType.toMap(), paramTypes)); + } + actionType->setParamTypes(paramTypes); + return actionType; +} + +Thing* ThingManager::unpackThing(ThingManager *thingManager, const QVariantMap &thingMap, ThingClasses *thingClasses, Thing *oldThing) +{ + QUuid thingClassId = thingMap.value("thingClassId").toUuid(); + ThingClass *thingClass = thingClasses->getThingClass(thingClassId); + if (!thingClass) { + qWarning() << "Cannot find a thing class for this thing"; + return nullptr; + } + + QUuid parentId = thingMap.value("parentId").toUuid(); + Thing *thing = nullptr; + if (oldThing) { + thing = oldThing; + } else { + thing = new Thing(thingManager, thingClass, parentId); + } + thing->setName(thingMap.value("name").toString()); + thing->setId(thingMap.value("id").toUuid()); + // As of JSONRPC 4.2 setupComplete is deprecated and setupStatus is new + if (thingMap.contains("setupStatus")) { + QString setupStatus = thingMap.value("setupStatus").toString(); + QString setupDisplayMessage = thingMap.value("setupDisplayMessage").toString(); + if (setupStatus == "ThingSetupStatusNone") { + thing->setSetupStatus(Thing::ThingSetupStatusNone, setupDisplayMessage); + } else if (setupStatus == "ThingSetupStatusInProgress") { + thing->setSetupStatus(Thing::ThingSetupStatusInProgress, setupDisplayMessage); + } else if (setupStatus == "ThingSetupStatusComplete") { + thing->setSetupStatus(Thing::ThingSetupStatusComplete, setupDisplayMessage); + } else if (setupStatus == "ThingSetupStatusFailed") { + thing->setSetupStatus(Thing::ThingSetupStatusFailed, setupDisplayMessage); + } + } else { + thing->setSetupStatus(thingMap.value("setupComplete").toBool() ? Thing::ThingSetupStatusComplete : Thing::ThingSetupStatusNone, QString()); + } + + Params *params = thing->params(); + if (!params) { + params = new Params(thing); + } + foreach (QVariant param, thingMap.value("params").toList()) { + Param *p = params->getParam(param.toMap().value("paramTypeId").toString()); + if (!p) { + p = new Param(); + params->addParam(p); + } + unpackParam(param.toMap(), p); + } + thing->setParams(params); + + Params *settings = thing->settings(); + if (!settings) { + settings = new Params(thing); + } + foreach (QVariant setting, thingMap.value("settings").toList()) { + Param *p = settings->getParam(setting.toMap().value("paramTypeId").toString()); + if (!p) { + p = new Param(); + settings->addParam(p); + } + unpackParam(setting.toMap(), p); + } + thing->setSettings(settings); + + States *states = thing->states(); + if (!states) { + states = new States(thing); + } + foreach (const QVariant &stateVariant, thingMap.value("states").toList()) { + State *state = states->getState(stateVariant.toMap().value("stateTypeId").toUuid()); + if (!state) { + state = new State(thing->id(), stateVariant.toMap().value("stateTypeId").toUuid(), stateVariant.toMap().value("value"), states); + states->addState(state); + } else { + state->setValue(stateVariant.toMap().value("value")); + } + } + thing->setStates(states); + + return thing; +} + + + + +QVariantMap ThingManager::packParam(Param *param) +{ + QVariantMap ret; + ret.insert("paramTypeId", param->paramTypeId()); + ret.insert("value", param->value()); + return ret; +} + +Thing::ThingError ThingManager::errorFromString(const QByteArray &thingErrorString) +{ + QMetaEnum metaEnum = QMetaEnum::fromType(); + return static_cast(metaEnum.keyToValue(thingErrorString)); +} + +ThingClass::SetupMethod ThingManager::stringToSetupMethod(const QString &setupMethodString) +{ + if (setupMethodString == "SetupMethodJustAdd") { + return ThingClass::SetupMethodJustAdd; + } else if (setupMethodString == "SetupMethodDisplayPin") { + return ThingClass::SetupMethodDisplayPin; + } else if (setupMethodString == "SetupMethodEnterPin") { + return ThingClass::SetupMethodEnterPin; + } else if (setupMethodString == "SetupMethodPushButton") { + return ThingClass::SetupMethodPushButton; + } else if (setupMethodString == "SetupMethodOAuth") { + return ThingClass::SetupMethodOAuth; + } else if (setupMethodString == "SetupMethodUserAndPassword") { + return ThingClass::SetupMethodUserAndPassword; + } + return ThingClass::SetupMethodJustAdd; +} + +QPair ThingManager::stringToUnit(const QString &unitString) +{ + if (unitString == "UnitNone") { + return QPair(Types::UnitNone, ""); + } else if (unitString == "UnitSeconds") { + return QPair(Types::UnitSeconds, "s"); + } else if (unitString == "UnitMinutes") { + return QPair(Types::UnitMinutes, "m"); + } else if (unitString == "UnitHours") { + return QPair(Types::UnitHours, "h"); + } else if (unitString == "UnitUnixTime") { + return QPair(Types::UnitUnixTime, "datetime"); + } else if (unitString == "UnitMeterPerSecond") { + return QPair(Types::UnitMeterPerSecond, "m/s"); + } else if (unitString == "UnitKiloMeterPerHour") { + return QPair(Types::UnitKiloMeterPerHour, "km/h"); + } else if (unitString == "UnitDegree") { + return QPair(Types::UnitDegree, "°"); + } else if (unitString == "UnitRadiant") { + return QPair(Types::UnitRadiant, "rad"); + } else if (unitString == "UnitDegreeCelsius") { + return QPair(Types::UnitDegreeCelsius, "°C"); + } else if (unitString == "UnitDegreeKelvin") { + return QPair(Types::UnitDegreeKelvin, "°K"); + } else if (unitString == "UnitMired") { + return QPair(Types::UnitMired, "mir"); + } else if (unitString == "UnitMilliBar") { + return QPair(Types::UnitMilliBar, "mbar"); + } else if (unitString == "UnitBar") { + return QPair(Types::UnitBar, "bar"); + } else if (unitString == "UnitPascal") { + return QPair(Types::UnitPascal, "Pa"); + } else if (unitString == "UnitHectoPascal") { + return QPair(Types::UnitHectoPascal, "hPa"); + } else if (unitString == "UnitAtmosphere") { + return QPair(Types::UnitAtmosphere, "atm"); + } else if (unitString == "UnitLumen") { + return QPair(Types::UnitLumen, "lm"); + } else if (unitString == "UnitLux") { + return QPair(Types::UnitLux, "lx"); + } else if (unitString == "UnitCandela") { + return QPair(Types::UnitCandela, "cd"); + } else if (unitString == "UnitMilliMeter") { + return QPair(Types::UnitMilliMeter, "mm"); + } else if (unitString == "UnitCentiMeter") { + return QPair(Types::UnitCentiMeter, "cm"); + } else if (unitString == "UnitMeter") { + return QPair(Types::UnitMeter, "m"); + } else if (unitString == "UnitKiloMeter") { + return QPair(Types::UnitKiloMeter, "km"); + } else if (unitString == "UnitGram") { + return QPair(Types::UnitGram, "g"); + } else if (unitString == "UnitKiloGram") { + return QPair(Types::UnitKiloGram, "kg"); + } else if (unitString == "UnitDezibel") { + return QPair(Types::UnitDezibel, "db"); + } else if (unitString == "UnitBpm") { + return QPair(Types::UnitBpm, "bpm"); + } else if (unitString == "UnitKiloByte") { + return QPair(Types::UnitKiloByte, "kB"); + } else if (unitString == "UnitMegaByte") { + return QPair(Types::UnitMegaByte, "MB"); + } else if (unitString == "UnitGigaByte") { + return QPair(Types::UnitGigaByte, "GB"); + } else if (unitString == "UnitTeraByte") { + return QPair(Types::UnitTeraByte, "TB"); + } else if (unitString == "UnitMilliWatt") { + return QPair(Types::UnitMilliWatt, "mW"); + } else if (unitString == "UnitWatt") { + return QPair(Types::UnitWatt, "W"); + } else if (unitString == "UnitKiloWatt") { + return QPair(Types::UnitKiloWatt, "kW"); + } else if (unitString == "UnitKiloWattHour") { + return QPair(Types::UnitKiloWattHour, "kWh"); + } else if (unitString == "UnitEuroPerMegaWattHour") { + return QPair(Types::UnitEuroPerMegaWattHour, "€/MWh"); + } else if (unitString == "UnitEuroCentPerKiloWattHour") { + return QPair(Types::UnitEuroCentPerKiloWattHour, "ct/kWh"); + } else if (unitString == "UnitPercentage") { + return QPair(Types::UnitPercentage, "%"); + } else if (unitString == "UnitPartsPerMillion") { + return QPair(Types::UnitPartsPerMillion, "ppm"); + } else if (unitString == "UnitEuro") { + return QPair(Types::UnitEuro, "€"); + } else if (unitString == "UnitDollar") { + return QPair(Types::UnitDollar, "$"); + } else if (unitString == "UnitHerz") { // legacy + return QPair(Types::UnitHertz, "Hz"); + } else if (unitString == "UnitHertz") { + return QPair(Types::UnitHertz, "Hz"); + } else if (unitString == "UnitAmpere") { + return QPair(Types::UnitAmpere, "A"); + } else if (unitString == "UnitMilliAmpere") { + return QPair(Types::UnitMilliAmpere, "mA"); + } else if (unitString == "UnitVolt") { + return QPair(Types::UnitVolt, "V"); + } else if (unitString == "UnitMilliVolt") { + return QPair(Types::UnitMilliVolt, "mV"); + } else if (unitString == "UnitVoltAmpere") { + return QPair(Types::UnitVoltAmpere, "VA"); + } else if (unitString == "UnitVoltAmpereReactive") { + return QPair(Types::UnitVoltAmpereReactive, "VAR"); + } else if (unitString == "UnitAmpereHour") { + return QPair(Types::UnitAmpereHour, "Ah"); + } else if (unitString == "UnitMicroSiemensPerCentimeter") { + return QPair(Types::UnitMicroSiemensPerCentimeter, "µS/cm"); + } else if (unitString == "UnitDuration") { + return QPair(Types::UnitDuration, "s"); + } + + return QPair(Types::UnitNone, ""); +} + +Types::InputType ThingManager::stringToInputType(const QString &inputTypeString) +{ + if (inputTypeString == "InputTypeNone") { + return Types::InputTypeNone; + } else if (inputTypeString == "InputTypeTextLine") { + return Types::InputTypeTextLine; + } else if (inputTypeString == "InputTypeTextArea") { + return Types::InputTypeTextArea; + } else if (inputTypeString == "InputTypePassword") { + return Types::InputTypePassword; + } else if (inputTypeString == "InputTypeSearch") { + return Types::InputTypeSearch; + } else if (inputTypeString == "InputTypeMail") { + return Types::InputTypeMail; + } else if (inputTypeString == "InputTypeIPv4Address") { + return Types::InputTypeIPv4Address; + } else if (inputTypeString == "InputTypeIPv6Address") { + return Types::InputTypeIPv6Address; + } else if (inputTypeString == "InputTypeUrl") { + return Types::InputTypeUrl; + } else if (inputTypeString == "InputTypeMacAddress") { + return Types::InputTypeMacAddress; + } + return Types::InputTypeNone; +} diff --git a/libnymea-app/devicemanager.h b/libnymea-app/thingmanager.h similarity index 53% rename from libnymea-app/devicemanager.h rename to libnymea-app/thingmanager.h index e8959c00..88f6ddff 100644 --- a/libnymea-app/devicemanager.h +++ b/libnymea-app/thingmanager.h @@ -28,14 +28,14 @@ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -#ifndef DEVICEMANAGER_H -#define DEVICEMANAGER_H +#ifndef THINGMANAGER_H +#define THINGMANAGER_H #include #include "types/vendors.h" -#include "devices.h" -#include "deviceclasses.h" +#include "things.h" +#include "thingclasses.h" #include "interfacesmodel.h" #include "types/plugins.h" #include "jsonrpc/jsonhandler.h" @@ -49,14 +49,15 @@ class IOConnections; class EventHandler; class IntegrationsHandler; -class DeviceManager : public JsonHandler +class ThingManager : public JsonHandler { Q_OBJECT Q_PROPERTY(Vendors* vendors READ vendors CONSTANT) Q_PROPERTY(Plugins* plugins READ plugins CONSTANT) - Q_PROPERTY(Devices* things READ things CONSTANT) - Q_PROPERTY(Devices* devices READ devices CONSTANT) - Q_PROPERTY(DeviceClasses* deviceClasses READ deviceClasses CONSTANT) + Q_PROPERTY(Things* things READ things CONSTANT) + Q_PROPERTY(Things* devices READ devices CONSTANT) + Q_PROPERTY(ThingClasses* thingClasses READ thingClasses CONSTANT) + Q_PROPERTY(ThingClasses* deviceClasses READ thingClasses CONSTANT) Q_PROPERTY(IOConnections* ioConnections READ ioConnections CONSTANT) Q_PROPERTY(bool fetchingData READ fetchingData NOTIFY fetchingDataChanged) @@ -70,7 +71,7 @@ public: }; Q_ENUM(RemovePolicy) - explicit DeviceManager(JsonRpcClient *jsonclient, QObject *parent = nullptr); + explicit ThingManager(JsonRpcClient *jsonclient, QObject *parent = nullptr); void clear(); void init(); @@ -79,33 +80,32 @@ public: Vendors* vendors() const; Plugins* plugins() const; - Devices* devices() const; - Devices* things() const; - DeviceClasses* deviceClasses() const; - DeviceClasses* thingClasses() const; + Things* devices() const; + Things* things() const; + ThingClasses* thingClasses() const; + ThingClasses* deviceClasses() const; IOConnections* ioConnections() const; bool fetchingData() const; - Q_INVOKABLE int addDevice(const QUuid &deviceClassId, const QString &name, const QVariantList &deviceParams); - // param deviceClassId is deprecated and should be removed when minimum JSONRPC version is 3.1 - Q_INVOKABLE int addDiscoveredDevice(const QUuid &deviceClassId, const QUuid &deviceDescriptorId, const QString &name, const QVariantList &deviceParams); - Q_INVOKABLE int pairDevice(const QUuid &deviceClassId, const QVariantList &deviceParams, const QString &name); - // param deviceClassId is deprecated and should be removed when minimum JSONRPC version is 3.1 - Q_INVOKABLE int pairDiscoveredDevice(const QUuid &deviceClassId, const QUuid &deviceDescriptorId, const QVariantList &deviceParams, const QString &name); - Q_INVOKABLE int rePairDevice(const QUuid &deviceId, const QVariantList &deviceParams, const QString &name = QString()); + Q_INVOKABLE int addThing(const QUuid &thingClassId, const QString &name, const QVariantList &thingParams); + // Param thingClassId is deprecated as of jsonrpc 5.4 + Q_INVOKABLE int addDiscoveredThing(const QUuid &thingClassId, const QUuid &thingDescriptorId, const QString &name, const QVariantList &thingParams); + Q_INVOKABLE int pairThing(const QUuid &thingClassId, const QVariantList &thingParams, const QString &name); + Q_INVOKABLE int pairDiscoveredThing(const QUuid &thingDescriptorId, const QVariantList &thingParams, const QString &name); + Q_INVOKABLE int rePairThing(const QUuid &thingId, const QVariantList &thingParams, const QString &name = QString()); Q_INVOKABLE int confirmPairing(const QUuid &pairingTransactionId, const QString &secret = QString(), const QString &username = QString()); Q_INVOKABLE int removeThing(const QUuid &thingId, RemovePolicy policy = RemovePolicyNone); Q_INVOKABLE int editThing(const QUuid &thingId, const QString &name); - Q_INVOKABLE int setDeviceSettings(const QUuid &deviceId, const QVariantList &settings); - Q_INVOKABLE int reconfigureDevice(const QUuid &deviceId, const QVariantList &deviceParams); - Q_INVOKABLE int reconfigureDiscoveredDevice(const QUuid &deviceId, const QUuid &deviceDescriptorId, const QVariantList ¶mOverride); - Q_INVOKABLE int executeAction(const QUuid &deviceId, const QUuid &actionTypeId, const QVariantList ¶ms = QVariantList()); - Q_INVOKABLE BrowserItems* browseDevice(const QUuid &deviceId, const QString &itemId = QString()); + Q_INVOKABLE int setThingSettings(const QUuid &thingId, const QVariantList &settings); + Q_INVOKABLE int reconfigureThing(const QUuid &thingId, const QVariantList &thingParams); + Q_INVOKABLE int reconfigureDiscoveredThing(const QUuid &thingDescriptorId, const QVariantList ¶mOverride); + Q_INVOKABLE int executeAction(const QUuid &thingId, const QUuid &actionTypeId, const QVariantList ¶ms = QVariantList()); + Q_INVOKABLE BrowserItems* browseThing(const QUuid &thingId, const QString &itemId = QString()); Q_INVOKABLE void refreshBrowserItems(BrowserItems *browserItems); - Q_INVOKABLE BrowserItem* browserItem(const QUuid &deviceId, const QString &itemId); - Q_INVOKABLE int executeBrowserItem(const QUuid &deviceId, const QString &itemId); - Q_INVOKABLE int executeBrowserItemAction(const QUuid &deviceId, const QString &itemId, const QUuid &actionTypeId, const QVariantList ¶ms = QVariantList()); + Q_INVOKABLE BrowserItem* browserItem(const QUuid &thingId, const QString &itemId); + Q_INVOKABLE int executeBrowserItem(const QUuid &thingId, const QString &itemId); + Q_INVOKABLE int executeBrowserItemAction(const QUuid &thingId, const QString &itemId, const QUuid &actionTypeId, const QVariantList ¶ms = QVariantList()); Q_INVOKABLE int connectIO(const QUuid &inputThingId, const QUuid &inputStateTypeId, const QUuid &outputThingId, const QUuid &outputStateTypeId, bool inverted); Q_INVOKABLE int disconnectIO(const QUuid &ioConnectionId); @@ -113,19 +113,19 @@ public: private: Q_INVOKABLE void notificationReceived(const QVariantMap &data); Q_INVOKABLE void getVendorsResponse(int commandId, const QVariantMap ¶ms); - Q_INVOKABLE void getSupportedDevicesResponse(int commandId, const QVariantMap ¶ms); + Q_INVOKABLE void getThingClassesResponse(int commandId, const QVariantMap ¶ms); Q_INVOKABLE void getPluginsResponse(int commandId, const QVariantMap ¶ms); Q_INVOKABLE void getPluginConfigResponse(int commandId, const QVariantMap ¶ms); - Q_INVOKABLE void getConfiguredDevicesResponse(int commandId, const QVariantMap ¶ms); - Q_INVOKABLE void addDeviceResponse(int commandId, const QVariantMap ¶ms); + Q_INVOKABLE void getThingsResponse(int commandId, const QVariantMap ¶ms); + Q_INVOKABLE void addThingResponse(int commandId, const QVariantMap ¶ms); Q_INVOKABLE void removeThingResponse(int commandId, const QVariantMap ¶ms); - Q_INVOKABLE void pairDeviceResponse(int commandId, const QVariantMap ¶ms); + Q_INVOKABLE void pairThingResponse(int commandId, const QVariantMap ¶ms); Q_INVOKABLE void confirmPairingResponse(int commandId, const QVariantMap ¶ms); Q_INVOKABLE void setPluginConfigResponse(int commandId, const QVariantMap ¶ms); Q_INVOKABLE void editThingResponse(int commandId, const QVariantMap ¶ms); Q_INVOKABLE void executeActionResponse(int commandId, const QVariantMap ¶ms); - Q_INVOKABLE void reconfigureDeviceResponse(int commandId, const QVariantMap ¶ms); - Q_INVOKABLE void browseDeviceResponse(int commandId, const QVariantMap ¶ms); + Q_INVOKABLE void reconfigureThingResponse(int commandId, const QVariantMap ¶ms); + Q_INVOKABLE void browseThingResponse(int commandId, const QVariantMap ¶ms); Q_INVOKABLE void browserItemResponse(int commandId, const QVariantMap ¶ms); Q_INVOKABLE void executeBrowserItemResponse(int commandId, const QVariantMap ¶ms); Q_INVOKABLE void executeBrowserItemActionResponse(int commandId, const QVariantMap ¶ms); @@ -136,30 +136,48 @@ private: public slots: int savePluginConfig(const QUuid &pluginId); - ThingGroup* createGroup(Interface *interface, DevicesProxy *things); + ThingGroup* createGroup(Interface *interface, ThingsProxy *things); signals: - void pairDeviceReply(int commandId, const QVariantMap ¶ms); - void confirmPairingReply(int commandId, const QVariantMap ¶ms); - void addDeviceReply(int commandId, const QVariantMap ¶ms); - void removeThingReply(int commandId, const QVariantMap ¶ms); - void savePluginConfigReply(int commandId, const QVariantMap ¶ms); - void editThingReply(int commandId, const QVariantMap ¶ms); - void reconfigureDeviceReply(int commandId, const QVariantMap ¶ms); - void executeActionReply(int commandId, const QVariantMap ¶ms); - void executeBrowserItemReply(int commandId, const QVariantMap ¶ms); - void executeBrowserItemActionReply(int commandId, const QVariantMap ¶ms); + void addThingReply(int commandId, Thing::ThingError thingError, const QUuid &thingId, const QString &displayMessage); + void pairThingReply(int commandId, Thing::ThingError thingError, const QUuid &pairingTransactionId, const QString &setupMethod, const QString &displayMessage, const QString &oAuthUrl); + void confirmPairingReply(int commandId, Thing::ThingError thingError, const QUuid &thingId, const QString &displayMessage); + void removeThingReply(int commandId, Thing::ThingError thingError, const QStringList ruleIds); + void savePluginConfigReply(int commandId, Thing::ThingError thingError); + void editThingReply(int commandId, Thing::ThingError thingError); + void reconfigureThingReply(int commandId, Thing::ThingError thingError, const QString &displayMessage); + void executeActionReply(int commandId, Thing::ThingError thingError, const QString &displayMessage); + void executeBrowserItemReply(int commandId, Thing::ThingError thingError, const QString &displayMessage); + void executeBrowserItemActionReply(int commandId, Thing::ThingError thingError, const QString &displayMessage); void fetchingDataChanged(); - void notificationReceived(const QString &deviceId, const QString &eventTypeId, const QVariantList ¶ms); + void notificationReceived(const QString &thingId, const QString &eventTypeId, const QVariantList ¶ms); - void eventTriggered(const QUuid &deviceId, const QUuid &eventTypeId, const QVariantMap params); - void thingStateChanged(const QUuid &deviceId, const QUuid &stateTypeId, const QVariant &value); + void eventTriggered(const QUuid &thingId, const QUuid &eventTypeId, const QVariantMap params); + void thingStateChanged(const QUuid &thingId, const QUuid &stateTypeId, const QVariant &value); + +private: + static Vendor *unpackVendor(const QVariantMap &vendorMap); + static Plugin *unpackPlugin(const QVariantMap &pluginMap, QObject *parent); + static ThingClass *unpackThingClass(const QVariantMap &deviceClassMap); + static void unpackParam(const QVariantMap ¶mMap, Param *param); + static ParamType *unpackParamType(const QVariantMap ¶mTypeMap, QObject *parent); + static StateType *unpackStateType(const QVariantMap &stateTypeMap, QObject *parent); + static EventType *unpackEventType(const QVariantMap &eventTypeMap, QObject *parent); + static ActionType *unpackActionType(const QVariantMap &actionTypeMap, QObject *parent); + static Thing *unpackThing(ThingManager *thingManager, const QVariantMap &thingMap, ThingClasses *thingClasses, Thing *oldThing = nullptr); + + static QVariantMap packParam(Param *param); + + static Thing::ThingError errorFromString(const QByteArray &thingErrorString); + static ThingClass::SetupMethod stringToSetupMethod(const QString &setupMethodString); + static QPair stringToUnit(const QString &unitString); + static Types::InputType stringToInputType(const QString &inputTypeString); private: Vendors *m_vendors; Plugins *m_plugins; - Devices *m_devices; - DeviceClasses *m_thingClasses; + Things *m_things; + ThingClasses *m_thingClasses; IOConnections *m_ioConnections; bool m_fetchingData = false; @@ -218,4 +236,4 @@ private: } }; -#endif // DEVICEMANAGER_H +#endif // THINGMANAGER_H diff --git a/libnymea-app/devices.cpp b/libnymea-app/things.cpp similarity index 74% rename from libnymea-app/devices.cpp rename to libnymea-app/things.cpp index 321600d3..cd4b7811 100644 --- a/libnymea-app/devices.cpp +++ b/libnymea-app/things.cpp @@ -28,22 +28,22 @@ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -#include "devices.h" +#include "things.h" #include "engine.h" #include -Devices::Devices(QObject *parent) : +Things::Things(QObject *parent) : QAbstractListModel(parent) { } -QList Devices::devices() +QList Things::devices() { return m_things; } -Device *Devices::get(int index) const +Thing *Things::get(int index) const { if (index < 0 || index >= m_things.count()) { return nullptr; @@ -51,9 +51,9 @@ Device *Devices::get(int index) const return m_things.at(index); } -Device *Devices::getThing(const QUuid &thingId) const +Thing *Things::getThing(const QUuid &thingId) const { - foreach (Device *thing, m_things) { + foreach (Thing *thing, m_things) { if (thing->id() == thingId) { return thing; } @@ -61,23 +61,18 @@ Device *Devices::getThing(const QUuid &thingId) const return nullptr; } -Device *Devices::getDevice(const QUuid &deviceId) const -{ - return getThing(deviceId); -} - -int Devices::rowCount(const QModelIndex &parent) const +int Things::rowCount(const QModelIndex &parent) const { Q_UNUSED(parent) return m_things.count(); } -QVariant Devices::data(const QModelIndex &index, int role) const +QVariant Things::data(const QModelIndex &index, int role) const { if (index.row() < 0 || index.row() >= m_things.count()) return QVariant(); - Device *thing = m_things.at(index.row()); + Thing *thing = m_things.at(index.row()); switch (role) { case RoleName: return thing->name(); @@ -86,8 +81,8 @@ QVariant Devices::data(const QModelIndex &index, int role) const case RoleDeviceClass: case RoleThingClass: return thing->thingClassId().toString(); - case RoleParentDeviceId: - return thing->parentDeviceId().toString(); + case RoleParentId: + return thing->parentId().toString(); case RoleSetupStatus: return thing->setupStatus(); case RoleSetupDisplayMessage: @@ -100,33 +95,32 @@ QVariant Devices::data(const QModelIndex &index, int role) const return QVariant(); } -void Devices::addDevice(Device *device) +void Things::addThing(Thing *thing) { - device->setParent(this); + thing->setParent(this); beginInsertRows(QModelIndex(), m_things.count(), m_things.count()); -// qDebug() << "Devices: add device" << device->name(); - m_things.append(device); + m_things.append(thing); endInsertRows(); - connect(device, &Device::nameChanged, this, [device, this]() { - int idx = m_things.indexOf(device); + connect(thing, &Thing::nameChanged, this, [thing, this]() { + int idx = m_things.indexOf(thing); if (idx < 0) return; emit dataChanged(index(idx), index(idx), {RoleName}); }); - connect(device, &Device::setupStatusChanged, this, [device, this]() { - int idx = m_things.indexOf(device); + connect(thing, &Thing::setupStatusChanged, this, [thing, this]() { + int idx = m_things.indexOf(thing); if (idx < 0) return; emit dataChanged(index(idx), index(idx), {RoleSetupStatus, RoleSetupDisplayMessage}); }); - connect(device->states(), &States::dataChanged, this, [device, this]() { - int idx = m_things.indexOf(device); + connect(thing->states(), &States::dataChanged, this, [thing, this]() { + int idx = m_things.indexOf(thing); if (idx < 0) return; emit dataChanged(index(idx), index(idx)); }); emit countChanged(); - emit thingAdded(device); + emit thingAdded(thing); } -void Devices::removeThing(Device *thing) +void Things::removeThing(Thing *thing) { int index = m_things.indexOf(thing); beginRemoveRows(QModelIndex(), index, index); @@ -137,7 +131,7 @@ void Devices::removeThing(Device *thing) emit thingRemoved(thing); } -void Devices::clearModel() +void Things::clearModel() { beginResetModel(); qDeleteAll(m_things); @@ -146,14 +140,14 @@ void Devices::clearModel() emit countChanged(); } -QHash Devices::roleNames() const +QHash Things::roleNames() const { QHash roles; roles[RoleName] = "name"; roles[RoleId] = "id"; roles[RoleDeviceClass] = "deviceClassId"; roles[RoleThingClass] = "thingClassId"; - roles[RoleParentDeviceId] = "parentDeviceId"; + roles[RoleParentId] = "parentId"; roles[RoleSetupStatus] = "setupStatus"; roles[RoleSetupDisplayMessage] = "setupDisplayMessage"; roles[RoleInterfaces] = "interfaces"; diff --git a/libnymea-app/devices.h b/libnymea-app/things.h similarity index 74% rename from libnymea-app/devices.h rename to libnymea-app/things.h index 9d406f25..213eefe7 100644 --- a/libnymea-app/devices.h +++ b/libnymea-app/things.h @@ -28,15 +28,15 @@ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -#ifndef DEVICES_H -#define DEVICES_H +#ifndef THINGS_H +#define THINGS_H #include -#include "types/device.h" -#include "types/deviceclass.h" +#include "types/thing.h" +#include "types/thingclass.h" -class Devices : public QAbstractListModel +class Things : public QAbstractListModel { Q_OBJECT Q_PROPERTY(int count READ rowCount NOTIFY countChanged) @@ -44,7 +44,7 @@ public: enum Roles { RoleName, RoleId, - RoleParentDeviceId, + RoleParentId, RoleDeviceClass, RoleThingClass, RoleSetupStatus, @@ -54,33 +54,32 @@ public: }; Q_ENUM(Roles) - explicit Devices(QObject *parent = nullptr); + explicit Things(QObject *parent = nullptr); - QList devices(); + QList devices(); - Q_INVOKABLE Device *get(int index) const; - Q_INVOKABLE Device *getThing(const QUuid &thingId) const; - Q_INVOKABLE Device *getDevice(const QUuid &deviceId) const; + Q_INVOKABLE Thing *get(int index) const; + Q_INVOKABLE Thing *getThing(const QUuid &thingId) const; - int rowCount(const QModelIndex & parent = QModelIndex()) const; - QVariant data(const QModelIndex & index, int role = RoleName) const; + int rowCount(const QModelIndex & parent = QModelIndex()) const override; + QVariant data(const QModelIndex & index, int role = RoleName) const override; - void addDevice(Device *device); - void removeThing(Device *thing); + void addThing(Thing *thing); + void removeThing(Thing *thing); void clearModel(); protected: - QHash roleNames() const; + QHash roleNames() const override; signals: void countChanged(); - void thingAdded(Device *device); - void thingRemoved(Device *device); + void thingAdded(Thing *device); + void thingRemoved(Thing *device); private: - QList m_things; + QList m_things; }; -#endif // DEVICES_H +#endif // THINGS_H diff --git a/libnymea-app/devicesproxy.cpp b/libnymea-app/thingsproxy.cpp similarity index 61% rename from libnymea-app/devicesproxy.cpp rename to libnymea-app/thingsproxy.cpp index 1145afee..51fea452 100644 --- a/libnymea-app/devicesproxy.cpp +++ b/libnymea-app/thingsproxy.cpp @@ -28,26 +28,26 @@ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -#include "devicesproxy.h" +#include "thingsproxy.h" #include "engine.h" #include "tagsmanager.h" #include "types/tag.h" -DevicesProxy::DevicesProxy(QObject *parent) : +ThingsProxy::ThingsProxy(QObject *parent) : QSortFilterProxyModel(parent) { } -Engine *DevicesProxy::engine() const +Engine *ThingsProxy::engine() const { return m_engine; } -void DevicesProxy::setEngine(Engine *engine) +void ThingsProxy::setEngine(Engine *engine) { if (m_engine != engine) { if (m_engine) { - disconnect(m_engine->tagsManager()->tags(), &Tags::countChanged, this, &DevicesProxy::invalidateFilter); + disconnect(m_engine->tagsManager()->tags(), &Tags::countChanged, this, &ThingsProxy::invalidateFilter); } m_engine = engine; emit engineChanged(); @@ -55,12 +55,12 @@ void DevicesProxy::setEngine(Engine *engine) return; } - connect(m_engine->tagsManager()->tags(), &Tags::countChanged, this, &DevicesProxy::invalidateFilter); + connect(m_engine->tagsManager()->tags(), &Tags::countChanged, this, &ThingsProxy::invalidateFilter); if (!sourceModel()) { - setSourceModel(m_engine->deviceManager()->devices()); + setSourceModel(m_engine->thingManager()->things()); - setSortRole(Devices::RoleName); + setSortRole(Things::RoleName); sort(0); connect(sourceModel(), SIGNAL(countChanged()), this, SIGNAL(countChanged())); connect(sourceModel(), &QAbstractItemModel::dataChanged, this, [this]() { @@ -72,12 +72,12 @@ void DevicesProxy::setEngine(Engine *engine) } } -DevicesProxy *DevicesProxy::parentProxy() const +ThingsProxy *ThingsProxy::parentProxy() const { return m_parentProxy; } -void DevicesProxy::setParentProxy(DevicesProxy *parentProxy) +void ThingsProxy::setParentProxy(ThingsProxy *parentProxy) { if (m_parentProxy != parentProxy) { m_parentProxy = parentProxy; @@ -86,7 +86,7 @@ void DevicesProxy::setParentProxy(DevicesProxy *parentProxy) if (!m_engine) { return; } - setSortRole(Devices::RoleName); + setSortRole(Things::RoleName); sort(0); connect(m_parentProxy, SIGNAL(countChanged()), this, SIGNAL(countChanged())); connect(m_parentProxy, &QAbstractItemModel::dataChanged, this, [this]() { @@ -105,12 +105,12 @@ void DevicesProxy::setParentProxy(DevicesProxy *parentProxy) } } -QString DevicesProxy::filterTagId() const +QString ThingsProxy::filterTagId() const { return m_filterTagId; } -void DevicesProxy::setFilterTagId(const QString &filterTag) +void ThingsProxy::setFilterTagId(const QString &filterTag) { if (m_filterTagId != filterTag) { m_filterTagId = filterTag; @@ -120,12 +120,12 @@ void DevicesProxy::setFilterTagId(const QString &filterTag) } } -QString DevicesProxy::filterTagValue() const +QString ThingsProxy::filterTagValue() const { return m_filterTagValue; } -void DevicesProxy::setFilterTagValue(const QString &tagValue) +void ThingsProxy::setFilterTagValue(const QString &tagValue) { if (m_filterTagValue != tagValue) { m_filterTagValue = tagValue; @@ -135,42 +135,42 @@ void DevicesProxy::setFilterTagValue(const QString &tagValue) } } -QString DevicesProxy::filterDeviceClassId() const +QString ThingsProxy::filterThingClassId() const { - return m_filterDeviceClassId; + return m_filterThingClassId; } -void DevicesProxy::setFilterDeviceClassId(const QString &filterDeviceClassId) +void ThingsProxy::setFilterThingClassId(const QString &filterThingClassId) { - if (m_filterDeviceClassId != filterDeviceClassId) { - m_filterDeviceClassId = filterDeviceClassId; - emit filterDeviceClassIdChanged(); + if (m_filterThingClassId != filterThingClassId) { + m_filterThingClassId = filterThingClassId; + emit filterThingClassIdChanged(); invalidateFilter(); emit countChanged(); } } -QString DevicesProxy::filterDeviceId() const +QString ThingsProxy::filterThingId() const { - return m_filterDeviceId; + return m_filterThingId; } -void DevicesProxy::setFilterDeviceId(const QString &filterDeviceId) +void ThingsProxy::setFilterThingId(const QString &filterThingId) { - if (m_filterDeviceId != filterDeviceId) { - m_filterDeviceId = filterDeviceId; - emit filterDeviceIdChanged(); + if (m_filterThingId != filterThingId) { + m_filterThingId = filterThingId; + emit filterThingIdChanged(); invalidateFilter(); emit countChanged(); } } -QStringList DevicesProxy::shownInterfaces() const +QStringList ThingsProxy::shownInterfaces() const { return m_shownInterfaces; } -void DevicesProxy::setShownInterfaces(const QStringList &shownInterfaces) +void ThingsProxy::setShownInterfaces(const QStringList &shownInterfaces) { if (m_shownInterfaces != shownInterfaces) { m_shownInterfaces = shownInterfaces; @@ -180,12 +180,12 @@ void DevicesProxy::setShownInterfaces(const QStringList &shownInterfaces) } } -QStringList DevicesProxy::hiddenInterfaces() const +QStringList ThingsProxy::hiddenInterfaces() const { return m_hiddenInterfaces; } -void DevicesProxy::setHiddenInterfaces(const QStringList &hiddenInterfaces) +void ThingsProxy::setHiddenInterfaces(const QStringList &hiddenInterfaces) { if (m_hiddenInterfaces != hiddenInterfaces) { m_hiddenInterfaces = hiddenInterfaces; @@ -195,12 +195,12 @@ void DevicesProxy::setHiddenInterfaces(const QStringList &hiddenInterfaces) } } -QString DevicesProxy::nameFilter() const +QString ThingsProxy::nameFilter() const { return m_nameFilter; } -void DevicesProxy::setNameFilter(const QString &nameFilter) +void ThingsProxy::setNameFilter(const QString &nameFilter) { if (m_nameFilter != nameFilter) { m_nameFilter = nameFilter; @@ -210,12 +210,12 @@ void DevicesProxy::setNameFilter(const QString &nameFilter) } } -QString DevicesProxy::requiredEventName() const +QString ThingsProxy::requiredEventName() const { return m_requiredEventName; } -void DevicesProxy::setRequiredEventName(const QString &requiredEventName) +void ThingsProxy::setRequiredEventName(const QString &requiredEventName) { if (m_requiredEventName != requiredEventName) { m_requiredEventName = requiredEventName; @@ -225,12 +225,12 @@ void DevicesProxy::setRequiredEventName(const QString &requiredEventName) } } -QString DevicesProxy::requiredStateName() const +QString ThingsProxy::requiredStateName() const { return m_requiredStateName; } -void DevicesProxy::setRequiredStateName(const QString &requiredStateName) +void ThingsProxy::setRequiredStateName(const QString &requiredStateName) { if (m_requiredStateName != requiredStateName) { m_requiredStateName = requiredStateName; @@ -240,12 +240,12 @@ void DevicesProxy::setRequiredStateName(const QString &requiredStateName) } } -QString DevicesProxy::requiredActionName() const +QString ThingsProxy::requiredActionName() const { return m_requiredActionName; } -void DevicesProxy::setRequiredActionName(const QString &requiredActionName) +void ThingsProxy::setRequiredActionName(const QString &requiredActionName) { if (m_requiredActionName != requiredActionName) { m_requiredActionName = requiredActionName; @@ -255,12 +255,12 @@ void DevicesProxy::setRequiredActionName(const QString &requiredActionName) } } -bool DevicesProxy::showDigitalInputs() const +bool ThingsProxy::showDigitalInputs() const { return m_showDigitalInputs; } -void DevicesProxy::setShowDigitalInputs(bool showDigitalInputs) +void ThingsProxy::setShowDigitalInputs(bool showDigitalInputs) { if (m_showDigitalInputs != showDigitalInputs) { m_showDigitalInputs = showDigitalInputs; @@ -270,12 +270,12 @@ void DevicesProxy::setShowDigitalInputs(bool showDigitalInputs) } } -bool DevicesProxy::showDigitalOutputs() const +bool ThingsProxy::showDigitalOutputs() const { return m_showDigitalOutputs; } -void DevicesProxy::setShowDigitalOutputs(bool showDigitalOutputs) +void ThingsProxy::setShowDigitalOutputs(bool showDigitalOutputs) { if (m_showDigitalOutputs != showDigitalOutputs) { m_showDigitalOutputs = showDigitalOutputs; @@ -285,12 +285,12 @@ void DevicesProxy::setShowDigitalOutputs(bool showDigitalOutputs) } } -bool DevicesProxy::showAnalogInputs() const +bool ThingsProxy::showAnalogInputs() const { return m_showAnalogInputs; } -void DevicesProxy::setShowAnalogInputs(bool showAnalogInputs) +void ThingsProxy::setShowAnalogInputs(bool showAnalogInputs) { if (m_showAnalogInputs != showAnalogInputs) { m_showAnalogInputs = showAnalogInputs; @@ -300,12 +300,12 @@ void DevicesProxy::setShowAnalogInputs(bool showAnalogInputs) } } -bool DevicesProxy::showAnalogOutputs() const +bool ThingsProxy::showAnalogOutputs() const { return m_showDigitalOutputs; } -void DevicesProxy::setShowAnalogOutputs(bool showAnalogOutputs) +void ThingsProxy::setShowAnalogOutputs(bool showAnalogOutputs) { if (m_showAnalogOutputs != showAnalogOutputs) { m_showAnalogOutputs = showAnalogOutputs; @@ -315,12 +315,12 @@ void DevicesProxy::setShowAnalogOutputs(bool showAnalogOutputs) } } -bool DevicesProxy::filterBatteryCritical() const +bool ThingsProxy::filterBatteryCritical() const { return m_filterBatteryCritical; } -void DevicesProxy::setFilterBatteryCritical(bool filterBatteryCritical) +void ThingsProxy::setFilterBatteryCritical(bool filterBatteryCritical) { if (m_filterBatteryCritical != filterBatteryCritical) { m_filterBatteryCritical = filterBatteryCritical; @@ -330,12 +330,12 @@ void DevicesProxy::setFilterBatteryCritical(bool filterBatteryCritical) } } -bool DevicesProxy::filterDisconnected() const +bool ThingsProxy::filterDisconnected() const { return m_filterDisconnected; } -void DevicesProxy::setFilterDisconnected(bool filterDisconnected) +void ThingsProxy::setFilterDisconnected(bool filterDisconnected) { if (m_filterDisconnected != filterDisconnected) { m_filterDisconnected = filterDisconnected; @@ -345,12 +345,12 @@ void DevicesProxy::setFilterDisconnected(bool filterDisconnected) } } -bool DevicesProxy::filterSetupFailed() const +bool ThingsProxy::filterSetupFailed() const { return m_filterSetupFailed; } -void DevicesProxy::setFilterSetupFailed(bool filterSetupFailed) +void ThingsProxy::setFilterSetupFailed(bool filterSetupFailed) { if (m_filterSetupFailed != filterSetupFailed) { m_filterSetupFailed = filterSetupFailed; @@ -360,12 +360,12 @@ void DevicesProxy::setFilterSetupFailed(bool filterSetupFailed) } } -bool DevicesProxy::filterUpdates() const +bool ThingsProxy::filterUpdates() const { return m_filterUpdates; } -void DevicesProxy::setFilterUpdates(bool filterUpdates) +void ThingsProxy::setFilterUpdates(bool filterUpdates) { if (m_filterUpdates != filterUpdates) { m_filterUpdates = filterUpdates; @@ -375,12 +375,12 @@ void DevicesProxy::setFilterUpdates(bool filterUpdates) } } -bool DevicesProxy::groupByInterface() const +bool ThingsProxy::groupByInterface() const { return m_groupByInterface; } -void DevicesProxy::setGroupByInterface(bool groupByInterface) +void ThingsProxy::setGroupByInterface(bool groupByInterface) { if (m_groupByInterface != groupByInterface) { m_groupByInterface = groupByInterface; @@ -390,70 +390,65 @@ void DevicesProxy::setGroupByInterface(bool groupByInterface) } } -Device *DevicesProxy::get(int index) const +Thing *ThingsProxy::get(int index) const { return getInternal(mapToSource(this->index(index, 0)).row()); } -Device *DevicesProxy::getDevice(const QUuid &deviceId) const +Thing *ThingsProxy::getThing(const QUuid &thingId) const { - return getThing(deviceId); -} - -Device *DevicesProxy::getThing(const QUuid &thingId) const -{ - Devices *d = qobject_cast(sourceModel()); + Things *d = qobject_cast(sourceModel()); if (d) { return d->getThing(thingId); } - DevicesProxy *dp = qobject_cast(sourceModel()); + ThingsProxy *dp = qobject_cast(sourceModel()); if (dp) { return dp->getThing(thingId); } return nullptr; } -Device *DevicesProxy::getInternal(int source_index) const +Thing *ThingsProxy::getInternal(int source_index) const { - Devices* d = qobject_cast(sourceModel()); + Things* d = qobject_cast(sourceModel()); if (d) { return d->get(source_index); } - DevicesProxy *dp = qobject_cast(sourceModel()); + ThingsProxy *dp = qobject_cast(sourceModel()); if (dp) { return dp->get(source_index); } return nullptr; } -bool DevicesProxy::lessThan(const QModelIndex &left, const QModelIndex &right) const +bool ThingsProxy::lessThan(const QModelIndex &left, const QModelIndex &right) const { if (m_groupByInterface) { - QString leftBaseInterface = sourceModel()->data(left, Devices::RoleBaseInterface).toString(); - QString rightBaseInterface = sourceModel()->data(right, Devices::RoleBaseInterface).toString(); + QString leftBaseInterface = sourceModel()->data(left, Things::RoleBaseInterface).toString(); + QString rightBaseInterface = sourceModel()->data(right, Things::RoleBaseInterface).toString(); if (leftBaseInterface != rightBaseInterface) { return QString::localeAwareCompare(leftBaseInterface, rightBaseInterface) < 0; } } - QString leftName = sourceModel()->data(left, Devices::RoleName).toString(); - QString rightName = sourceModel()->data(right, Devices::RoleName).toString(); + QString leftName = sourceModel()->data(left, Things::RoleName).toString(); + QString rightName = sourceModel()->data(right, Things::RoleName).toString(); int comparison = QString::localeAwareCompare(leftName, rightName); if (comparison == 0) { // If there are 2 identically named things we don't want undefined behavor as it may cause items // to reorder randomly. Use something static like thingId as fallback - QString leftThingId = sourceModel()->data(left, Devices::RoleId).toString(); - QString rightThingId = sourceModel()->data(right, Devices::RoleId).toString(); + QString leftThingId = sourceModel()->data(left, Things::RoleId).toString(); + QString rightThingId = sourceModel()->data(right, Things::RoleId).toString(); comparison = QString::localeAwareCompare(leftThingId, rightThingId); } return comparison < 0; } -bool DevicesProxy::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const +bool ThingsProxy::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const { - Device *device = getInternal(source_row); + Thing *thing = getInternal(source_row); if (!m_filterTagId.isEmpty()) { - Tag *tag = m_engine->tagsManager()->tags()->findDeviceTag(device->id().toString(), m_filterTagId); + Tag *tag = m_engine->tagsManager()->tags()->findThingTag(thing->id().toString(), m_filterTagId); if (!tag) { return false; } @@ -461,22 +456,22 @@ bool DevicesProxy::filterAcceptsRow(int source_row, const QModelIndex &source_pa return false; } } - if (!m_filterDeviceClassId.isEmpty()) { - if (device->deviceClassId() != QUuid(m_filterDeviceClassId)) { + if (!m_filterThingClassId.isEmpty()) { + if (thing->thingClassId() != QUuid(m_filterThingClassId)) { return false; } } - if (!m_filterDeviceId.isEmpty()) { - if (device->id() != QUuid(m_filterDeviceId)) { + if (!m_filterThingId.isEmpty()) { + if (thing->id() != QUuid(m_filterThingId)) { return false; } } - DeviceClass *deviceClass = m_engine->deviceManager()->deviceClasses()->getDeviceClass(device->deviceClassId()); -// qDebug() << "Checking device" << deviceClass->name() << deviceClass->interfaces(); + ThingClass *thingClass = m_engine->thingManager()->thingClasses()->getThingClass(thing->thingClassId()); +// qDebug() << "Checking thing" << thingClass->name() << thingClass->interfaces(); if (!m_shownInterfaces.isEmpty()) { bool foundMatch = false; foreach (const QString &filterInterface, m_shownInterfaces) { - if (deviceClass->interfaces().contains(filterInterface)) { + if (thingClass->interfaces().contains(filterInterface)) { foundMatch = true; continue; } @@ -488,72 +483,72 @@ bool DevicesProxy::filterAcceptsRow(int source_row, const QModelIndex &source_pa if (!m_hiddenInterfaces.isEmpty()) { foreach (const QString &filterInterface, m_hiddenInterfaces) { - if (deviceClass->interfaces().contains(filterInterface)) { + if (thingClass->interfaces().contains(filterInterface)) { return false; } } } if (m_showDigitalInputs || m_showDigitalOutputs || m_showAnalogInputs || m_showAnalogOutputs) { - if (m_showDigitalInputs && deviceClass->stateTypes()->ioStateTypes(Types::IOTypeDigitalInput).isEmpty()) { + if (m_showDigitalInputs && thingClass->stateTypes()->ioStateTypes(Types::IOTypeDigitalInput).isEmpty()) { return false; } - if (m_showDigitalOutputs && deviceClass->stateTypes()->ioStateTypes(Types::IOTypeDigitalOutput).isEmpty()) { + if (m_showDigitalOutputs && thingClass->stateTypes()->ioStateTypes(Types::IOTypeDigitalOutput).isEmpty()) { return false; } - if (m_showAnalogInputs && deviceClass->stateTypes()->ioStateTypes(Types::IOTypeAnalogInput).isEmpty()) { + if (m_showAnalogInputs && thingClass->stateTypes()->ioStateTypes(Types::IOTypeAnalogInput).isEmpty()) { return false; } - if (m_showAnalogOutputs && deviceClass->stateTypes()->ioStateTypes(Types::IOTypeAnalogOutput).isEmpty()) { + if (m_showAnalogOutputs && thingClass->stateTypes()->ioStateTypes(Types::IOTypeAnalogOutput).isEmpty()) { return false; } } if (m_filterBatteryCritical) { - if (!deviceClass->interfaces().contains("battery") || device->stateValue(deviceClass->stateTypes()->findByName("batteryCritical")->id()).toBool() == false) { + if (!thingClass->interfaces().contains("battery") || thing->stateValue(thingClass->stateTypes()->findByName("batteryCritical")->id()).toBool() == false) { return false; } } if (m_filterDisconnected) { - if (!deviceClass->interfaces().contains("connectable") || device->stateValue(deviceClass->stateTypes()->findByName("connected")->id()).toBool() == true) { + if (!thingClass->interfaces().contains("connectable") || thing->stateValue(thingClass->stateTypes()->findByName("connected")->id()).toBool() == true) { return false; } } if (m_filterSetupFailed) { - if (device->setupStatus() != Device::ThingSetupStatusFailed) { + if (thing->setupStatus() != Thing::ThingSetupStatusFailed) { return false; } } if (m_filterUpdates) { - if (!deviceClass->interfaces().contains("update")) { + if (!thingClass->interfaces().contains("update")) { return false; } - if (device->stateValue(deviceClass->stateTypes()->findByName("updateStatus")->id()).toString() == "idle") { + if (thing->stateValue(thingClass->stateTypes()->findByName("updateStatus")->id()).toString() == "idle") { return false; } } if (!m_nameFilter.isEmpty()) { - if (!device->name().toLower().contains(m_nameFilter.toLower().trimmed())) { + if (!thing->name().toLower().contains(m_nameFilter.toLower().trimmed())) { return false; } } if (!m_requiredEventName.isEmpty()) { - if (!device->thingClass()->eventTypes()->findByName(m_requiredEventName)) { + if (!thing->thingClass()->eventTypes()->findByName(m_requiredEventName)) { return false; } } if (!m_requiredStateName.isEmpty()) { - if (!device->thingClass()->stateTypes()->findByName(m_requiredStateName)) { + if (!thing->thingClass()->stateTypes()->findByName(m_requiredStateName)) { return false; } } if (!m_requiredActionName.isEmpty()) { - if (!device->thingClass()->actionTypes()->findByName(m_requiredActionName)) { + if (!thing->thingClass()->actionTypes()->findByName(m_requiredActionName)) { return false; } } diff --git a/libnymea-app/devicesproxy.h b/libnymea-app/thingsproxy.h similarity index 85% rename from libnymea-app/devicesproxy.h rename to libnymea-app/thingsproxy.h index 4363b00f..a42724e4 100644 --- a/libnymea-app/devicesproxy.h +++ b/libnymea-app/thingsproxy.h @@ -28,27 +28,27 @@ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -#ifndef DEVICESPROXY_H -#define DEVICESPROXY_H +#ifndef THINGSPROXY_H +#define THINGSPROXY_H #include #include #include -#include "devices.h" +#include "things.h" class Engine; -class DevicesProxy : public QSortFilterProxyModel +class ThingsProxy : public QSortFilterProxyModel { Q_OBJECT Q_PROPERTY(int count READ rowCount NOTIFY countChanged) Q_PROPERTY(Engine* engine READ engine WRITE setEngine NOTIFY engineChanged) - Q_PROPERTY(DevicesProxy *parentProxy READ parentProxy WRITE setParentProxy NOTIFY parentProxyChanged) + Q_PROPERTY(ThingsProxy *parentProxy READ parentProxy WRITE setParentProxy NOTIFY parentProxyChanged) Q_PROPERTY(QString filterTagId READ filterTagId WRITE setFilterTagId NOTIFY filterTagIdChanged) Q_PROPERTY(QString filterTagValue READ filterTagValue WRITE setFilterTagValue NOTIFY filterTagValueChanged) - Q_PROPERTY(QString filterDeviceClassId READ filterDeviceClassId WRITE setFilterDeviceClassId NOTIFY filterDeviceClassIdChanged) - Q_PROPERTY(QString filterDeviceId READ filterDeviceId WRITE setFilterDeviceId NOTIFY filterDeviceIdChanged) + Q_PROPERTY(QString filterThingClassId READ filterThingClassId WRITE setFilterThingClassId NOTIFY filterThingClassIdChanged) + Q_PROPERTY(QString filterThingId READ filterThingId WRITE setFilterThingId NOTIFY filterThingIdChanged) Q_PROPERTY(QStringList shownInterfaces READ shownInterfaces WRITE setShownInterfaces NOTIFY shownInterfacesChanged) Q_PROPERTY(QStringList hiddenInterfaces READ hiddenInterfaces WRITE setHiddenInterfaces NOTIFY hiddenInterfacesChanged) Q_PROPERTY(QString nameFilter READ nameFilter WRITE setNameFilter NOTIFY nameFilterChanged) @@ -76,13 +76,13 @@ class DevicesProxy : public QSortFilterProxyModel Q_PROPERTY(bool groupByInterface READ groupByInterface WRITE setGroupByInterface NOTIFY groupByInterfaceChanged) public: - explicit DevicesProxy(QObject *parent = nullptr); + explicit ThingsProxy(QObject *parent = nullptr); Engine *engine() const; void setEngine(Engine *engine); - DevicesProxy *parentProxy() const; - void setParentProxy(DevicesProxy *parentProxy); + ThingsProxy *parentProxy() const; + void setParentProxy(ThingsProxy *parentProxy); QString filterTagId() const; void setFilterTagId(const QString &filterTag); @@ -90,11 +90,11 @@ public: QString filterTagValue() const; void setFilterTagValue(const QString &tagValue); - QString filterDeviceClassId() const; - void setFilterDeviceClassId(const QString &filterDeviceClassId); + QString filterThingClassId() const; + void setFilterThingClassId(const QString &filterThingClassId); - QString filterDeviceId() const; - void setFilterDeviceId(const QString &filterDeviceId); + QString filterThingId() const; + void setFilterThingId(const QString &filterThingId); QStringList shownInterfaces() const; void setShownInterfaces(const QStringList &shownInterfaces); @@ -141,17 +141,16 @@ public: bool groupByInterface() const; void setGroupByInterface(bool groupByInterface); - Q_INVOKABLE Device *get(int index) const; - Q_INVOKABLE Device *getDevice(const QUuid &deviceId) const; - Q_INVOKABLE Device *getThing(const QUuid &thingId) const; + Q_INVOKABLE Thing *get(int index) const; + Q_INVOKABLE Thing *getThing(const QUuid &thingId) const; signals: void engineChanged(); void parentProxyChanged(); void filterTagIdChanged(); void filterTagValueChanged(); - void filterDeviceClassIdChanged(); - void filterDeviceIdChanged(); + void filterThingClassIdChanged(); + void filterThingIdChanged(); void shownInterfacesChanged(); void hiddenInterfacesChanged(); void nameFilterChanged(); @@ -170,14 +169,14 @@ signals: void countChanged(); private: - Device *getInternal(int source_index) const; + Thing *getInternal(int source_index) const; Engine *m_engine = nullptr; - DevicesProxy *m_parentProxy = nullptr; + ThingsProxy *m_parentProxy = nullptr; QString m_filterTagId; QString m_filterTagValue; - QString m_filterDeviceClassId; - QString m_filterDeviceId; + QString m_filterThingClassId; + QString m_filterThingId; QStringList m_shownInterfaces; QStringList m_hiddenInterfaces; QString m_nameFilter; @@ -203,4 +202,4 @@ protected: bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override; }; -#endif // DEVICESPROXY_H +#endif // THINGSPROXY_H diff --git a/libnymea-app/types/browseritems.cpp b/libnymea-app/types/browseritems.cpp index 27641a89..fbaeac55 100644 --- a/libnymea-app/types/browseritems.cpp +++ b/libnymea-app/types/browseritems.cpp @@ -33,9 +33,9 @@ #include -BrowserItems::BrowserItems(const QUuid &deviceId, const QString &itemId, QObject *parent): +BrowserItems::BrowserItems(const QUuid &thingId, const QString &itemId, QObject *parent): QAbstractListModel (parent), - m_deviceId(deviceId), + m_thingId(thingId), m_itemId(itemId) { @@ -46,9 +46,9 @@ BrowserItems::~BrowserItems() qDebug() << "Deleting BrowserItems"; } -QUuid BrowserItems::deviceId() const +QUuid BrowserItems::thingId() const { - return m_deviceId; + return m_thingId; } QString BrowserItems::itemId() const diff --git a/libnymea-app/types/browseritems.h b/libnymea-app/types/browseritems.h index ce9f6d61..c04f7d9c 100644 --- a/libnymea-app/types/browseritems.h +++ b/libnymea-app/types/browseritems.h @@ -57,10 +57,10 @@ public: }; Q_ENUM(Roles) - explicit BrowserItems(const QUuid &deviceId, const QString &itemId, QObject *parent = nullptr); + explicit BrowserItems(const QUuid &thingId, const QString &itemId, QObject *parent = nullptr); virtual ~BrowserItems() override; - QUuid deviceId() const; + QUuid thingId() const; QString itemId() const; bool busy() const; @@ -89,7 +89,7 @@ protected: bool m_busy = false; QList m_list; - QUuid m_deviceId; + QUuid m_thingId; QString m_itemId; }; diff --git a/libnymea-app/types/eventdescriptor.h b/libnymea-app/types/eventdescriptor.h index ad893144..dc93c65a 100644 --- a/libnymea-app/types/eventdescriptor.h +++ b/libnymea-app/types/eventdescriptor.h @@ -40,7 +40,6 @@ class EventDescriptor : public QObject { Q_OBJECT Q_PROPERTY(QUuid thingId READ thingId WRITE setThingId NOTIFY thingIdChanged) - Q_PROPERTY(QUuid deviceId READ thingId WRITE setThingId NOTIFY thingIdChanged) Q_PROPERTY(QUuid eventTypeId READ eventTypeId WRITE setEventTypeId NOTIFY eventTypeIdChanged) Q_PROPERTY(QString interfaceName READ interfaceName WRITE setInterfaceName NOTIFY interfaceNameChanged) diff --git a/libnymea-app/types/eventdescriptors.cpp b/libnymea-app/types/eventdescriptors.cpp index 75c59eb3..b3c09ebb 100644 --- a/libnymea-app/types/eventdescriptors.cpp +++ b/libnymea-app/types/eventdescriptors.cpp @@ -49,7 +49,6 @@ QVariant EventDescriptors::data(const QModelIndex &index, int role) const { switch (role) { case RoleThingId: - case RoleDeviceId: return m_list.at(index.row())->thingId(); case RoleEventTypeId: return m_list.at(index.row())->eventTypeId(); @@ -61,7 +60,6 @@ QHash EventDescriptors::roleNames() const { QHash roles; roles.insert(RoleThingId, "thingId"); - roles.insert(RoleDeviceId, "deviceId"); roles.insert(RoleEventTypeId, "eventId"); return roles; } diff --git a/libnymea-app/types/eventdescriptors.h b/libnymea-app/types/eventdescriptors.h index 89b542dd..079d055b 100644 --- a/libnymea-app/types/eventdescriptors.h +++ b/libnymea-app/types/eventdescriptors.h @@ -42,7 +42,6 @@ class EventDescriptors : public QAbstractListModel public: enum Roles { RoleThingId, - RoleDeviceId, RoleEventTypeId }; explicit EventDescriptors(QObject *parent = nullptr); diff --git a/libnymea-app/types/interface.cpp b/libnymea-app/types/interface.cpp index 55ecd526..350c6b62 100644 --- a/libnymea-app/types/interface.cpp +++ b/libnymea-app/types/interface.cpp @@ -33,7 +33,7 @@ #include "eventtypes.h" #include "statetypes.h" #include "actiontypes.h" -#include "deviceclass.h" +#include "thingclass.h" Interface::Interface(const QString &name, const QString &displayName, QObject *parent) : QObject(parent), @@ -71,9 +71,9 @@ ActionTypes* Interface::actionTypes() const return m_actionTypes; } -DeviceClass *Interface::createDeviceClass() +ThingClass *Interface::createDeviceClass() { - DeviceClass* dc = new DeviceClass(); + ThingClass* dc = new ThingClass(); dc->setName(m_name); dc->setParamTypes(new ParamTypes(dc)); dc->setSettingsTypes(new ParamTypes(dc)); diff --git a/libnymea-app/types/interface.h b/libnymea-app/types/interface.h index 58f32fe3..1b387b7c 100644 --- a/libnymea-app/types/interface.h +++ b/libnymea-app/types/interface.h @@ -36,7 +36,7 @@ class EventTypes; class StateTypes; class ActionTypes; -class DeviceClass; +class ThingClass; class Interface : public QObject { @@ -56,7 +56,7 @@ public: StateTypes* stateTypes() const; ActionTypes* actionTypes() const; - DeviceClass* createDeviceClass(); + ThingClass* createDeviceClass(); private: QString m_name; diff --git a/libnymea-app/types/interfaces.cpp b/libnymea-app/types/interfaces.cpp index da9ca3a5..a38248ef 100644 --- a/libnymea-app/types/interfaces.cpp +++ b/libnymea-app/types/interfaces.cpp @@ -38,7 +38,7 @@ #include "statetype.h" #include "statetypes.h" -#include "device.h" +#include "thing.h" #include "paramtypes.h" diff --git a/libnymea-app/types/interfaces.h b/libnymea-app/types/interfaces.h index 23b666e6..b0d5a421 100644 --- a/libnymea-app/types/interfaces.h +++ b/libnymea-app/types/interfaces.h @@ -38,7 +38,7 @@ class Interface; class ParamType; class ParamTypes; -class Devices; +class Things; class Interfaces : public QAbstractListModel { diff --git a/libnymea-app/types/logentry.h b/libnymea-app/types/logentry.h index 6201f5a0..481ecbd7 100644 --- a/libnymea-app/types/logentry.h +++ b/libnymea-app/types/logentry.h @@ -41,7 +41,6 @@ class LogEntry : public QObject Q_OBJECT Q_PROPERTY(QVariant value READ value CONSTANT) Q_PROPERTY(QUuid thingId READ thingId CONSTANT) - Q_PROPERTY(QUuid deviceId READ thingId CONSTANT) Q_PROPERTY(QUuid typeId READ typeId CONSTANT) Q_PROPERTY(LoggingSource source READ source CONSTANT) Q_PROPERTY(LoggingEventType loggingEventType READ loggingEventType CONSTANT) diff --git a/libnymea-app/types/rule.cpp b/libnymea-app/types/rule.cpp index 3276e095..cff395ee 100644 --- a/libnymea-app/types/rule.cpp +++ b/libnymea-app/types/rule.cpp @@ -262,8 +262,8 @@ QDebug operator <<(QDebug &dbg, Rule *rule) for (int i = 0; i < rule->actions()->rowCount(); i++) { RuleAction *ra = rule->actions()->get(i); dbg << " " << i << ":"; - if (!ra->deviceId().isNull() && !ra->actionTypeId().isNull()) { - dbg << "Device ID:" << ra->deviceId() << "Action Type ID:" << ra->actionTypeId() << endl; + if (!ra->thingId().isNull() && !ra->actionTypeId().isNull()) { + dbg << "Device ID:" << ra->thingId() << "Action Type ID:" << ra->actionTypeId() << endl; } else { dbg << "Interface Name:" << ra->interfaceName() << "Action Name:" << ra->interfaceAction() << endl; } @@ -283,8 +283,8 @@ QDebug operator <<(QDebug &dbg, Rule *rule) for (int i = 0; i < rule->exitActions()->rowCount(); i++) { RuleAction *ra = rule->exitActions()->get(i); dbg << " " << i << ":"; - if (!ra->deviceId().isNull() && !ra->actionTypeId().isNull()) { - dbg << "Device ID:" << ra->deviceId() << "Action Type ID:" << ra->actionTypeId() << endl;; + if (!ra->thingId().isNull() && !ra->actionTypeId().isNull()) { + dbg << "Device ID:" << ra->thingId() << "Action Type ID:" << ra->actionTypeId() << endl;; } else { dbg << "Interface Name:" << ra->interfaceName() << "Action Name:" << ra->interfaceAction() << endl;; } @@ -305,8 +305,8 @@ QDebug printStateEvaluator(QDebug &dbg, StateEvaluator *stateEvaluator, int inde if (stateEvaluator->stateDescriptor()) { for (int i = 0; i < indentLevel; i++) { dbg << " "; } dbg << "State Descriptor:"; - if (!stateEvaluator->stateDescriptor()->deviceId().isNull() && !stateEvaluator->stateDescriptor()->stateTypeId().isNull()) { - dbg << "Device ID:" << stateEvaluator->stateDescriptor()->deviceId().toString() << "State Type ID:" << stateEvaluator->stateDescriptor()->stateTypeId().toString(); + if (!stateEvaluator->stateDescriptor()->thingId().isNull() && !stateEvaluator->stateDescriptor()->stateTypeId().isNull()) { + dbg << "Device ID:" << stateEvaluator->stateDescriptor()->thingId().toString() << "State Type ID:" << stateEvaluator->stateDescriptor()->stateTypeId().toString(); } else { dbg << "Interface name:" << stateEvaluator->stateDescriptor()->interfaceName() << "State Name:" << stateEvaluator->stateDescriptor()->interfaceState(); } diff --git a/libnymea-app/types/ruleaction.cpp b/libnymea-app/types/ruleaction.cpp index 32d3af27..44bc2edd 100644 --- a/libnymea-app/types/ruleaction.cpp +++ b/libnymea-app/types/ruleaction.cpp @@ -40,16 +40,16 @@ RuleAction::RuleAction(QObject *parent) : QObject(parent) m_ruleActionParams = new RuleActionParams(this); } -QUuid RuleAction::deviceId() const +QUuid RuleAction::thingId() const { - return m_deviceId; + return m_thingId; } -void RuleAction::setDeviceId(const QUuid &deviceId) +void RuleAction::setThingId(const QUuid &thingId) { - if (m_deviceId != deviceId) { - m_deviceId = deviceId; - emit deviceIdChanged(); + if (m_thingId != thingId) { + m_thingId = thingId; + emit thingIdChanged(); } } @@ -113,7 +113,7 @@ RuleActionParams *RuleAction::ruleActionParams() const RuleAction *RuleAction::clone() const { RuleAction *ret = new RuleAction(); - ret->setDeviceId(deviceId()); + ret->setThingId(thingId()); ret->setActionTypeId(actionTypeId()); ret->setBrowserItemId(browserItemId()); ret->setInterfaceName(interfaceName()); @@ -128,7 +128,7 @@ RuleAction *RuleAction::clone() const #define COMPARE_PTR(a, b) if (!a->operator==(b)) { qDebug() << a << "!=" << b; return false; } bool RuleAction::operator==(RuleAction *other) const { - COMPARE(m_deviceId, other->deviceId()); + COMPARE(m_thingId, other->thingId()); COMPARE(m_actionTypeId, other->actionTypeId()); COMPARE(m_interfaceName, other->interfaceName()); COMPARE(m_interfaceAction, other->interfaceAction()); diff --git a/libnymea-app/types/ruleaction.h b/libnymea-app/types/ruleaction.h index e154f257..c3160c6a 100644 --- a/libnymea-app/types/ruleaction.h +++ b/libnymea-app/types/ruleaction.h @@ -39,8 +39,7 @@ class RuleActionParams; class RuleAction : public QObject { Q_OBJECT - Q_PROPERTY(QUuid thingId READ deviceId WRITE setDeviceId NOTIFY deviceIdChanged) - Q_PROPERTY(QUuid deviceId READ deviceId WRITE setDeviceId NOTIFY deviceIdChanged) + Q_PROPERTY(QUuid thingId READ thingId WRITE setThingId NOTIFY thingIdChanged) Q_PROPERTY(QUuid actionTypeId READ actionTypeId WRITE setActionTypeId NOTIFY actionTypeIdChanged) Q_PROPERTY(QString interfaceName READ interfaceName WRITE setInterfaceName NOTIFY interfaceNameChanged) Q_PROPERTY(QString interfaceAction READ interfaceAction WRITE setInterfaceAction NOTIFY interfaceActionChanged) @@ -50,8 +49,8 @@ class RuleAction : public QObject public: explicit RuleAction(QObject *parent = nullptr); - QUuid deviceId() const; - void setDeviceId(const QUuid &deviceId); + QUuid thingId() const; + void setThingId(const QUuid &thingId); QUuid actionTypeId() const; void setActionTypeId(const QUuid &actionTypeId); @@ -71,14 +70,14 @@ public: bool operator==(RuleAction *other) const; signals: - void deviceIdChanged(); + void thingIdChanged(); void actionTypeIdChanged(); void interfaceNameChanged(); void interfaceActionChanged(); bool browserItemIdChanged(); private: - QUuid m_deviceId; + QUuid m_thingId; QUuid m_actionTypeId; QString m_interfaceName; QString m_interfaceAction; diff --git a/libnymea-app/types/ruleactionparam.cpp b/libnymea-app/types/ruleactionparam.cpp index 1cf933bf..bc4dca39 100644 --- a/libnymea-app/types/ruleactionparam.cpp +++ b/libnymea-app/types/ruleactionparam.cpp @@ -87,16 +87,16 @@ void RuleActionParam::setEventParamTypeId(const QString &eventParamTypeId) } } -QString RuleActionParam::stateDeviceId() const +QString RuleActionParam::stateThingId() const { - return m_stateDeviceId; + return m_stateThingId; } -void RuleActionParam::setStateDeviceId(const QString &stateDeviceId) +void RuleActionParam::setStateThingId(const QString &stateThingId) { - if (m_stateDeviceId != stateDeviceId) { - m_stateDeviceId = stateDeviceId; - emit stateDeviceIdChanged(); + if (m_stateThingId != stateThingId) { + m_stateThingId = stateThingId; + emit stateThingIdChanged(); emit isStateValueBasedChanged(); } } @@ -127,7 +127,7 @@ bool RuleActionParam::isEventParamBased() const bool RuleActionParam::isStateValueBased() const { - return !m_stateDeviceId.isNull() && !m_stateTypeId.isNull(); + return !m_stateThingId.isNull() && !m_stateTypeId.isNull(); } RuleActionParam *RuleActionParam::clone() const @@ -138,7 +138,7 @@ RuleActionParam *RuleActionParam::clone() const ret->setValue(value()); ret->setEventTypeId(eventTypeId()); ret->setEventParamTypeId(eventParamTypeId()); - ret->setStateDeviceId(stateDeviceId()); + ret->setStateThingId(stateThingId()); ret->setStateTypeId(stateTypeId()); return ret; } @@ -151,7 +151,7 @@ bool RuleActionParam::operator==(RuleActionParam *other) const COMPARE(m_paramName, other->paramName()); COMPARE(m_eventTypeId, other->eventTypeId()); COMPARE(m_eventParamTypeId, other->eventParamTypeId()); - COMPARE(m_stateDeviceId, other->stateDeviceId()); + COMPARE(m_stateThingId, other->stateThingId()); COMPARE(m_stateTypeId, other->stateTypeId()); COMPARE(m_value, other->value()); return true; diff --git a/libnymea-app/types/ruleactionparam.h b/libnymea-app/types/ruleactionparam.h index e6c96171..a3909824 100644 --- a/libnymea-app/types/ruleactionparam.h +++ b/libnymea-app/types/ruleactionparam.h @@ -43,7 +43,7 @@ class RuleActionParam : public Param Q_PROPERTY(QString paramName READ paramName WRITE setParamName NOTIFY paramNameChanged) Q_PROPERTY(QString eventTypeId READ eventTypeId WRITE setEventTypeId NOTIFY eventTypeIdChanged) Q_PROPERTY(QString eventParamTypeId READ eventParamTypeId WRITE setEventParamTypeId NOTIFY eventParamTypeIdChanged) - Q_PROPERTY(QString stateDeviceId READ stateDeviceId WRITE setStateDeviceId NOTIFY stateDeviceIdChanged) + Q_PROPERTY(QString stateThingId READ stateThingId WRITE setStateThingId NOTIFY stateThingIdChanged) Q_PROPERTY(QString stateTypeId READ stateTypeId WRITE setStateTypeId NOTIFY stateTypeIdChanged) Q_PROPERTY(bool isValueBased READ isValueBased NOTIFY isValueBasedChanged) @@ -63,8 +63,8 @@ public: QString eventParamTypeId() const; void setEventParamTypeId(const QString &eventParamTypeId); - QString stateDeviceId() const; - void setStateDeviceId(const QString &stateDeviceId); + QString stateThingId() const; + void setStateThingId(const QString &stateThingId); QString stateTypeId() const; void setStateTypeId(const QString &stateTypeId); @@ -79,7 +79,7 @@ signals: void paramNameChanged(); void eventTypeIdChanged(); void eventParamTypeIdChanged(); - void stateDeviceIdChanged(); + void stateThingIdChanged(); void stateTypeIdChanged(); void isValueBasedChanged(); @@ -90,7 +90,7 @@ protected: QString m_paramName; QString m_eventTypeId; QString m_eventParamTypeId; - QString m_stateDeviceId; + QString m_stateThingId; QString m_stateTypeId; }; diff --git a/libnymea-app/types/ruleactionparams.cpp b/libnymea-app/types/ruleactionparams.cpp index e75aae2a..58544eec 100644 --- a/libnymea-app/types/ruleactionparams.cpp +++ b/libnymea-app/types/ruleactionparams.cpp @@ -141,34 +141,34 @@ void RuleActionParams::setRuleActionParamEventByName(const QString ¶mName, c addRuleActionParam(rap); } -void RuleActionParams::setRuleActionParamState(const QString ¶mTypeId, const QString &stateDeviceId, const QString &stateTypeId) +void RuleActionParams::setRuleActionParamState(const QString ¶mTypeId, const QString &stateThingId, const QString &stateTypeId) { foreach (RuleActionParam *rap, m_list) { if (rap->paramTypeId() == paramTypeId) { - rap->setStateDeviceId(stateDeviceId); + rap->setStateThingId(stateThingId); rap->setStateTypeId(stateTypeId); return; } } RuleActionParam *rap = new RuleActionParam(this); rap->setParamTypeId(paramTypeId); - rap->setStateDeviceId(stateDeviceId); + rap->setStateThingId(stateThingId); rap->setStateTypeId(stateTypeId); addRuleActionParam(rap); } -void RuleActionParams::setRuleActionParamStateByName(const QString ¶mName, const QString &stateDeviceId, const QString &stateTypeId) +void RuleActionParams::setRuleActionParamStateByName(const QString ¶mName, const QString &stateThingId, const QString &stateTypeId) { foreach (RuleActionParam *rap, m_list) { if (rap->paramName() == paramName) { - rap->setStateDeviceId(stateDeviceId); + rap->setStateThingId(stateThingId); rap->setStateTypeId(stateTypeId); return; } } RuleActionParam *rap = new RuleActionParam(this); rap->setParamName(paramName); - rap->setStateDeviceId(stateDeviceId); + rap->setStateThingId(stateThingId); rap->setStateTypeId(stateTypeId); addRuleActionParam(rap); } diff --git a/libnymea-app/types/ruleactionparams.h b/libnymea-app/types/ruleactionparams.h index 2e6fcd07..7042f3b5 100644 --- a/libnymea-app/types/ruleactionparams.h +++ b/libnymea-app/types/ruleactionparams.h @@ -60,8 +60,8 @@ public: Q_INVOKABLE void setRuleActionParamByName(const QString ¶mName, const QVariant &value); Q_INVOKABLE void setRuleActionParamEvent(const QString ¶mTypeId, const QString &eventTypeId, const QString &eventParamTypeId); Q_INVOKABLE void setRuleActionParamEventByName(const QString ¶mName, const QString &eventTypeId, const QString &eventParamTypeId); - Q_INVOKABLE void setRuleActionParamState(const QString ¶mTypeId, const QString &stateDeviceId, const QString &stateTypeId); - Q_INVOKABLE void setRuleActionParamStateByName(const QString ¶mName, const QString &stateDeviceId, const QString &stateTypeId); + Q_INVOKABLE void setRuleActionParamState(const QString ¶mTypeId, const QString &stateThingId, const QString &stateTypeId); + Q_INVOKABLE void setRuleActionParamStateByName(const QString ¶mName, const QString &stateThingId, const QString &stateTypeId); Q_INVOKABLE RuleActionParam* get(int index) const; diff --git a/libnymea-app/types/state.cpp b/libnymea-app/types/state.cpp index d67a8569..a1aad74c 100644 --- a/libnymea-app/types/state.cpp +++ b/libnymea-app/types/state.cpp @@ -32,17 +32,17 @@ #include -State::State(const QUuid &deviceId, const QUuid &stateTypeId, const QVariant &value, QObject *parent) : +State::State(const QUuid &thingId, const QUuid &stateTypeId, const QVariant &value, QObject *parent) : QObject(parent), - m_deviceId(deviceId), + m_thingId(thingId), m_stateTypeId(stateTypeId), m_value(value) { } -QUuid State::deviceId() const +QUuid State::thingId() const { - return m_deviceId; + return m_thingId; } QUuid State::stateTypeId() const diff --git a/libnymea-app/types/state.h b/libnymea-app/types/state.h index 3d4ef336..e061195c 100644 --- a/libnymea-app/types/state.h +++ b/libnymea-app/types/state.h @@ -38,21 +38,21 @@ class State : public QObject { Q_OBJECT - Q_PROPERTY(QUuid deviceId READ deviceId CONSTANT) + Q_PROPERTY(QUuid thingId READ thingId CONSTANT) Q_PROPERTY(QUuid stateTypeId READ stateTypeId CONSTANT) Q_PROPERTY(QVariant value READ value NOTIFY valueChanged) public: - explicit State(const QUuid &deviceId, const QUuid &stateTypeId, const QVariant &value, QObject *parent = nullptr); + explicit State(const QUuid &thingId, const QUuid &stateTypeId, const QVariant &value, QObject *parent = nullptr); - QUuid deviceId() const; + QUuid thingId() const; QUuid stateTypeId() const; QVariant value() const; void setValue(const QVariant &value); private: - QUuid m_deviceId; + QUuid m_thingId; QUuid m_stateTypeId; QVariant m_value; diff --git a/libnymea-app/types/statedescriptor.cpp b/libnymea-app/types/statedescriptor.cpp index c0d4c0e6..e02d0bd6 100644 --- a/libnymea-app/types/statedescriptor.cpp +++ b/libnymea-app/types/statedescriptor.cpp @@ -32,9 +32,9 @@ #include -StateDescriptor::StateDescriptor(const QUuid &deviceId, const QUuid &stateTypeId, StateDescriptor::ValueOperator valueOperator, const QVariant &value, QObject *parent): +StateDescriptor::StateDescriptor(const QUuid &thingId, const QUuid &stateTypeId, StateDescriptor::ValueOperator valueOperator, const QVariant &value, QObject *parent): QObject(parent), - m_deviceId(deviceId), + m_thingId(thingId), m_stateTypeId(stateTypeId), m_operator(valueOperator), m_value(value) @@ -57,16 +57,16 @@ StateDescriptor::StateDescriptor(QObject *parent) : QObject(parent) } -QUuid StateDescriptor::deviceId() const +QUuid StateDescriptor::thingId() const { - return m_deviceId; + return m_thingId; } -void StateDescriptor::setDeviceId(const QUuid &deviceId) +void StateDescriptor::setThingId(const QUuid &thingId) { - if (m_deviceId != deviceId) { - m_deviceId = deviceId; - emit deviceIdChanged(); + if (m_thingId != thingId) { + m_thingId = thingId; + emit thingIdChanged(); } } @@ -137,7 +137,7 @@ void StateDescriptor::setValue(const QVariant &value) StateDescriptor *StateDescriptor::clone() const { - StateDescriptor *ret = new StateDescriptor(deviceId(), stateTypeId(), valueOperator(), value()); + StateDescriptor *ret = new StateDescriptor(thingId(), stateTypeId(), valueOperator(), value()); ret->setInterfaceName(interfaceName()); ret->setInterfaceState(interfaceState()); return ret; @@ -147,7 +147,7 @@ StateDescriptor *StateDescriptor::clone() const #define COMPARE_PTR(a, b) if (!a->operator==(b)) { qDebug() << a << "!=" << b; return false; } bool StateDescriptor::operator==(StateDescriptor *other) const { - COMPARE(m_deviceId, other->deviceId()); + COMPARE(m_thingId, other->thingId()); COMPARE(m_stateTypeId, other->stateTypeId()); COMPARE(m_interfaceName, other->interfaceName()); COMPARE(m_interfaceState, other->interfaceState()); diff --git a/libnymea-app/types/statedescriptor.h b/libnymea-app/types/statedescriptor.h index d7fe5d47..322814ea 100644 --- a/libnymea-app/types/statedescriptor.h +++ b/libnymea-app/types/statedescriptor.h @@ -38,7 +38,7 @@ class StateDescriptor : public QObject { Q_OBJECT - Q_PROPERTY(QUuid deviceId READ deviceId WRITE setDeviceId NOTIFY deviceIdChanged) + Q_PROPERTY(QUuid thingId READ thingId WRITE setThingId NOTIFY thingIdChanged) Q_PROPERTY(QUuid stateTypeId READ stateTypeId WRITE setStateTypeId NOTIFY stateTypeIdChanged) Q_PROPERTY(QString interfaceName READ interfaceName WRITE setInterfaceName NOTIFY interfaceNameChanged) Q_PROPERTY(QString interfaceState READ interfaceState WRITE setInterfaceState NOTIFY interfaceStateChanged) @@ -56,12 +56,12 @@ public: }; Q_ENUM(ValueOperator) - explicit StateDescriptor(const QUuid &deviceId, const QUuid &stateTypeId, ValueOperator valueOperator, const QVariant &value, QObject *parent = nullptr); + explicit StateDescriptor(const QUuid &thingId, const QUuid &stateTypeId, ValueOperator valueOperator, const QVariant &value, QObject *parent = nullptr); explicit StateDescriptor(const QString &interfaceName, const QString &interfaceState, ValueOperator valueOperator, const QVariant &value, QObject *parent = nullptr); StateDescriptor(QObject *parent = nullptr); - QUuid deviceId() const; - void setDeviceId(const QUuid &deviceId); + QUuid thingId() const; + void setThingId(const QUuid &thingId); QUuid stateTypeId() const; void setStateTypeId(const QUuid &stateTypeId); @@ -82,7 +82,7 @@ public: bool operator==(StateDescriptor *other) const; signals: - void deviceIdChanged(); + void thingIdChanged(); void stateTypeIdChanged(); void interfaceNameChanged(); void interfaceStateChanged(); @@ -90,7 +90,7 @@ signals: void valueChanged(); private: - QUuid m_deviceId; + QUuid m_thingId; QUuid m_stateTypeId; QString m_interfaceName; QString m_interfaceState; diff --git a/libnymea-app/types/stateevaluator.cpp b/libnymea-app/types/stateevaluator.cpp index 9887f294..29d72c18 100644 --- a/libnymea-app/types/stateevaluator.cpp +++ b/libnymea-app/types/stateevaluator.cpp @@ -72,13 +72,13 @@ void StateEvaluator::setStateDescriptor(StateDescriptor *stateDescriptor) m_stateDescriptor = stateDescriptor; } -bool StateEvaluator::containsDevice(const QUuid &deviceId) const +bool StateEvaluator::containsThing(const QUuid &thingId) const { - if (m_stateDescriptor && m_stateDescriptor->deviceId() == deviceId) { + if (m_stateDescriptor && m_stateDescriptor->thingId() == thingId) { return true; } for (int i = 0; i < m_childEvaluators->rowCount(); i++) { - if (m_childEvaluators->get(i)->containsDevice(deviceId)) { + if (m_childEvaluators->get(i)->containsThing(thingId)) { return true; } } @@ -96,7 +96,7 @@ StateEvaluator *StateEvaluator::clone() const { StateEvaluator *ret = new StateEvaluator(); ret->m_operator = this->m_operator; - ret->m_stateDescriptor->setDeviceId(this->m_stateDescriptor->deviceId()); + ret->m_stateDescriptor->setThingId(this->m_stateDescriptor->thingId()); ret->m_stateDescriptor->setStateTypeId(this->m_stateDescriptor->stateTypeId()); ret->m_stateDescriptor->setInterfaceName(this->m_stateDescriptor->interfaceName()); ret->m_stateDescriptor->setInterfaceState(this->m_stateDescriptor->interfaceState()); diff --git a/libnymea-app/types/stateevaluator.h b/libnymea-app/types/stateevaluator.h index fb1537b8..7668367c 100644 --- a/libnymea-app/types/stateevaluator.h +++ b/libnymea-app/types/stateevaluator.h @@ -59,7 +59,7 @@ public: StateDescriptor* stateDescriptor() const; void setStateDescriptor(StateDescriptor *stateDescriptor); - bool containsDevice(const QUuid &deviceId) const; + bool containsThing(const QUuid &thingId) const; Q_INVOKABLE StateEvaluator* addChildEvaluator(); diff --git a/libnymea-app/types/tag.h b/libnymea-app/types/tag.h index f38efd96..b78b6638 100644 --- a/libnymea-app/types/tag.h +++ b/libnymea-app/types/tag.h @@ -38,7 +38,6 @@ class Tag : public QObject { Q_OBJECT Q_PROPERTY(QUuid thingId READ thingId CONSTANT) - Q_PROPERTY(QUuid deviceId READ thingId CONSTANT) Q_PROPERTY(QUuid ruleId READ ruleId CONSTANT) Q_PROPERTY(QString tagId READ tagId CONSTANT) Q_PROPERTY(QString value READ value NOTIFY valueChanged) diff --git a/libnymea-app/types/tags.cpp b/libnymea-app/types/tags.cpp index 90db8f86..bbee21d0 100644 --- a/libnymea-app/types/tags.cpp +++ b/libnymea-app/types/tags.cpp @@ -48,7 +48,6 @@ QVariant Tags::data(const QModelIndex &index, int role) const { switch (role) { case RoleThingId: - case RoleDeviceId: return m_list.at(index.row())->thingId(); case RoleRuleId: return m_list.at(index.row())->ruleId(); @@ -64,7 +63,6 @@ QHash Tags::roleNames() const { QHash roles; roles.insert(RoleThingId, "thingId"); - roles.insert(RoleDeviceId, "deviceId"); roles.insert(RoleRuleId, "ruleId"); roles.insert(RoleTagId, "tagId"); roles.insert(RoleValue, "value"); @@ -129,11 +127,6 @@ Tag *Tags::findThingTag(const QUuid &thingId, const QString &tagId) const return nullptr; } -Tag *Tags::findDeviceTag(const QUuid &deviceId, const QString &tagId) const -{ - return findThingTag(deviceId, tagId); -} - Tag *Tags::findRuleTag(const QString &ruleId, const QString &tagId) const { foreach (Tag *tag, m_list) { diff --git a/libnymea-app/types/tags.h b/libnymea-app/types/tags.h index ba573eb3..c81c7ffe 100644 --- a/libnymea-app/types/tags.h +++ b/libnymea-app/types/tags.h @@ -42,7 +42,6 @@ class Tags: public QAbstractListModel public: enum Roles { RoleThingId, - RoleDeviceId, RoleRuleId, RoleTagId, RoleValue @@ -62,7 +61,6 @@ public: Q_INVOKABLE Tag* get(int index) const; Q_INVOKABLE Tag* findThingTag(const QUuid &thingId, const QString &tagId) const; - Q_INVOKABLE Tag* findDeviceTag(const QUuid &deviceId, const QString &tagId) const; Q_INVOKABLE Tag* findRuleTag(const QString &ruleId, const QString &tagId) const; void clear(); diff --git a/libnymea-app/types/device.cpp b/libnymea-app/types/thing.cpp similarity index 79% rename from libnymea-app/types/device.cpp rename to libnymea-app/types/thing.cpp index 34b70cbd..d577cf5a 100644 --- a/libnymea-app/types/device.cpp +++ b/libnymea-app/types/thing.cpp @@ -28,78 +28,78 @@ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -#include "device.h" -#include "deviceclass.h" -#include "devicemanager.h" +#include "thing.h" +#include "thingclass.h" +#include "thingmanager.h" #include -Device::Device(DeviceManager *thingManager, DeviceClass *thingClass, const QUuid &parentId, QObject *parent) : +Thing::Thing(ThingManager *thingManager, ThingClass *thingClass, const QUuid &parentId, QObject *parent) : QObject(parent), m_thingManager(thingManager), m_parentId(parentId), m_thingClass(thingClass) { - connect(thingManager, &DeviceManager::executeActionReply, this, [=](int commandId, const QVariantMap ¶ms){ + connect(thingManager, &ThingManager::executeActionReply, this, [=](int commandId, Thing::ThingError thingError, const QString &displayMessage){ if (m_pendingActions.contains(commandId)) { m_pendingActions.removeAll(commandId); - emit executeActionReply(commandId, params); + emit executeActionReply(commandId, thingError, displayMessage); } }); } -QString Device::name() const +QString Thing::name() const { return m_name; } -void Device::setName(const QString &name) +void Thing::setName(const QString &name) { m_name = name; emit nameChanged(); } -QUuid Device::id() const +QUuid Thing::id() const { return m_id; } -void Device::setId(const QUuid &id) +void Thing::setId(const QUuid &id) { m_id = id; } -QUuid Device::deviceClassId() const +QUuid Thing::deviceClassId() const { return m_thingClass->id(); } -QUuid Device::thingClassId() const +QUuid Thing::thingClassId() const { return m_thingClass->id(); } -QUuid Device::parentDeviceId() const +QUuid Thing::parentId() const { return m_parentId; } -bool Device::isChild() const +bool Thing::isChild() const { return !m_parentId.isNull(); } -Device::ThingSetupStatus Device::setupStatus() const +Thing::ThingSetupStatus Thing::setupStatus() const { return m_setupStatus; } -QString Device::setupDisplayMessage() const +QString Thing::setupDisplayMessage() const { return m_setupDisplayMessage; } -void Device::setSetupStatus(Device::ThingSetupStatus setupStatus, const QString &displayMessage) +void Thing::setSetupStatus(Thing::ThingSetupStatus setupStatus, const QString &displayMessage) { if (m_setupStatus != setupStatus || m_setupDisplayMessage != displayMessage) { m_setupStatus = setupStatus; @@ -108,12 +108,12 @@ void Device::setSetupStatus(Device::ThingSetupStatus setupStatus, const QString } } -Params *Device::params() const +Params *Thing::params() const { return m_params; } -void Device::setParams(Params *params) +void Thing::setParams(Params *params) { if (m_params != params) { if (m_params) { @@ -125,12 +125,12 @@ void Device::setParams(Params *params) } } -Params *Device::settings() const +Params *Thing::settings() const { return m_settings; } -void Device::setSettings(Params *settings) +void Thing::setSettings(Params *settings) { if (m_settings != settings) { if (m_settings) { @@ -142,12 +142,12 @@ void Device::setSettings(Params *settings) } } -States *Device::states() const +States *Thing::states() const { return m_states; } -void Device::setStates(States *states) +void Thing::setStates(States *states) { if (m_states != states) { if (m_states) { @@ -159,12 +159,12 @@ void Device::setStates(States *states) } } -State *Device::state(const QUuid &stateTypeId) const +State *Thing::state(const QUuid &stateTypeId) const { return m_states->getState(stateTypeId); } -State *Device::stateByName(const QString &stateName) const +State *Thing::stateByName(const QString &stateName) const { StateType *st = m_thingClass->stateTypes()->findByName(stateName); if (!st) { @@ -173,12 +173,12 @@ State *Device::stateByName(const QString &stateName) const return m_states->getState(st->id()); } -Param *Device::param(const QUuid ¶mTypeId) const +Param *Thing::param(const QUuid ¶mTypeId) const { return m_params->getParam(paramTypeId); } -Param *Device::paramByName(const QString ¶mName) const +Param *Thing::paramByName(const QString ¶mName) const { ParamType *paramType = m_thingClass->paramTypes()->findByName(paramName); if (!paramType) { @@ -187,12 +187,12 @@ Param *Device::paramByName(const QString ¶mName) const return m_params->getParam(paramType->id()); } -DeviceClass *Device::thingClass() const +ThingClass *Thing::thingClass() const { return m_thingClass; } -bool Device::hasState(const QUuid &stateTypeId) const +bool Thing::hasState(const QUuid &stateTypeId) const { foreach (State *state, states()->states()) { if (state->stateTypeId() == stateTypeId) { @@ -202,7 +202,7 @@ bool Device::hasState(const QUuid &stateTypeId) const return false; } -QVariant Device::stateValue(const QUuid &stateTypeId) const +QVariant Thing::stateValue(const QUuid &stateTypeId) const { foreach (State *state, states()->states()) { if (state->stateTypeId() == stateTypeId) { @@ -212,7 +212,7 @@ QVariant Device::stateValue(const QUuid &stateTypeId) const return QVariant(); } -void Device::setStateValue(const QUuid &stateTypeId, const QVariant &value) +void Thing::setStateValue(const QUuid &stateTypeId, const QVariant &value) { foreach (State *state, states()->states()) { if (state->stateTypeId() == stateTypeId) { @@ -222,7 +222,7 @@ void Device::setStateValue(const QUuid &stateTypeId, const QVariant &value) } } -int Device::executeAction(const QString &actionName, const QVariantList ¶ms) +int Thing::executeAction(const QString &actionName, const QVariantList ¶ms) { ActionType *actionType = m_thingClass->actionTypes()->findByName(actionName); @@ -240,7 +240,7 @@ int Device::executeAction(const QString &actionName, const QVariantList ¶ms) return commandId; } -QDebug operator<<(QDebug &dbg, Device *thing) +QDebug operator<<(QDebug &dbg, Thing *thing) { dbg.nospace() << "Thing: " << thing->name() << " (" << thing->id().toString() << ") Class:" << thing->thingClass()->name() << " (" << thing->thingClassId().toString() << ")" << endl; for (int i = 0; i < thing->thingClass()->paramTypes()->rowCount(); i++) { diff --git a/libnymea-app/types/device.h b/libnymea-app/types/thing.h similarity index 67% rename from libnymea-app/types/device.h rename to libnymea-app/types/thing.h index 4f043b0a..8c022958 100644 --- a/libnymea-app/types/device.h +++ b/libnymea-app/types/thing.h @@ -28,8 +28,8 @@ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -#ifndef DEVICE_H -#define DEVICE_H +#ifndef THING_H +#define THING_H #include #include @@ -38,16 +38,16 @@ #include "states.h" #include "statesproxy.h" -class DeviceClass; -class DeviceManager; +class ThingClass; +class ThingManager; -class Device : public QObject +class Thing : public QObject { Q_OBJECT Q_PROPERTY(QUuid id READ id CONSTANT) Q_PROPERTY(QUuid deviceClassId READ deviceClassId CONSTANT) Q_PROPERTY(QUuid thingClassId READ thingClassId CONSTANT) - Q_PROPERTY(QUuid parentDeviceId READ parentDeviceId CONSTANT) + Q_PROPERTY(QUuid parentId READ parentId CONSTANT) Q_PROPERTY(bool isChild READ isChild CONSTANT) Q_PROPERTY(QString name READ name NOTIFY nameChanged) Q_PROPERTY(ThingSetupStatus setupStatus READ setupStatus NOTIFY setupStatusChanged) @@ -55,8 +55,8 @@ class Device : public QObject Q_PROPERTY(Params *params READ params NOTIFY paramsChanged) Q_PROPERTY(Params *settings READ settings NOTIFY settingsChanged) Q_PROPERTY(States *states READ states NOTIFY statesChanged) - Q_PROPERTY(DeviceClass *deviceClass READ thingClass CONSTANT) - Q_PROPERTY(DeviceClass *thingClass READ thingClass CONSTANT) + Q_PROPERTY(ThingClass *deviceClass READ thingClass CONSTANT) + Q_PROPERTY(ThingClass *thingClass READ thingClass CONSTANT) public: enum ThingSetupStatus { @@ -67,7 +67,38 @@ public: }; Q_ENUM(ThingSetupStatus) - explicit Device(DeviceManager *thingManager, DeviceClass *thingClass, const QUuid &parentId = QUuid(), QObject *parent = nullptr); + enum ThingError { + ThingErrorNoError, + ThingErrorPluginNotFound, + ThingErrorVendorNotFound, + ThingErrorThingNotFound, + ThingErrorThingClassNotFound, + ThingErrorActionTypeNotFound, + ThingErrorStateTypeNotFound, + ThingErrorEventTypeNotFound, + ThingErrorThingDescriptorNotFound, + ThingErrorMissingParameter, + ThingErrorInvalidParameter, + ThingErrorSetupFailed, + ThingErrorDuplicateUuid, + ThingErrorCreationMethodNotSupported, + ThingErrorSetupMethodNotSupported, + ThingErrorHardwareNotAvailable, + ThingErrorHardwareFailure, + ThingErrorAuthenticationFailure, + ThingErrorThingInUse, + ThingErrorThingInRule, + ThingErrorThingIsChild, + ThingErrorPairingTransactionIdNotFound, + ThingErrorParameterNotWritable, + ThingErrorItemNotFound, + ThingErrorItemNotExecutable, + ThingErrorUnsupportedFeature, + ThingErrorTimeout, + }; + Q_ENUM(ThingError) + + explicit Thing(ThingManager *thingManager, ThingClass *thingClass, const QUuid &parentId = QUuid(), QObject *parent = nullptr); QUuid id() const; void setId(const QUuid &id); @@ -77,12 +108,12 @@ public: QUuid deviceClassId() const; QUuid thingClassId() const; - QUuid parentDeviceId() const; + QUuid parentId() const; bool isChild() const; - Device::ThingSetupStatus setupStatus() const; + Thing::ThingSetupStatus setupStatus() const; QString setupDisplayMessage() const; - void setSetupStatus(Device::ThingSetupStatus setupStatus, const QString &displayMessage); + void setSetupStatus(Thing::ThingSetupStatus setupStatus, const QString &displayMessage); Params *params() const; void setParams(Params *params); @@ -94,7 +125,7 @@ public: void setStates(States *states); void setStateValue(const QUuid &stateTypeId, const QVariant &value); - DeviceClass *thingClass() const; + ThingClass *thingClass() const; Q_INVOKABLE bool hasState(const QUuid &stateTypeId) const; Q_INVOKABLE State *state(const QUuid &stateTypeId) const; @@ -115,10 +146,10 @@ signals: void eventTriggered(const QUuid &eventTypeId, const QVariantMap ¶ms); signals: - void executeActionReply(int commandId, const QVariantMap ¶ms); + void executeActionReply(int commandId, Thing::ThingError thingError, const QString &displayMessage); protected: - DeviceManager *m_thingManager = nullptr; + ThingManager *m_thingManager = nullptr; QString m_name; QUuid m_id; QUuid m_parentId; @@ -127,11 +158,12 @@ protected: Params *m_params = nullptr; Params *m_settings = nullptr; States *m_states = nullptr; - DeviceClass *m_thingClass = nullptr; + ThingClass *m_thingClass = nullptr; QList m_pendingActions; }; +Q_DECLARE_METATYPE(Thing::ThingError) -QDebug operator<<(QDebug &dbg, Device* thing); +QDebug operator<<(QDebug &dbg, Thing* thing); -#endif // DEVICE_H +#endif // THING_H diff --git a/libnymea-app/types/deviceclass.cpp b/libnymea-app/types/thingclass.cpp similarity index 74% rename from libnymea-app/types/deviceclass.cpp rename to libnymea-app/types/thingclass.cpp index 2f6b6197..95b40a12 100644 --- a/libnymea-app/types/deviceclass.cpp +++ b/libnymea-app/types/thingclass.cpp @@ -28,96 +28,96 @@ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -#include "deviceclass.h" +#include "thingclass.h" #include -DeviceClass::DeviceClass(QObject *parent) : +ThingClass::ThingClass(QObject *parent) : QObject(parent) { } -QUuid DeviceClass::id() const +QUuid ThingClass::id() const { return m_id; } -void DeviceClass::setId(const QUuid &id) +void ThingClass::setId(const QUuid &id) { m_id = id; } -QUuid DeviceClass::vendorId() const +QUuid ThingClass::vendorId() const { return m_vendorId; } -void DeviceClass::setVendorId(const QUuid &vendorId) +void ThingClass::setVendorId(const QUuid &vendorId) { m_vendorId = vendorId; } -QUuid DeviceClass::pluginId() const +QUuid ThingClass::pluginId() const { return m_pluginId; } -void DeviceClass::setPluginId(const QUuid &pluginId) +void ThingClass::setPluginId(const QUuid &pluginId) { m_pluginId = pluginId; } -QString DeviceClass::name() const +QString ThingClass::name() const { return m_name; } -void DeviceClass::setName(const QString &name) +void ThingClass::setName(const QString &name) { m_name = name; } -QString DeviceClass::displayName() const +QString ThingClass::displayName() const { return m_displayName; } -void DeviceClass::setDisplayName(const QString &displayName) +void ThingClass::setDisplayName(const QString &displayName) { m_displayName = displayName; } -QStringList DeviceClass::createMethods() const +QStringList ThingClass::createMethods() const { return m_createMethods; } -void DeviceClass::setCreateMethods(const QStringList &createMethods) +void ThingClass::setCreateMethods(const QStringList &createMethods) { m_createMethods = createMethods; } -DeviceClass::SetupMethod DeviceClass::setupMethod() const +ThingClass::SetupMethod ThingClass::setupMethod() const { return m_setupMethod; } -void DeviceClass::setSetupMethod(DeviceClass::SetupMethod setupMethod) +void ThingClass::setSetupMethod(ThingClass::SetupMethod setupMethod) { m_setupMethod = setupMethod; } -QStringList DeviceClass::interfaces() const +QStringList ThingClass::interfaces() const { return m_interfaces; } -void DeviceClass::setInterfaces(const QStringList &interfaces) +void ThingClass::setInterfaces(const QStringList &interfaces) { m_interfaces = interfaces; } -QString DeviceClass::baseInterface() const +QString ThingClass::baseInterface() const { foreach (const QString &interface, m_interfaces) { if (interface == "gateway") { @@ -181,22 +181,22 @@ QString DeviceClass::baseInterface() const return "uncategorized"; } -bool DeviceClass::browsable() const +bool ThingClass::browsable() const { return m_browsable; } -void DeviceClass::setBrowsable(bool browsable) +void ThingClass::setBrowsable(bool browsable) { m_browsable = browsable; } -ParamTypes *DeviceClass::paramTypes() const +ParamTypes *ThingClass::paramTypes() const { return m_paramTypes; } -void DeviceClass::setParamTypes(ParamTypes *paramTypes) +void ThingClass::setParamTypes(ParamTypes *paramTypes) { if (m_paramTypes) { m_paramTypes->deleteLater(); @@ -205,12 +205,12 @@ void DeviceClass::setParamTypes(ParamTypes *paramTypes) emit paramTypesChanged(); } -ParamTypes *DeviceClass::settingsTypes() const +ParamTypes *ThingClass::settingsTypes() const { return m_settingsTypes; } -void DeviceClass::setSettingsTypes(ParamTypes *settingsTypes) +void ThingClass::setSettingsTypes(ParamTypes *settingsTypes) { if (m_settingsTypes) { m_settingsTypes->deleteLater(); @@ -219,12 +219,12 @@ void DeviceClass::setSettingsTypes(ParamTypes *settingsTypes) emit settingsTypesChanged(); } -ParamTypes *DeviceClass::discoveryParamTypes() const +ParamTypes *ThingClass::discoveryParamTypes() const { return m_discoveryParamTypes; } -void DeviceClass::setDiscoveryParamTypes(ParamTypes *paramTypes) +void ThingClass::setDiscoveryParamTypes(ParamTypes *paramTypes) { if (m_discoveryParamTypes) { m_discoveryParamTypes->deleteLater(); @@ -233,12 +233,12 @@ void DeviceClass::setDiscoveryParamTypes(ParamTypes *paramTypes) emit discoveryParamTypesChanged(); } -StateTypes *DeviceClass::stateTypes() const +StateTypes *ThingClass::stateTypes() const { return m_stateTypes; } -void DeviceClass::setStateTypes(StateTypes *stateTypes) +void ThingClass::setStateTypes(StateTypes *stateTypes) { if (m_stateTypes) { m_stateTypes->deleteLater(); @@ -247,12 +247,12 @@ void DeviceClass::setStateTypes(StateTypes *stateTypes) emit stateTypesChanged(); } -EventTypes *DeviceClass::eventTypes() const +EventTypes *ThingClass::eventTypes() const { return m_eventTypes; } -void DeviceClass::setEventTypes(EventTypes *eventTypes) +void ThingClass::setEventTypes(EventTypes *eventTypes) { if (m_eventTypes) { m_eventTypes->deleteLater(); @@ -261,12 +261,12 @@ void DeviceClass::setEventTypes(EventTypes *eventTypes) emit eventTypesChanged(); } -ActionTypes *DeviceClass::actionTypes() const +ActionTypes *ThingClass::actionTypes() const { return m_actionTypes; } -void DeviceClass::setActionTypes(ActionTypes *actionTypes) +void ThingClass::setActionTypes(ActionTypes *actionTypes) { if (m_actionTypes) { m_actionTypes->deleteLater(); @@ -275,12 +275,12 @@ void DeviceClass::setActionTypes(ActionTypes *actionTypes) emit actionTypesChanged(); } -ActionTypes *DeviceClass::browserItemActionTypes() const +ActionTypes *ThingClass::browserItemActionTypes() const { return m_browserItemActionTypes; } -void DeviceClass::setBrowserItemActionTypes(ActionTypes *browserActionTypes) +void ThingClass::setBrowserItemActionTypes(ActionTypes *browserActionTypes) { if (m_browserItemActionTypes) { m_browserItemActionTypes->deleteLater(); @@ -289,7 +289,7 @@ void DeviceClass::setBrowserItemActionTypes(ActionTypes *browserActionTypes) emit browserItemActionTypesChanged(); } -bool DeviceClass::hasActionType(const QString &actionTypeId) +bool ThingClass::hasActionType(const QString &actionTypeId) { foreach (ActionType *actionType, m_actionTypes->actionTypes()) { if (actionType->id() == actionTypeId) { diff --git a/libnymea-app/types/deviceclass.h b/libnymea-app/types/thingclass.h similarity index 97% rename from libnymea-app/types/deviceclass.h rename to libnymea-app/types/thingclass.h index acb88b46..fc7ecccf 100644 --- a/libnymea-app/types/deviceclass.h +++ b/libnymea-app/types/thingclass.h @@ -28,8 +28,8 @@ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -#ifndef DEVICECLASS_H -#define DEVICECLASS_H +#ifndef THINGCLASS_H +#define THINGCLASS_H #include #include @@ -41,7 +41,7 @@ #include "eventtypes.h" #include "actiontypes.h" -class DeviceClass : public QObject +class ThingClass : public QObject { Q_OBJECT @@ -74,7 +74,7 @@ public: }; Q_ENUM(SetupMethod) - DeviceClass(QObject *parent = nullptr); + ThingClass(QObject *parent = nullptr); QString name() const; void setName(const QString &name); @@ -156,4 +156,4 @@ private: ActionTypes *m_actionTypes = nullptr; ActionTypes *m_browserItemActionTypes = nullptr; }; -#endif // DEVICECLASS_H +#endif // THINGCLASS_H diff --git a/nymea-app/nfcthingactionwriter.cpp b/nymea-app/nfcthingactionwriter.cpp index 1214ffed..6c5fb15a 100644 --- a/nymea-app/nfcthingactionwriter.cpp +++ b/nymea-app/nfcthingactionwriter.cpp @@ -1,5 +1,5 @@ #include "nfcthingactionwriter.h" -#include "types/deviceclass.h" +#include "types/thingclass.h" #include "types/statetype.h" #include "types/ruleaction.h" #include "types/ruleactionparams.h" @@ -50,12 +50,12 @@ void NfcThingActionWriter::setEngine(Engine *engine) } } -Device *NfcThingActionWriter::thing() const +Thing *NfcThingActionWriter::thing() const { return m_thing; } -void NfcThingActionWriter::setThing(Device *thing) +void NfcThingActionWriter::setThing(Thing *thing) { if (m_thing != thing) { m_thing = thing; diff --git a/nymea-app/nfcthingactionwriter.h b/nymea-app/nfcthingactionwriter.h index 0463b7e5..06912808 100644 --- a/nymea-app/nfcthingactionwriter.h +++ b/nymea-app/nfcthingactionwriter.h @@ -5,7 +5,7 @@ #include #include -#include "types/device.h" +#include "types/thing.h" #include "engine.h" #include "types/ruleactions.h" @@ -14,7 +14,7 @@ class NfcThingActionWriter : public QObject Q_OBJECT Q_PROPERTY(bool isAvailable READ isAvailable CONSTANT) Q_PROPERTY(Engine *engine READ engine WRITE setEngine NOTIFY engineChanged) - Q_PROPERTY(Device *thing READ thing WRITE setThing NOTIFY thingChanged) + Q_PROPERTY(Thing *thing READ thing WRITE setThing NOTIFY thingChanged) Q_PROPERTY(RuleActions *actions READ actions CONSTANT) Q_PROPERTY(int messageSize READ messageSize NOTIFY messageSizeChanged) Q_PROPERTY(TagStatus status READ status NOTIFY statusChanged) @@ -39,8 +39,8 @@ public: Engine *engine() const; void setEngine(Engine *engine); - Device *thing() const; - void setThing(Device *thing); + Thing *thing() const; + void setThing(Thing *thing); RuleActions *actions() const; @@ -64,7 +64,7 @@ private slots: private: QNearFieldManager *m_manager = nullptr; Engine *m_engine = nullptr; - Device *m_thing = nullptr; + Thing *m_thing = nullptr; RuleActions* m_actions; TagStatus m_status = TagStatusWaiting; diff --git a/nymea-app/resources.qrc b/nymea-app/resources.qrc index bfa51ef1..88480023 100644 --- a/nymea-app/resources.qrc +++ b/nymea-app/resources.qrc @@ -47,31 +47,31 @@ ui/customviews/GenericTypeLogView.qml ui/customviews/WeatherView.qml ui/devicepages/MediaThingPage.qml - ui/devicepages/ButtonDevicePage.qml + ui/devicepages/ButtonThingPage.qml ui/devicepages/GenericDevicePage.qml ui/devicepages/WeatherDevicePage.qml ui/devicepages/SensorDevicePage.qml - ui/devicepages/DevicePageBase.qml + ui/devicepages/ThingPageBase.qml ui/devicepages/InputTriggerDevicePage.qml ui/devicepages/StateLogPage.qml ui/devicepages/ShutterDevicePage.qml ui/devicepages/GarageThingPage.qml - ui/devicepages/AwningDevicePage.qml + ui/devicepages/AwningThingPage.qml ui/devicepages/NotificationsDevicePage.qml ui/devicepages/LightDevicePage.qml ui/devicepages/FingerprintReaderDevicePage.qml ui/devicepages/DeviceLogPage.qml - ui/devicelistpages/GenericDeviceListPage.qml - ui/devicelistpages/ClosablesDeviceListPage.qml - ui/devicelistpages/GarageThingListPage.qml - ui/devicelistpages/AwningDeviceListPage.qml + ui/devicelistpages/GenericThingsListPage.qml + ui/devicelistpages/ClosablesThingsListPage.qml + ui/devicelistpages/GarageThingsListPage.qml + ui/devicelistpages/AwningThingsListPage.qml ui/devicelistpages/ShutterDeviceListPage.qml - ui/devicelistpages/BlindDeviceListPage.qml - ui/devicelistpages/LightsDeviceListPage.qml + ui/devicelistpages/BlindThingsListPage.qml + ui/devicelistpages/LightThingsListPage.qml ui/devicelistpages/SensorsDeviceListPage.qml ui/devicelistpages/WeatherDeviceListPage.qml - ui/devicelistpages/DeviceListPageBase.qml - ui/magic/DeviceRulesPage.qml + ui/devicelistpages/ThingsListPageBase.qml + ui/magic/ThingRulesPage.qml ui/magic/EditRulePage.qml ui/magic/SelectThingPage.qml ui/magic/ComposeEventDescriptorPage.qml diff --git a/nymea-app/ui/MagicPage.qml b/nymea-app/ui/MagicPage.qml index b2ad453c..e22c3dcf 100644 --- a/nymea-app/ui/MagicPage.qml +++ b/nymea-app/ui/MagicPage.qml @@ -59,9 +59,7 @@ Page { RuleTemplatesFilterModel { id: ruleTemplatesModel ruleTemplates: RuleTemplates {} - readonly property var deviceClass: root.device ? engine.deviceManager.deviceClasses.getDeviceClass(root.device.deviceClassId) : null - filterByDevices: DevicesProxy { engine: _engine } - filterInterfaceNames: deviceClass ? deviceClass.interfaces : [] + filterByThings: ThingsProxy { engine: _engine } } function addRule() { diff --git a/nymea-app/ui/MainPage.qml b/nymea-app/ui/MainPage.qml index ce2bf6b1..3e2bacf1 100644 --- a/nymea-app/ui/MainPage.qml +++ b/nymea-app/ui/MainPage.qml @@ -228,7 +228,7 @@ Page { ColumnLayout { anchors { left: parent.left; right: parent.right; verticalCenter: parent.verticalCenter; margins: app.margins } spacing: app.margins - visible: engine.deviceManager.fetchingData + visible: engine.thingManager.fetchingData BusyIndicator { Layout.alignment: Qt.AlignHCenter running: parent.visible diff --git a/nymea-app/ui/components/BrowserContextMenu.qml b/nymea-app/ui/components/BrowserContextMenu.qml index 44ff0377..6a295d1f 100644 --- a/nymea-app/ui/components/BrowserContextMenu.qml +++ b/nymea-app/ui/components/BrowserContextMenu.qml @@ -37,7 +37,7 @@ import "../delegates" MeaDialog { id: root - property Device device + property Thing thing property string itemId property alias actionTypeIds: actionListView.model @@ -63,7 +63,7 @@ MeaDialog { width: parent.width text: actionType.displayName progressive: false - property ActionType actionType: root.device.deviceClass.browserItemActionTypes.getActionType(modelData) + property ActionType actionType: root.thing.thingClass.browserItemActionTypes.getActionType(modelData) onClicked: { var hasParams = actionType.paramTypes.count > 0 if (hasParams) { diff --git a/nymea-app/ui/components/ClosablesControlLarge.qml b/nymea-app/ui/components/ClosablesControlLarge.qml index 93e516e5..a9b8c19d 100644 --- a/nymea-app/ui/components/ClosablesControlLarge.qml +++ b/nymea-app/ui/components/ClosablesControlLarge.qml @@ -39,11 +39,11 @@ import "../customviews" Item { id: root - property Device thing: null - readonly property DeviceClass thingClass: thing.deviceClass + property Thing thing: null + readonly property ThingClass thingClass: thing.thingClass readonly property string type: "shutter" - readonly property bool isExtended: thing.deviceClass.interfaces.indexOf("extendedclosable") >= 0 + readonly property bool isExtended: thing.thingClass.interfaces.indexOf("extendedclosable") >= 0 readonly property State movingState: isExtended ? thing.states.getState(thingClass.stateTypes.findByName("moving").id) : 0 readonly property State percentageState: isExtended ? thing.states.getState(thingClass.stateTypes.findByName("percentage").id) : 0 @@ -155,7 +155,7 @@ Item { percentageParam["value"] = percentage params.push(percentageParam); print("executing", percentage) - engine.deviceManager.executeAction(root.thing.id, actionType.id, params); + engine.thingManager.executeAction(root.thing.id, actionType.id, params); } } diff --git a/nymea-app/ui/components/ErrorDialog.qml b/nymea-app/ui/components/ErrorDialog.qml index b60e60c6..04fb1fcd 100644 --- a/nymea-app/ui/components/ErrorDialog.qml +++ b/nymea-app/ui/components/ErrorDialog.qml @@ -38,9 +38,13 @@ MeaDialog { title: qsTr("Oh snap!") headerIcon: "../images/dialog-error-symbolic.svg" + property int error: 0 + + // Legacy as some places might still use strings instead of enums property string errorCode: "" text: qsTr("An unexpected error happened. We're sorry for that.") + - (errorCode.length > 0 ? "\n\n" + qsTr("Error code: %1").arg(errorCode) : "") + (errorCode.length > 0 ? "\n\n" + qsTr("Error code: %1").arg(errorCode) : "") + + (error != 0 ? "\n\n" + qsTr("Error code: %1").arg(error) : "") } diff --git a/nymea-app/ui/components/Graph.qml b/nymea-app/ui/components/Graph.qml index e1644045..73b08753 100644 --- a/nymea-app/ui/components/Graph.qml +++ b/nymea-app/ui/components/Graph.qml @@ -47,9 +47,9 @@ Item { } onModelChanged: canvas.requestPaint() - readonly property var device: root.model ? engine.deviceManager.devices.getDevice(root.model.deviceId) : null - readonly property var deviceClass: device ? engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId) : null - readonly property var stateType: deviceClass ? deviceClass.stateTypes.getStateType(root.model.typeIds[0]) : null + readonly property Thing thing: root.model ? engine.thingManager.things.getThing(root.model.thingId) : null + readonly property ThingClass thingClass: thing ? engine.thingManager.thingClasses.getThingClass(thing.thingClassId) : null + readonly property StateType stateType: thingClass ? thingClass.stateTypes.getStateType(root.model.typeIds[0]) : null Label { anchors.centerIn: parent diff --git a/nymea-app/ui/components/MediaBrowser.qml b/nymea-app/ui/components/MediaBrowser.qml index 77fe07bb..708ffcbe 100644 --- a/nymea-app/ui/components/MediaBrowser.qml +++ b/nymea-app/ui/components/MediaBrowser.qml @@ -70,13 +70,13 @@ Item { target: engine.thingManager onExecuteBrowserItemReply: { if (commandId == d.pendingItemExecutionId) { - if (params.thingError === "ThingErrorNoError") { + if (thingError === Thing.ThingErrorNoError) { root.itemLaunched(); } else { var errorDialog = Qt.createComponent(Qt.resolvedUrl("ErrorDialog.qml")); var text = qsTr("Sorry. An error happened launching the item. (Error code: %1)").arg(params.error); - if (params.displayMessage.length > 0) { - text = params.displayMessage; + if (displayMessage.length > 0) { + text = displayMessage; } var popup = errorDialog.createObject(app, {text: text}) popup.open() @@ -102,7 +102,7 @@ Item { // Need to keep a explicit property here or the GC will eat it too early property BrowserItems browserItems: null Component.onCompleted: { - browserItems = engine.thingManager.browseDevice(root.thing.id, nodeId); + browserItems = engine.thingManager.browseThing(root.thing.id, nodeId); } delegate: BrowserItemDelegate { diff --git a/nymea-app/ui/components/MediaPlayer.qml b/nymea-app/ui/components/MediaPlayer.qml index 9bb381d4..248021e1 100644 --- a/nymea-app/ui/components/MediaPlayer.qml +++ b/nymea-app/ui/components/MediaPlayer.qml @@ -79,12 +79,12 @@ Item { target: engine.thingManager onExecuteActionReply: { if (commandId == d.pendingCallId) { - if (params.deviceError !== "DeviceErrorNoError") { + if (thingError !== Thing.ThingErrorNoError) { var errorDialog = Qt.createComponent(Qt.resolvedUrl("../components/ErrorDialog.qml")); var dialogParams = {} - dialogParams.errorCode = params.deviceError - if (params.displayMessage && params.displayMessage.length > 0) { - dialogParams.text = params.displayMessage + dialogParams.error = thingError + if (displayMessage.length > 0) { + dialogParams.text = displayMessage } var popup = errorDialog.createObject(app, dialogParams) popup.open() @@ -392,7 +392,7 @@ Item { anchors.margins: app.margins spacing: app.margins - NavigationPad { Layout.fillWidth: true; Layout.fillHeight: true; device: root.thing } + NavigationPad { Layout.fillWidth: true; Layout.fillHeight: true; thing: root.thing } MediaControls { Layout.fillWidth: true; thing: root.thing } ShuffleRepeatVolumeControl { Layout.fillWidth: true; Layout.fillHeight: false; Layout.preferredHeight: app.iconSize; thing: root.thing } } diff --git a/nymea-app/ui/components/NavigationPad.qml b/nymea-app/ui/components/NavigationPad.qml index f1386050..327249ae 100644 --- a/nymea-app/ui/components/NavigationPad.qml +++ b/nymea-app/ui/components/NavigationPad.qml @@ -37,11 +37,11 @@ import QtQuick.Layouts 1.3 Item { id: root - property Device device: null + property Thing thing: null - readonly property bool isExtended: device && device.deviceClass.interfaces.indexOf("extendednavigationpad") >= 0 + readonly property bool isExtended: thing && thing.thingClass.interfaces.indexOf("extendednavigationpad") >= 0 - readonly property ActionType navigateActionType: device ? device.deviceClass.actionTypes.findByName("navigate") : null + readonly property ActionType navigateActionType: thing ? thing.thingClass.actionTypes.findByName("navigate") : null Pane { id: pane @@ -75,7 +75,7 @@ Item { anchors { right: parent.right; top: parent.top; margins: parent.width * .1 } height: app.iconSize width: app.iconSize - visible: root.device.deviceClass.interfaces.indexOf("extendednavigationpad") >= 0 + visible: root.thing.thingClass.interfaces.indexOf("extendednavigationpad") >= 0 imageSource: "../images/navigation-menu.svg" Item { id: menuButtonArea; anchors.centerIn: parent; width: pane.width / 4; height: width; rotation: 45 } } @@ -85,7 +85,7 @@ Item { height: app.iconSize width: app.iconSize imageSource: "../images/home.svg" - visible: root.device.deviceClass.interfaces.indexOf("extendednavigationpad") >= 0 + visible: root.thing.thingClass.interfaces.indexOf("extendednavigationpad") >= 0 Item { id: homeButtonArea; anchors.centerIn: parent; width: pane.width / 4; height: width; rotation: 45 } } KeypadButton { @@ -94,7 +94,7 @@ Item { height: app.iconSize width: app.iconSize imageSource: "../images/info.svg" - visible: root.device.deviceClass.interfaces.indexOf("extendednavigationpad") >= 0 + visible: root.thing.thingClass.interfaces.indexOf("extendednavigationpad") >= 0 Item { id: infoButtonArea; anchors.centerIn: parent; width: pane.width / 4; height: width; rotation: 45 } } Rectangle { @@ -259,7 +259,7 @@ Item { param["paramTypeId"] = root.navigateActionType.paramTypes.findByName("to").id; param["value"] = direction; params.push(param); - engine.deviceManager.executeAction(root.device.id, root.navigateActionType.id, params) + engine.thingManager.executeAction(root.thing.id, root.navigateActionType.id, params) PlatformHelper.vibrate(PlatformHelper.HapticsFeedbackSelection) } diff --git a/nymea-app/ui/components/RemoveThingMethodDialog.qml b/nymea-app/ui/components/RemoveThingMethodDialog.qml index 928b67cb..8d4e5390 100644 --- a/nymea-app/ui/components/RemoveThingMethodDialog.qml +++ b/nymea-app/ui/components/RemoveThingMethodDialog.qml @@ -40,7 +40,7 @@ Dialog { y: (parent.height - height) / 2 modal: true - property var device: null + property Thing thing: null property var rulesList: null ColumnLayout { @@ -73,7 +73,7 @@ Dialog { text: qsTr("Remove all those rules") progressive: false onClicked: { - engine.thingManager.removeThing(root.device.id, DeviceManager.RemovePolicyCascade) + engine.thingManager.removeThing(root.thing.id, ThingManager.RemovePolicyCascade) root.close() root.destroy(); } @@ -84,7 +84,7 @@ Dialog { Layout.fillWidth: true progressive: false onClicked: { - engine.thingManager.removeThing(root.device.id, DeviceManager.RemovePolicyUpdate) + engine.thingManager.removeThing(root.thing.id, ThingManager.RemovePolicyUpdate) root.close() root.destroy(); } diff --git a/nymea-app/ui/components/ShutterControls.qml b/nymea-app/ui/components/ShutterControls.qml index a168082c..f0ef5571 100644 --- a/nymea-app/ui/components/ShutterControls.qml +++ b/nymea-app/ui/components/ShutterControls.qml @@ -37,11 +37,9 @@ import Nymea 1.0 RowLayout { id: root - property Device thing: null - property alias device: root.thing - readonly property var deviceClass: device ? engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId) : null - readonly property var openState: device ? device.states.getState(deviceClass.stateTypes.findByName("state").id) : null - readonly property bool canStop: device && device.deviceClass.actionTypes.findByName("stop") + property Thing thing: null + readonly property State openState: thing.stateByName("state") + readonly property bool canStop: thing && thing.thingClass.actionTypes.findByName("stop") property bool invert: false @@ -54,7 +52,7 @@ RowLayout { imageSource: root.invert ? "../images/down.svg" : "../images/up.svg" color: root.openState && root.openState.value === "opening" ? Material.accent : Style.iconColor onClicked: { - engine.deviceManager.executeAction(root.device.id, root.deviceClass.actionTypes.findByName("open").id) + engine.thingManager.executeAction(root.thing.id, root.thing.thingClass.actionTypes.findByName("open").id) root.activated("open") } } @@ -66,7 +64,7 @@ RowLayout { longpressEnabled: false imageSource: "../images/media-playback-stop.svg" onClicked: { - engine.deviceManager.executeAction(root.device.id, root.deviceClass.actionTypes.findByName("stop").id) + engine.thingManager.executeAction(root.thing.id, root.thing.thingClass.actionTypes.findByName("stop").id) root.activated("stop") } } @@ -78,7 +76,7 @@ RowLayout { longpressEnabled: false color: root.openState && root.openState.value === "closing" ? Material.accent : Style.iconColor onClicked: { - engine.deviceManager.executeAction(root.device.id, root.deviceClass.actionTypes.findByName("close").id) + engine.thingManager.executeAction(root.thing.id, root.thing.thingClass.actionTypes.findByName("close").id) root.activated("close") } } diff --git a/nymea-app/ui/components/SmartMeterChart.qml b/nymea-app/ui/components/SmartMeterChart.qml index 49b46b74..a66b7c3a 100644 --- a/nymea-app/ui/components/SmartMeterChart.qml +++ b/nymea-app/ui/components/SmartMeterChart.qml @@ -99,7 +99,7 @@ ChartView { onClicked: { print("clicked slice", slice, d.sliceMap[slice], meters.get(d.sliceMap[slice])) - pageStack.push("../devicepages/SmartMeterDevicePage.qml", {device: meters.get(d.sliceMap[slice])}) + pageStack.push("../devicepages/SmartMeterDevicePage.qml", {thing: meters.get(d.sliceMap[slice])}) } } diff --git a/nymea-app/ui/components/ThingContextMenu.qml b/nymea-app/ui/components/ThingContextMenu.qml index cd5ace82..a0604aa7 100644 --- a/nymea-app/ui/components/ThingContextMenu.qml +++ b/nymea-app/ui/components/ThingContextMenu.qml @@ -50,7 +50,7 @@ AutoSizeMenu { } function openThingMagicPage() { - pageStack.push(Qt.resolvedUrl("../magic/DeviceRulesPage.qml"), {thing: root.thing}) + pageStack.push(Qt.resolvedUrl("../magic/ThingRulesPage.qml"), {thing: root.thing}) } function openGenericThingPage() { pageStack.push(Qt.resolvedUrl("../devicepages/GenericDevicePage.qml"), {thing: root.thing}) @@ -82,7 +82,7 @@ AutoSizeMenu { TagsProxyModel { id: favoritesProxy tags: engine.tagsManager.tags - filterDeviceId: root.thing.id + filterThingId: root.thing.id filterTagId: "favorites" } @@ -153,7 +153,7 @@ AutoSizeMenu { id: innerProxy engine: _engine filterTagId: model.tagId - filterDeviceId: root.thing.id + filterThingId: root.thing.id } } } diff --git a/nymea-app/ui/customviews/GenericTypeGraph.qml b/nymea-app/ui/customviews/GenericTypeGraph.qml index 0d6240e4..303eb304 100644 --- a/nymea-app/ui/customviews/GenericTypeGraph.qml +++ b/nymea-app/ui/customviews/GenericTypeGraph.qml @@ -41,23 +41,22 @@ Item { id: root implicitHeight: width * .6 - property Device device: null + property Thing thing: null property StateType stateType: null property int roundTo: 2 property color color: Style.accentColor property string iconSource: "" property alias title: titleLabel.text - readonly property var valueState: device.states.getState(stateType.id) - readonly property var deviceClass: engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId); - readonly property bool hasConnectable: deviceClass.interfaces.indexOf("connectable") >= 0 - readonly property var connectedStateType: hasConnectable ? deviceClass.stateTypes.findByName("connected") : null + readonly property var valueState: thing.states.getState(stateType.id) + readonly property bool hasConnectable: thing.thingClass.interfaces.indexOf("connectable") >= 0 + readonly property StateType connectedStateType: hasConnectable ? thing.thingClass.stateTypes.findByName("connected") : null LogsModelNg { id: logsModelNg engine: _engine - deviceId: root.device.id + thingId: root.thing.id typeIds: [root.stateType.id] live: true graphSeries: lineSeries1 @@ -67,7 +66,7 @@ Item { LogsModelNg { id: connectedLogsModel engine: root.hasConnectable ? _engine : null // don't even try to poll if we don't have a connectable interface - deviceId: root.device.id + thingId: root.thing.id typeIds: root.hasConnectable ? [root.connectedStateType.id] : [] live: true graphSeries: connectedLineSeries diff --git a/nymea-app/ui/customviews/GenericTypeLogView.qml b/nymea-app/ui/customviews/GenericTypeLogView.qml index d99e8ea3..0ea48dfe 100644 --- a/nymea-app/ui/customviews/GenericTypeLogView.qml +++ b/nymea-app/ui/customviews/GenericTypeLogView.qml @@ -63,11 +63,11 @@ Item { id: logEntryDelegate width: parent.width implicitHeight: app.delegateHeight - property var device: engine.deviceManager.devices.getDevice(model.deviceId) - property var deviceClass: engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId) + property Thing thing: engine.thingManager.things.getThing(model.thingId) + property Thing thingClass: engine.thingManager.thingClasses.getThingClass(thing.thingClassId) iconName: "../images/event.svg" text: Qt.formatDateTime(model.timestamp,"dd.MM.yy - hh:mm:ss") - subText: deviceClass.eventTypes.getEventType(model.typeId).displayName + (model.value.length > 0 ? (": " + model.value.trim()) : "") + subText: thingClass.eventTypes.getEventType(model.typeId).displayName + (model.value.length > 0 ? (": " + model.value.trim()) : "") prominentSubText: true progressive: false contextOptions: [ diff --git a/nymea-app/ui/delegates/BrowserItemDelegate.qml b/nymea-app/ui/delegates/BrowserItemDelegate.qml index 4f81dc31..aa4a3885 100644 --- a/nymea-app/ui/delegates/BrowserItemDelegate.qml +++ b/nymea-app/ui/delegates/BrowserItemDelegate.qml @@ -48,7 +48,8 @@ NymeaSwipeDelegate { secondaryIconName: model.actionTypeIds.length > 0 ? "../images/navigation-menu.svg" : "" secondaryIconClickable: true - property Device device: null + property Thing thing: null + property alias device: root.thing onPressAndHold: openContextMenu() onSecondaryIconClicked: openContextMenu() @@ -63,7 +64,7 @@ NymeaSwipeDelegate { var actionDialogComponent = Qt.createComponent(Qt.resolvedUrl("../components/BrowserContextMenu.qml")); var popup = actionDialogComponent.createObject(app, { - device: root.device, + thing: root.thing, title: model.displayName, itemId: model.id, actionTypeIds: model.actionTypeIds diff --git a/nymea-app/ui/delegates/InterfaceTile.qml b/nymea-app/ui/delegates/InterfaceTile.qml index 8c66eea4..adcf9b15 100644 --- a/nymea-app/ui/delegates/InterfaceTile.qml +++ b/nymea-app/ui/delegates/InterfaceTile.qml @@ -47,26 +47,26 @@ MainPageTile { updateStatus: thingsSubProxyUpdates.count > 0 property Interface iface: null - property alias filterTagId: devicesProxy.filterTagId + property alias filterTagId: thingsProxy.filterTagId backgroundImage: inlineControlLoader.item && inlineControlLoader.item.hasOwnProperty("backgroundImage") ? inlineControlLoader.item.backgroundImage : "" onClicked: { var page; // Only one item? Go streight to the thing page - if (devicesProxy.count === 1) { + if (thingsProxy.count === 1) { if (!iface) { page = "GenericDevicePage.qml"; } else { page = NymeaUtils.interfaceListToDevicePage([iface.name]); } - pageStack.push(Qt.resolvedUrl("../devicepages/" + page), {thing: devicesProxy.get(0)}) + pageStack.push(Qt.resolvedUrl("../devicepages/" + page), {thing: thingsProxy.get(0)}) return; } // No (supported by app) interfaces at all? Open generic list if (!iface) { - page = "GenericDeviceListPage.qml" + page = "GenericThingsListPage.qml" pageStack.push(Qt.resolvedUrl("../devicelistpages/" + page), {hiddenInterfaces: app.supportedInterfaces, filterTagId: root.filterTagId}) return; } @@ -81,22 +81,22 @@ MainPageTile { page = "WeatherDeviceListPage.qml" break; case "light": - page = "LightsDeviceListPage.qml" + page = "LightThingsListPage.qml" break; case "smartmeter": page ="SmartMeterDeviceListPage.qml"; break; case "garagegate": // Deprecated, might not inherit garagedoor in old versions case "garagedoor": - page = "GarageThingListPage.qml"; + page = "GarageThingsListPage.qml"; break; case "awning": case "extendedAwning": - page = "AwningDeviceListPage.qml"; + page = "AwningThingsListPage.qml"; break; case "blind": case "extendedBlind": - page = "ShutterDeviceListPage.qml"; + page = "BlindThingsListPage.qml"; break; case "shutter": case "extendedShutter": @@ -109,46 +109,46 @@ MainPageTile { page = "MediaDeviceListPage.qml"; break; default: - page = "GenericDeviceListPage.qml" + page = "GenericThingsListPage.qml" } print("entering for shown interfaces:", iface.name) pageStack.push(Qt.resolvedUrl("../devicelistpages/" + page), {shownInterfaces: [iface.name], filterTagId: root.filterTagId}) } - DevicesProxy { - id: devicesProxy + ThingsProxy { + id: thingsProxy engine: _engine shownInterfaces: iface ? [iface.name] : [] hiddenInterfaces: iface ? [] : app.supportedInterfaces } - DevicesProxy { + ThingsProxy { id: devicesSubProxyConnectables engine: _engine - parentProxy: devicesProxy + parentProxy: thingsProxy filterDisconnected: true } - DevicesProxy { + ThingsProxy { id: devicesSubProxyBattery engine: _engine - parentProxy: devicesProxy + parentProxy: thingsProxy filterBatteryCritical: true } - DevicesProxy { + ThingsProxy { id: thingsSubProxySetupFailure engine: _engine - parentProxy: devicesProxy + parentProxy: thingsProxy filterSetupFailed: true } ThingsProxy { id: thingsSubProxyUpdates engine: _engine - parentProxy: devicesProxy + parentProxy: thingsProxy filterUpdates: true } property int currentDeviceIndex: 0 - readonly property Device currentDevice: devicesProxy.get(currentDeviceIndex) + readonly property Thing currentDevice: thingsProxy.get(currentDeviceIndex) contentItem: Loader { id: inlineControlLoader @@ -200,7 +200,7 @@ MainPageTile { onClicked: { switch (iface.name) { case "light": - var group = engine.thingManager.createGroup(Interfaces.findByName("colorlight"), devicesProxy); + var group = engine.thingManager.createGroup(Interfaces.findByName("colorlight"), thingsProxy); print("opening lights page for group", group) pageStack.push("../devicepages/LightDevicePage.qml", {thing: group}) } @@ -216,15 +216,15 @@ MainPageTile { property string backgroundImage: artworkState ? artworkState.value : "" property int currentDeviceIndex: 0 - readonly property Device currentDevice: devicesProxy.get(currentDeviceIndex) + readonly property Thing currentDevice: thingsProxy.get(currentDeviceIndex) readonly property StateType playbackStateType: currentDevice.deviceClass.stateTypes.findByName("playbackStatus") readonly property State playbackState: currentDevice.states.getState(playbackStateType.id) readonly property StateType artworkStateType: currentDevice.deviceClass.stateTypes.findByName("artwork") readonly property State artworkState: artworkStateType ? currentDevice.states.getState(artworkStateType.id) : null Component.onCompleted: { - for (var i = 0; i < devicesProxy.count; i++) { - var d = devicesProxy.get(i); + for (var i = 0; i < thingsProxy.count; i++) { + var d = thingsProxy.get(i); var st = d.deviceClass.stateTypes.findByName("playbackStatus") var s = d.states.getState(st.id) s.valueChanged.connect(function() {inlineMediaControl.updateTile()}) @@ -235,8 +235,8 @@ MainPageTile { function updateTile() { var playingIndex = -1; var pausedIndex = -1; - for (var i = 0; i < devicesProxy.count; i++) { - var d = devicesProxy.get(i); + for (var i = 0; i < thingsProxy.count; i++) { + var d = thingsProxy.get(i); var st = d.deviceClass.stateTypes.findByName("playbackStatus"); if (!st) continue; var s = d.states.getState(st.id); @@ -275,17 +275,15 @@ MainPageTile { text: { switch (iface.name) { case "media": - return devicesProxy.get(0).name; + return thingsProxy.get(0).name; case "light": case "irrigation": case "ventilation": case "powersocket": var count = 0; - for (var i = 0; i < devicesProxy.count; i++) { - var device = devicesProxy.get(i); - var deviceClass = engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId); - var stateType = deviceClass.stateTypes.findByName("power") - if (device.states.getState(stateType.id).value === true) { + for (var i = 0; i < thingsProxy.count; i++) { + var thing = thingsProxy.get(i); + if (thing.stateByName("power").value === true) { count++; } } @@ -298,7 +296,7 @@ MainPageTile { case "shutter": case "extendedshutter": return "" - // return qsTr("%1 installed").arg(devicesProxy.count) + // return qsTr("%1 installed").arg(thingsProxy.count) } console.warn("InterfaceTile, inlineButtonControl: Unhandled interface", model.name) } @@ -318,7 +316,7 @@ MainPageTile { case "ventilation": return "" case "garagedoor": - var dev = devicesProxy.get(0) + var dev = thingsProxy.get(0) if (dev.thingClass.interfaces.indexOf("simplegaragedoor") >= 0 || dev.thingClass.interfaces.indexOf("statefulgaragedoor") >= 0 || dev.thingClass.interfaces.indexOf("extendedstatefulgaragedoor") >= 0 @@ -347,15 +345,15 @@ MainPageTile { case "ventilation": break; case "garagedoor": - for (var i = 0; i < devicesProxy.count; i++) { - var thing = devicesProxy.get(i); + for (var i = 0; i < thingsProxy.count; i++) { + var thing = thingsProxy.get(i); if (thing.thingClass.interfaces.indexOf("simplegaragedoor") >= 0 || thing.thingClass.interfaces.indexOf("statefulgaragedoor") >= 0 || thing.thingClass.interfaces.indexOf("extendedstatefulgaragedoor") >= 0 || thing.thingClass.interfaces.indexOf("garagegate") >= 0) { var actionType = thing.thingClass.actionTypes.findByName("open"); - engine.deviceManager.executeAction(thing.id, actionType.id) + engine.thingManager.executeAction(thing.id, actionType.id) } } break; @@ -366,11 +364,10 @@ MainPageTile { case "awning": case "extendedawning": case "simpleclosable": - for (var i = 0; i < devicesProxy.count; i++) { - var device = devicesProxy.get(i); - var deviceClass = engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId); - var actionType = deviceClass.actionTypes.findByName("open"); - engine.deviceManager.executeAction(device.id, actionType.id) + for (var i = 0; i < thingsProxy.count; i++) { + var thing = thingsProxy.get(i); + var actionType = thing.thingClass.actionTypes.findByName("open"); + engine.thingManager.executeAction(device.id, actionType.id) } break; default: @@ -393,7 +390,7 @@ MainPageTile { case "ventilation": return "" case "garagedoor": - var dev = devicesProxy.get(0) + var dev = thingsProxy.get(0) if (dev.thingClass.interfaces.indexOf("simplegaragedoor") >= 0 || dev.thingClass.interfaces.indexOf("statefulgaragedoor") >= 0 || dev.thingClass.interfaces.indexOf("extendedstatefulgaragedoor") >= 0 @@ -422,8 +419,8 @@ MainPageTile { case "ventilation": break; case "garagedoor": - for (var i = 0; i < devicesProxy.count; i++) { - var thing = devicesProxy.get(i); + for (var i = 0; i < thingsProxy.count; i++) { + var thing = thingsProxy.get(i); if (thing.thingClass.interfaces.indexOf("simplegaragedoor") >= 0 || thing.thingClass.interfaces.indexOf("statefulgaragedoor") >= 0 || thing.thingClass.interfaces.indexOf("extendedstatefulgaragedoor") >= 0 @@ -441,11 +438,10 @@ MainPageTile { case "awning": case "extendedawning": case "simpleclosable": - for (var i = 0; i < devicesProxy.count; i++) { - var device = devicesProxy.get(i); - var deviceClass = engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId); - var actionType = deviceClass.actionTypes.findByName("stop"); - engine.deviceManager.executeAction(device.id, actionType.id) + for (var i = 0; i < thingsProxy.count; i++) { + var thing = thingsProxy.get(i); + var actionType = thing.thingClass.actionTypes.findByName("stop"); + engine.thingManager.executeAction(device.id, actionType.id) } break; default: @@ -461,9 +457,8 @@ MainPageTile { imageSource: { switch (iface.name) { case "media": - var device = devicesProxy.get(0) - var deviceClass = engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId); - var stateType = deviceClass.stateTypes.findByName("playbackStatus"); + var thing = thingsProxy.get(0) + var stateType = thing.thingClass.stateTypes.findByName("playbackStatus"); var state = device.states.getState(stateType.id) return state.value === "Playing" ? "../images/media-playback-pause.svg" : state.value === "Paused" ? "../images/media-playback-start.svg" : @@ -474,7 +469,7 @@ MainPageTile { case "ventilation": return "../images/system-shutdown.svg" case "garagedoor": - var dev = devicesProxy.get(0) + var dev = thingsProxy.get(0) if (dev.thingClass.interfaces.indexOf("simplegaragedoor") >= 0 || dev.thingClass.interfaces.indexOf("statefulgaragedoor") >= 0 || dev.thingClass.interfaces.indexOf("extendedstatefulgaragedoor") >= 0 @@ -504,32 +499,29 @@ MainPageTile { case "irrigation": case "ventilation": var allOff = true; - for (var i = 0; i < devicesProxy.count; i++) { - var device = devicesProxy.get(i); - if (device.states.getState(device.deviceClass.stateTypes.findByName("power").id).value === true) { + for (var i = 0; i < thingsProxy.count; i++) { + var thing = thingsProxy.get(i); + if (thing.stateByName("power").value === true) { allOff = false; break; } } - for (var i = 0; i < devicesProxy.count; i++) { - var device = devicesProxy.get(i); - var deviceClass = engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId); - var actionType = deviceClass.actionTypes.findByName("power"); + for (var i = 0; i < thingsProxy.count; i++) { + var thing = thingsProxy.get(i); + var actionType = thing.thingClass.actionTypes.findByName("power"); var params = []; var param1 = {}; param1["paramTypeId"] = actionType.paramTypes.get(0).id; param1["value"] = allOff ? true : false; params.push(param1) - engine.deviceManager.executeAction(device.id, actionType.id, params) + engine.thingManager.executeAction(thing.id, actionType.id, params) } break; case "media": - var device = devicesProxy.get(0) - var deviceClass = engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId); - var stateType = deviceClass.stateTypes.findByName("playbackStatus"); - var state = device.states.getState(stateType.id) + var thing = thingsProxy.get(0) + var state = thing.stateByName("playbackStatus") var actionName switch (state.value) { @@ -540,25 +532,25 @@ MainPageTile { actionName = "play"; break; } - var actionTypeId = deviceClass.actionTypes.findByName(actionName).id; + var actionTypeId = thing.thingClass.actionTypes.findByName(actionName).id; - print("executing", device, device.id, actionTypeId, actionName, deviceClass.actionTypes) + print("executing", thing, thing.id, actionTypeId, actionName, thing.thingClass.actionTypes) - engine.deviceManager.executeAction(device.id, actionTypeId) + engine.thingManager.executeAction(thing.id, actionTypeId) case "garagedoor": - for (var i = 0; i < devicesProxy.count; i++) { - var thing = devicesProxy.get(i); + for (var i = 0; i < thingsProxy.count; i++) { + var thing = thingsProxy.get(i); if (thing.thingClass.interfaces.indexOf("simplegaragedoor") >= 0 || thing.thingClass.interfaces.indexOf("statefulgaragedoor") >= 0 || thing.thingClass.interfaces.indexOf("extendedstatefulgaragedoor") >= 0 || thing.thingClass.interfaces.indexOf("garagegate") >= 0) { var actionType = thing.thingClass.actionTypes.findByName("close"); - engine.deviceManager.executeAction(thing.id, actionType.id) + engine.thingManager.executeAction(thing.id, actionType.id) } if (thing.thingClass.interfaces.indexOf("impulsegaragedoor") >= 0) { var actionType = thing.thingClass.actionTypes.findByName("triggerImpulse"); - engine.deviceManager.executeAction(thing.id, actionType.id) + engine.thingManager.executeAction(thing.id, actionType.id) } } break; @@ -569,11 +561,10 @@ MainPageTile { case "awning": case "extendedawning": case "simpleclosable": - for (var i = 0; i < devicesProxy.count; i++) { - var device = devicesProxy.get(i); - var deviceClass = engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId); - var actionType = deviceClass.actionTypes.findByName("close"); - engine.deviceManager.executeAction(device.id, actionType.id) + for (var i = 0; i < thingsProxy.count; i++) { + var thing = thingsProxy.get(i); + var actionType = thing.thingClass.actionTypes.findByName("close"); + engine.thingManager.executeAction(thing.id, actionType.id) } default: @@ -591,11 +582,10 @@ MainPageTile { ColumnLayout { spacing: 0 - property var device: devicesProxy.get(0) - property var deviceClass: device ? engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId) : null + property Thing thing: thingsProxy.get(0) Label { - text: parent.device.name + text: parent.thing.name font.pixelSize: app.smallFont Layout.fillWidth: true elide: Text.ElideRight @@ -609,10 +599,9 @@ MainPageTile { id: sensorsRoot property int currentDevice: 0 - property Device device: devicesProxy.get(currentDevice) - property DeviceClass deviceClass: device ? device.deviceClass : null + property Thing thing: thingsProxy.get(currentDevice) - property var shownSensors: findSensors(deviceClass) + property var shownSensors: findSensors(thing.thingClass) property int currentSensor: 0 ListModel { @@ -636,10 +625,10 @@ MainPageTile { ListElement { ifaceName: "heating"; stateName: "power" } ListElement { ifaceName: "extendedHeating"; stateName: "percentage" } } - function findSensors(deviceClass) { + function findSensors(thingClass) { var ret = [] for (var i = 0; i < supportedSensors.count; i++) { - if (deviceClass.interfaces.indexOf(supportedSensors.get(i).ifaceName) >= 0) { + if (thingClass.interfaces.indexOf(supportedSensors.get(i).ifaceName) >= 0) { ret.push({ifaceName: supportedSensors.get(i).ifaceName, stateName: supportedSensors.get(i).stateName}) } } @@ -647,13 +636,13 @@ MainPageTile { } property StateType shownStateType: shownSensors.length > currentSensor && currentSensor >= 0 - ? deviceClass.stateTypes.findByName(shownSensors[currentSensor].stateName) + ? thing.thingClass.stateTypes.findByName(shownSensors[currentSensor].stateName) : null function nextSensor() { var newSensorIndex = sensorsRoot.currentSensor + 1; if (newSensorIndex > sensorsRoot.shownSensors.length - 1) { - var newDeviceIndex = (sensorsRoot.currentDevice + 1) % devicesProxy.count; + var newDeviceIndex = (sensorsRoot.currentDevice + 1) % thingsProxy.count; newSensorIndex = 0; sensorsRoot.currentDevice = newDeviceIndex; } @@ -675,7 +664,7 @@ MainPageTile { id: timer interval: 10000 repeat: true - running: sensorsRoot.shownSensors.length > 1 || devicesProxy.count > 1 + running: sensorsRoot.shownSensors.length > 1 || thingsProxy.count > 1 onTriggered: nextSensorAnimation.start() } @@ -693,7 +682,7 @@ MainPageTile { ColumnLayout { Label { - text: sensorsRoot.device.name + text: sensorsRoot.thing.name font.pixelSize: app.smallFont Layout.fillWidth: true elide: Text.ElideRight @@ -701,7 +690,7 @@ MainPageTile { Label { text: sensorsRoot.shownStateType - ? (Math.round(Types.toUiValue(sensorsRoot.device.states.getState(sensorsRoot.shownStateType.id).value, sensorsRoot.shownStateType.unit) * 100) / 100) + " " + Types.toUiUnit(sensorsRoot.shownStateType.unit) + ? (Math.round(Types.toUiValue(sensorsRoot.thing.states.getState(sensorsRoot.shownStateType.id).value, sensorsRoot.shownStateType.unit) * 100) / 100) + " " + Types.toUiUnit(sensorsRoot.shownStateType.unit) : "" font.pixelSize: app.smallFont Layout.fillWidth: true @@ -711,7 +700,7 @@ MainPageTile { Led { Layout.preferredHeight: app.iconSize * .5 Layout.preferredWidth: height - state: visible && sensorsRoot.device.states.getState(sensorsRoot.shownStateType.id).value === true ? "on" : "off" + state: visible && sensorsRoot.thing.states.getState(sensorsRoot.shownStateType.id).value === true ? "on" : "off" visible: sensorsRoot.shownStateType && sensorsRoot.shownStateType.type.toLowerCase() === "bool" } } diff --git a/nymea-app/ui/delegates/ThingDelegate.qml b/nymea-app/ui/delegates/ThingDelegate.qml index 5ab29fca..e8272ba1 100644 --- a/nymea-app/ui/delegates/ThingDelegate.qml +++ b/nymea-app/ui/delegates/ThingDelegate.qml @@ -70,8 +70,8 @@ NymeaSwipeDelegate { return Style.iconColor } - property Device device: null - property Thing thing: device + property Thing thing: null + property alias device: root.thing readonly property bool hasBatteryInterface: thing && thing.thingClass.interfaces.indexOf("battery") >= 0 readonly property StateType batteryCriticalStateType: hasBatteryInterface ? thing.thingClass.stateTypes.findByName("batteryCritical") : null diff --git a/nymea-app/ui/delegates/ThingTile.qml b/nymea-app/ui/delegates/ThingTile.qml index 9fe34506..6e22fcc9 100644 --- a/nymea-app/ui/delegates/ThingTile.qml +++ b/nymea-app/ui/delegates/ThingTile.qml @@ -37,32 +37,32 @@ import "../components" MainPageTile { id: root - text: device.name.toUpperCase() - iconName: app.interfacesToIcon(deviceClass.interfaces) + text: thing.name.toUpperCase() + iconName: app.interfacesToIcon(thing.thingClass.interfaces) iconColor: Style.accentColor - isWireless: deviceClass.interfaces.indexOf("wirelessconnectable") >= 0 + isWireless: thing.thingClass.interfaces.indexOf("wirelessconnectable") >= 0 batteryCritical: batteryCriticalState && batteryCriticalState.value === true disconnected: connectedState && connectedState.value === false signalStrength: signalStrengthState ? signalStrengthState.value : -1 - setupStatus: device.setupStatus + setupStatus: thing.setupStatus updateStatus: updateStatusState && updateStatusState.value !== "idle" backgroundImage: artworkState && artworkState.value.length > 0 ? artworkState.value : "" - property Device device: null - readonly property DeviceClass deviceClass: device ? engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId) : null - readonly property State connectedState: deviceClass.interfaces.indexOf("connectable") >= 0 ? device.states.getState(deviceClass.stateTypes.findByName("connected").id) : null - readonly property State signalStrengthState: device.stateByName("signalStrength") - readonly property State batteryCriticalState: deviceClass.interfaces.indexOf("battery") >= 0 ? device.states.getState(deviceClass.stateTypes.findByName("batteryCritical").id) : null - readonly property State artworkState: deviceClass.interfaces.indexOf("mediametadataprovider") >= 0 ? device.states.getState(deviceClass.stateTypes.findByName("artwork").id) : null - readonly property State updateStatusState: device.stateByName("updateStatus") + property Thing thing: null + property alias device: root.thing + readonly property State connectedState: thing.stateByName("connected") + readonly property State signalStrengthState: thing.stateByName("signalStrength") + readonly property State batteryCriticalState: thing.stateByName("batteryCritical") + readonly property State artworkState: thing.stateByName("artwork") + readonly property State updateStatusState: thing.stateByName("updateStatus") contentItem: Loader { id: loader anchors.fill: parent sourceComponent: { - for (var i = 0; i < root.deviceClass.interfaces.length; i++) { - switch (root.deviceClass.interfaces[i]) { + for (var i = 0; i < root.thing.thingClass.interfaces.length; i++) { + switch (root.thing.thingClass.interfaces[i]) { case "closable": return closableComponent; case "mediacontroller": @@ -78,40 +78,33 @@ MainPageTile { } } } - Binding { target: loader.item ? loader.item : null; property: "deviceClass"; value: root.deviceClass } - Binding { target: loader.item ? loader.item : null; property: "device"; value: root.device } + Binding { target: loader.item ? loader.item : null; property: "thing"; value: root.thing } } Component { id: lightsComponent RowLayout { - property var device: null - property var deviceClass: null - - readonly property var powerStateType: deviceClass.stateTypes.findByName("power"); - readonly property var powerState: device.states.getState(powerStateType.id) - - readonly property var brightnessStateType: deviceClass.stateTypes.findByName("brightness"); - readonly property var brightnessState: brightnessStateType ? device.states.getState(brightnessStateType.id) : null + property Thing thing: null + readonly property State powerState: thing.stateByName("power") + readonly property State brightnessState: thing.stateByName("brightness") ThrottledSlider { Layout.fillWidth: true Layout.leftMargin: app.margins / 2 Layout.alignment: Qt.AlignVCenter - opacity: deviceClass.interfaces.indexOf("dimmablelight") >= 0 ? 1 : 0 + opacity: thing.thingClass.interfaces.indexOf("dimmablelight") >= 0 ? 1 : 0 enabled: opacity > 0 from: 0 to: 100 value: brightnessState ? brightnessState.value : 0 onMoved: { - var deviceClass = engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId); - var actionType = deviceClass.actionTypes.findByName("brightness"); + var actionType = thing.thingClass.actionTypes.findByName("brightness"); var params = []; var powerParam = {} powerParam["paramTypeId"] = actionType.paramTypes.get(0).id; powerParam["value"] = value; params.push(powerParam) - engine.deviceManager.executeAction(device.id, actionType.id, params); + engine.thingManager.executeAction(thing.id, actionType.id, params); } } @@ -123,20 +116,19 @@ MainPageTile { padding: 0; topPadding: 0; bottomPadding: 0 contentItem: ColorIcon { - name: deviceClass.interfaces.indexOf("light") >= 0 + name: thing.thingClass.interfaces.indexOf("light") >= 0 ? (powerState.value === true ? "../images/light-on.svg" : "../images/light-off.svg") - : app.interfacesToIcon(deviceClass.interfaces) + : app.interfacesToIcon(thing.thingClass.interfaces) color: powerState.value === true ? Style.accentColor : Style.iconColor } onClicked: { - var deviceClass = engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId); - var actionType = deviceClass.actionTypes.findByName("power"); + var actionType = thing.thingClass.actionTypes.findByName("power"); var params = []; var powerParam = {} powerParam["paramTypeId"] = actionType.paramTypes.get(0).id; powerParam["value"] = !powerState.value; params.push(powerParam) - engine.deviceManager.executeAction(device.id, actionType.id, params); + engine.thingManager.executeAction(thing.id, actionType.id, params); } } } @@ -146,59 +138,58 @@ MainPageTile { id: sensorsComponent RowLayout { id: sensorsRoot - property var device: null - property var deviceClass: null + property Thing thing: null spacing: 0 property var shownInterfaces: [] property int currentStateIndex: -1 - property var currentStateType: deviceClass ? deviceClass.stateTypes.findByName(shownInterfaces[currentStateIndex].state) : null - property var currentState: currentStateType ? device.states.getState(currentStateType.id) : null + property StateType currentStateType: thing ? thing.thingClass.stateTypes.findByName(shownInterfaces[currentStateIndex].state) : null + property State currentState: currentStateType ? thing.states.getState(currentStateType.id) : null - onDeviceClassChanged: { - if (deviceClass == null) { + onThingChanged: { + if (thing == null) { return; } var tmp = [] - if (deviceClass.interfaces.indexOf("temperaturesensor") >= 0) { + if (thing.thingClass.interfaces.indexOf("temperaturesensor") >= 0) { tmp.push({iface: "temperaturesensor", state: "temperature"}); } - if (deviceClass.interfaces.indexOf("humiditysensor") >= 0) { + if (thing.thingClass.interfaces.indexOf("humiditysensor") >= 0) { tmp.push({iface: "humiditysensor", state: "humidity"}); } - if (deviceClass.interfaces.indexOf("moisturesensor") >= 0) { + if (thing.thingClass.interfaces.indexOf("moisturesensor") >= 0) { tmp.push({iface: "moisturesensor", state: "moisture"}); } - if (deviceClass.interfaces.indexOf("pressuresensor") >= 0) { + if (thing.thingClass.interfaces.indexOf("pressuresensor") >= 0) { tmp.push({iface: "pressuresensor", state: "pressure"}); } - if (deviceClass.interfaces.indexOf("lightsensor") >= 0) { + if (thing.thingClass.interfaces.indexOf("lightsensor") >= 0) { tmp.push({iface: "lightsensor", state: "lightIntensity"}); } - if (deviceClass.interfaces.indexOf("conductivitysensor") >= 0) { + if (thing.thingClass.interfaces.indexOf("conductivitysensor") >= 0) { tmp.push({iface: "conductivitysensor", state: "conductivity"}); } - if (deviceClass.interfaces.indexOf("noisesensor") >= 0) { + if (thing.thingClass.interfaces.indexOf("noisesensor") >= 0) { tmp.push({iface: "noisesensor", state: "noise"}); } - if (deviceClass.interfaces.indexOf("co2sensor") >= 0) { + if (thing.thingClass.interfaces.indexOf("co2sensor") >= 0) { tmp.push({iface: "co2sensor", state: "co2"}); } - if (deviceClass.interfaces.indexOf("smartmeterconsumer") >= 0) { + if (thing.thingClass.interfaces.indexOf("smartmeterconsumer") >= 0) { tmp.push({iface: "smartmeterconsumer", state: "totalEnergyConsumed"}); } - if (deviceClass.interfaces.indexOf("smartmeterproducer") >= 0) { + if (thing.thingClass.interfaces.indexOf("smartmeterproducer") >= 0) { tmp.push({iface: "smartmeterproducer", state: "totalEnergyProduced"}); } - if (deviceClass.interfaces.indexOf("daylightsensor") >= 0) { + if (thing.thingClass.interfaces.indexOf("daylightsensor") >= 0) { tmp.push({iface: "daylightsensor", state: "daylight"}); } - if (deviceClass.interfaces.indexOf("presencesensor") >= 0) { + if (thing.thingClass.interfaces.indexOf("presencesensor") >= 0) { tmp.push({iface: "presencesensor", state: "isPresent"}); } - if (deviceClass.interfaces.indexOf("weather") >= 0) { + if (thing.thingClass.interfaces.indexOf("weather") >= 0) { tmp.push({iface: "temperaturesensor", state: "temperature"}); tmp.push({iface: "humiditysensor", state: "humidity"}); tmp.push({iface: "pressuresensor", state: "pressure"}); @@ -271,18 +262,11 @@ MainPageTile { Component { id: closableComponent - - ShutterControls { - - } + ShutterControls {} } Component { id: mediaComponent - - MediaControls { - property Device device: null - thing: device - } + MediaControls {} } } diff --git a/nymea-app/ui/devicelistpages/AwningDeviceListPage.qml b/nymea-app/ui/devicelistpages/AwningThingsListPage.qml similarity index 98% rename from nymea-app/ui/devicelistpages/AwningDeviceListPage.qml rename to nymea-app/ui/devicelistpages/AwningThingsListPage.qml index 91c9ac4d..8dc50750 100644 --- a/nymea-app/ui/devicelistpages/AwningDeviceListPage.qml +++ b/nymea-app/ui/devicelistpages/AwningThingsListPage.qml @@ -30,7 +30,7 @@ import QtQuick 2.9 -ClosablesDeviceListPage { +ClosablesThingsListPage { title: qsTr("Awnings") iconBasename: "../images/awning/awning" invertControls: true diff --git a/nymea-app/ui/devicelistpages/BlindDeviceListPage.qml b/nymea-app/ui/devicelistpages/BlindThingsListPage.qml similarity index 98% rename from nymea-app/ui/devicelistpages/BlindDeviceListPage.qml rename to nymea-app/ui/devicelistpages/BlindThingsListPage.qml index 58f482cd..358d8d32 100644 --- a/nymea-app/ui/devicelistpages/BlindDeviceListPage.qml +++ b/nymea-app/ui/devicelistpages/BlindThingsListPage.qml @@ -30,7 +30,7 @@ import QtQuick 2.9 -ClosablesDeviceListPage { +ClosablesThingsListPage { title: qsTr("Blinds") iconBasename: "../images/shutter/shutter" } diff --git a/nymea-app/ui/devicelistpages/ClosablesDeviceListPage.qml b/nymea-app/ui/devicelistpages/ClosablesThingsListPage.qml similarity index 80% rename from nymea-app/ui/devicelistpages/ClosablesDeviceListPage.qml rename to nymea-app/ui/devicelistpages/ClosablesThingsListPage.qml index 7243ee8c..f04382d8 100644 --- a/nymea-app/ui/devicelistpages/ClosablesDeviceListPage.qml +++ b/nymea-app/ui/devicelistpages/ClosablesThingsListPage.qml @@ -36,7 +36,7 @@ import QtGraphicalEffects 1.0 import Nymea 1.0 import "../components" -DeviceListPageBase { +ThingsListPageBase { id: root property string iconBasename @@ -51,33 +51,30 @@ DeviceListPageBase { HeaderButton { imageSource: root.invertControls ? "../images/down.svg" : "../images/up.svg" onClicked: { - for (var i = 0; i < devicesProxy.count; i++) { - var device = devicesProxy.get(i); - var deviceClass = engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId); - var actionType = deviceClass.actionTypes.findByName("open"); - engine.deviceManager.executeAction(device.id, actionType.id) + for (var i = 0; i < thingProxy.count; i++) { + var thing = thingsProxy.get(i); + var actionType = thing.thingClass.actionTypes.findByName("open"); + engine.thingManager.executeAction(thing.id, actionType.id) } } } HeaderButton { imageSource: "../images/media-playback-stop.svg" onClicked: { - for (var i = 0; i < devicesProxy.count; i++) { - var device = devicesProxy.get(i); - var deviceClass = engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId); - var actionType = deviceClass.actionTypes.findByName("stop"); - engine.deviceManager.executeAction(device.id, actionType.id) + for (var i = 0; i < thingsProxy.count; i++) { + var thing = thingsProxy.get(i); + var actionType = thing.thingClass.actionTypes.findByName("stop"); + engine.thingManager.executeAction(thing.id, actionType.id) } } } HeaderButton { imageSource: root.invertControls ? "../images/up.svg" : "../images/down.svg" onClicked: { - for (var i = 0; i < devicesProxy.count; i++) { - var device = devicesProxy.get(i); - var deviceClass = engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId); - var actionType = deviceClass.actionTypes.findByName("close"); - engine.deviceManager.executeAction(device.id, actionType.id) + for (var i = 0; i < thingsProxy.count; i++) { + var thing = thingsProxy.get(i); + var actionType = thing.thingClass.actionTypes.findByName("close"); + engine.thingManager.executeAction(thing.id, actionType.id) } } } @@ -146,7 +143,7 @@ DeviceListPageBase { id: shutterControls Layout.fillWidth: false height: parent.height - device: itemDelegate.thing + thing: itemDelegate.thing invert: root.invertControls enabled: itemDelegate.isEnabled } diff --git a/nymea-app/ui/devicelistpages/GarageThingListPage.qml b/nymea-app/ui/devicelistpages/GarageThingsListPage.qml similarity index 98% rename from nymea-app/ui/devicelistpages/GarageThingListPage.qml rename to nymea-app/ui/devicelistpages/GarageThingsListPage.qml index 8c20ebbc..5b3431f5 100644 --- a/nymea-app/ui/devicelistpages/GarageThingListPage.qml +++ b/nymea-app/ui/devicelistpages/GarageThingsListPage.qml @@ -36,7 +36,7 @@ import QtGraphicalEffects 1.0 import Nymea 1.0 import "../components" -DeviceListPageBase { +ThingsListPageBase { id: root property string iconBasename: "../images/garage/garage" @@ -112,7 +112,7 @@ DeviceListPageBase { id: shutterControls Layout.fillWidth: false height: parent.height - device: itemDelegate.thing + thing: itemDelegate.thing invert: root.invertControls visible: !itemDelegate.isImpulseBased enabled: itemDelegate.isEnabled diff --git a/nymea-app/ui/devicelistpages/GenericDeviceListPage.qml b/nymea-app/ui/devicelistpages/GenericThingsListPage.qml similarity index 99% rename from nymea-app/ui/devicelistpages/GenericDeviceListPage.qml rename to nymea-app/ui/devicelistpages/GenericThingsListPage.qml index 9ebea896..fa980522 100644 --- a/nymea-app/ui/devicelistpages/GenericDeviceListPage.qml +++ b/nymea-app/ui/devicelistpages/GenericThingsListPage.qml @@ -35,7 +35,7 @@ import Nymea 1.0 import "../components" import "../delegates" -DeviceListPageBase { +ThingsListPageBase { id: root header: NymeaHeader { diff --git a/nymea-app/ui/devicelistpages/LightsDeviceListPage.qml b/nymea-app/ui/devicelistpages/LightThingsListPage.qml similarity index 95% rename from nymea-app/ui/devicelistpages/LightsDeviceListPage.qml rename to nymea-app/ui/devicelistpages/LightThingsListPage.qml index 55da90af..e1b88f11 100644 --- a/nymea-app/ui/devicelistpages/LightsDeviceListPage.qml +++ b/nymea-app/ui/devicelistpages/LightThingsListPage.qml @@ -37,7 +37,7 @@ import Nymea 1.0 import "../components" import "../utils" -DeviceListPageBase { +ThingsListPageBase { id: root header: NymeaHeader { @@ -48,25 +48,24 @@ DeviceListPageBase { imageSource: "../images/system-shutdown.svg" onClicked: { var allOff = true; - for (var i = 0; i < devicesProxy.count; i++) { - var device = devicesProxy.get(i); - if (device.states.getState(device.deviceClass.stateTypes.findByName("power").id).value === true) { + for (var i = 0; i < thingsProxy.count; i++) { + var thing = thingsProxy.get(i); + if (thing.stateByName("power").value === true) { allOff = false; break; } } - for (var i = 0; i < devicesProxy.count; i++) { - var device = devicesProxy.get(i); - var deviceClass = engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId); - var actionType = deviceClass.actionTypes.findByName("power"); + for (var i = 0; i < thingsProxy.count; i++) { + var thing = thingsProxy.get(i); + var actionType = thing.thingClass.actionTypes.findByName("power"); var params = []; var param1 = {}; param1["paramTypeId"] = actionType.paramTypes.get(0).id; param1["value"] = allOff ? true : false; params.push(param1) - engine.deviceManager.executeAction(device.id, actionType.id, params) + engine.thingManager.executeAction(thing.id, actionType.id, params) } } } @@ -179,7 +178,7 @@ DeviceListPageBase { param1["value"] = checked; params.push(param1) print("executing for thing:", itemDelegate.thing.id) - engine.deviceManager.executeAction(itemDelegate.thing.id, itemDelegate.powerState.stateTypeId, params) + engine.thingManager.executeAction(itemDelegate.thing.id, itemDelegate.powerState.stateTypeId, params) } indicator: Item { diff --git a/nymea-app/ui/devicelistpages/MediaDeviceListPage.qml b/nymea-app/ui/devicelistpages/MediaDeviceListPage.qml index 05c91def..1cdc9543 100644 --- a/nymea-app/ui/devicelistpages/MediaDeviceListPage.qml +++ b/nymea-app/ui/devicelistpages/MediaDeviceListPage.qml @@ -36,7 +36,7 @@ import Nymea 1.0 import QtGraphicalEffects 1.0 import "../components" -DeviceListPageBase { +ThingsListPageBase { id: root header: NymeaHeader { diff --git a/nymea-app/ui/devicelistpages/PowerSocketsDeviceListPage.qml b/nymea-app/ui/devicelistpages/PowerSocketsDeviceListPage.qml index f5f46367..15935407 100644 --- a/nymea-app/ui/devicelistpages/PowerSocketsDeviceListPage.qml +++ b/nymea-app/ui/devicelistpages/PowerSocketsDeviceListPage.qml @@ -36,7 +36,7 @@ import "../components" import "../delegates" import QtQuick.Controls.Material 2.1 -DeviceListPageBase { +ThingsListPageBase { id: root header: NymeaHeader { @@ -111,7 +111,7 @@ DeviceListPageBase { param1["paramTypeId"] = itemDelegate.powerState.stateTypeId; param1["value"] = checked; params.push(param1) - engine.deviceManager.executeAction(itemDelegate.thing.id, itemDelegate.powerState.stateTypeId, params) + engine.thingManager.executeAction(itemDelegate.thing.id, itemDelegate.powerState.stateTypeId, params) } } } diff --git a/nymea-app/ui/devicelistpages/SensorsDeviceListPage.qml b/nymea-app/ui/devicelistpages/SensorsDeviceListPage.qml index f6443a81..c00150b1 100644 --- a/nymea-app/ui/devicelistpages/SensorsDeviceListPage.qml +++ b/nymea-app/ui/devicelistpages/SensorsDeviceListPage.qml @@ -35,7 +35,7 @@ import QtQuick.Layouts 1.1 import Nymea 1.0 import "../components" -DeviceListPageBase { +ThingsListPageBase { id: root header: NymeaHeader { diff --git a/nymea-app/ui/devicelistpages/ShutterDeviceListPage.qml b/nymea-app/ui/devicelistpages/ShutterDeviceListPage.qml index de4b4c99..168c6cdb 100644 --- a/nymea-app/ui/devicelistpages/ShutterDeviceListPage.qml +++ b/nymea-app/ui/devicelistpages/ShutterDeviceListPage.qml @@ -30,7 +30,7 @@ import QtQuick 2.9 -ClosablesDeviceListPage { +ClosablesThingsListPage { title: qsTr("Shutters") iconBasename: "../images/shutter/shutter" } diff --git a/nymea-app/ui/devicelistpages/SmartMeterDeviceListPage.qml b/nymea-app/ui/devicelistpages/SmartMeterDeviceListPage.qml index cf0dcef3..0148a328 100644 --- a/nymea-app/ui/devicelistpages/SmartMeterDeviceListPage.qml +++ b/nymea-app/ui/devicelistpages/SmartMeterDeviceListPage.qml @@ -35,7 +35,7 @@ import QtQuick.Layouts 1.1 import Nymea 1.0 import "../components" -DeviceListPageBase { +ThingsListPageBase { id: root header: NymeaHeader { diff --git a/nymea-app/ui/devicelistpages/DeviceListPageBase.qml b/nymea-app/ui/devicelistpages/ThingsListPageBase.qml similarity index 94% rename from nymea-app/ui/devicelistpages/DeviceListPageBase.qml rename to nymea-app/ui/devicelistpages/ThingsListPageBase.qml index 05b51e27..d2c608b3 100644 --- a/nymea-app/ui/devicelistpages/DeviceListPageBase.qml +++ b/nymea-app/ui/devicelistpages/ThingsListPageBase.qml @@ -42,8 +42,7 @@ Page { property alias hiddenInterfaces: thingsProxyInternal.hiddenInterfaces property alias filterTagId: thingsProxyInternal.filterTagId - property var devicesProxy: thingsProxyInternal - property var thingsProxy: thingsProxyInternal + property ThingsProxy thingsProxy: thingsProxyInternal function enterPage(index) { var thing = thingsProxy.get(index); @@ -51,7 +50,7 @@ Page { pageStack.push(Qt.resolvedUrl("../devicepages/" + page), {thing: thingsProxy.get(index)}) } - DevicesProxy { + ThingsProxy { id: thingsProxyInternal engine: _engine } diff --git a/nymea-app/ui/devicelistpages/WeatherDeviceListPage.qml b/nymea-app/ui/devicelistpages/WeatherDeviceListPage.qml index 3594b9bd..8bf463a5 100644 --- a/nymea-app/ui/devicelistpages/WeatherDeviceListPage.qml +++ b/nymea-app/ui/devicelistpages/WeatherDeviceListPage.qml @@ -36,7 +36,7 @@ import Nymea 1.0 import "../components" import "../customviews" -DeviceListPageBase { +ThingsListPageBase { id: root header: NymeaHeader { diff --git a/nymea-app/ui/devicepages/AwningDevicePage.qml b/nymea-app/ui/devicepages/AwningThingPage.qml similarity index 87% rename from nymea-app/ui/devicepages/AwningDevicePage.qml rename to nymea-app/ui/devicepages/AwningThingPage.qml index a95f8596..518c2673 100644 --- a/nymea-app/ui/devicepages/AwningDevicePage.qml +++ b/nymea-app/ui/devicepages/AwningThingPage.qml @@ -36,13 +36,13 @@ import Nymea 1.0 import "../components" import "../customviews" -DevicePageBase { +ThingPageBase { id: root readonly property bool landscape: width > height - readonly property bool isExtended: deviceClass.interfaces.indexOf("extendedawning") >= 0 - readonly property var percentageState: isExtended ? device.states.getState(deviceClass.stateTypes.findByName("percentage").id) : 0 - readonly property var movingState: isExtended ? device.states.getState(deviceClass.stateTypes.findByName("moving").id) : 0 + readonly property bool isExtended: thing.thingClass.interfaces.indexOf("extendedawning") >= 0 + readonly property State percentageState: thing.stateByName("percentage") + readonly property State movingState: thing.stateByName("moving") GridLayout { anchors.fill: parent @@ -94,25 +94,24 @@ DevicePageBase { } print("should move", value) - var actionType = root.deviceClass.actionTypes.findByName("percentage"); + var actionType = root.thing.thingClass.actionTypes.findByName("percentage"); var params = []; var percentageParam = {} percentageParam["paramTypeId"] = actionType.paramTypes.findByName("percentage").id; percentageParam["value"] = value params.push(percentageParam); - engine.deviceManager.executeAction(root.device.id, actionType.id, params); + engine.thingManager.executeAction(root.thing.id, actionType.id, params); } } ShutterControls { id: shutterControls - device: root.device + thing: root.thing invert: true anchors.horizontalCenter: parent.horizontalCenter spacing: (parent.width - app.iconSize*2*children.length) / (children.length - 1) } } - } } } diff --git a/nymea-app/ui/devicepages/BarcodeScannerThingPage.qml b/nymea-app/ui/devicepages/BarcodeScannerThingPage.qml index 87c31d5d..12b8c6fb 100644 --- a/nymea-app/ui/devicepages/BarcodeScannerThingPage.qml +++ b/nymea-app/ui/devicepages/BarcodeScannerThingPage.qml @@ -35,7 +35,7 @@ import Nymea 1.0 import "../components" import "../customviews" -DevicePageBase { +ThingPageBase { id: root EmptyViewPlaceholder { @@ -99,7 +99,7 @@ DevicePageBase { LogsModelNg { id: logsModelNg engine: _engine - deviceId: root.thing.id + thingId: root.thing.id live: true typeIds: [root.thing.thingClass.eventTypes.findByName("codeScanned").id] } @@ -109,17 +109,17 @@ DevicePageBase { var typeId = logView.logsModel.get(index).typeId var rule = engine.ruleManager.createNewRule(); var eventDescriptor = rule.eventDescriptors.createNewEventDescriptor(); - eventDescriptor.deviceId = device.id; - var eventType = root.deviceClass.eventTypes.getEventType(typeId); + eventDescriptor.thingId = thing.id; + var eventType = root.thing.thingClass.eventTypes.getEventType(typeId); eventDescriptor.eventTypeId = eventType.id; - rule.name = root.device.name + " - " + eventType.displayName; + rule.name = root.thing.name + " - " + eventType.displayName; if (eventType.paramTypes.count === 1) { var paramType = eventType.paramTypes.get(0); eventDescriptor.paramDescriptors.setParamDescriptor(paramType.id, value, ParamDescriptor.ValueOperatorEquals); rule.eventDescriptors.addEventDescriptor(eventDescriptor); rule.name = rule.name + " - " + value } - var rulePage = pageStack.push(Qt.resolvedUrl("../magic/DeviceRulesPage.qml"), {device: root.device}); + var rulePage = pageStack.push(Qt.resolvedUrl("../magic/ThingRulesPage.qml"), {thing: root.thing}); rulePage.addRule(rule); } diff --git a/nymea-app/ui/devicepages/ButtonDevicePage.qml b/nymea-app/ui/devicepages/ButtonThingPage.qml similarity index 96% rename from nymea-app/ui/devicepages/ButtonDevicePage.qml rename to nymea-app/ui/devicepages/ButtonThingPage.qml index 1265bb64..4453ec84 100644 --- a/nymea-app/ui/devicepages/ButtonDevicePage.qml +++ b/nymea-app/ui/devicepages/ButtonThingPage.qml @@ -35,7 +35,7 @@ import Nymea 1.0 import "../components" import "../customviews" -DevicePageBase { +ThingPageBase { id: root EmptyViewPlaceholder { @@ -73,7 +73,7 @@ DevicePageBase { var typeId = logView.logsModel.get(index).typeId var rule = engine.ruleManager.createNewRule(); var eventDescriptor = rule.eventDescriptors.createNewEventDescriptor(); - eventDescriptor.deviceId = root.thing.id; + eventDescriptor.thingId = root.thing.id; var eventType = root.thing.thingClass.eventTypes.getEventType(typeId); eventDescriptor.eventTypeId = eventType.id; rule.name = root.thing.name + " - " + eventType.displayName; @@ -83,7 +83,7 @@ DevicePageBase { rule.eventDescriptors.addEventDescriptor(eventDescriptor); rule.name = rule.name + " - " + value } - var rulePage = pageStack.push(Qt.resolvedUrl("../magic/DeviceRulesPage.qml"), {device: root.thing}); + var rulePage = pageStack.push(Qt.resolvedUrl("../magic/ThingRulesPage.qml"), {thing: root.thing}); rulePage.addRule(rule); } } diff --git a/nymea-app/ui/devicepages/DeviceBrowserPage.qml b/nymea-app/ui/devicepages/DeviceBrowserPage.qml index ac39fa5d..e1f6c633 100644 --- a/nymea-app/ui/devicepages/DeviceBrowserPage.qml +++ b/nymea-app/ui/devicepages/DeviceBrowserPage.qml @@ -38,23 +38,24 @@ import "../delegates" Page { id: root header: NymeaHeader { - text: qsTr("Browse %1").arg(root.device.name) + text: qsTr("Browse %1").arg(root.thing.name) onBackPressed: pageStack.pop() } - property Device device: null + property Thing thing: null + property alias device: root.thing property string nodeId: "" Component.onCompleted: { - d.model = engine.deviceManager.browseDevice(root.device.id, root.nodeId); + d.model = engine.thingManager.browseThing(root.thing.id, root.nodeId); } function executeBrowserItem(itemId) { d.pendingItemId = itemId - d.pendingBrowserItemId = engine.deviceManager.executeBrowserItem(root.device.id, itemId) + d.pendingBrowserItemId = engine.thingManager.executeBrowserItem(root.thing.id, itemId) } function executeBrowserItemAction(itemId, actionTypeId, params) { d.pendingItemId = itemId - d.pendingBrowserItemId = engine.deviceManager.executeBrowserItemAction(root.device.id, itemId, actionTypeId, params) + d.pendingBrowserItemId = engine.thingManager.executeBrowserItemAction(root.thing.id, itemId, actionTypeId, params) } QtObject { @@ -65,23 +66,23 @@ Page { } Connections { - target: engine.deviceManager - onExecuteBrowserItemReply: actionExecuted(commandId, params) - onExecuteBrowserItemActionReply: actionExecuted(commandId, params) + target: engine.thingManager + onExecuteBrowserItemReply: actionExecuted(commandId, thingError, displayMessage) + onExecuteBrowserItemActionReply: actionExecuted(commandId, thingError, displayMessage) } - function actionExecuted(commandId, params) { + function actionExecuted(commandId, thingError, displayMessage) { if (commandId === d.pendingBrowserItemId) { d.pendingBrowserItemId = -1; d.pendingItemId = "" - if (params.thinggError !== "ThingErrorNoError") { - if (params.displayMessage.length > 0) { - header.showInfo(qsTr("Error: %1").arg(params.displayMessage), true) + if (thingError !== Thing.ThingErrorNoError) { + if (displayMessage.length > 0) { + header.showInfo(qsTr("Error: %1").arg(displayMessage), true) } else { - header.showInfo(qsTr("Error: %1").arg(params.thingError), true) + header.showInfo(qsTr("Error: %1").arg(thingError), true) } } } - engine.deviceManager.refreshBrowserItems(d.model) + engine.thingManager.refreshBrowserItems(d.model) } ListView { @@ -93,14 +94,14 @@ Page { delegate: BrowserItemDelegate { id: delegate busy: d.pendingItemId === model.id - device: root.device + thing: root.thing onClicked: { print("clicked:", model.id) if (model.executable) { root.executeBrowserItem(model.id) } else if (model.browsable) { - pageStack.push(Qt.resolvedUrl("DeviceBrowserPage.qml"), {device: root.device, nodeId: model.id}) + pageStack.push(Qt.resolvedUrl("DeviceBrowserPage.qml"), {thing: root.thing, nodeId: model.id}) } } diff --git a/nymea-app/ui/devicepages/DeviceLogPage.qml b/nymea-app/ui/devicepages/DeviceLogPage.qml index c1ae039d..161806f2 100644 --- a/nymea-app/ui/devicepages/DeviceLogPage.qml +++ b/nymea-app/ui/devicepages/DeviceLogPage.qml @@ -58,20 +58,20 @@ Page { LogsModelNg { id: logsModelNg engine: _engine - deviceId: root.thing.id + thingId: root.thing.id typeIds: root.filterTypeIds.length > 0 ? root.filterTypeIds : filterEnabled - ? [filterDeviceModel.getData(filterComboBox.currentIndex, DeviceModel.RoleId)] + ? [filterDeviceModel.getData(filterComboBox.currentIndex, ThingModel.RoleId)] : [] live: true property bool filterEnabled: false } - DeviceModel { + ThingModel { id: filterDeviceModel - device: root.thing + thing: root.thing } Pane { @@ -142,7 +142,7 @@ Page { } var source = Qt.resolvedUrl("../customviews/GenericTypeGraph.qml"); - setSource(source, {device: root.thing, stateType: stateType}) + setSource(source, {thing: root.thing, stateType: stateType}) } } diff --git a/nymea-app/ui/devicepages/DoorbellDevicePage.qml b/nymea-app/ui/devicepages/DoorbellDevicePage.qml index 0895af09..f55edc6e 100644 --- a/nymea-app/ui/devicepages/DoorbellDevicePage.qml +++ b/nymea-app/ui/devicepages/DoorbellDevicePage.qml @@ -35,10 +35,10 @@ import Nymea 1.0 import "../components" import "../customviews" -DevicePageBase { +ThingPageBase { id: root - readonly property EventType doorbellPressedType: deviceClass.eventTypes.findByName("doorbellPressed") + readonly property EventType doorbellPressedType: thing.thingClass.eventTypes.findByName("doorbellPressed") GridLayout { anchors.fill: parent @@ -71,7 +71,7 @@ DevicePageBase { } Connections { - target: root.device + target: root.thing onEventTriggered: { print("evenEmitted", params) if (eventTypeId == root.doorbellPressedType.id) { @@ -123,7 +123,7 @@ DevicePageBase { model: LogsModelNg { engine: _engine live: true - deviceId: root.device.id + thingId: root.thing.id typeIds: [root.doorbellPressedType.id] } delegate: NymeaSwipeDelegate { diff --git a/nymea-app/ui/devicepages/FingerprintReaderDevicePage.qml b/nymea-app/ui/devicepages/FingerprintReaderDevicePage.qml index 889d7a41..6909ded9 100644 --- a/nymea-app/ui/devicepages/FingerprintReaderDevicePage.qml +++ b/nymea-app/ui/devicepages/FingerprintReaderDevicePage.qml @@ -35,14 +35,13 @@ import Nymea 1.0 import "../components" import "../customviews" -DevicePageBase { +ThingPageBase { id: root - readonly property var usersStateType: deviceClass.stateTypes.findByName("users") - readonly property var usersState: device.states.getState(usersStateType.id) + readonly property State usersState: thing.stateByName("users") - readonly property var accessGrantedEventType: deviceClass.eventTypes.findByName("accessGranted") - readonly property var accessDeniedEventType: deviceClass.eventTypes.findByName("accessDenied") + readonly property EventType accessGrantedEventType: thing.thingClass.eventTypes.findByName("accessGranted") + readonly property EventType accessDeniedEventType: thing.thingClass.eventTypes.findByName("accessDenied") ColumnLayout { anchors.fill: parent @@ -70,7 +69,7 @@ DevicePageBase { logsModel: LogsModel { id: logsModel - thingId: root.device.id + thingId: root.thing.id engine: _engine live: true typeIds: [root.accessGrantedEventType.id, root.accessDeniedEventType.id]; @@ -136,13 +135,13 @@ DevicePageBase { } onDeleteClicked: { - var actionType = root.deviceClass.actionTypes.findByName("removeUser") + var actionType = root.thing.thingClass.actionTypes.findByName("removeUser") var params = [] var titleParam = {} titleParam["paramTypeId"] = actionType.paramTypes.findByName("userId").id titleParam["value"] = modelData params.push(titleParam) - engine.deviceManager.executeAction(root.device.id, actionType.id, params) + engine.thingManager.executeAction(root.thing.id, actionType.id, params) } } @@ -189,10 +188,9 @@ DevicePageBase { property bool error: false Connections { - target: engine.deviceManager + target: engine.thingManager onExecuteActionReply: { - print("Execute action reply:", JSON.stringify(params)); - addUserPage.error = params["deviceError"] !== "DeviceErrorNoError" + addUserPage.error = thingError !== Thing.ThingErrorNoError var masks =[] masks.push({x: 0, y: 0, width: 1, height: 1}); addUserPage.done = true @@ -250,7 +248,7 @@ DevicePageBase { text: qsTr("Add user") Layout.fillWidth: true onClicked: { - var actionType = root.deviceClass.actionTypes.findByName("addUser") + var actionType = root.thing.thingClass.actionTypes.findByName("addUser") var params = [] var titleParam = {} titleParam["paramTypeId"] = actionType.paramTypes.findByName("userId").id @@ -260,7 +258,7 @@ DevicePageBase { fingerParam["paramTypeId"] = actionType.paramTypes.findByName("finger").id fingerParam["value"] = fingerComboBox.model.get(fingerComboBox.currentIndex).enumValue params.push(fingerParam) - engine.deviceManager.executeAction(root.device.id, actionType.id, params) + engine.thingManager.executeAction(root.thing.id, actionType.id, params) addUserSwipeView.currentIndex++ } } diff --git a/nymea-app/ui/devicepages/GarageThingPage.qml b/nymea-app/ui/devicepages/GarageThingPage.qml index 5308b05d..2326123f 100644 --- a/nymea-app/ui/devicepages/GarageThingPage.qml +++ b/nymea-app/ui/devicepages/GarageThingPage.qml @@ -36,7 +36,7 @@ import Nymea 1.0 import "../components" import "../customviews" -DevicePageBase { +ThingPageBase { id: root GarageController { diff --git a/nymea-app/ui/devicepages/GenericDevicePage.qml b/nymea-app/ui/devicepages/GenericDevicePage.qml index 1cb59460..5e0ae0c6 100644 --- a/nymea-app/ui/devicepages/GenericDevicePage.qml +++ b/nymea-app/ui/devicepages/GenericDevicePage.qml @@ -36,7 +36,7 @@ import Nymea 1.0 import "../components" import "../delegates" -DevicePageBase { +ThingPageBase { id: root showDetailsButton: false @@ -56,58 +56,58 @@ DevicePageBase { section.delegate: ListSectionHeader { text: { switch (parseInt(section)) { - case DeviceModel.TypeStateType: + case ThingModel.TypeStateType: return qsTr("States") - case DeviceModel.TypeActionType: + case ThingModel.TypeActionType: return qsTr("Actions") - case DeviceModel.TypeEventType: + case ThingModel.TypeEventType: return qsTr("Events") } } } - model: DeviceModel { - device: root.device + model: ThingModel { + thing: root.thing } delegate: SwipeDelegate { id: delegate width: parent.width - readonly property StateType stateType: model.type === DeviceModel.TypeStateType ? root.deviceClass.stateTypes.getStateType(model.id) : null - readonly property ActionType actionType: model.writable ? root.deviceClass.actionTypes.getActionType(model.id) : null - readonly property EventType eventType: model.type === DeviceModel.TypeEventType ? root.deviceClass.eventTypes.getEventType(model.id) : null + readonly property StateType stateType: model.type === ThingModel.TypeStateType ? root.thing.thingClass.stateTypes.getStateType(model.id) : null + readonly property ActionType actionType: model.writable ? root.thing.thingClass.actionTypes.getActionType(model.id) : null + readonly property EventType eventType: model.type === ThingModel.TypeEventType ? root.thing.thingClass.eventTypes.getEventType(model.id) : null Layout.fillWidth: true - topPadding: model.type === DeviceModel.TypeActionType ? app.margins / 2 : 0 + topPadding: model.type === ThingModel.TypeActionType ? app.margins / 2 : 0 bottomPadding: 0 contentItem: Loader { id: inlineLoader sourceComponent: { switch (model.type) { - case DeviceModel.TypeStateType: + case ThingModel.TypeStateType: return stateComponent; - case DeviceModel.TypeActionType: + case ThingModel.TypeActionType: return actionComponent; - case DeviceModel.TypeEventType: + case ThingModel.TypeEventType: return eventComponent; } } Binding { target: inlineLoader.item - when: model.type === DeviceModel.TypeStateType + when: model.type === ThingModel.TypeStateType property: "stateType" value: delegate.stateType } Binding { target: inlineLoader.item - when: model.type === DeviceModel.TypeActionType + when: model.type === ThingModel.TypeActionType property: "actionType" value: delegate.actionType } Binding { target: inlineLoader.item - when: model.type === DeviceModel.TypeEventType + when: model.type === ThingModel.TypeEventType property: "eventType" value: delegate.eventType } @@ -128,7 +128,7 @@ DevicePageBase { } onClicked: { swipe.close(); - pageStack.push(Qt.resolvedUrl("DeviceLogPage.qml"), {device: root.device, filterTypeIds: [model.id]}) + pageStack.push(Qt.resolvedUrl("DeviceLogPage.qml"), {thing: root.thing, filterTypeIds: [model.id]}) } } } @@ -141,8 +141,8 @@ DevicePageBase { RowLayout { id: stateDelegate property StateType stateType: null - readonly property State deviceState: stateType ? root.device.states.getState(stateType.id) : null - readonly property bool writable: root.deviceClass.actionTypes.getActionType(stateType.id) !== null + readonly property State thingState: stateType ? root.thing.states.getState(stateType.id) : null + readonly property bool writable: root.thing.thingClass.actionTypes.getActionType(stateType.id) !== null Label { Layout.fillWidth: true @@ -167,7 +167,7 @@ DevicePageBase { return; } - var isWritable = root.deviceClass.actionTypes.getActionType(stateType.id) !== null; + var isWritable = root.thing.thingClass.actionTypes.getActionType(stateType.id) !== null; var sourceComp; switch (stateDelegate.stateType.type.toLowerCase()) { @@ -213,7 +213,7 @@ DevicePageBase { } if (!sourceComp) { sourceComp = "LabelDelegate.qml"; - print("GenericDevicePage: unhandled entry", stateDelegate.stateType.displayName) + print("GenericThingPage: unhandled entry", stateDelegate.stateType.displayName) } var minValue = stateDelegate.stateType.minValue !== undefined @@ -228,7 +228,7 @@ DevicePageBase { print("pushing delegate for", stateDelegate.stateType.name, "from:", minValue, "to:", maxValue) stateDelegateLoader.setSource("../delegates/statedelegates/" + sourceComp, { -// value: root.device.states.getState(stateType.id).value, +// value: root.thing.states.getState(stateType.id).value, possibleValues: stateDelegate.stateType.allowedValues, from: minValue, to: maxValue, @@ -265,7 +265,7 @@ DevicePageBase { Binding { target: stateDelegateLoader.item property: "value" - value: stateDelegate.deviceState.value + value: stateDelegate.thingState.value when: !stateDelegate.valueCacheDirty && stateDelegate.pendingActionId === -1 } Binding { @@ -281,7 +281,7 @@ DevicePageBase { } } Connections { - target: engine.deviceManager + target: engine.thingManager onExecuteActionReply: { if (stateDelegate.pendingActionId === commandId) { stateDelegate.pendingActionId = -1 @@ -306,11 +306,11 @@ DevicePageBase { property bool lastSuccess: false Connections { - target: engine.deviceManager + target: engine.thingManager onExecuteActionReply: { if (commandId === actionDelegate.pendingActionId) { pendingTimer.start(); - actionDelegate.lastSuccess = params["deviceError"] === "DeviceErrorNoError" + actionDelegate.lastSuccess = thingError === Thing.ThingErrorNoError actionDelegate.pendingActionId = -1 } } @@ -430,7 +430,7 @@ DevicePageBase { } } Connections { - target: root.device + target: root.thing onEventTriggered: { if (eventTypeId === eventComponentItem.eventType.id) { flashlightAnimation.start(); diff --git a/nymea-app/ui/devicepages/HeatingDevicePage.qml b/nymea-app/ui/devicepages/HeatingDevicePage.qml index 8fdca878..727087d0 100644 --- a/nymea-app/ui/devicepages/HeatingDevicePage.qml +++ b/nymea-app/ui/devicepages/HeatingDevicePage.qml @@ -35,12 +35,11 @@ import QtQuick.Controls.Material 2.1 import Nymea 1.0 import "../components" -DevicePageBase { +ThingPageBase { id: root - readonly property var powerStateType: deviceClass.stateTypes.findByName("power") - readonly property var powerState: device.states.getState(powerStateType.id) - readonly property var powerActionType: deviceClass.actionTypes.findByName("power"); + readonly property State powerState: thing.stateByName("power") + readonly property ActionType powerActionType: thing.thingClass.actionTypes.findByName("power"); GridLayout { anchors.fill: parent @@ -84,7 +83,7 @@ DevicePageBase { param["paramTypeId"] = root.powerActionType.paramTypes.get(0).id; param["value"] = !root.powerState.value; params.push(param) - engine.deviceManager.executeAction(root.device.id, root.powerStateType.id, params); + engine.thingManager.executeAction(root.thing.id, root.powerActionType.id, params); } } } diff --git a/nymea-app/ui/devicepages/InputTriggerDevicePage.qml b/nymea-app/ui/devicepages/InputTriggerDevicePage.qml index a07ee807..ec591239 100644 --- a/nymea-app/ui/devicepages/InputTriggerDevicePage.qml +++ b/nymea-app/ui/devicepages/InputTriggerDevicePage.qml @@ -35,7 +35,7 @@ import Nymea 1.0 import "../components" import "../customviews" -DevicePageBase { +ThingPageBase { id: root GenericTypeLogView { @@ -46,9 +46,9 @@ DevicePageBase { LogsModelNg { id: logsModelNg engine: _engine - deviceId: root.device.id + thingId: root.thing.id live: true - typeIds: [root.deviceClass.eventTypes.findByName("triggered").id]; + typeIds: [root.thing.thingClass.eventTypes.findByName("triggered").id]; } // delegate: NymeaSwipeDelegate { @@ -72,17 +72,17 @@ DevicePageBase { var typeId = logView.logsModel.get(index).typeId var rule = engine.ruleManager.createNewRule(); var eventDescriptor = rule.eventDescriptors.createNewEventDescriptor(); - eventDescriptor.deviceId = device.id; - var eventType = root.deviceClass.eventTypes.getEventType(typeId); + eventDescriptor.thingId = thing.id; + var eventType = root.thing.thingClass.eventTypes.getEventType(typeId); eventDescriptor.eventTypeId = eventType.id; - rule.name = root.device.name + " - " + eventType.displayName; + rule.name = root.thing.name + " - " + eventType.displayName; if (eventType.paramTypes.count === 1) { var paramType = eventType.paramTypes.get(0); eventDescriptor.paramDescriptors.setParamDescriptor(paramType.id, value, ParamDescriptor.ValueOperatorEquals); rule.eventDescriptors.addEventDescriptor(eventDescriptor); rule.name = rule.name + " - " + value } - var rulePage = pageStack.push(Qt.resolvedUrl("../magic/DeviceRulesPage.qml"), {device: root.device}); + var rulePage = pageStack.push(Qt.resolvedUrl("../magic/ThingRulesPage.qml"), {thing: root.thing}); rulePage.addRule(rule); } } diff --git a/nymea-app/ui/devicepages/IrrigationDevicePage.qml b/nymea-app/ui/devicepages/IrrigationDevicePage.qml index 842205ff..dfd46bae 100644 --- a/nymea-app/ui/devicepages/IrrigationDevicePage.qml +++ b/nymea-app/ui/devicepages/IrrigationDevicePage.qml @@ -35,7 +35,7 @@ import QtQuick.Controls.Material 2.1 import Nymea 1.0 import "../components" -DevicePageBase { +ThingPageBase { id: root readonly property var powerStateType: thing.thingClass.stateTypes.findByName("power") @@ -184,7 +184,7 @@ DevicePageBase { param["paramTypeId"] = root.powerActionType.paramTypes.get(0).id; param["value"] = !root.powerState.value; params.push(param) - engine.thingManager.executeAction(root.device.id, root.powerStateType.id, params); + engine.thingManager.executeAction(root.thing.id, root.powerStateType.id, params); PlatformHelper.vibrate(PlatformHelper.HapticsFeedbackSelection) } } diff --git a/nymea-app/ui/devicepages/LightDevicePage.qml b/nymea-app/ui/devicepages/LightDevicePage.qml index 6b0da711..3918a39a 100644 --- a/nymea-app/ui/devicepages/LightDevicePage.qml +++ b/nymea-app/ui/devicepages/LightDevicePage.qml @@ -36,24 +36,19 @@ import Nymea 1.0 import QtGraphicalEffects 1.0 import "../components" -DevicePageBase { +ThingPageBase { id: root - readonly property var powerStateType: deviceClass.stateTypes.findByName("power") - readonly property var powerState: device.states.getState(powerStateType.id) - readonly property var powerActionType: deviceClass.actionTypes.findByName("power"); + readonly property State powerState: thing.stateByName("power") - readonly property var brightnessStateType: deviceClass.stateTypes.findByName("brightness") - readonly property var brightnessState: brightnessStateType ? device.states.getState(brightnessStateType.id) : null - readonly property var brightnessActionType: deviceClass.actionTypes.findByName("brightness"); + readonly property State brightnessState: thing.stateByName("brightness") + readonly property ActionType brightnessActionType: thingClass.actionTypes.findByName("brightness"); - readonly property var colorStateType: deviceClass.stateTypes.findByName("color") - readonly property var colorState: colorStateType ? device.states.getState(colorStateType.id) : null - readonly property var colorActionType: deviceClass.actionTypes.findByName("color") + readonly property State colorState: thing.stateByName("color") - readonly property var ctStateType: deviceClass.stateTypes.findByName("colorTemperature") - readonly property var ctState: ctStateType ? device.states.getState(ctStateType.id) : null - readonly property var ctActionType: deviceClass.actionTypes.findByName("colorTemperature") + readonly property StateType ctStateType: thingClass.stateTypes.findByName("colorTemperature") + readonly property State ctState: thing.stateByName("colorTemperature") + readonly property ActionType ctActionType: thingClass.actionTypes.findByName("colorTemperature") readonly property int statesCount: (powerState !== null ? 1 : 0) + (brightnessState !== null ? 1 : 0) + diff --git a/nymea-app/ui/devicepages/MediaThingPage.qml b/nymea-app/ui/devicepages/MediaThingPage.qml index dc180e04..1cfa89a1 100644 --- a/nymea-app/ui/devicepages/MediaThingPage.qml +++ b/nymea-app/ui/devicepages/MediaThingPage.qml @@ -38,7 +38,7 @@ import "../components" import "../customviews" import "../delegates" -DevicePageBase { +ThingPageBase { id: root showBrowserButton: false diff --git a/nymea-app/ui/devicepages/NotificationsDevicePage.qml b/nymea-app/ui/devicepages/NotificationsDevicePage.qml index 9a6566a5..10055db3 100644 --- a/nymea-app/ui/devicepages/NotificationsDevicePage.qml +++ b/nymea-app/ui/devicepages/NotificationsDevicePage.qml @@ -35,7 +35,7 @@ import Nymea 1.0 import "../components" import "../customviews" -DevicePageBase { +ThingPageBase { id: root QtObject { @@ -54,7 +54,7 @@ DevicePageBase { function sendMessage(title, text) { print("sending message", title, text) - var actionType = root.deviceClass.actionTypes.findByName("notify") + var actionType = root.thing.thingClass.actionTypes.findByName("notify") var params = [] var titleParam = {} titleParam["paramTypeId"] = actionType.paramTypes.findByName("title").id @@ -64,7 +64,7 @@ DevicePageBase { bodyParam["paramTypeId"] = actionType.paramTypes.findByName("body").id bodyParam["value"] = text params.push(bodyParam) - d.pendingAction = engine.deviceManager.executeAction(root.device.id, actionType.id, params) + d.pendingAction = engine.thingManager.executeAction(root.thing.id, actionType.id, params) titleTextField.clear(); bodyTextField.clear(); } @@ -143,10 +143,10 @@ DevicePageBase { model: LogsModel { id: logsModel - thingId: root.device.id + thingId: root.thing.id engine: _engine live: true - typeIds: [root.deviceClass.actionTypes.findByName("notify").id]; + typeIds: [root.thing.thingClass.actionTypes.findByName("notify").id]; } delegate: BigTile { diff --git a/nymea-app/ui/devicepages/PowersocketDevicePage.qml b/nymea-app/ui/devicepages/PowersocketDevicePage.qml index 4ee72cea..17884549 100644 --- a/nymea-app/ui/devicepages/PowersocketDevicePage.qml +++ b/nymea-app/ui/devicepages/PowersocketDevicePage.qml @@ -35,12 +35,11 @@ import QtQuick.Controls.Material 2.1 import Nymea 1.0 import "../components" -DevicePageBase { +ThingPageBase { id: root - readonly property var powerStateType: deviceClass.stateTypes.findByName("power") - readonly property var powerState: device.states.getState(powerStateType.id) - readonly property var powerActionType: deviceClass.actionTypes.findByName("power"); + readonly property State powerState: thing.stateByName("power") + readonly property var powerActionType: thing.thingClass.actionTypes.findByName("power"); GridLayout { anchors.fill: parent @@ -84,7 +83,7 @@ DevicePageBase { param["paramTypeId"] = root.powerActionType.paramTypes.get(0).id; param["value"] = !root.powerState.value; params.push(param) - engine.deviceManager.executeAction(root.device.id, root.powerStateType.id, params); + engine.thingManager.executeAction(root.thing.id, root.powerActionType.id, params); } } } diff --git a/nymea-app/ui/devicepages/SensorDevicePage.qml b/nymea-app/ui/devicepages/SensorDevicePage.qml index 9987a04e..6e1bd1e2 100644 --- a/nymea-app/ui/devicepages/SensorDevicePage.qml +++ b/nymea-app/ui/devicepages/SensorDevicePage.qml @@ -35,7 +35,7 @@ import Nymea 1.0 import "../components" import "../customviews" -DevicePageBase { +ThingPageBase { id: root Flickable { @@ -58,7 +58,7 @@ DevicePageBase { Component.onCompleted: { var supportedInterfaces = ["temperaturesensor", "humiditysensor", "pressuresensor", "moisturesensor", "lightsensor", "conductivitysensor", "noisesensor", "co2sensor", "presencesensor", "daylightsensor", "closablesensor", "watersensor"] for (var i = 0; i < supportedInterfaces.length; i++) { - if (root.deviceClass.interfaces.indexOf(supportedInterfaces[i]) >= 0) { + if (root.thingClass.interfaces.indexOf(supportedInterfaces[i]) >= 0) { append({name: supportedInterfaces[i]}); } } @@ -70,7 +70,7 @@ DevicePageBase { Layout.fillWidth: true Layout.preferredHeight: item.implicitHeight - property StateType stateType: root.deviceClass.stateTypes.findByName(interfaceStateMap[modelData]) + property StateType stateType: root.thingClass.stateTypes.findByName(interfaceStateMap[modelData]) property State state: root.thing.stateByName(interfaceStateMap[modelData]) property string interfaceName: modelData @@ -103,7 +103,7 @@ DevicePageBase { GenericTypeGraph { id: graph - device: root.device + thing: root.thing color: app.interfaceToColor(interfaceName) iconSource: app.interfaceToIcon(interfaceName) implicitHeight: width * .6 @@ -151,7 +151,7 @@ DevicePageBase { name: { switch (boolView.interfaceName) { case "closablesensor": - return device.states.getState(boolView.stateType.id).value === true ? Qt.resolvedUrl("../images/lock-closed.svg") : Qt.resolvedUrl("../images/lock-open.svg") + return thing.states.getState(boolView.stateType.id).value === true ? Qt.resolvedUrl("../images/lock-closed.svg") : Qt.resolvedUrl("../images/lock-open.svg") default: return app.interfaceToIcon(boolView.interfaceName) } @@ -159,9 +159,9 @@ DevicePageBase { color: { switch (boolView.interfaceName) { case "closablesensor": - return device.states.getState(boolView.stateType.id).value === true ? "green" : "red" + return thing.states.getState(boolView.stateType.id).value === true ? "green" : "red" default: - device.states.getState(boolView.stateType.id).value === true ? app.interfaceToColor(boolView.interfaceName) : Style.iconColor + thing.states.getState(boolView.stateType.id).value === true ? app.interfaceToColor(boolView.interfaceName) : Style.iconColor } } } @@ -173,8 +173,8 @@ DevicePageBase { RowLayout { Layout.fillWidth: false Layout.alignment: Qt.AlignHCenter - property StateType lastSeenStateType: root.deviceClass.stateTypes.findByName("lastSeenTime") - property State lastSeenState: lastSeenStateType ? root.device.states.getState(lastSeenStateType.id) : null + property StateType lastSeenStateType: root.thingClass.stateTypes.findByName("lastSeenTime") + property State lastSeenState: lastSeenStateType ? root.thing.states.getState(lastSeenStateType.id) : null visible: lastSeenStateType !== null Label { text: qsTr("Last seen:") @@ -187,8 +187,8 @@ DevicePageBase { RowLayout { Layout.fillWidth: false Layout.alignment: Qt.AlignHCenter - property StateType sunriseStateType: root.deviceClass.stateTypes.findByName("sunriseTime") - property State sunriseState: sunriseStateType ? root.device.states.getState(sunriseStateType.id) : null + property StateType sunriseStateType: root.thingClass.stateTypes.findByName("sunriseTime") + property State sunriseState: sunriseStateType ? root.thing.states.getState(sunriseStateType.id) : null visible: sunriseStateType !== null Label { text: qsTr("Sunrise:") @@ -201,8 +201,8 @@ DevicePageBase { RowLayout { Layout.fillWidth: false Layout.alignment: Qt.AlignHCenter - property StateType sunsetStateType: root.deviceClass.stateTypes.findByName("sunsetTime") - property State sunsetState: sunsetStateType ? root.device.states.getState(sunsetStateType.id) : null + property StateType sunsetStateType: root.thingClass.stateTypes.findByName("sunsetTime") + property State sunsetState: sunsetStateType ? root.thing.states.getState(sunsetStateType.id) : null visible: sunsetStateType !== null Label { text: qsTr("Sunset:") diff --git a/nymea-app/ui/devicepages/ShutterDevicePage.qml b/nymea-app/ui/devicepages/ShutterDevicePage.qml index 7a2d0ba2..3379750b 100644 --- a/nymea-app/ui/devicepages/ShutterDevicePage.qml +++ b/nymea-app/ui/devicepages/ShutterDevicePage.qml @@ -37,19 +37,18 @@ import Nymea 1.0 import "../components" import "../customviews" -DevicePageBase { +ThingPageBase { id: root readonly property bool landscape: width > height * 1.5 - readonly property bool isExtended: deviceClass.interfaces.indexOf("extendedclosable") >= 0 - readonly property bool isVenetian: deviceClass.interfaces.indexOf("venetianblind") >= 0 + readonly property bool isExtended: thing.thingClass.interfaces.indexOf("extendedclosable") >= 0 + readonly property bool isVenetian: thing.thingClass.interfaces.indexOf("venetianblind") >= 0 - readonly property StateType movingStateType: isExtended ? deviceClass.stateTypes.findByName("moving") : null - readonly property StateType angleStateType: isVenetian ? deviceClass.stateTypes.findByName("angle") : null + readonly property StateType angleStateType: isVenetian ? thing.thingClass.stateTypes.findByName("angle") : null - readonly property State movingState: isExtended ? device.states.getState(movingStateType.id) : null - readonly property State percentageState: isExtended ? device.states.getState(deviceClass.stateTypes.findByName("percentage").id) : null - readonly property State angleState: isVenetian ? device.states.getState(angleStateType.id) : null + readonly property State movingState: thing.stateByName("moving") + readonly property State percentageState: thing.stateByName("percentage") + readonly property State angleState: isVenetian ? thing.states.getState(angleStateType.id) : null readonly property bool moving: movingState ? movingState.value === true : false @@ -82,7 +81,7 @@ DevicePageBase { ClosablesControlLarge { anchors { left: parent.left; top: parent.top; bottom: parent.bottom; } width: height - thing: root.device + thing: root.thing ClosableArrowAnimation { id: arrowAnimation @@ -256,13 +255,13 @@ DevicePageBase { angleMovable.angle = targetAngle - var actionType = root.deviceClass.actionTypes.findByName("angle"); + var actionType = root.thing.thingClass.actionTypes.findByName("angle"); var params = []; var percentageParam = {} percentageParam["paramTypeId"] = actionType.paramTypes.findByName("angle").id; percentageParam["value"] = targetAngle params.push(percentageParam); - engine.deviceManager.executeAction(root.device.id, actionType.id, params); + engine.thingManager.executeAction(root.thing.id, actionType.id, params); } } @@ -286,7 +285,7 @@ DevicePageBase { ShutterControls { id: shutterControls - device: root.device + thing: root.thing width: parent.width anchors.horizontalCenter: parent.horizontalCenter anchors.verticalCenter: parent.verticalCenter diff --git a/nymea-app/ui/devicepages/SmartMeterDevicePage.qml b/nymea-app/ui/devicepages/SmartMeterDevicePage.qml index 73f76fb3..8c94fa68 100644 --- a/nymea-app/ui/devicepages/SmartMeterDevicePage.qml +++ b/nymea-app/ui/devicepages/SmartMeterDevicePage.qml @@ -35,7 +35,7 @@ import Nymea 1.0 import "../components" import "../customviews" -DevicePageBase { +ThingPageBase { id: root readonly property State totalEnergyConsumedState: root.thing.stateByName("totalEnergyConsumed") @@ -94,8 +94,8 @@ DevicePageBase { GenericTypeGraph { Layout.preferredWidth: contentGrid.width / contentGrid.columns - device: root.device - stateType: root.deviceClass.stateTypes.findByName("currentPower") + thing: root.thing + stateType: root.thingClass.stateTypes.findByName("currentPower") color: app.stateColor("currentPower") iconSource: app.stateIcon("currentPower") roundTo: 5 diff --git a/nymea-app/ui/devicepages/StateLogPage.qml b/nymea-app/ui/devicepages/StateLogPage.qml index f3c40c39..ff52e842 100644 --- a/nymea-app/ui/devicepages/StateLogPage.qml +++ b/nymea-app/ui/devicepages/StateLogPage.qml @@ -39,8 +39,8 @@ import "../customviews" Page { id: root - property var device: null - property var stateType: null + property Thing thing: null + property StateType stateType: null readonly property bool canShowGraph: { switch (root.stateType.type) { @@ -61,7 +61,7 @@ Page { LogsModelNg { id: logsModelNg engine: _engine - deviceId: root.device.id + thingId: root.thing.id typeIds: [root.stateType.id] live: true } @@ -100,14 +100,14 @@ Page { var typeId = logView.logsModel.get(index).typeId var rule = engine.ruleManager.createNewRule(); var stateEvaluator = rule.createStateEvaluator(); - stateEvaluator.stateDescriptor.deviceId = device.id; + stateEvaluator.stateDescriptor.thingId = thing.id; stateEvaluator.stateDescriptor.stateTypeId = typeId; stateEvaluator.stateDescriptor.value = value; stateEvaluator.stateDescriptor.valueOperator = StateDescriptor.ValueOperatorEquals; rule.setStateEvaluator(stateEvaluator); - rule.name = root.device.name + " - " + stateType.displayName + " = " + value; + rule.name = root.thing.name + " - " + stateType.displayName + " = " + value; - var rulePage = pageStack.push(Qt.resolvedUrl("../magic/DeviceRulesPage.qml"), {device: root.device}); + var rulePage = pageStack.push(Qt.resolvedUrl("../magic/ThingRulesPage.qml"), {thing: root.thing}); rulePage.addRule(rule); } } @@ -119,7 +119,7 @@ Page { Component.onCompleted: { var source; source = Qt.resolvedUrl("../customviews/GenericTypeGraph.qml"); - setSource(source, {device: root.device, stateType: root.stateType}) + setSource(source, {thing: root.thing, stateType: root.stateType}) } } } diff --git a/nymea-app/ui/devicepages/ThermostatDevicePage.qml b/nymea-app/ui/devicepages/ThermostatDevicePage.qml index 5ad700f1..78e8d05f 100644 --- a/nymea-app/ui/devicepages/ThermostatDevicePage.qml +++ b/nymea-app/ui/devicepages/ThermostatDevicePage.qml @@ -36,7 +36,7 @@ import Nymea 1.0 import "../components" import "../customviews" -DevicePageBase { +ThingPageBase { id: root readonly property bool landscape: width > height diff --git a/nymea-app/ui/devicepages/DevicePageBase.qml b/nymea-app/ui/devicepages/ThingPageBase.qml similarity index 92% rename from nymea-app/ui/devicepages/DevicePageBase.qml rename to nymea-app/ui/devicepages/ThingPageBase.qml index 116408ad..5837ff3d 100644 --- a/nymea-app/ui/devicepages/DevicePageBase.qml +++ b/nymea-app/ui/devicepages/ThingPageBase.qml @@ -39,9 +39,6 @@ Page { property Thing thing: null readonly property ThingClass thingClass: thing.thingClass - property alias device: root.thing - property alias deviceClass: root.thingClass - property bool showLogsButton: true property bool showDetailsButton: true property bool showBrowserButton: true @@ -64,7 +61,7 @@ Page { imageSource: "../images/folder-symbolic.svg" visible: root.thingClass.browsable && root.showBrowserButton onClicked: { - pageStack.push(Qt.resolvedUrl("DeviceBrowserPage.qml"), {device: root.device}) + pageStack.push(Qt.resolvedUrl("DeviceBrowserPage.qml"), {thing: root.thing}) } } @@ -83,10 +80,10 @@ Page { } Connections { - target: engine.deviceManager.devices + target: engine.thingManager.things onThingRemoved:{ - if (device == root.device) { - print("Device destroyed") + if (thing == root.thing) { + print("Thing destroyed") pageStack.pop() } } diff --git a/nymea-app/ui/devicepages/VentilationDevicePage.qml b/nymea-app/ui/devicepages/VentilationDevicePage.qml index 01a35aaf..38761e04 100644 --- a/nymea-app/ui/devicepages/VentilationDevicePage.qml +++ b/nymea-app/ui/devicepages/VentilationDevicePage.qml @@ -35,12 +35,11 @@ import QtQuick.Controls.Material 2.1 import Nymea 1.0 import "../components" -DevicePageBase { +ThingPageBase { id: root - readonly property var powerStateType: deviceClass.stateTypes.findByName("power") - readonly property var powerState: device.states.getState(powerStateType.id) - readonly property var powerActionType: deviceClass.actionTypes.findByName("power"); + readonly property State powerState: thing.stateByName("power") + readonly property StateType powerActionType: thing.thingClass.actionTypes.findByName("power"); GridLayout { anchors.fill: parent @@ -96,7 +95,7 @@ DevicePageBase { param["paramTypeId"] = root.powerActionType.paramTypes.get(0).id; param["value"] = !root.powerState.value; params.push(param) - engine.deviceManager.executeAction(root.device.id, root.powerStateType.id, params); + engine.thingManager.executeAction(root.thing.id, root.powerActionType.id, params); } } } diff --git a/nymea-app/ui/devicepages/WeatherDevicePage.qml b/nymea-app/ui/devicepages/WeatherDevicePage.qml index a4232c92..b1c7fa54 100644 --- a/nymea-app/ui/devicepages/WeatherDevicePage.qml +++ b/nymea-app/ui/devicepages/WeatherDevicePage.qml @@ -35,7 +35,7 @@ import Nymea 1.0 import "../components" import "../customviews" -DevicePageBase { +ThingPageBase { id: root Flickable { @@ -59,29 +59,29 @@ DevicePageBase { GenericTypeGraph { Layout.fillWidth: true - device: root.device - stateType: root.deviceClass.stateTypes.findByName("temperature") + thing: root.thing + stateType: root.thingClass.stateTypes.findByName("temperature") iconSource: app.interfaceToIcon("temperaturesensor") color: app.interfaceToColor("temperaturesensor") } GenericTypeGraph { Layout.fillWidth: true - device: root.device - stateType: root.deviceClass.stateTypes.findByName("humidity") + thing: root.thing + stateType: root.thingClass.stateTypes.findByName("humidity") iconSource: app.interfaceToIcon("humiditysensor") color: app.interfaceToColor("humiditysensor") } GenericTypeGraph { Layout.fillWidth: true - device: root.device - stateType: root.deviceClass.stateTypes.findByName("pressure") + thing: root.thing + stateType: root.thingClass.stateTypes.findByName("pressure") iconSource: app.interfaceToIcon("pressuresensor") color: app.interfaceToColor("pressuresensor") } GenericTypeGraph { Layout.fillWidth: true - device: root.device - stateType: root.deviceClass.stateTypes.findByName("windSpeed") + thing: root.thing + stateType: root.thingClass.stateTypes.findByName("windSpeed") iconSource: app.interfaceToIcon("windspeedsensor") color: app.interfaceToColor("windspeedsensor") } diff --git a/nymea-app/ui/experiences/heating/Main.qml b/nymea-app/ui/experiences/heating/Main.qml index ec9f589e..b49b5ae0 100644 --- a/nymea-app/ui/experiences/heating/Main.qml +++ b/nymea-app/ui/experiences/heating/Main.qml @@ -41,8 +41,8 @@ Item { readonly property string title: qsTr("Celsi°s") readonly property string icon: Qt.resolvedUrl("qrc:/ui/images/radiator.svg") - readonly property Device duwWpDevice: duwWpFilterModel.count > 0 ? duwWpFilterModel.get(0) : null - readonly property Device duwLuDevice: duwLuFilterModel.count > 0 ? duwLuFilterModel.get(0) : null + readonly property Thing duwWpDevice: duwWpFilterModel.count > 0 ? duwWpFilterModel.get(0) : null + readonly property Thing duwLuDevice: duwLuFilterModel.count > 0 ? duwLuFilterModel.get(0) : null readonly property State temperatureState: duwWpDevice ? duwWpDevice.states.getState(duwWpDevice.deviceClass.stateTypes.findByName("temperature").id) : null readonly property State targetTemperatureState: duwWpDevice ? duwWpDevice.states.getState(duwWpDevice.deviceClass.stateTypes.findByName("targetTemperature").id) : null @@ -97,7 +97,7 @@ Item { param["paramTypeId"] = root.ventilationModeState.stateTypeId param["value"] = root.uiModeToVentilationMode(uiModeIndex, sliderIndex) params.push(param) - engine.deviceManager.executeAction(root.duwLuDevice.id, root.ventilationModeState.stateTypeId, params) + engine.thingManager.executeAction(root.duwLuDevice.id, root.ventilationModeState.stateTypeId, params) } function setTargetTemp(targetTemp) { @@ -112,12 +112,12 @@ Item { param["paramTypeId"] = root.targetTemperatureState.stateTypeId param["value"] = targetTemp params.push(param) - d.pendingCallId = engine.deviceManager.executeAction(root.duwWpDevice.id, root.targetTemperatureState.stateTypeId, params) + d.pendingCallId = engine.thingManager.executeAction(root.duwWpDevice.id, root.targetTemperatureState.stateTypeId, params) d.setTempPending = false; } Connections { - target: engine.deviceManager + target: engine.thingManager onExecuteActionReply: { print("executeActionReply:", commandId) if (commandId === d.pendingCallId) { @@ -136,16 +136,16 @@ Item { property real queuedTargetTemp: 0 } - DevicesProxy { + ThingsProxy { id: duwWpFilterModel engine: _engine - filterDeviceClassId: "e548f962-92db-4110-8279-10fbcde35f93" + filterThingClassId: "e548f962-92db-4110-8279-10fbcde35f93" } - DevicesProxy { + ThingsProxy { id: duwLuFilterModel engine: _engine - filterDeviceClassId: "0de8e21e-392a-4790-a78a-b1a7eaa7571b" + filterThingClassId: "0de8e21e-392a-4790-a78a-b1a7eaa7571b" } EmptyViewPlaceholder { @@ -155,7 +155,7 @@ Item { imageSource: "qrc:/ui/images/radiator.svg" buttonVisible: false buttonText: qsTr("Set up now") - visible: duwWpFilterModel.count === 0 && !engine.deviceManager.fetchingData + visible: duwWpFilterModel.count === 0 && !engine.thingManager.fetchingData } @@ -244,7 +244,7 @@ Item { name: "qrc:/ui/images/magic.svg" MouseArea { anchors.fill: parent - onClicked: pageStack.push("qrc:/ui/magic/DeviceRulesPage.qml", {device: root.duwWpDevice}) + onClicked: pageStack.push("qrc:/ui/magic/ThingRulesPage.qml", {thing: root.duwWpDevice}) } } Label { diff --git a/nymea-app/ui/grouping/GroupInterfacesPage.qml b/nymea-app/ui/grouping/GroupInterfacesPage.qml index 435c6ef2..f45a6342 100644 --- a/nymea-app/ui/grouping/GroupInterfacesPage.qml +++ b/nymea-app/ui/grouping/GroupInterfacesPage.qml @@ -46,8 +46,8 @@ Page { property string groupTag - DevicesProxy { - id: devicesInGroup + ThingsProxy { + id: thingsInGroup engine: _engine filterTagId: root.groupTag } @@ -60,7 +60,7 @@ Page { model: InterfacesSortModel { interfacesModel: InterfacesModel { engine: _engine - things: devicesInGroup + things: thingsInGroup shownInterfaces: app.supportedInterfaces showUncategorized: true } diff --git a/nymea-app/ui/grouping/GroupThingsPage.qml b/nymea-app/ui/grouping/GroupThingsPage.qml index f800bc16..cd7da31c 100644 --- a/nymea-app/ui/grouping/GroupThingsPage.qml +++ b/nymea-app/ui/grouping/GroupThingsPage.qml @@ -46,7 +46,7 @@ Page { property string groupTag - DevicesProxy { + ThingsProxy { id: devicesInGroup engine: _engine filterTagId: root.groupTag @@ -58,28 +58,28 @@ Page { showStates: true } - DevicesProxy { + ThingsProxy { id: lightsInGroup engine: _engine sourceModel: devicesInGroup filterTagId: root.groupTag shownInterfaces: "light" } - DevicesProxy { + ThingsProxy { id: dimmableLightsInGroup engine: _engine sourceModel: devicesInGroup filterTagId: root.groupTag shownInterfaces: "dimmablelight" } - DevicesProxy { + ThingsProxy { id: colorLightsInGroup engine: _engine sourceModel: devicesInGroup filterTagId: root.groupTag shownInterfaces: "colorlight" } - DevicesProxy { + ThingsProxy { id: socketsInGroup engine: _engine sourceModel: devicesInGroup @@ -129,11 +129,8 @@ Page { device: devicesInGroup.get(index) - onClicked: pageStack.push(Qt.resolvedUrl("../devicepages/" + NymeaUtils.interfaceListToDevicePage(deviceClass.interfaces)), {device: device}) - + onClicked: pageStack.push(Qt.resolvedUrl("../devicepages/" + NymeaUtils.interfaceListToDevicePage(thing.thingClass.interfaces)), {device: device}) } } } - - } diff --git a/nymea-app/ui/magic/EditRulePage.qml b/nymea-app/ui/magic/EditRulePage.qml index 0f3f219d..b3f20692 100644 --- a/nymea-app/ui/magic/EditRulePage.qml +++ b/nymea-app/ui/magic/EditRulePage.qml @@ -38,7 +38,7 @@ Page { id: root property Rule rule: null - property Device initialDeviceToBeAdded: null + property Thing initialDeviceToBeAdded: null property bool busy: false @@ -84,9 +84,9 @@ Page { page.onBackPressed.connect(function() { pageStack.pop(); }); - page.onThingSelected.connect(function(device) { + page.onThingSelected.connect(function(thing) { var eventDescriptor = root.rule.eventDescriptors.createNewEventDescriptor(); - eventDescriptor.deviceId = device.id; + eventDescriptor.thingId = thing.id; selectEventDescriptorData(eventDescriptor); }) page.onInterfaceSelected.connect(function(interfaceName) { @@ -158,15 +158,15 @@ Page { stateEvaluator.stateDescriptor.interfaceName = interfaceName; selectStateDescriptorData(stateEvaluator) }); - page.thingSelected.connect(function(device) { + page.thingSelected.connect(function(thing) { var stateEvaluator = root.rule.createStateEvaluator(); - stateEvaluator.stateDescriptor.deviceId = device.id + stateEvaluator.stateDescriptor.thingId = thing.id selectStateDescriptorData(stateEvaluator) }) } function selectStateDescriptorData(stateEvaluator) { - print("Selecting stateDescriptorData for", stateEvaluator.stateDescriptor.deviceId, stateEvaluator.stateDescriptor.interfaceName) + print("Selecting stateDescriptorData for", stateEvaluator.stateDescriptor.thingId, stateEvaluator.stateDescriptor.interfaceName) var statePage = pageStack.push(Qt.resolvedUrl("SelectStateDescriptorPage.qml"), {text: "Select state", stateDescriptor: stateEvaluator.stateDescriptor}) statePage.backPressed.connect(function() { statePage.StackView.onRemoved.connect(function() { @@ -198,9 +198,9 @@ Page { page.onBackPressed.connect(function() { pageStack.pop(); }) - page.onThingSelected.connect(function(device) { + page.onThingSelected.connect(function(thing) { var ruleAction = root.rule.actions.createNewRuleAction(); - ruleAction.deviceId = device.id; + ruleAction.thingId = thing.id; selectRuleActionData(root.rule.actions, ruleAction) }) page.onInterfaceSelected.connect(function(interfaceName) { @@ -222,9 +222,9 @@ Page { page.onBackPressed.connect(function() { pageStack.pop(); }) - page.onThingSelected.connect(function(device) { + page.onThingSelected.connect(function(thing) { var ruleAction = root.rule.exitActions.createNewRuleAction(); - ruleAction.deviceId = device.id; + ruleAction.thingId = thing.id; selectRuleActionData(root.rule.exitActions, ruleAction) }) page.onInterfaceSelected.connect(function(interfaceName) { @@ -258,7 +258,7 @@ Page { } if (root.initialDeviceToBeAdded !== null) { var ruleAction = root.rule.actions.createNewRuleAction(); - ruleAction.deviceId = root.initialDeviceToBeAdded.id; + ruleAction.thingId = root.initialDeviceToBeAdded.id; root.initialDeviceToBeAdded = null; selectRuleActionData(root.rule.actions, ruleAction) } else { @@ -504,7 +504,7 @@ Page { onClicked: { if (root.initialDeviceToBeAdded !== null) { var eventDescriptor = root.rule.eventDescriptors.createNewEventDescriptor(); - eventDescriptor.deviceId = root.initialDeviceToBeAdded.id; + eventDescriptor.thingId = root.initialDeviceToBeAdded.id; root.initialDeviceToBeAdded = null; selectEventDescriptorData(eventDescriptor); } else if (root.rule.timeDescriptor.calendarItems.count > 0) { @@ -599,7 +599,7 @@ Page { onClicked: { if (root.initialDeviceToBeAdded !== null) { var stateEvaluator = root.rule.createStateEvaluator(); - stateEvaluator.stateDescriptor.deviceId = root.initialDeviceToBeAdded.id + stateEvaluator.stateDescriptor.thingId = root.initialDeviceToBeAdded.id root.initialDeviceToBeAdded = null; selectStateDescriptorData(stateEvaluator) } else if (root.rule.timeDescriptor.timeEventItems.count > 0) { diff --git a/nymea-app/ui/magic/EventDescriptorDelegate.qml b/nymea-app/ui/magic/EventDescriptorDelegate.qml index fe05e958..586b7de7 100644 --- a/nymea-app/ui/magic/EventDescriptorDelegate.qml +++ b/nymea-app/ui/magic/EventDescriptorDelegate.qml @@ -41,18 +41,18 @@ NymeaSwipeDelegate { progressive: false property EventDescriptor eventDescriptor: null - readonly property Device device: eventDescriptor ? engine.deviceManager.devices.getDevice(eventDescriptor.deviceId) : null - readonly property DeviceClass deviceClass: device ? engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId) : null + readonly property Thing thing: eventDescriptor ? engine.thingManager.things.getThing(eventDescriptor.thingId) : null + readonly property ThingClass thingClass: thing ? engine.thingManager.thingClasses.getThingClass(thing.thingClassId) : null readonly property Interface iface: eventDescriptor.interfaceName ? Interfaces.findByName(eventDescriptor.interfaceName) : null - readonly property EventType eventType: deviceClass ? deviceClass.eventTypes.getEventType(eventDescriptor.eventTypeId) + readonly property EventType eventType: thingClass ? thingClass.eventTypes.getEventType(eventDescriptor.eventTypeId) : iface ? iface.eventTypes.findByName(eventDescriptor.interfaceEvent) : null signal removeEventDescriptor() onDeleteClicked: root.removeEventDescriptor() - iconName: root.device ? "../images/event.svg" : "../images/event-interface.svg" - text: qsTr("%1 - %2").arg(root.device ? root.device.name : root.iface.displayName).arg(root.eventType.displayName) + iconName: root.thing ? "../images/event.svg" : "../images/event-interface.svg" + text: qsTr("%1 - %2").arg(root.thing ? root.thing.name : root.iface.displayName).arg(root.eventType.displayName) subText: { var ret = qsTr("anytime"); for (var i = 0; i < root.eventDescriptor.paramDescriptors.count; i++) { diff --git a/nymea-app/ui/magic/NewScenePage.qml b/nymea-app/ui/magic/NewScenePage.qml index 59cd13fb..75245c58 100644 --- a/nymea-app/ui/magic/NewScenePage.qml +++ b/nymea-app/ui/magic/NewScenePage.qml @@ -50,7 +50,7 @@ Page { model: RuleTemplatesFilterModel { ruleTemplates: RuleTemplates {} - filterByDevices: DevicesProxy { + filterByThings: ThingsProxy { engine: _engine } diff --git a/nymea-app/ui/magic/NewThingMagicPage.qml b/nymea-app/ui/magic/NewThingMagicPage.qml index 5def81a1..8f9aca7b 100644 --- a/nymea-app/ui/magic/NewThingMagicPage.qml +++ b/nymea-app/ui/magic/NewThingMagicPage.qml @@ -37,8 +37,8 @@ import "../components" Page { id: root - property Device device: null - readonly property DeviceClass deviceClass: device ? device.deviceClass : null + property Thing thing: null + readonly property ThingClass thingClass: thing ? thing.thingClass : null property bool busy: false signal done(); @@ -66,27 +66,27 @@ Page { print("RuleFromTemplate: Filling eventDescriptor:", eventDescriptorTemplate.interfaceName, eventDescriptorTemplate.eventName, eventDescriptorTemplate.selectionId) // If we already have a thing selected for this selectionIndex, use that if (eventDescriptorTemplate.selectionId in selectedThings) { - var device = engine.deviceManager.devices.getDevice(selectedThings[eventDescriptorTemplate.selectionId]); - print("Already have a device for selectionId", eventDescriptorTemplate.selectionId, ":", device.name) - createEventDescriptor(rule, ruleTemplate, device, eventDescriptorTemplate) + var thing = engine.thingManager.things.getThing(selectedThings[eventDescriptorTemplate.selectionId]); + print("Already have a thing for selectionId", eventDescriptorTemplate.selectionId, ":", thing.name) + createEventDescriptor(rule, ruleTemplate, thing, eventDescriptorTemplate) return; } // Ok, we didn't pick a thing for this selectionId before. Did we already use the one we opened this page from? - if (root.device && !deviceIsUsed(root.device.id) && root.deviceClass.interfaces.indexOf(eventDescriptorTemplate.interfaceName) >= 0) { - print("Root device is matching and not used. Using for selectionId", eventDescriptorTemplate.selectionId, ":", root.device.name) - selectedThings[eventDescriptorTemplate.selectionId] = root.device.id; - selectedThingNames[eventDescriptorTemplate.selectionId] = root.device.name; - createEventDescriptor(rule, ruleTemplate, root.device, eventDescriptorTemplate) + if (root.thing && !thingIsUsed(root.thing.id) && root.thingClass.interfaces.indexOf(eventDescriptorTemplate.interfaceName) >= 0) { + print("Root thing is matching and not used. Using for selectionId", eventDescriptorTemplate.selectionId, ":", root.thing.name) + selectedThings[eventDescriptorTemplate.selectionId] = root.thing.id; + selectedThingNames[eventDescriptorTemplate.selectionId] = root.thing.name; + createEventDescriptor(rule, ruleTemplate, root.thing, eventDescriptorTemplate) return; } // We need to pick a thing - print("We need to pick a new device for selectionId", eventDescriptorTemplate.selectionId) + print("We need to pick a new thing for selectionId", eventDescriptorTemplate.selectionId) var page = pageStack.push(Qt.resolvedUrl("SelectThingPage.qml"), {shownInterfaces: [eventDescriptorTemplate.interfaceName], requiredEventName: eventDescriptorTemplate.eventName}); - page.thingSelected.connect(function(device) { - selectedThings[eventDescriptorTemplate.selectionId] = device.id; - selectedThingNames[eventDescriptorTemplate.selectionId] = device.name; - createEventDescriptor(rule, ruleTemplate, device, eventDescriptorTemplate) + page.thingSelected.connect(function(thing) { + selectedThings[eventDescriptorTemplate.selectionId] = thing.id; + selectedThingNames[eventDescriptorTemplate.selectionId] = thing.name; + createEventDescriptor(rule, ruleTemplate, thing, eventDescriptorTemplate) return; }) page.backPressed.connect(function() {rule.destroy(); root.done();}) @@ -171,37 +171,37 @@ Page { // Did we pick a thing for this index before? if (ruleActionTemplate.selectionId in selectedThings) { - var device = engine.deviceManager.devices.getDevice(selectedThings[ruleActionTemplate.selectionId]); - print("Already have a device for selectionId", ruleActionTemplate.selectionId, ":", device.name) - createRuleAction(rule, ruleTemplate, rule.actions, [device], ruleActionTemplate) + var thing = engine.thingManager.things.getThing(selectedThings[ruleActionTemplate.selectionId]); + print("Already have a thing for selectionId", ruleActionTemplate.selectionId, ":", thing.name) + createRuleAction(rule, ruleTemplate, rule.actions, [thing], ruleActionTemplate) return; } // Did we already use the thing we opened this page from? - if (root.device && !deviceIsUsed(root.device.id) && root.deviceClass.interfaces.indexOf(ruleActionTemplate.interfaceName) >= 0) { - print("Root device is matching and not used. Using for selectionId", ruleActionTemplate.selectionId, ":", root.device.name) - selectedThings[ruleActionTemplate.selectionId] = root.device.id; - selectedThingNames[ruleActionTemplate.selectionId] = root.device.name; - createRuleAction(rule, ruleTemplate, rule.actions, [root.device], ruleActionTemplate) + if (root.thing && !thingIsUsed(root.thing.id) && root.thingClass.interfaces.indexOf(ruleActionTemplate.interfaceName) >= 0) { + print("Root thing is matching and not used. Using for selectionId", ruleActionTemplate.selectionId, ":", root.thing.name) + selectedThings[ruleActionTemplate.selectionId] = root.thing.id; + selectedThingNames[ruleActionTemplate.selectionId] = root.thing.name; + createRuleAction(rule, ruleTemplate, rule.actions, [root.thing], ruleActionTemplate) return; } // Ok, we need to pick a thing var multipleSelection = ruleActionTemplate.selectionMode === RuleActionTemplate.SelectionModeDevices; var page = pageStack.push(Qt.resolvedUrl("SelectThingPage.qml"), {shownInterfaces: [ruleActionTemplate.interfaceName], requiredActionName: ruleActionTemplate.actionName, multipleSelection: multipleSelection}); - page.thingSelected.connect(function(device) { - selectedThings[ruleActionTemplate.selectionId] = device.id; - selectedThingNames[ruleActionTemplate.selectionId] = device.name; - createRuleAction(rule, ruleTemplate, rule.actions, [device], ruleActionTemplate) + page.thingSelected.connect(function(thing) { + selectedThings[ruleActionTemplate.selectionId] = thing.id; + selectedThingNames[ruleActionTemplate.selectionId] = thing.name; + createRuleAction(rule, ruleTemplate, rule.actions, [thing], ruleActionTemplate) }) - page.thingsSelected.connect(function(devices) { + page.thingsSelected.connect(function(things) { var names = [] - for (var i = 0; i < devices.length; i++) { - names.push(devices[i].name) + for (var i = 0; i < things.length; i++) { + names.push(things[i].name) } selectedThingNames[ruleActionTemplate.selectionId] = names.join(", "); - createRuleAction(rule, ruleTemplate, rule.actions, devices, ruleActionTemplate) + createRuleAction(rule, ruleTemplate, rule.actions, things, ruleActionTemplate) }); page.backPressed.connect(function() {rule.destroy(); root.done();}) @@ -229,35 +229,35 @@ Page { // Did we pick a thing for this index before? if (ruleExitActionTemplate.selectionId in selectedThings) { - var device = engine.deviceManager.devices.getDevice(selectedThings[ruleExitActionTemplate.selectionId]); - createRuleAction(rule, ruleTemplate, rule.exitActions, [device], ruleExitActionTemplate); + var thing = engine.thingManager.things.getThing(selectedThings[ruleExitActionTemplate.selectionId]); + createRuleAction(rule, ruleTemplate, rule.exitActions, [thing], ruleExitActionTemplate); return; } // Did we already use the thing we opened this page from? - if (root.device && !deviceIsUsed(root.device.id) && root.deviceClass.interfaces.indexOf(ruleExitActionTemplate.interfaceName) >= 0) { - selectedThings[ruleExitActionTemplate.selectionId] = root.device.id; - selectedThingNames[ruleExitActionTemplate.selectionId] = root.device.name; - createRuleAction(rule, ruleTemplate, rule.exitActions, [root.device], ruleExitActionTemplate); + if (root.thing && !thingIsUsed(root.thing.id) && root.thingClass.interfaces.indexOf(ruleExitActionTemplate.interfaceName) >= 0) { + selectedThings[ruleExitActionTemplate.selectionId] = root.thing.id; + selectedThingNames[ruleExitActionTemplate.selectionId] = root.thing.name; + createRuleAction(rule, ruleTemplate, rule.exitActions, [root.thing], ruleExitActionTemplate); return; } // Ok, we need to pick a thing var multipleSelection = ruleActionTemplate.selectionMode === RuleActionTemplate.SelectionModeDevices; var page = pageStack.push(Qt.resolvedUrl("SelectThingPage.qml"), {shownInterfaces: [ruleExitActionTemplate.interfaceName], requiredActionName: ruleExitActionTemplate.actionName, multipleSelection: multipleSelection}); - page.thingSelected.connect(function(device) { - selectedThings[ruleExitActionTemplate.selectionId] = device.id; - selectedThingNames[ruleExitActionTemplate.selectionId] = device.name; - createRuleAction(rule, ruleTemplate, rule.exitActions, [device], ruleExitActionTemplate); + page.thingSelected.connect(function(thing) { + selectedThings[ruleExitActionTemplate.selectionId] = thing.id; + selectedThingNames[ruleExitActionTemplate.selectionId] = thing.name; + createRuleAction(rule, ruleTemplate, rule.exitActions, [thing], ruleExitActionTemplate); return; }) - page.thingsSelected.connect(function(devices) { + page.thingsSelected.connect(function(things) { var names = [] - for (var i = 0; i < devices.length; i++) { - names.push(devices[i].name) + for (var i = 0; i < things.length; i++) { + names.push(things[i].name) } - selectedThingNames[ruleExitActionTemplate.selectionId] = devices.join(", "); - createRuleAction(rule, ruleTemplate, rule.exitActions, [device], ruleExitActionTemplate); + selectedThingNames[ruleExitActionTemplate.selectionId] = things.join(", "); + createRuleAction(rule, ruleTemplate, rule.exitActions, [things], ruleExitActionTemplate); }); page.backPressed.connect(function() {rule.destroy(); root.done();}) return; @@ -303,7 +303,7 @@ Page { } function fillStateEvaluatorFromTemplate(rule, ruleTemplate, stateEvaluator, stateEvaluatorTemplate) { - if (stateEvaluatorTemplate.stateDescriptorTemplate !== null && !deviceIsUsed(stateEvaluator.stateDescriptor.deviceId) && stateEvaluator.stateDescriptor.interfaceName.length === 0) { + if (stateEvaluatorTemplate.stateDescriptorTemplate !== null && !thingIsUsed(stateEvaluator.stateDescriptor.thingId) && stateEvaluator.stateDescriptor.interfaceName.length === 0) { // need to fill stateDescriptor print("filling in state evaluator for selection mode:", stateEvaluatorTemplate.stateDescriptorTemplate.selectionMode) @@ -319,37 +319,35 @@ Page { // did we pick a thing for this index before? if (stateEvaluatorTemplate.stateDescriptorTemplate.selectionId in selectedThings) { - var deviceId = selectedThings[stateEvaluatorTemplate.stateDescriptorTemplate.selectionId] - var device = engine.deviceManager.devices.getDevice(deviceId) - var deviceClass = engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId); - stateEvaluator.stateDescriptor.deviceId = deviceId; - stateEvaluator.stateDescriptor.stateTypeId = deviceClass.stateTypes.findByName(stateEvaluatorTemplate.stateDescriptorTemplate.stateName).id + var thingId = selectedThings[stateEvaluatorTemplate.stateDescriptorTemplate.selectionId] + var thing = engine.thingManager.things.getThing(thingId) + stateEvaluator.stateDescriptor.thingId = thingId; + stateEvaluator.stateDescriptor.stateTypeId = thing.thingClass.stateTypes.findByName(stateEvaluatorTemplate.stateDescriptorTemplate.stateName).id stateEvaluator.stateDescriptor.valueOperator = stateEvaluatorTemplate.stateDescriptorTemplate.valueOperator; stateEvaluator.stateDescriptor.value = stateEvaluatorTemplate.stateDescriptorTemplate.value; fillRuleFromTemplate(rule, ruleTemplate); return true; } - if (root.device && !deviceIsUsed(root.device.id) && root.deviceClass.interfaces.indexOf(stateEvaluatorTemplate.stateDescriptorTemplate.interfaceName) >= 0) { - stateEvaluator.stateDescriptor.deviceId = root.device.id; - stateEvaluator.stateDescriptor.stateTypeId = root.deviceClass.stateTypes.findByName(stateEvaluatorTemplate.stateDescriptorTemplate.stateName).id + if (root.thing && !thingIsUsed(root.thing.id) && root.thingClass.interfaces.indexOf(stateEvaluatorTemplate.stateDescriptorTemplate.interfaceName) >= 0) { + stateEvaluator.stateDescriptor.thingId = root.thing.id; + stateEvaluator.stateDescriptor.stateTypeId = root.thingClass.stateTypes.findByName(stateEvaluatorTemplate.stateDescriptorTemplate.stateName).id stateEvaluator.stateDescriptor.valueOperator = stateEvaluatorTemplate.stateDescriptorTemplate.valueOperator; stateEvaluator.stateDescriptor.value = stateEvaluatorTemplate.stateDescriptorTemplate.value; - selectedThings[stateEvaluatorTemplate.stateDescriptorTemplate.selectionId] = root.device.id; - selectedThingNames[stateEvaluatorTemplate.stateDescriptorTemplate.selectionId] = root.device.name; + selectedThings[stateEvaluatorTemplate.stateDescriptorTemplate.selectionId] = root.thing.id; + selectedThingNames[stateEvaluatorTemplate.stateDescriptorTemplate.selectionId] = root.thing.name; fillRuleFromTemplate(rule, ruleTemplate); return true; } print("opening SelectThingPage for shownInterfaces:") print("..", stateEvaluatorTemplate.stateDescriptorTemplate.interfaceName) var page = pageStack.push(Qt.resolvedUrl("SelectThingPage.qml"), {shownInterfaces: [stateEvaluatorTemplate.stateDescriptorTemplate.interfaceName], requiredStateName: stateEvaluatorTemplate.stateDescriptorTemplate.stateName, allowSelectAny: stateEvaluatorTemplate.stateDescriptorTemplate.selectionMode === StateDescriptorTemplate.SelectionModeAny}); - page.thingSelected.connect(function(device) { - var deviceClass = engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId); - stateEvaluator.stateDescriptor.deviceId = device.id; - stateEvaluator.stateDescriptor.stateTypeId = deviceClass.stateTypes.findByName(stateEvaluatorTemplate.stateDescriptorTemplate.stateName).id; + page.thingSelected.connect(function(thing) { + stateEvaluator.stateDescriptor.thingId = thing.id; + stateEvaluator.stateDescriptor.stateTypeId = thing.thingClass.stateTypes.findByName(stateEvaluatorTemplate.stateDescriptorTemplate.stateName).id; stateEvaluator.stateDescriptor.valueOperator = stateEvaluatorTemplate.stateDescriptorTemplate.valueOperator; stateEvaluator.stateDescriptor.value = stateEvaluatorTemplate.stateDescriptorTemplate.value; - selectedThings[stateEvaluatorTemplate.stateDescriptorTemplate.selectionId] = device.id; - selectedThingNames[stateEvaluatorTemplate.stateDescriptorTemplate.selectionId] = device.name; + selectedThings[stateEvaluatorTemplate.stateDescriptorTemplate.selectionId] = thing.id; + selectedThingNames[stateEvaluatorTemplate.stateDescriptorTemplate.selectionId] = thing.name; fillRuleFromTemplate(rule, ruleTemplate) }) page.onAnySelected.connect(function() { @@ -377,14 +375,13 @@ Page { return false; } - function createEventDescriptor(rule, ruleTemplate, device, eventDescriptorTemplate) { + function createEventDescriptor(rule, ruleTemplate, thing, eventDescriptorTemplate) { var eventDescriptor = rule.eventDescriptors.createNewEventDescriptor(); - eventDescriptor.deviceId = device.id; - var deviceClass = engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId); - eventDescriptor.eventTypeId = deviceClass.eventTypes.findByName(eventDescriptorTemplate.eventName).id + eventDescriptor.thingId = thing.id; + eventDescriptor.eventTypeId = thing.thingClass.eventTypes.findByName(eventDescriptorTemplate.eventName).id var needsParams = false; - var eventType = deviceClass.eventTypes.getEventType(eventDescriptor.eventTypeId); + var eventType = thing.thingClass.eventTypes.getEventType(eventDescriptor.eventTypeId); for (var j = 0; j < eventType.paramTypes.count; j++) { var paramType = eventType.paramTypes.get(j); var paramDescriptorTemplate = eventDescriptorTemplate.paramDescriptors.getParamDescriptorByName(paramType.name) @@ -414,21 +411,20 @@ Page { fillRuleFromTemplate(rule, ruleTemplate); } - function createRuleAction(rule, ruleTemplate, ruleActions, devices, ruleActionTemplate) { + function createRuleAction(rule, ruleTemplate, ruleActions, things, ruleActionTemplate) { - var device = devices.shift(); - // device param -> devices + var thing = things.shift(); + // thing param -> things // take first, run code - // at end, if devices is empty, continue with fillRuleFromTemplate otherwise run again + // at end, if things is empty, continue with fillRuleFromTemplate otherwise run again var ruleAction = ruleActions.createNewRuleAction(); - var deviceClass = engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId); - ruleAction.actionTypeId = deviceClass.actionTypes.findByName(ruleActionTemplate.actionName).id - ruleAction.deviceId = device.id; - print("Creating action", ruleActionTemplate.actionName, "on device class", deviceClass.displayName) + ruleAction.actionTypeId = thing.thingClass.actionTypes.findByName(ruleActionTemplate.actionName).id + ruleAction.thingId = thing.id; + print("Creating action", ruleActionTemplate.actionName, "on thing class", thing.thingClass.displayName) - var actionType = deviceClass.actionTypes.getActionType(ruleAction.actionTypeId); + var actionType = thing.thingClass.actionTypes.getActionType(ruleAction.actionTypeId); for (var j = 0; j < ruleActionTemplate.ruleActionParamTemplates.count; j++) { var ruleActionParamTemplate = ruleActionTemplate.ruleActionParamTemplates.get(j) @@ -451,10 +447,9 @@ Page { console.warn("Unable to find an event matching the criteria:", ruleActionParamTemplate.eventInterface, ruleActionParamTemplate.eventName, ruleActionParamTemplate.eventParamName) break } - print("selected device:", selectedThings, eventDescriptorTemplate.selectionId) - var eventDevice = engine.deviceManager.devices.getDevice(selectedThings[eventDescriptorTemplate.selectionId]) - var eventDeviceClass = engine.deviceManager.deviceClasses.getDeviceClass(eventDevice.deviceClassId); - var eventType = eventDeviceClass.eventTypes.findByName(ruleActionParamTemplate.eventName); + print("selected thing:", selectedThings, eventDescriptorTemplate.selectionId) + var eventThing = engine.thingManager.things.getThing(selectedThings[eventDescriptorTemplate.selectionId]) + var eventType = eventThing.thingClass.eventTypes.findByName(ruleActionParamTemplate.eventName); var eventParamType = eventType.paramTypes.findByName(ruleActionParamTemplate.eventParamName); ruleAction.ruleActionParams.setRuleActionParamEvent(paramType.id, eventType.id, eventParamType.id) @@ -475,10 +470,10 @@ Page { paramsPage.onCompleted.connect(function() { pageStack.pop(); ruleActions.addRuleAction(ruleAction); - if (devices.length === 0) { + if (things.length === 0) { fillRuleFromTemplate(rule, ruleTemplate); } else { - createRuleAction(rule, ruleTemplate, rule.actions, devices, ruleActionTemplate) + createRuleAction(rule, ruleTemplate, rule.actions, things, ruleActionTemplate) } }) return; @@ -486,16 +481,16 @@ Page { } ruleActions.addRuleAction(ruleAction); - if (devices.length === 0) { + if (things.length === 0) { fillRuleFromTemplate(rule, ruleTemplate); } else { - createRuleAction(rule, ruleTemplate, rule.actions, devices, ruleActionTemplate) + createRuleAction(rule, ruleTemplate, rule.actions, things, ruleActionTemplate) } } - function deviceIsUsed(deviceId) { + function thingIsUsed(thingId) { for (var key in selectedThings) { - if (selectedThings.hasOwnProperty(key) && selectedThings[key] === deviceId) { + if (selectedThings.hasOwnProperty(key) && selectedThings[key] === thingId) { return true; } } @@ -504,7 +499,7 @@ Page { } header: NymeaHeader { - text: root.device ? qsTr("New magic for %1").arg(root.device.name) : qsTr("New magic") + text: root.thing ? qsTr("New magic for %1").arg(root.thing.name) : qsTr("New magic") onBackPressed: root.done() } @@ -517,11 +512,11 @@ Page { model: RuleTemplatesFilterModel { id: ruleTemplatesModel ruleTemplates: RuleTemplates {} - filterByDevices: DevicesProxy { + filterByThings: ThingsProxy { engine: _engine } - filterInterfaceNames: root.device ? root.device.deviceClass.interfaces : [] + filterInterfaceNames: root.thing ? root.thing.thingClass.interfaces : [] } delegate: NymeaSwipeDelegate { width: parent.width diff --git a/nymea-app/ui/magic/RuleActionDelegate.qml b/nymea-app/ui/magic/RuleActionDelegate.qml index ee7587d1..35cee485 100644 --- a/nymea-app/ui/magic/RuleActionDelegate.qml +++ b/nymea-app/ui/magic/RuleActionDelegate.qml @@ -42,27 +42,26 @@ NymeaSwipeDelegate { property RuleAction ruleAction: null - readonly property Device device: ruleAction.deviceId ? engine.deviceManager.devices.getDevice(ruleAction.deviceId) : null + readonly property Thing thing: ruleAction.thingId ? engine.thingManager.things.getThing(ruleAction.thingId) : null readonly property Interface iface: ruleAction.interfaceName ? Interfaces.findByName(ruleAction.interfaceName) : null - readonly property DeviceClass deviceClass: device ? engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId) : null - readonly property ActionType actionType: deviceClass ? deviceClass.actionTypes.getActionType(ruleAction.actionTypeId) + readonly property ActionType actionType: thing ? thing.thingClass.actionTypes.getActionType(ruleAction.actionTypeId) : iface ? iface.actionTypes.findByName(ruleAction.interfaceAction) : null readonly property string browserItemId: ruleAction.browserItemId - readonly property BrowserItem browserItem: device && browserItemId.length > 0 ? engine.deviceManager.browserItem(device.id, browserItemId) : null + readonly property BrowserItem browserItem: thing && browserItemId.length > 0 ? engine.thingManager.browserItem(thing.id, browserItemId) : null signal removeRuleAction() onDeleteClicked: root.removeRuleAction() - iconName: root.device ? (root.browserItemId ? "../images/browser/BrowserIconFolder.svg" : "../images/action.svg") : "../images/action-interface.svg" + iconName: root.thing ? (root.browserItemId ? "../images/browser/BrowserIconFolder.svg" : "../images/action.svg") : "../images/action-interface.svg" text: qsTr("%1 - %2") - .arg(root.device ? root.device.name : root.iface.displayName) + .arg(root.thing ? root.thing.name : root.iface.displayName) .arg(root.actionType ? root.actionType.displayName : (root.browserItem.displayName.length > 0 ? root.browserItem.displayName : qsTr("Unknown item"))) subText: { var ret = []; for (var i = 0; i < root.ruleAction.ruleActionParams.count; i++) { var ruleActionParam = root.ruleAction.ruleActionParams.get(i) - print("populating subtext:", ruleActionParam.eventTypeId, ruleActionParam.eventParamTypeId, ruleActionParam.stateDeviceId, ruleActionParam.stateTypeId, ruleActionParam.isValueBased, ruleActionParam.isEventParamBased, ruleActionParam.isStateValueBased) + print("populating subtext:", ruleActionParam.eventTypeId, ruleActionParam.eventParamTypeId, ruleActionParam.stateThingId, ruleActionParam.stateTypeId, ruleActionParam.isValueBased, ruleActionParam.isEventParamBased, ruleActionParam.isStateValueBased) var paramType = root.actionType.paramTypes.getParamType(ruleActionParam.paramTypeId); var paramString = qsTr("%1: %2").arg(paramType.displayName) @@ -82,10 +81,10 @@ NymeaSwipeDelegate { } else if (ruleActionParam.isEventParamBased) { paramString = paramString.arg(qsTr("value from event")) } else if (ruleActionParam.isStateValueBased) { - var stateDevice = engine.deviceManager.devices.getDevice(ruleActionParam.stateDeviceId) - var stateType = stateDevice.deviceClass.stateTypes.getStateType(ruleActionParam.stateTypeId) - print("have state value based param:", stateDevice.name) - paramString = paramString.arg("{" + stateDevice.name + " - " + stateType.displayName + "}") + var stateThing = engine.thingManager.things.getThing(ruleActionParam.stateThingId) + var stateType = stateThing.thingClass.stateTypes.getStateType(ruleActionParam.stateTypeId) + print("have state value based param:", stateThing.name) + paramString = paramString.arg("{" + stateThing.name + " - " + stateType.displayName + "}") } ret.push(paramString) diff --git a/nymea-app/ui/magic/SelectBrowserItemActionPage.qml b/nymea-app/ui/magic/SelectBrowserItemActionPage.qml index 51ee9f31..b6e9b891 100644 --- a/nymea-app/ui/magic/SelectBrowserItemActionPage.qml +++ b/nymea-app/ui/magic/SelectBrowserItemActionPage.qml @@ -37,7 +37,7 @@ import "../delegates" Page { id: root - property Device device: null + property Thing thing: null property string itemId: "" signal selected(string selectedItemId) @@ -48,7 +48,7 @@ Page { } Component.onCompleted: { - listView.model = engine.deviceManager.browseDevice(root.device.id, root.itemId) + listView.model = engine.thingManager.browseThing(root.thing.id, root.itemId) } ListView { @@ -64,12 +64,12 @@ Page { delegate: BrowserItemDelegate { width: parent.width - device: root.device + thing: root.thing secondaryIconName: "" // We don't support BrowserItemActions in rules yet onClicked: { if (model.browsable) { - var page = pageStack.push(Qt.resolvedUrl("SelectBrowserItemActionPage.qml"), {device: root.device, itemId: model.id}); + var page = pageStack.push(Qt.resolvedUrl("SelectBrowserItemActionPage.qml"), {thing: root.thing, itemId: model.id}); page.selected.connect(function(selectedItemId) { pageStack.pop(); root.selected(selectedItemId); diff --git a/nymea-app/ui/magic/SelectEventDescriptorPage.qml b/nymea-app/ui/magic/SelectEventDescriptorPage.qml index 4f17e5ef..0fcd10b3 100644 --- a/nymea-app/ui/magic/SelectEventDescriptorPage.qml +++ b/nymea-app/ui/magic/SelectEventDescriptorPage.qml @@ -37,11 +37,10 @@ Page { id: root property alias text: header.text - // an eventDescriptor object needs to be set and prefilled with either deviceId or interfaceName + // an eventDescriptor object needs to be set and prefilled with either thingId or interfaceName property var eventDescriptor: null - readonly property var device: eventDescriptor && eventDescriptor.deviceId ? engine.deviceManager.devices.getDevice(eventDescriptor.deviceId) : null - readonly property var deviceClass: device ? engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId) : null + readonly property Thing thing: eventDescriptor && eventDescriptor.thingId ? engine.thingManager.things.getThing(eventDescriptor.thingId) : null signal backPressed(); signal done(); @@ -70,14 +69,14 @@ Page { function buildInterface() { if (header.interfacesMode) { - if (root.device) { + if (root.thing) { generatedModel.clear(); for (var i = 0; i < Interfaces.count; i++) { var iface = Interfaces.get(i); - if (root.deviceClass.interfaces.indexOf(iface.name) >= 0) { + if (root.thing.thingClass.interfaces.indexOf(iface.name) >= 0) { for (var j = 0; j < iface.eventTypes.count; j++) { var ifaceEt = iface.eventTypes.get(j); - var dcEt = root.deviceClass.eventTypes.findByName(ifaceEt.name) + var dcEt = root.thing.thingClass.eventTypes.findByName(ifaceEt.name) generatedModel.append({displayName: ifaceEt.displayName, eventTypeId: dcEt.id}) } } @@ -86,11 +85,11 @@ Page { } else if (root.eventDescriptor.interfaceName !== "") { listView.model = Interfaces.findByName(root.eventDescriptor.interfaceName).eventTypes } else { - console.warn("You need to set device or interfaceName"); + console.warn("You need to set thing or interfaceName"); } } else { - if (root.device) { - listView.model = deviceClass.eventTypes; + if (root.thing) { + listView.model = root.thing.thingClass.eventTypes; } } } @@ -104,9 +103,9 @@ Page { text: model.displayName onClicked: { if (header.interfacesMode) { - if (root.device) { + if (root.thing) { root.eventDescriptor.eventTypeId = model.eventTypeId; - var eventType = root.deviceClass.eventTypes.getEventType(model.eventTypeId) + var eventType = root.thing.thingClass.eventTypes.getEventType(model.eventTypeId) if (eventType.paramTypes.count > 0) { var paramsPage = pageStack.push(Qt.resolvedUrl("SelectEventDescriptorParamsPage.qml"), {eventDescriptor: root.eventDescriptor}) paramsPage.onBackPressed.connect(function() {pageStack.pop()}); @@ -130,11 +129,11 @@ Page { root.done(); } } else { - console.warn("Neither deviceId not interfaceName set. Cannot continue..."); + console.warn("Neither thingId not interfaceName set. Cannot continue..."); } } else { - if (root.device) { - var eventType = root.deviceClass.eventTypes.getEventType(model.id); + if (root.thing) { + var eventType = root.thing.thingClass.eventTypes.getEventType(model.id); root.eventDescriptor.eventTypeId = model.id; if (eventType.paramTypes.count > 0) { var paramsPage = pageStack.push(Qt.resolvedUrl("SelectEventDescriptorParamsPage.qml"), {eventDescriptor: root.eventDescriptor}) diff --git a/nymea-app/ui/magic/SelectEventDescriptorParamsPage.qml b/nymea-app/ui/magic/SelectEventDescriptorParamsPage.qml index aafd58f0..c20132c5 100644 --- a/nymea-app/ui/magic/SelectEventDescriptorParamsPage.qml +++ b/nymea-app/ui/magic/SelectEventDescriptorParamsPage.qml @@ -37,12 +37,12 @@ import Nymea 1.0 Page { id: root - // Needs to be set and filled in with deviceId and eventTypeId + // Needs to be set and filled in with thingId and eventTypeId property var eventDescriptor: null - readonly property var device: eventDescriptor && eventDescriptor.deviceId ? engine.deviceManager.devices.getDevice(eventDescriptor.deviceId) : null + readonly property Thing thing: eventDescriptor && eventDescriptor.thingId ? engine.thingManager.things.getThing(eventDescriptor.thingId) : null readonly property var iface: eventDescriptor && eventDescriptor.interfaceName ? Interfaces.findByName(eventDescriptor.interfaceName) : null - readonly property var eventType: device ? engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId).eventTypes.getEventType(eventDescriptor.eventTypeId) + readonly property var eventType: thing ? thing.thingClass.eventTypes.getEventType(eventDescriptor.eventTypeId) : iface ? iface.eventTypes.findByName(eventDescriptor.interfaceEvent) : null signal backPressed(); @@ -94,8 +94,7 @@ Page { for (var i = 0; i < delegateRepeater.count; i++) { var paramDelegate = delegateRepeater.itemAt(i); if (paramDelegate.considerParam) { - print("adding param descriptor") - if (root.device) { + if (root.thing) { root.eventDescriptor.paramDescriptors.setParamDescriptor(paramDelegate.paramType.id, paramDelegate.value, paramDelegate.operatorType) } else if (root.iface) { print("setting param descriptors by name", root.eventType.paramTypes.get(i), root.eventType.paramTypes.get(i).name) diff --git a/nymea-app/ui/magic/SelectRuleActionPage.qml b/nymea-app/ui/magic/SelectRuleActionPage.qml index f6f18168..189ea89f 100644 --- a/nymea-app/ui/magic/SelectRuleActionPage.qml +++ b/nymea-app/ui/magic/SelectRuleActionPage.qml @@ -37,14 +37,13 @@ Page { id: root property alias text: header.text - // a ruleAction object needs to be set and prefilled with either deviceId or interfaceName + // a ruleAction object needs to be set and prefilled with either thingId or interfaceName property RuleAction ruleAction: null // optionally, a rule which will be used when determining params for the actions property Rule rule: null - readonly property Device device: ruleAction && ruleAction.deviceId ? engine.deviceManager.devices.getDevice(ruleAction.deviceId) : null - readonly property DeviceClass deviceClass: device ? engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId) : null + readonly property Thing thing: ruleAction && ruleAction.thingId ? engine.thingManager.things.getThing(ruleAction.thingId) : null signal backPressed(); signal done(); @@ -74,14 +73,14 @@ Page { function buildInterface() { print("building iface", root.ruleAction, root.ruleAction.interfaceName, header.interfacesMode, root.ruleAction.interfaceName === "") if (header.interfacesMode) { - if (root.device) { + if (root.thing) { generatedModel.clear(); for (var i = 0; i < Interfaces.count; i++) { var iface = Interfaces.get(i); - if (root.deviceClass.interfaces.indexOf(iface.name) >= 0) { + if (root.thing.thingClass.interfaces.indexOf(iface.name) >= 0) { for (var j = 0; j < iface.actionTypes.count; j++) { var ifaceAt = iface.actionTypes.get(j); - var dcAt = root.deviceClass.actionTypes.findByName(ifaceAt.name) + var dcAt = root.thing.thingClass.actionTypes.findByName(ifaceAt.name) generatedModel.append({displayName: ifaceAt.displayName, actionTypeId: dcAt.id}) } } @@ -91,24 +90,24 @@ Page { print("showing actions for interface", root.ruleAction.interfaceName) listView.model = Interfaces.findByName(root.ruleAction.interfaceName).actionTypes } else { - console.warn("You need to set device or interfaceName"); + console.warn("You need to set thing or interfaceName"); } } else { - if (root.device) { + if (root.thing) { generatedModel.clear(); - for (var i = 0; i < deviceClass.actionTypes.count; i++) { - var actionType = deviceClass.actionTypes.get(i); + for (var i = 0; i < root.thing.thingClass.actionTypes.count; i++) { + var actionType = root.thing.thingClass.actionTypes.get(i); generatedModel.append({displayName: actionType.displayName, actionTypeId: actionType.id}) } // Append an item for browse mode - if (root.deviceClass.browsable) { + if (root.thing.thingClass.browsable) { generatedModel.append({displayName: qsTr("Open an item on this thing..."), actionTypeId: "browse"}) } listView.model = generatedModel; -// listView.model = deviceClass.actionTypes +// listView.model = root.thing.thingClass.actionTypes } } } @@ -123,16 +122,16 @@ Page { text: model.displayName width: parent.width iconName: model.actionTypeId === "browse" ? "../images/browser/BrowserIconFolder.svg" : "../images/action.svg" - property ActionType actionType: root.deviceClass.actionTypes.getActionType(model.actionTypeId) + property ActionType actionType: root.thing.thingClass.actionTypes.getActionType(model.actionTypeId) progressive: model.actionTypeId === "browse" || actionType.paramTypes.count > 0 onClicked: { if (header.interfacesMode) { - if (root.device) { + if (root.thing) { root.ruleAction.actionTypeId = model.actionTypeId; root.ruleAction.browserItemId = ""; root.ruleAction.interfaceAction = ""; - var actionType = root.deviceClass.actionTypes.getActionType(model.actionTypeId) + var actionType = root.thing.thingClass.actionTypes.getActionType(model.actionTypeId) if (actionType.paramTypes.count > 0) { var paramsPage = pageStack.push(Qt.resolvedUrl("SelectRuleActionParamsPage.qml"), {ruleAction: root.ruleAction, rule: root.rule}) paramsPage.onBackPressed.connect(function() {pageStack.pop()}); @@ -158,12 +157,12 @@ Page { root.done(); } } else { - console.warn("Neither deviceId not interfaceName set. Cannot continue..."); + console.warn("Neither thingId not interfaceName set. Cannot continue..."); } } else { - if (root.device) { + if (root.thing) { if (model.actionTypeId === "browse") { - var page = pageStack.push(Qt.resolvedUrl("SelectBrowserItemActionPage.qml"), {device: root.device}); + var page = pageStack.push(Qt.resolvedUrl("SelectBrowserItemActionPage.qml"), {thing: root.thing}); page.selected.connect(function(selectedItemId) { print("selected is", selectedItemId) root.ruleAction.browserItemId = selectedItemId; @@ -173,7 +172,7 @@ Page { root.done(); }) } else { - var actionType = root.deviceClass.actionTypes.getActionType(model.actionTypeId); + var actionType = root.thing.thingClass.actionTypes.getActionType(model.actionTypeId); console.log("ActionType", actionType.id, "selected. Has", actionType.paramTypes.count, "params"); if (root.ruleAction.actionTypeId !== actionType.id) { root.ruleAction.actionTypeId = actionType.id; diff --git a/nymea-app/ui/magic/SelectRuleActionParamsPage.qml b/nymea-app/ui/magic/SelectRuleActionParamsPage.qml index 55b94455..b1cdca03 100644 --- a/nymea-app/ui/magic/SelectRuleActionParamsPage.qml +++ b/nymea-app/ui/magic/SelectRuleActionParamsPage.qml @@ -37,15 +37,15 @@ import Nymea 1.0 Page { id: root - // Needs to be set and have rule.ruleActions filled in with deviceId and actionTypeId or interfaceName and interfaceAction + // Needs to be set and have rule.ruleActions filled in with thingId and actionTypeId or interfaceName and interfaceAction property RuleAction ruleAction: null // optionally a rule which will be used to propose events params as param values - property var rule: null + property Rule rule: null - readonly property Device device: ruleAction && ruleAction.deviceId ? engine.deviceManager.devices.getDevice(ruleAction.deviceId) : null + readonly property Thing thing: ruleAction && ruleAction.thingId ? engine.thingManager.things.getThing(ruleAction.thingId) : null readonly property var iface: ruleAction && ruleAction.interfaceName ? Interfaces.findByName(ruleAction.interfaceName) : null - readonly property var actionType: device ? device.deviceClass.actionTypes.getActionType(ruleAction.actionTypeId) + readonly property ActionType actionType: thing ? thing.thingClass.actionTypes.getActionType(ruleAction.actionTypeId) : iface ? iface.actionTypes.findByName(ruleAction.interfaceAction) : null signal backPressed(); @@ -86,7 +86,7 @@ Page { property alias value: paramDelegate.value property alias eventType: eventParamsComboBox.eventType property alias eventParamTypeId: eventParamsComboBox.currentParamTypeId - property alias stateDeviceId: statePickerDelegate.deviceId + property alias stateThingId: statePickerDelegate.thingId property alias stateTypeId: statePickerDelegate.stateTypeId GroupBox { @@ -134,25 +134,26 @@ Page { id: eventParamsComboBox Layout.fillWidth: true visible: eventParamRadioButton.checked && count > 0 - Component.onCompleted: currentIndex = 0; property var eventDescriptor: root.rule.eventDescriptors.count === 1 ? root.rule.eventDescriptors.get(0) : null - property var device: eventDescriptor ? engine.deviceManager.devices.getDevice(eventDescriptor.deviceId) : null - property var deviceClass: device ? engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId) : null - property var eventType: deviceClass ? deviceClass.eventTypes.getEventType(eventDescriptor.eventTypeId) : null + property Thing thing: eventDescriptor ? engine.thingManager.things.getThing(eventDescriptor.thingId) : null + property EventType eventType: thing ? thing.thingClass.eventTypes.getEventType(eventDescriptor.eventTypeId) : null property var currentParamDescriptor: eventType.paramTypes.get(eventParamsComboBox.currentIndex) property var currentParamTypeId: currentParamDescriptor.id + Component.onCompleted: { + currentIndex = 0; + } model: eventType.paramTypes delegate: ItemDelegate { width: parent.width - text: eventParamsComboBox.device.name + " - " + eventParamsComboBox.eventType.displayName + " - " + eventParamsComboBox.eventType.paramTypes.getParamType(model.id).displayName + text: eventParamsComboBox.thing.name + " - " + eventParamsComboBox.eventType.displayName + " - " + eventParamsComboBox.eventType.paramTypes.getParamType(model.id).displayName } contentItem: Label { id: eventParamsComboBoxContentItem anchors.fill: parent anchors.margins: app.margins - text: eventParamsComboBox.device.name + " - " + eventParamsComboBox.eventType.displayName + " - " + eventParamsComboBox.currentParamDescriptor.displayName + text: eventParamsComboBox.thing.name + " - " + eventParamsComboBox.eventType.displayName + " - " + eventParamsComboBox.currentParamDescriptor.displayName elide: Text.ElideRight } } @@ -160,22 +161,22 @@ Page { NymeaSwipeDelegate { id: statePickerDelegate Layout.fillWidth: true - text: deviceId === null || stateTypeId === null + text: thingId === null || stateTypeId === null ? qsTr("Select a state") - : dev.name + " - " + dev.deviceClass.stateTypes.getStateType(stateTypeId).displayName + : dev.name + " - " + thing.thingClass.stateTypes.getStateType(stateTypeId).displayName visible: stateValueRadioButton.checked - property var deviceId: null + property var thingId: null property var stateTypeId: null - readonly property Device dev: engine.deviceManager.devices.getDevice(deviceId) + readonly property Thing thing: engine.thingManager.things.getThing(thingId) onClicked: { var page = pageStack.push(Qt.resolvedUrl("SelectThingPage.qml"), {showStates: true, showEvents: false, showActions: false }); - page.thingSelected.connect(function(device) { - print("Thing selected", device.name); - statePickerDelegate.deviceId = device.id - var selectStatePage = pageStack.replace(Qt.resolvedUrl("SelectStatePage.qml"), {device: device}) + page.thingSelected.connect(function(thing) { + print("Thing selected", thing.name); + statePickerDelegate.thingId = thing.id + var selectStatePage = pageStack.replace(Qt.resolvedUrl("SelectStatePage.qml"), {thing: thing}) selectStatePage.stateSelected.connect(function(stateTypeId) { print("State selected", stateTypeId) pageStack.pop(); @@ -217,10 +218,10 @@ Page { var params = []; for (var i = 0; i < delegateRepeater.count; i++) { var paramDelegate = delegateRepeater.itemAt(i); - print("Working on parameter", paramDelegate.paramType, paramDelegate.paramType.id, paramDelegate.value, paramDelegate.eventType, paramDelegate.eventParamTypeId, paramDelegate.stateDeviceId, paramDelegate.stateTypeId) + print("Working on parameter", paramDelegate.paramType, paramDelegate.paramType.id, paramDelegate.value, paramDelegate.eventType, paramDelegate.eventParamTypeId, paramDelegate.stateThingId, paramDelegate.stateTypeId) if (paramDelegate.type === "static") { - if (root.device) { + if (root.thing) { print("Setting static value rule action param", paramDelegate.paramType.id, paramDelegate.value) root.ruleAction.ruleActionParams.setRuleActionParam(paramDelegate.paramType.id, paramDelegate.value) } else if (root.iface) { @@ -228,7 +229,7 @@ Page { root.ruleAction.ruleActionParams.setRuleActionParamByName(root.actionType.paramTypes.get(i).name, paramDelegate.value) } } else if (paramDelegate.type === "event") { - if (root.device) { + if (root.thing) { print("adding event based rule action param", paramDelegate.paramType.id, paramDelegate.eventType.id, paramDelegate.eventParamTypeId) root.ruleAction.ruleActionParams.setRuleActionParamEvent(paramDelegate.paramType.id, paramDelegate.eventType.id, paramDelegate.eventParamTypeId) } else if (root.iface) { @@ -236,12 +237,12 @@ Page { root.ruleAction.ruleActionParams.setRuleActionParamEventByName(root.actionType.paramTypes.get(i).name, paramDelegate.eventType.id, paramDelegate.eventParamTypeId) } } else if (paramDelegate.type === "state") { - if (root.device) { - print("adding state value based rule action param", paramDelegate.paramType.id, paramDelegate.stateDeviceId, paramDelegate.stateTypeId) - root.ruleAction.ruleActionParams.setRuleActionParamState(paramDelegate.paramType.id, paramDelegate.stateDeviceId, paramDelegate.stateTypeId) + if (root.thing) { + print("adding state value based rule action param", paramDelegate.paramType.id, paramDelegate.stateThingId, paramDelegate.stateTypeId) + root.ruleAction.ruleActionParams.setRuleActionParamState(paramDelegate.paramType.id, paramDelegate.stateThingId, paramDelegate.stateTypeId) } else if (root.iface) { - print("adding state value based rule action param by name", root.actionType.paramTypes.get(i).name, paramDelegate.stateDeviceId, paramDelegate.stateTypeId) - root.ruleAction.ruleActionParams.setRuleActionParamStateByName(root.actionType.paramTypes.get(i).name, paramDelegate.stateDeviceId, paramDelegate.stateTypeId) + print("adding state value based rule action param by name", root.actionType.paramTypes.get(i).name, paramDelegate.stateThingId, paramDelegate.stateTypeId) + root.ruleAction.ruleActionParams.setRuleActionParamStateByName(root.actionType.paramTypes.get(i).name, paramDelegate.stateThingId, paramDelegate.stateTypeId) } } } diff --git a/nymea-app/ui/magic/SelectStateDescriptorPage.qml b/nymea-app/ui/magic/SelectStateDescriptorPage.qml index 4edd3145..d6ac6b47 100644 --- a/nymea-app/ui/magic/SelectStateDescriptorPage.qml +++ b/nymea-app/ui/magic/SelectStateDescriptorPage.qml @@ -37,11 +37,10 @@ Page { id: root property alias text: header.text - // a ruleAction object needs to be set and prefilled with either deviceId or interfaceName + // a ruleAction object needs to be set and prefilled with either thingId or interfaceName property var stateDescriptor: null - readonly property var device: stateDescriptor && stateDescriptor.deviceId ? engine.deviceManager.devices.getDevice(stateDescriptor.deviceId) : null - readonly property var deviceClass: device ? engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId) : null + readonly property Thing thing: stateDescriptor && stateDescriptor.thingId ? engine.thingManager.things.getThing(stateDescriptor.thingId) : null signal backPressed(); signal done(); @@ -71,16 +70,16 @@ Page { function buildInterface() { print("building interface:", header.interfacesMode, root.stateDescriptor, root.stateDescriptor.interfaceName) if (header.interfacesMode) { - if (root.device) { + if (root.thing) { generatedModel.clear(); for (var i = 0; i < Interfaces.count; i++) { var iface = Interfaces.get(i); - if (root.deviceClass.interfaces.indexOf(iface.name) >= 0) { - print("root has device class:", iface.name, iface.stateTypes.count) + if (root.thing.thingClass.interfaces.indexOf(iface.name) >= 0) { + print("root has thing class:", iface.name, iface.stateTypes.count) for (var j = 0; j < iface.stateTypes.count; j++) { var ifaceSt = iface.stateTypes.get(j); print("ifaceSt:", ifaceSt, j, iface.stateTypes.count) - var dcSt = root.deviceClass.stateTypes.findByName(ifaceSt.name) + var dcSt = root.thing.thingClass.stateTypes.findByName(ifaceSt.name) print("adding:", ifaceSt.displayName, dcSt.id) generatedModel.append({displayName: ifaceSt.displayName, stateTypeId: dcSt.id}) } @@ -90,11 +89,11 @@ Page { } else if (root.stateDescriptor.interfaceName !== "") { listView.model = Interfaces.findByName(root.stateDescriptor.interfaceName).stateTypes } else { - console.warn("You need to set device or interfaceName"); + console.warn("You need to set thing or interfaceName"); } } else { - if (root.device) { - listView.model = deviceClass.stateTypes; + if (root.thing) { + listView.model = thingClass.stateTypes; } } } @@ -108,10 +107,10 @@ Page { width: parent.width onClicked: { if (header.interfacesMode) { - if (root.device) { + if (root.thing) { print("selected:", model.stateTypeId) root.stateDescriptor.stateTypeId = model.stateTypeId; - var stateType = root.deviceClass.stateTypes.getStateType(model.stateTypeId) + var stateType = root.thing.thingClass.stateTypes.getStateType(model.stateTypeId) var paramsPage = pageStack.push(Qt.resolvedUrl("SelectStateDescriptorParamsPage.qml"), {stateDescriptor: root.stateDescriptor}) paramsPage.onBackPressed.connect(function() {pageStack.pop()}); paramsPage.onCompleted.connect(function() { @@ -127,11 +126,11 @@ Page { root.done(); }) } else { - console.warn("Neither deviceId not interfaceName set. Cannot continue..."); + console.warn("Neither thingId not interfaceName set. Cannot continue..."); } } else { - if (root.device) { - var stateType = root.deviceClass.stateTypes.getStateType(model.id); + if (root.thing) { + var stateType = root.thingClass.stateTypes.getStateType(model.id); root.stateDescriptor.stateTypeId = model.id; var paramsPage = pageStack.push(Qt.resolvedUrl("SelectStateDescriptorParamsPage.qml"), {stateDescriptor: root.stateDescriptor}) paramsPage.onBackPressed.connect(function() {pageStack.pop()}); diff --git a/nymea-app/ui/magic/SelectStateDescriptorParamsPage.qml b/nymea-app/ui/magic/SelectStateDescriptorParamsPage.qml index 6a533629..87df3e32 100644 --- a/nymea-app/ui/magic/SelectStateDescriptorParamsPage.qml +++ b/nymea-app/ui/magic/SelectStateDescriptorParamsPage.qml @@ -37,12 +37,12 @@ import Nymea 1.0 Page { id: root - // Needs to be set and filled in with deviceId and eventTypeId + // Needs to be set and filled in with thingId and eventTypeId property var stateDescriptor: null - readonly property var device: stateDescriptor && stateDescriptor.deviceId ? engine.deviceManager.devices.getDevice(stateDescriptor.deviceId) : null + readonly property Thing thing: stateDescriptor && stateDescriptor.thingId ? engine.thingManager.things.getThing(stateDescriptor.thingId) : null readonly property var iface: stateDescriptor && stateDescriptor.interfaceName ? Interfaces.findByName(stateDescriptor.interfaceName) : null - readonly property var stateType: device ? engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId).stateTypes.getStateType(stateDescriptor.stateTypeId) + readonly property var stateType: thing ? thing.thingClass.stateTypes.getStateType(stateDescriptor.stateTypeId) : iface ? iface.stateTypes.findByName(stateDescriptor.interfaceState) : null signal backPressed(); diff --git a/nymea-app/ui/magic/SelectStatePage.qml b/nymea-app/ui/magic/SelectStatePage.qml index 3c9792ff..a815ce40 100644 --- a/nymea-app/ui/magic/SelectStatePage.qml +++ b/nymea-app/ui/magic/SelectStatePage.qml @@ -42,20 +42,20 @@ Page { onBackPressed: pageStack.pop() } - property Device device: null + property Thing thing: null signal stateSelected(var stateTypeId); ListView { anchors.fill: parent - model: device.deviceClass.stateTypes + model: thing.thingClass.stateTypes delegate: NymeaSwipeDelegate { width: parent.width iconName: "../images/state.svg" text: model.displayName - subText: root.device.states.getState(model.id).value + subText: root.thing.states.getState(model.id).value prominentSubText: false onClicked: { root.stateSelected(model.id) diff --git a/nymea-app/ui/magic/SelectThingPage.qml b/nymea-app/ui/magic/SelectThingPage.qml index 6e5d0f2c..c8e1af6b 100644 --- a/nymea-app/ui/magic/SelectThingPage.qml +++ b/nymea-app/ui/magic/SelectThingPage.qml @@ -42,16 +42,16 @@ Page { property alias showEvents: interfacesProxy.showEvents property alias showActions: interfacesProxy.showActions property alias showStates: interfacesProxy.showStates - property alias shownInterfaces: devicesProxy.shownInterfaces + property alias shownInterfaces: thingsProxy.shownInterfaces property bool allowSelectAny: false property bool multipleSelection: false - property alias requiredEventName: devicesProxy.requiredEventName - property alias requiredStateName: devicesProxy.requiredStateName - property alias requiredActionName: devicesProxy.requiredActionName + property alias requiredEventName: thingsProxy.requiredEventName + property alias requiredStateName: thingsProxy.requiredStateName + property alias requiredActionName: thingsProxy.requiredActionName signal backPressed(); - signal thingSelected(var device); - signal thingsSelected(var devices); + signal thingSelected(var thing); + signal thingsSelected(var thing); signal interfaceSelected(string interfaceName); signal anySelected(); @@ -73,13 +73,13 @@ Page { thingsFilter: engine.thingManager.things } - DevicesProxy { - id: devicesProxy + ThingsProxy { + id: thingsProxy engine: _engine groupByInterface: true nameFilter: filterInput.shown ? filterInput.text : "" Component.onCompleted: { - print("showing devices for interfaces", devicesProxy.shownInterfaces) + print("showing things for interfaces", thingsProxy.shownInterfaces) } } @@ -105,18 +105,18 @@ Page { id: listView Layout.fillWidth: true Layout.fillHeight: true - model: root.selectInterface ? interfacesProxy : devicesProxy + model: root.selectInterface ? interfacesProxy : thingsProxy clip: true property var checkBoxCache: ({}) - function toggleCheckBoxCache(deviceId) { + function toggleCheckBoxCache(thingId) { var newCache = listView.checkBoxCache; - if (!newCache.hasOwnProperty(deviceId) || !newCache[deviceId]) { - newCache[deviceId] = true + if (!newCache.hasOwnProperty(thingId) || !newCache[thingId]) { + newCache[thingId] = true } else { - newCache[deviceId] = false + newCache[thingId] = false } listView.checkBoxCache = newCache; - print("new checked state;", newCache[deviceId]) + print("new checked state;", newCache[thingId]) } delegate: NymeaSwipeDelegate { @@ -127,7 +127,7 @@ Page { if (root.selectInterface) { root.interfaceSelected(interfacesProxy.get(index).name) } else if (!root.multipleSelection) { - root.thingSelected(devicesProxy.get(index)) + root.thingSelected(thingsProxy.get(index)) } else { listView.toggleCheckBoxCache(model.id) } @@ -151,14 +151,14 @@ Page { text: qsTr("OK") visible: root.multipleSelection onClicked: { - var devices = [] - for (var i = 0; i < devicesProxy.count; i++) { - var device = devicesProxy.get(i); - if (listView.checkBoxCache.hasOwnProperty(device.id) && listView.checkBoxCache[device.id]) { - devices.push(device) + var things = [] + for (var i = 0; i < thingsProxy.count; i++) { + var thing = thingsProxy.get(i); + if (listView.checkBoxCache.hasOwnProperty(thing.id) && listView.checkBoxCache[thing.id]) { + things.push(thing) } } - root.thingsSelected(devices) + root.thingsSelected(things) } } } diff --git a/nymea-app/ui/magic/SimpleStateEvaluatorDelegate.qml b/nymea-app/ui/magic/SimpleStateEvaluatorDelegate.qml index 6a9d5741..f917e11b 100644 --- a/nymea-app/ui/magic/SimpleStateEvaluatorDelegate.qml +++ b/nymea-app/ui/magic/SimpleStateEvaluatorDelegate.qml @@ -42,10 +42,9 @@ SwipeDelegate { property var stateEvaluator: null property bool showChilds: false - readonly property var device: stateEvaluator ? engine.deviceManager.devices.getDevice(stateEvaluator.stateDescriptor.deviceId) : null - readonly property var deviceClass: device ? engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId) : null + readonly property Thing thing: stateEvaluator ? engine.thingManager.things.getThing(stateEvaluator.stateDescriptor.thingId) : null readonly property var iface: stateEvaluator ? Interfaces.findByName(stateEvaluator.stateDescriptor.interfaceName) : null - readonly property var stateType: deviceClass ? deviceClass.stateTypes.getStateType(stateEvaluator.stateDescriptor.stateTypeId) + readonly property var stateType: thing ? thing.thingClass.stateTypes.getStateType(stateEvaluator.stateDescriptor.stateTypeId) : iface ? iface.stateTypes.findByName(stateEvaluator.stateDescriptor.interfaceState) : null signal deleteClicked(); @@ -104,8 +103,8 @@ SwipeDelegate { break; } - if (root.device) { - return qsTr("%1: %2 %3 %4").arg(root.device.name).arg(root.stateType.displayName).arg(operatorString).arg(valueText) + if (root.thing) { + return qsTr("%1: %2 %3 %4").arg(root.thing.name).arg(root.stateType.displayName).arg(operatorString).arg(valueText) } else if (root.iface) { return qsTr("%1: %2 %3 %4").arg(root.iface.displayName).arg(root.stateType.displayName).arg(operatorString).arg(valueText) } @@ -123,10 +122,9 @@ SwipeDelegate { property var stateEvaluator: root.stateEvaluator.childEvaluators.get(index) property var stateDescriptor: stateEvaluator.stateDescriptor - readonly property var device: engine.deviceManager.devices.getDevice(stateDescriptor.deviceId) - readonly property var deviceClass: device ? engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId) : null + readonly property Thing thing: engine.thingManager.things.getThing(stateDescriptor.thingId) readonly property var iface: Interfaces.findByName(stateEvaluator.stateDescriptor.interfaceName) - readonly property var stateType: device ? deviceClass.stateTypes.getStateType(stateDescriptor.stateTypeId) + readonly property var stateType: thing ? thing.thingClass.stateTypes.getStateType(stateDescriptor.stateTypeId) : iface ? iface.stateTypes.findByName(stateEvaluator.stateDescriptor.interfaceState) : null @@ -157,7 +155,7 @@ SwipeDelegate { } return "FIXME" } - text: device ? ("%1 %2: %3 %4 %5%6").arg(root.stateEvaluator.stateOperator === StateEvaluator.StateOperatorAnd ? "and" : "or").arg(childEvaluatorDelegate.device.name).arg(childEvaluatorDelegate.stateType.displayName).arg(operatorString).arg(childEvaluatorDelegate.stateDescriptor.value).arg(childEvaluatorDelegate.stateEvaluator.childEvaluators.count > 0 ? "..." : "") + text: thing ? ("%1 %2: %3 %4 %5%6").arg(root.stateEvaluator.stateOperator === StateEvaluator.StateOperatorAnd ? "and" : "or").arg(childEvaluatorDelegate.thing.name).arg(childEvaluatorDelegate.stateType.displayName).arg(operatorString).arg(childEvaluatorDelegate.stateDescriptor.value).arg(childEvaluatorDelegate.stateEvaluator.childEvaluators.count > 0 ? "..." : "") : iface ? ("%1 %2: %3 %4 %5%6").arg(root.stateEvaluator.stateOperator === StateEvaluator.StateOperatorAnd ? "and" : "or").arg(childEvaluatorDelegate.iface.displayName).arg(childEvaluatorDelegate.stateType.displayName).arg(operatorString).arg(childEvaluatorDelegate.stateDescriptor.value).arg(childEvaluatorDelegate.stateEvaluator.childEvaluators.count > 0 ? "..." : "") : "???" } diff --git a/nymea-app/ui/magic/StateEvaluatorDelegate.qml b/nymea-app/ui/magic/StateEvaluatorDelegate.qml index e18d2139..8c7e5896 100644 --- a/nymea-app/ui/magic/StateEvaluatorDelegate.qml +++ b/nymea-app/ui/magic/StateEvaluatorDelegate.qml @@ -38,9 +38,8 @@ ItemDelegate { id: root property var stateEvaluator: null - readonly property var device: stateEvaluator ? engine.deviceManager.devices.getDevice(stateEvaluator.stateDescriptor.deviceId) : null - readonly property var deviceClass: device ? engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId) : null - readonly property var stateType: deviceClass ? deviceClass.stateTypes.getStateType(stateEvaluator.stateDescriptor.stateTypeId) : null + readonly property Thing thing: stateEvaluator ? engine.thingManager.things.getThing(stateEvaluator.stateDescriptor.thingId) : null + readonly property StateType stateType: thing ? thing.thingClass.stateTypes.getStateType(stateEvaluator.stateDescriptor.stateTypeId) : null property bool canDelete: true signal deleteClicked() @@ -54,13 +53,13 @@ ItemDelegate { page.backPressed.connect(function() { pageStack.pop() }) - page.thingSelected.connect(function(device) { + page.thingSelected.connect(function(thing) { root.stateEvaluator.stateDescriptor.interfaceName = ""; - root.stateEvaluator.stateDescriptor.deviceId = device.id; + root.stateEvaluator.stateDescriptor.thingId = thing.id; selectStateDescriptorData() }); page.interfaceSelected.connect(function(interfaceName) { - root.stateEvaluator.stateDescriptor.deviceId = ""; + root.stateEvaluator.stateDescriptor.thingId = ""; root.stateEvaluator.stateDescriptor.interfaceName = interfaceName; selectStateDescriptorData(); }); diff --git a/nymea-app/ui/magic/DeviceRulesPage.qml b/nymea-app/ui/magic/ThingRulesPage.qml similarity index 89% rename from nymea-app/ui/magic/DeviceRulesPage.qml rename to nymea-app/ui/magic/ThingRulesPage.qml index 854e8d80..c9d51631 100644 --- a/nymea-app/ui/magic/DeviceRulesPage.qml +++ b/nymea-app/ui/magic/ThingRulesPage.qml @@ -38,13 +38,9 @@ Page { id: root property Thing thing: null - property alias device: root.thing - - Component.onCompleted: print("+++ created devicerulespage") - Component.onDestruction: print("--- destroying devicerulespage") header: NymeaHeader { - text: qsTr("Magic involving %1").arg(root.device.name) + text: qsTr("Magic involving %1").arg(root.thing.name) onBackPressed: pageStack.pop() HeaderButton { @@ -57,18 +53,17 @@ Page { RuleTemplatesFilterModel { id: ruleTemplatesModel ruleTemplates: RuleTemplates {} - readonly property var deviceClass: device ? engine.deviceManager.deviceClasses.getDeviceClass(root.device.deviceClassId) : null - filterByDevices: DevicesProxy { engine: _engine } - filterInterfaceNames: deviceClass ? deviceClass.interfaces : [] + filterByThings: ThingsProxy { engine: _engine } + filterInterfaceNames: root.thing ? root.thing.thingClass.interfaces : [] } // Rule is optional and might be initialized with anything wanted. A new, empty one will be created if null // This Page will take ownership of the rule and delete it eventually. function addRule(rule) { if (rule === null || rule === undefined) { - print("creating new rule. have", ruleTemplatesModel.count, "templates", ruleTemplatesModel.deviceClass.interfaces) + print("creating new rule. have", ruleTemplatesModel.count, "templates", root.thing.thingClass.interfaces) if (ruleTemplatesModel.count > 0) { - d.editRulePage = pageStack.push(Qt.resolvedUrl("NewThingMagicPage.qml"), {device: root.device}); + d.editRulePage = pageStack.push(Qt.resolvedUrl("NewThingMagicPage.qml"), {thing: root.thing}); d.editRulePage.manualCreation.connect(function() { pageStack.pop(); rule = engine.ruleManager.createNewRule(); @@ -78,7 +73,7 @@ Page { return; } rule = engine.ruleManager.createNewRule(); - d.editRulePage = pageStack.push(Qt.resolvedUrl("EditRulePage.qml"), {rule: rule, initialDeviceToBeAdded: root.device}); + d.editRulePage = pageStack.push(Qt.resolvedUrl("EditRulePage.qml"), {rule: rule, initialDeviceToBeAdded: root.thing}); } else { d.editRulePage = pageStack.push(Qt.resolvedUrl("EditRulePage.qml"), {rule: rule}); } @@ -96,7 +91,7 @@ Page { // if (rule.eventDescriptors.count === 0) { // var eventDescriptor = rule.eventDescriptors.createNewEventDescriptor(); - // eventDescriptor.deviceId = device.id; + // eventDescriptor.thingId = thing.id; // page.selectEventDescriptorData(eventDescriptor); // } @@ -139,7 +134,7 @@ Page { model: RulesFilterModel { id: rulesFilterModel rules: engine.ruleManager.rules - filterDeviceId: root.device.id + filterThingId: root.thing.id } delegate: NymeaSwipeDelegate { @@ -181,7 +176,7 @@ Page { width: parent.width wrapMode: Text.WordWrap horizontalAlignment: Text.AlignHCenter - text: qsTr("There's no magic involving %1.").arg(root.device.name) + text: qsTr("There's no magic involving %1.").arg(root.thing.name) font.pixelSize: app.largeFont color: Style.accentColor } diff --git a/nymea-app/ui/mainviews/FavoritesView.qml b/nymea-app/ui/mainviews/FavoritesView.qml index 5b8f29ef..644cd740 100644 --- a/nymea-app/ui/mainviews/FavoritesView.qml +++ b/nymea-app/ui/mainviews/FavoritesView.qml @@ -64,10 +64,10 @@ MainViewBase { id: delegateRoot width: gridView.cellWidth height: gridView.cellHeight - device: engine.deviceManager.devices.getDevice(deviceId) - visible: thingId !== fakeDragItem.deviceId + thing: engine.thingManager.things.getThing(thingId) + visible: thingId !== fakeDragItem.thingId - onClicked: pageStack.push(Qt.resolvedUrl("../devicepages/" + NymeaUtils.interfaceListToDevicePage(deviceClass.interfaces)), {device: device}) + onClicked: pageStack.push(Qt.resolvedUrl("../devicepages/" + NymeaUtils.interfaceListToDevicePage(thing.thingClass.interfaces)), {thing: thing}) onPressAndHold: root.editMode = true @@ -79,8 +79,6 @@ MainViewBase { NumberAnimation { from: 3; to: -3; target: delegateRoot; duration: 150; property: "rotation" } NumberAnimation { from: -3; to: 0; target: delegateRoot; duration: 75; property: "rotation" } } - - } MouseArea { @@ -100,7 +98,7 @@ MainViewBase { fakeDragItem.text = item.text fakeDragItem.iconName = item.iconName fakeDragItem.iconColor = item.iconColor; - fakeDragItem.deviceId = item.device.id + fakeDragItem.thingId = item.thing.id fakeDragItem.batteryCritical = item.batteryCritical fakeDragItem.disconnected = item.disconnected drag.target = fakeDragItem @@ -108,7 +106,7 @@ MainViewBase { onReleased: { drag.target = null draggedItem = null - fakeDragItem.deviceId = "" + fakeDragItem.thingId = "" } onClicked: { @@ -121,8 +119,8 @@ MainViewBase { width: gridView.cellWidth height: gridView.cellHeight Drag.active: dragArea.drag.active - visible: deviceId !== "" - property var deviceId: "" + visible: thingId !== "" + property var thingId: "" } DropArea { @@ -172,13 +170,13 @@ MainViewBase { EmptyViewPlaceholder { anchors { left: parent.left; right: parent.right; margins: app.margins } anchors.verticalCenter: parent.verticalCenter - visible: gridView.count === 0 && !engine.deviceManager.fetchingData + visible: gridView.count === 0 && !engine.thingManager.fetchingData title: qsTr("There are no favorite things yet.") - text: engine.deviceManager.devices.count === 0 ? + text: engine.thingManager.things.count === 0 ? qsTr("It appears there are no things set up either yet. In order to use favorites you need to add some things first.") : qsTr("Favorites allow you to keep track of your most important things when you have lots of them. Watch out for the star when interacting with things and use it to mark them as your favorites.") imageSource: "../images/starred.svg" - buttonVisible: engine.deviceManager.devices.count === 0 + buttonVisible: engine.thingManager.things.count === 0 buttonText: qsTr("Add things") onButtonClicked: pageStack.push(Qt.resolvedUrl("../thingconfiguration/NewThingPage.qml")) } diff --git a/nymea-app/ui/mainviews/GaragesView.qml b/nymea-app/ui/mainviews/GaragesView.qml index ba97a708..48c89bc7 100644 --- a/nymea-app/ui/mainviews/GaragesView.qml +++ b/nymea-app/ui/mainviews/GaragesView.qml @@ -41,7 +41,7 @@ MainViewBase { readonly property bool landscape: width > height - DevicesProxy { + ThingsProxy { id: garagesFilterModel engine: _engine shownInterfaces: ["garagedoor", "garagegate"] diff --git a/nymea-app/ui/mainviews/GroupsView.qml b/nymea-app/ui/mainviews/GroupsView.qml index 3acb49ae..fdb07a49 100644 --- a/nymea-app/ui/mainviews/GroupsView.qml +++ b/nymea-app/ui/mainviews/GroupsView.qml @@ -70,236 +70,13 @@ MainViewBase { } } - 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 ? Style.accentColor : Style.iconColor - - 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; - } - - 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}]) - } - } - } - } - } - } - - Component { - id: lightDelegate - RowLayout { - property var devices - - DevicesProxy { - id: lights - engine: _engine - parentProxy: devices - shownInterfaces: ["light"] - } - - DevicesProxy { - id: dimmableLights - engine: _engine - parentProxy: devices - shownInterfaces: ["dimmablelight"] - } - - Label { - text: qsTr("Lighting") - Layout.fillWidth: true - Layout.preferredHeight: slider.height - verticalAlignment: Text.AlignVCenter - visible: dimmableLights.count == 0 - } - - Slider { - id: slider - from: 0 - to: 100 - visible: dimmableLights.count > 0 - value: { - var median = 0 - var count = 0; - for (var i = 0; i < dimmableLights.count; i++) { - var device = dimmableLights.get(i); - var brightnessId = device.deviceClass.stateTypes.findByName("brightness").id - median += device.states.getState(brightnessId).value - count++ - } - return median / count; - } - - Layout.fillWidth: true - onPressedChanged: { - for (var i = 0; i < dimmableLights.count; i++) { - var device = dimmableLights.get(i); - var brightnessId = device.deviceClass.actionTypes.findByName("brightness").id - engine.deviceManager.executeAction(device.id, brightnessId, [{paramTypeId: brightnessId, value: value}]); - } - } - } - ColorIcon { - Layout.preferredHeight: app.iconSize - Layout.preferredWidth: app.iconSize - name: isOn ? "../images/light-on.svg" : "../images/light-off.svg" - color: isOn ? Style.accentColor : Style.iconColor - - property bool isOn: { - for (var i = 0; i < lights.count; i++) { - var device = lights.get(i) - var powerId = device.deviceClass.stateTypes.findByName("power").id - if (device.states.getState(powerId).value === true) { - return true - } - } - return false; - } - - MouseArea { - anchors.fill: parent - onClicked: { - for (var i = 0; i < lights.count; i++) { - var device = lights.get(i) - var powerId = device.deviceClass.stateTypes.findByName("power").id - engine.deviceManager.executeAction(device.id, powerId, [{paramTypeId: powerId, value: !parent.isOn}]) - } - } - } - } - } - } - - Component { - id: closableDelegate - - RowLayout { - - property var devices: null - DevicesProxy { - id: simpleClosables - engine: _engine - parentProxy: devices - shownInterfaces: ["simpleclosable"] - } - DevicesProxy { - id: closables - engine: _engine - parentProxy: devices - shownInterfaces: ["closable"] - } - - ItemDelegate { - Layout.fillWidth: true - Layout.preferredHeight: app.iconSize - - ColorIcon { - height: parent.height - width: height - anchors.centerIn: parent - name: Qt.resolvedUrl("../images/up.svg") - } - onClicked: { - for (var i = 0; i < simpleClosables.count; i++) { - var device = simpleClosables.get(i) - var openId = device.deviceClass.actionTypes.findByName("open").id - engine.deviceManager.executeAction(device.id, openId) - } - } - } - ItemDelegate { - Layout.fillWidth: true - Layout.preferredHeight: app.iconSize - visible: closables.count > 0 - - ColorIcon { - height: parent.height - width: height - anchors.centerIn: parent - name: Qt.resolvedUrl("../images/media-playback-stop.svg") - } - onClicked: { - for (var i = 0; i < closables.count; i++) { - var device = closables.get(i) - var openId = device.deviceClass.actionTypes.findByName("stop").id - engine.deviceManager.executeAction(device.id, openId) - } - } - } - ItemDelegate { - Layout.fillWidth: true - Layout.preferredHeight: app.iconSize - - ColorIcon { - height: parent.height - width: height - anchors.centerIn: parent - name: Qt.resolvedUrl("../images/down.svg") - } - onClicked: { - for (var i = 0; i < simpleClosables.count; i++) { - var device = simpleClosables.get(i) - var closeId = device.deviceClass.actionTypes.findByName("close").id - engine.deviceManager.executeAction(device.id, closeId) - } - } - } - } - } - - Component { - id: mediaControllerDelegate - MediaControls { - property var devices: null - DevicesProxy { - id: mediaControllers - engine: _engine - parentProxy: devices - shownInterfaces: ["mediacontroller"] - } - - // involve count in the statement to make the binding re-evaluate when the group is changed - thing: mediaControllers.count > 0 ? mediaControllers.get(0) : null - } - } - EmptyViewPlaceholder { anchors { left: parent.left; right: parent.right; margins: app.margins } anchors.verticalCenter: parent.verticalCenter - visible: groupsGridView.count == 0 && !engine.deviceManager.fetchingData && !engine.tagsManager.busy + visible: groupsGridView.count == 0 && !engine.thingManager.fetchingData && !engine.tagsManager.busy title: qsTr("There are no groups set up yet.") text: qsTr("Grouping things can be useful to control multiple devices at once, for example an entire room. Watch out for the group symbol when interacting with things and use it to add them to groups.") imageSource: "../images/view-grid-symbolic.svg" buttonVisible: false } - } diff --git a/nymea-app/ui/mainviews/ScenesView.qml b/nymea-app/ui/mainviews/ScenesView.qml index e2cc7ca2..ea9bf399 100644 --- a/nymea-app/ui/mainviews/ScenesView.qml +++ b/nymea-app/ui/mainviews/ScenesView.qml @@ -80,15 +80,15 @@ MainViewBase { EmptyViewPlaceholder { anchors { left: parent.left; right: parent.right; margins: app.margins } anchors.verticalCenter: parent.verticalCenter - visible: interfacesGridView.count === 0 && !engine.deviceManager.fetchingData + visible: interfacesGridView.count === 0 && !engine.thingManager.fetchingData title: qsTr("There are no scenes set up yet.") - text: engine.deviceManager.devices.count === 0 ? + text: engine.thingManager.things.count === 0 ? qsTr("It appears there are no things set up either yet. In order to use scenes you need to add some things first.") : qsTr("Scenes provide a useful way to control your things with just one click.") imageSource: "../images/slideshow.svg" - buttonText: engine.deviceManager.devices.count === 0 ? qsTr("Add things") : qsTr("Add scenes") + buttonText: engine.thingManager.things.count === 0 ? qsTr("Add things") : qsTr("Add scenes") onButtonClicked: { - if (engine.deviceManager.devices.count === 0) { + if (engine.thingManager.things.count === 0) { pageStack.push(Qt.resolvedUrl("../thingconfiguration/NewThingPage.qml")) } else { var newRule = engine.ruleManager.createNewRule(); @@ -107,5 +107,4 @@ MainViewBase { } } } - } diff --git a/nymea-app/ui/mainviews/ThingsView.qml b/nymea-app/ui/mainviews/ThingsView.qml index 55aca788..13c07a7a 100644 --- a/nymea-app/ui/mainviews/ThingsView.qml +++ b/nymea-app/ui/mainviews/ThingsView.qml @@ -43,7 +43,7 @@ MainViewBase { id: mainModel interfacesModel: InterfacesModel { engine: _engine - things: DevicesProxy { + things: ThingsProxy { engine: _engine } shownInterfaces: app.supportedInterfaces @@ -72,7 +72,7 @@ MainViewBase { EmptyViewPlaceholder { anchors { left: parent.left; right: parent.right; margins: app.margins } anchors.verticalCenter: parent.verticalCenter - visible: engine.deviceManager.devices.count === 0 && !engine.deviceManager.fetchingData + visible: engine.thingManager.things.count === 0 && !engine.thingManager.fetchingData title: qsTr("Welcome to %1!").arg(app.systemName) // Have that split in 2 because we need those strings separated in EditDevicesPage too and don't want translators to do them twice text: qsTr("There are no things set up yet.") + "\n" + qsTr("In order for your %1 system to be useful, go ahead and add some things.").arg(app.systemName) diff --git a/nymea-app/ui/system/LogViewerPage.qml b/nymea-app/ui/system/LogViewerPage.qml index 7e1c9cac..a65e116d 100644 --- a/nymea-app/ui/system/LogViewerPage.qml +++ b/nymea-app/ui/system/LogViewerPage.qml @@ -87,8 +87,7 @@ Page { delegate: ItemDelegate { id: delegate width: parent.width - property var device: engine.deviceManager.devices.getDevice(model.deviceId) - property var deviceClass: device ? engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId) : null + property Thing thing: engine.thingManager.things.getThing(model.thingId) leftPadding: 0 rightPadding: 0 topPadding: 0 @@ -137,7 +136,7 @@ Page { qsTr("%1 Server").arg(app.systemName) : model.source === LogEntry.LoggingSourceRules ? engine.ruleManager.rules.getRule(model.typeId).name - : delegate.device.name + : delegate.thing.name elide: Text.ElideRight } Label { @@ -150,14 +149,14 @@ Page { text : { switch (model.source) { case LogEntry.LoggingSourceStates: - var stateType = delegate.deviceClass.stateTypes.getStateType(model.typeId); + var stateType = delegate.thing.thingClass.stateTypes.getStateType(model.typeId); return "%1 -> %2 %3".arg(stateType.displayName).arg(Types.toUiValue(model.value, stateType.unit)).arg(Types.toUiUnit(stateType.unit)); case LogEntry.LoggingSourceSystem: return model.loggingEventType === LogEntry.LoggingEventTypeActiveChange ? qsTr("System started") : "N/A" case LogEntry.LoggingSourceActions: - return "%1 (%2)".arg(delegate.deviceClass.actionTypes.getActionType(model.typeId).displayName).arg(model.value); + return "%1 (%2)".arg(delegate.thing.thingClass.actionTypes.getActionType(model.typeId).displayName).arg(model.value); case LogEntry.LoggingSourceEvents: - return "%1 (%2)".arg(delegate.deviceClass.eventTypes.getEventType(model.typeId).displayName).arg(model.value); + return "%1 (%2)".arg(delegate.thing.thingClass.eventTypes.getEventType(model.typeId).displayName).arg(model.value); case LogEntry.LoggingSourceRules: switch (model.loggingEventType) { case LogEntry.LoggingEventTypeTrigger: diff --git a/nymea-app/ui/system/PluginParamsPage.qml b/nymea-app/ui/system/PluginParamsPage.qml index 8a2ca538..890d4a75 100644 --- a/nymea-app/ui/system/PluginParamsPage.qml +++ b/nymea-app/ui/system/PluginParamsPage.qml @@ -48,19 +48,19 @@ SettingsPageBase { HeaderButton { imageSource: "../images/tick.svg" onClicked: { - engine.deviceManager.savePluginConfig(root.plugin.pluginId) + engine.thingManager.savePluginConfig(root.plugin.pluginId) } } } Connections { - target: engine.deviceManager + target: engine.thingManager onSavePluginConfigReply: { - if (params.deviceError === "DeviceErrorNoError") { + if (thingError === Thing.ThingErrorNoError) { pageStack.pop(); } else { - console.warn("Error saving plugin params:", JSON.stringify(params)) - var dialog = errorDialog.createObject(root, {errorCode: params.deviceError}); + console.warn("Error saving plugin params:", thingError) + var dialog = errorDialog.createObject(root, {error: thingError}); dialog.open(); } } diff --git a/nymea-app/ui/system/PluginsPage.qml b/nymea-app/ui/system/PluginsPage.qml index b1669ced..2630ed1e 100644 --- a/nymea-app/ui/system/PluginsPage.qml +++ b/nymea-app/ui/system/PluginsPage.qml @@ -58,7 +58,7 @@ SettingsPageBase { Repeater { model: PluginsProxy { id: pluginsProxy - plugins: engine.deviceManager.plugins + plugins: engine.thingManager.plugins } delegate: NymeaSwipeDelegate { diff --git a/nymea-app/ui/thingconfiguration/ConfigureThingPage.qml b/nymea-app/ui/thingconfiguration/ConfigureThingPage.qml index b6e675b4..749b67ff 100644 --- a/nymea-app/ui/thingconfiguration/ConfigureThingPage.qml +++ b/nymea-app/ui/thingconfiguration/ConfigureThingPage.qml @@ -38,11 +38,9 @@ import "../delegates" SettingsPageBase { id: root property Thing thing: null - property alias device: root.thing - readonly property DeviceClass deviceClass: device ? device.deviceClass : null header: NymeaHeader { - text: root.device.name + text: root.thing.name onBackPressed: pageStack.pop() HeaderButton { @@ -66,12 +64,12 @@ SettingsPageBase { deviceMenu.addItem(menuEntryComponent.createObject(deviceMenu, {text: qsTr("Rename"), iconSource: "../images/edit.svg", functionName: "renameThing"})) // FIXME: This isn't entirely correct... we should have a way to know if a particular thing is in fact autocreated // This check might be wrong for thingClasses with multiple create methods... - if (!root.device.isChild || root.deviceClass.createMethods.indexOf("CreateMethodAuto") < 0) { + if (!root.thing.isChild || root.thing.thingClass.createMethods.indexOf("CreateMethodAuto") < 0) { deviceMenu.addItem(menuEntryComponent.createObject(deviceMenu, {text: qsTr("Delete"), iconSource: "../images/delete.svg", functionName: "deleteThing"})) } // FIXME: This isn't entirely correct... we should have a way to know if a particular thing is in fact autocreated // This check might be wrong for thingClasses with multiple create methods... - if (!root.device.isChild || root.deviceClass.createMethods.indexOf("CreateMethodAuto") < 0) { + if (!root.thing.isChild || root.thingClass.createMethods.indexOf("CreateMethodAuto") < 0) { deviceMenu.addItem(menuEntryComponent.createObject(deviceMenu, {text: qsTr("Reconfigure"), iconSource: "../images/configure.svg", functionName: "reconfigureThing"})) } } @@ -82,11 +80,11 @@ SettingsPageBase { } function deleteThing() { - engine.thingManager.removeThing(root.device.id) + engine.thingManager.removeThing(root.thing.id) } function reconfigureThing() { - var configPage = pageStack.push(Qt.resolvedUrl("SetupWizard.qml"), {device: root.device}) + var configPage = pageStack.push(Qt.resolvedUrl("SetupWizard.qml"), {thing: root.thing}) configPage.done.connect(function() {pageStack.pop(root)}) } @@ -102,16 +100,17 @@ SettingsPageBase { Connections { target: engine.thingManager onRemoveThingReply: { - switch (params.deviceError) { - case "DeviceErrorNoError": + switch (thingError) { + case Thing.ThingErrorNoError: pageStack.pop(); return; - case "DeviceErrorDeviceInRule": - var popup = removeMethodComponent.createObject(root, {device: root.device, rulesList: params["ruleIds"]}); + case Thing.ThingErrorThingInRule: + var removeMethodComponent = Qt.createComponent(Qt.resolvedUrl("../components/RemoveThingMethodDialog.qml")) + var popup = removeMethodComponent.createObject(root, {thing: root.thing, rulesList: ruleIds}); popup.open(); return; default: - var popup = errorDialog.createObject(root, {errorCode: params.deviceError}) + var popup = errorDialog.createObject(root, {error: thingError}) popup.open(); } } @@ -124,23 +123,23 @@ SettingsPageBase { NymeaSwipeDelegate { Layout.fillWidth: true text: qsTr("Vendor:") - subText: engine.deviceManager.vendors.getVendor(root.deviceClass.vendorId).displayName + subText: engine.thingManager.vendors.getVendor(root.thing.thingClass.vendorId).displayName progressive: false } NymeaSwipeDelegate { Layout.fillWidth: true text: qsTr("Type:") - subText: root.deviceClass.displayName + subText: root.thing.thingClass.displayName progressive: false } NymeaSwipeDelegate { Layout.fillWidth: true text: qsTr("ID:") - subText: root.device.id.toString().replace(/[{}]/g, "") + subText: root.thing.id.toString().replace(/[{}]/g, "") progressive: false onClicked: { - PlatformHelper.toClipBoard(root.device.id.toString().replace(/[{}]/g, "")); + PlatformHelper.toClipBoard(root.thing.id.toString().replace(/[{}]/g, "")); ToolTip.show(qsTr("ID copied to clipboard"), 500); } } @@ -150,21 +149,21 @@ SettingsPageBase { text: qsTr("Thing class") subText: qsTr("View the type definition for this thing") onClicked: { - pageStack.push(Qt.resolvedUrl("ThingClassDetailsPage.qml"), {device: root.device}) + pageStack.push(Qt.resolvedUrl("ThingClassDetailsPage.qml"), {thing: root.thing}) } } SettingsPageSectionHeader { text: qsTr("Parameters") - visible: root.device.params.count > 0 + visible: root.thing.params.count > 0 } Repeater { - model: root.device.params + model: root.thing.params delegate: ParamDelegate { Layout.fillWidth: true - paramType: root.deviceClass.paramTypes.getParamType(model.id) - param: root.device.params.get(index) + paramType: root.thing.thingClass.paramTypes.getParamType(model.id) + param: root.thing.params.get(index) writable: false } } @@ -176,7 +175,7 @@ SettingsPageBase { StateTypesProxy { id: ioModel - stateTypes: root.deviceClass.stateTypes + stateTypes: root.thing.thingClass.stateTypes digitalInputs: true digitalOutputs: true analogInputs: true @@ -207,19 +206,19 @@ SettingsPageBase { IOInputConnectionWatcher { id: inputConnectionWatcher - ioConnections: engine.deviceManager.ioConnections - inputThingId: root.device.id + ioConnections: engine.thingManager.ioConnections + inputThingId: root.thing.id inputStateTypeId: ioStateType.id - property Device outputThing: ioConnection ? engine.deviceManager.devices.getDevice(ioConnection.outputThingId) : null - property StateType outputStateType: ioConnection ? outputThing.deviceClass.stateTypes.getStateType(ioConnection.outputStateTypeId) : null + property Thing outputThing: ioConnection ? engine.thingManager.things.getThing(ioConnection.outputThingId) : null + property StateType outputStateType: ioConnection ? outputThing.thingClass.stateTypes.getStateType(ioConnection.outputStateTypeId) : null } IOOutputConnectionWatcher { id: outputConnectionWatcher - ioConnections: engine.deviceManager.ioConnections - outputThingId: root.device.id + ioConnections: engine.thingManager.ioConnections + outputThingId: root.thing.id outputStateTypeId: ioStateType.id - property Device inputThing: ioConnection ? engine.deviceManager.devices.getDevice(ioConnection.inputThingId) : null - property StateType inputStateType: ioConnection ? inputThing.deviceClass.stateTypes.getStateType(ioConnection.inputStateTypeId) : null + property Thing inputThing: ioConnection ? engine.thingManager.things.getThing(ioConnection.inputThingId) : null + property StateType inputStateType: ioConnection ? inputThing.thingClass.stateTypes.getStateType(ioConnection.inputStateTypeId) : null } onClicked: { @@ -232,18 +231,18 @@ SettingsPageBase { SettingsPageSectionHeader { text: qsTr("Settings") - visible: root.deviceClass.settingsTypes.count > 0 + visible: root.thing.thingClass.settingsTypes.count > 0 } Repeater { id: settingsRepeater - model: root.device.settings + model: root.thing.settings delegate: ParamDelegate { Layout.fillWidth: true - paramType: root.deviceClass.settingsTypes.getParamType(model.id) - value: root.device.settings.get(index).value + paramType: root.thing.thingClass.settingsTypes.getParamType(model.id) + value: root.thing.settings.get(index).value writable: true - property bool dirty: root.device.settings.get(index).value !== value + property bool dirty: root.thing.settings.get(index).value !== value onDirtyChanged: settingsRepeater.checkDirty() } function checkDirty() { @@ -277,7 +276,7 @@ SettingsPageBase { params.push(setting) } - engine.deviceManager.setDeviceSettings(root.device.id, params); + engine.thingManager.setThingSettings(root.thing.id, params); } } @@ -301,24 +300,17 @@ SettingsPageBase { TextField { id: textField - text: root.device.name + text: root.thing.name width: parent.width } onAccepted: { - engine.deviceManager.editThing(root.device.id, textField.text) + engine.thingManager.editThing(root.thing.id, textField.text) dialog.destroy(); } } } - Component { - id: removeMethodComponent - RemoveThingMethodDialog { - - } - } - Component { id: ioConnectionsDialogComponent MeaDialog { @@ -349,7 +341,7 @@ SettingsPageBase { ComboBox { id: ioThingComboBox - model: DevicesProxy { + model: ThingsProxy { id: connectableIODevices engine: _engine showDigitalInputs: ioConnectionDialog.ioStateType.ioType == Types.IOTypeDigitalOutput @@ -385,7 +377,7 @@ SettingsPageBase { id: ioStateComboBox model: StateTypesProxy { id: connectableStateTypes - stateTypes: connectableIODevices.get(ioThingComboBox.currentIndex).deviceClass.stateTypes + stateTypes: connectableIODevices.get(ioThingComboBox.currentIndex).thingClass.stateTypes digitalInputs: ioConnectionDialog.ioStateType.ioType == Types.IOTypeDigitalOutput digitalOutputs: ioConnectionDialog.ioStateType.ioType == Types.IOTypeDigitalInput analogInputs: ioConnectionDialog.ioStateType.ioType == Types.IOTypeAnalogOutput @@ -451,9 +443,9 @@ SettingsPageBase { onClicked: { if (ioConnectionDialog.ioStateType.ioType == Types.IOTypeDigitalInput || ioConnectionDialog.ioStateType.ioType == Types.IOTypeAnalogInput) { - engine.deviceManager.disconnectIO(ioConnectionDialog.inputWatcher.ioConnection.id); + engine.thingManager.disconnectIO(ioConnectionDialog.inputWatcher.ioConnection.id); } else { - engine.deviceManager.disconnectIO(ioConnectionDialog.outputWatcher.ioConnection.id); + engine.thingManager.disconnectIO(ioConnectionDialog.outputWatcher.ioConnection.id); } ioConnectionDialog.reject(); @@ -472,20 +464,20 @@ SettingsPageBase { var outputStateTypeId; if (ioConnectionDialog.ioStateType.ioType == Types.IOTypeDigitalInput || ioConnectionDialog.ioStateType.ioType == Types.IOTypeAnalogInput) { - inputThingId = root.device.id; + inputThingId = root.thing.id; inputStateTypeId = ioConnectionDialog.ioStateType.id; outputThingId = connectableIODevices.get(ioThingComboBox.currentIndex).id; outputStateTypeId = connectableStateTypes.get(ioStateComboBox.currentIndex).id; } else { inputThingId = connectableIODevices.get(ioThingComboBox.currentIndex).id; inputStateTypeId = connectableStateTypes.get(ioStateComboBox.currentIndex).id; - outputThingId = root.device.id; + outputThingId = root.thing.id; outputStateTypeId = ioConnectionDialog.ioStateType.id; } var inverted = invertCheckBox.checked print("connecting", inputThingId, inputStateTypeId, outputThingId, outputStateTypeId, inverted) - engine.deviceManager.connectIO(inputThingId, inputStateTypeId, outputThingId, outputStateTypeId, inverted); + engine.thingManager.connectIO(inputThingId, inputStateTypeId, outputThingId, outputStateTypeId, inverted); ioConnectionDialog.accept(); } diff --git a/nymea-app/ui/thingconfiguration/EditThingsPage.qml b/nymea-app/ui/thingconfiguration/EditThingsPage.qml index 002d4825..4f1e8a3a 100644 --- a/nymea-app/ui/thingconfiguration/EditThingsPage.qml +++ b/nymea-app/ui/thingconfiguration/EditThingsPage.qml @@ -60,24 +60,24 @@ Page { } Connections { - target: engine.deviceManager + target: engine.thingManager onRemoveThingReply: { if (!d.thingToRemove) { return; } - switch (params.deviceError) { - case "DeviceErrorNoError": + switch (thingError) { + case Thing.ThingErrorNoError: d.thingToRemove = null; return; - case "DeviceErrorDeviceInRule": - var removeMethodComponent = Qt.createComponent(Qt.resolvedUrl("../components/RemoveTThingMethodDialog.qml")) - var popup = removeMethodComponent.createObject(root, {device: d.thingToRemove, rulesList: params["ruleIds"]}); + case Thing.ThingErrorThingInRule: + var removeMethodComponent = Qt.createComponent(Qt.resolvedUrl("../components/RemoveThingMethodDialog.qml")) + var popup = removeMethodComponent.createObject(root, {thing: d.thingToRemove, rulesList: ruleIds}); popup.open(); return; default: var errorDialog = Qt.createComponent(Qt.resolvedUrl("../components/ErrorDialog.qml")) - var popup = errorDialog.createObject(root, {errorCode: params.deviceError}) + var popup = errorDialog.createObject(root, {error: thingError}) popup.open(); } } @@ -96,23 +96,23 @@ Page { Layout.fillHeight: true clip: true - model: DevicesProxy { - id: deviceProxy + model: ThingsProxy { + id: thingsProxy engine: _engine groupByInterface: true nameFilter: filterInput.shown ? filterInput.text : "" } delegate: ThingDelegate { - device: deviceProxy.getDevice(model.id) + thing: thingsProxy.getThing(model.id) // FIXME: This isn't entirely correct... we should have a way to know if a particular thing is in fact autocreated // This check might be wrong for thingClasses with multiple create methods... - canDelete: !device.isChild || device.deviceClass.createMethods.indexOf("CreateMethodAuto") < 0 + canDelete: !thing.isChild || thing.thingClass.createMethods.indexOf("CreateMethodAuto") < 0 onClicked: { - pageStack.push(Qt.resolvedUrl("ConfigureThingPage.qml"), {device: device}) + pageStack.push(Qt.resolvedUrl("ConfigureThingPage.qml"), {thing: thing}) } onDeleteClicked: { - d.thingToRemove = device; + d.thingToRemove = thing; engine.thingManager.removeThing(d.thingToRemove.id) } } @@ -123,7 +123,7 @@ Page { EmptyViewPlaceholder { anchors { left: parent.left; right: parent.right; margins: app.margins } anchors.verticalCenter: parent.verticalCenter - visible: engine.deviceManager.devices.count === 0 && !engine.deviceManager.fetchingData + visible: engine.thingManager.things.count === 0 && !engine.thingManager.fetchingData title: qsTr("There are no things set up yet.") text: qsTr("In order for your %1 system to be useful, go ahead and add some things.").arg(app.systemName) imageSource: "qrc:/styles/%1/logo.svg".arg(styleController.currentStyle) diff --git a/nymea-app/ui/thingconfiguration/NewThingPage.qml b/nymea-app/ui/thingconfiguration/NewThingPage.qml index fdeb3df1..aeee91db 100644 --- a/nymea-app/ui/thingconfiguration/NewThingPage.qml +++ b/nymea-app/ui/thingconfiguration/NewThingPage.qml @@ -75,7 +75,7 @@ Page { currentIndex: -1 VendorsProxy { id: vendorsProxy - vendors: engine.deviceManager.vendors + vendors: engine.thingManager.vendors } model: ListModel { id: vendorsFilterModel @@ -148,8 +148,8 @@ Page { bottom: parent.bottom } - model: DeviceClassesProxy { - id: deviceClassesProxy + model: ThingClassesProxy { + id: thingClassesProxy engine: _engine filterInterface: typeFilterModel.get(typeFilterComboBox.currentIndex).interfaceName filterVendorId: vendorFilterComboBox.currentIndex >= 0 ? vendorsFilterModel.get(vendorFilterComboBox.currentIndex).vendorId : "" @@ -158,18 +158,18 @@ Page { } delegate: NymeaSwipeDelegate { - id: deviceClassDelegate + id: tingClassDelegate width: parent.width text: model.displayName - subText: engine.deviceManager.vendors.getVendor(model.vendorId).displayName - iconName: app.interfacesToIcon(deviceClass.interfaces) + subText: engine.thingManager.vendors.getVendor(model.vendorId).displayName + iconName: app.interfacesToIcon(thingClass.interfaces) prominentSubText: false wrapTexts: false - property var deviceClass: deviceClassesProxy.get(index) + property ThingClass thingClass: thingClassesProxy.get(index) onClicked: { - var page = pageStack.push(Qt.resolvedUrl("SetupWizard.qml"), {deviceClass: deviceClassesProxy.get(index)}); + var page = pageStack.push(Qt.resolvedUrl("SetupWizard.qml"), {thingClass: thingClassesProxy.get(index)}); page.done.connect(function() { pageStack.pop(root, StackView.Immediate); pageStack.pop(); diff --git a/nymea-app/ui/thingconfiguration/SetupWizard.qml b/nymea-app/ui/thingconfiguration/SetupWizard.qml index f6588254..36bd1835 100644 --- a/nymea-app/ui/thingconfiguration/SetupWizard.qml +++ b/nymea-app/ui/thingconfiguration/SetupWizard.qml @@ -41,7 +41,6 @@ Page { id: root property ThingClass thingClass: thing ? thing.thingClass : null - property alias deviceClass: root.thingClass // Optional: If set, it will be reconfigred, otherwise a new one will be created property Thing thing: null @@ -50,7 +49,7 @@ Page { signal done(); header: NymeaHeader { - text: root.device ? qsTr("Reconfigure %1").arg(root.device.name) : qsTr("Set up %1").arg(root.deviceClass.displayName) + text: root.thing ? qsTr("Reconfigure %1").arg(root.thing.name) : qsTr("Set up %1").arg(root.thingClass.displayName) onBackPressed: { if (internalPageStack.depth > 1) { internalPageStack.pop(); @@ -70,25 +69,25 @@ Page { property var vendorId: null property ThingDescriptor thingDescriptor: null property var discoveryParams: [] - property string deviceName: "" + property string thingName: "" property int pairRequestId: 0 property var pairingTransactionId: null property int addRequestId: 0 } Component.onCompleted: { - print("Starting setup wizard. Create Methods:", root.deviceClass.createMethods, "Setup method:", root.deviceClass.setupMethod) - if (root.deviceClass.createMethods.indexOf("CreateMethodDiscovery") !== -1) { + print("Starting setup wizard. Create Methods:", root.thingClass.createMethods, "Setup method:", root.thingClass.setupMethod) + if (root.thingClass.createMethods.indexOf("CreateMethodDiscovery") !== -1) { print("CreateMethodDiscovery") - if (deviceClass["discoveryParamTypes"].count > 0) { - print("Discovery params:", deviceClass.discoveryParamTypes.count) + if (thingClass["discoveryParamTypes"].count > 0) { + print("Discovery params:", thingClass.discoveryParamTypes.count) internalPageStack.push(discoveryParamsPage) } else { print("Starting discovery...") - discovery.discoverThings(deviceClass.id) - internalPageStack.push(discoveryPage, {deviceClass: deviceClass}) + discovery.discoverThings(thingClass.id) + internalPageStack.push(discoveryPage, {thingClass: thingClass}) } - } else if (root.deviceClass.createMethods.indexOf("CreateMethodUser") !== -1) { + } else if (root.thingClass.createMethods.indexOf("CreateMethodUser") !== -1) { print("CreateMethodUser") // Setting up a new device if (!root.thing) { @@ -96,21 +95,21 @@ Page { internalPageStack.push(paramsPage) // Reconfigure - } else if (root.device) { + } else if (root.thing) { print("Existing device") // There are params. Open params page in any case - if (root.deviceClass.paramTypes.count > 0) { - print("Params:", root.deviceClass.paramTypes.count) + if (root.thingClass.paramTypes.count > 0) { + print("Params:", root.thingClass.paramTypes.count) internalPageStack.push(paramsPage) // No params... go straight to reconfigure/repair } else { print("no params") - switch (root.deviceClass.setupMethod) { + switch (root.thingClass.setupMethod) { case 0: print("reconfiguring...") // This totally does not make sense... Maybe we should hide the reconfigure button if there are no params? - engine.deviceManager.reconfigureDevice(root.device.id, []) + engine.thingManager.reconfigureThing(root.thing.id, []) busyOverlay.shown = true; break; case 1: @@ -118,8 +117,8 @@ Page { case 3: case 4: case 5: - print("re-pairing", root.device.id) - engine.deviceManager.rePairDevice(root.device.id, []); + print("re-pairing", root.thing.id) + engine.thingManager.rePairThing(root.thing.id, []); break; default: console.warn("Unhandled setup method!") @@ -130,43 +129,42 @@ Page { } Connections { - target: engine.deviceManager - onPairDeviceReply: { + target: engine.thingManager + onPairThingReply: { busyOverlay.shown = false - if (params["deviceError"] !== "DeviceErrorNoError") { + if (thingError !== Thing.ThingErrorNoError) { busyOverlay.shown = false; - internalPageStack.push(resultsPage, {deviceError: params["deviceError"], message: params["displayMessage"]}); + internalPageStack.push(resultsPage, {thingError: thingError, message: displayMessage}); return; } - d.pairingTransactionId = params["pairingTransactionId"]; + d.pairingTransactionId = pairingTransactionId; - switch (params["setupMethod"]) { + switch (setupMethod) { case "SetupMethodPushButton": case "SetupMethodDisplayPin": case "SetupMethodUserAndPassword": - internalPageStack.push(pairingPageComponent, {text: params["displayMessage"], setupMethod: params["setupMethod"]}) + internalPageStack.push(pairingPageComponent, {text: displayMessage, setupMethod: setupMethod}) break; case "SetupMethodOAuth": - internalPageStack.push(oAuthPageComponent, {oAuthUrl: params["oAuthUrl"]}) + internalPageStack.push(oAuthPageComponent, {oAuthUrl: oAuthUrl}) break; default: - print("Setup method reply not handled:", JSON.stringify(params)); + print("Setup method reply not handled:", setupMethod); } } onConfirmPairingReply: { busyOverlay.shown = false - internalPageStack.push(resultsPage, {deviceError: params["deviceError"], deviceId: params["deviceId"], message: params["displayMessage"]}) + internalPageStack.push(resultsPage, {thingError: thingError, thingId: thingId, message: displayMessage}) } - onAddDeviceReply: { - print("Device added:", JSON.stringify(params)) + onAddThingReply: { busyOverlay.shown = false; - internalPageStack.push(resultsPage, {deviceError: params["deviceError"], deviceId: params["deviceId"], message: params["displayMessage"]}) + internalPageStack.push(resultsPage, {thingError: thingError, thingId: thingId, message: displayMessage}) } - onReconfigureDeviceReply: { + onReconfigureThingReply: { busyOverlay.shown = false; - internalPageStack.push(resultsPage, {deviceError: params["deviceError"], deviceId: params["deviceId"], message: params["displayMessage"]}) + internalPageStack.push(resultsPage, {thingError: thingError, thingId: root.thing.id, message: displayMessage}) } } @@ -197,7 +195,7 @@ Page { Repeater { id: paramRepeater - model: root.deviceClass ? root.deviceClass["discoveryParamTypes"] : null + model: root.thingClass ? root.thingClass["discoveryParamTypes"] : null Loader { Layout.fillWidth: true sourceComponent: searchStringEntryComponent @@ -209,7 +207,7 @@ Page { Layout.fillWidth: true text: "Next" onClicked: { - var paramTypes = root.deviceClass["discoveryParamTypes"]; + var paramTypes = root.thingClass["discoveryParamTypes"]; d.discoveryParams = []; for (var i = 0; i < paramTypes.count; i++) { var param = {}; @@ -217,8 +215,8 @@ Page { param["value"] = paramRepeater.itemAt(i).value d.discoveryParams.push(param); } - discovery.discoverThings(root.deviceClass.id, d.discoveryParams) - internalPageStack.push(discoveryPage, {deviceClass: root.deviceClass}) + discovery.discoverThings(root.thingClass.id, d.discoveryParams) + internalPageStack.push(discoveryPage, {thingClass: root.thingClass}) } } } @@ -248,7 +246,7 @@ Page { Page { id: discoveryView - property var deviceClass: null + property ThingClass thingClass: null ColumnLayout { anchors.fill: parent @@ -261,19 +259,19 @@ Page { model: ThingDiscoveryProxy { id: discoveryProxy thingDiscovery: discovery - showAlreadyAdded: root.device !== null - showNew: root.device === null - filterThingId: root.device ? root.device.id : "" + showAlreadyAdded: root.thing !== null + showNew: root.thing === null + filterThingId: root.thing ? root.thing.id : "" } delegate: NymeaSwipeDelegate { width: parent.width height: app.delegateHeight text: model.name subText: model.description - iconName: app.interfacesToIcon(discoveryView.deviceClass.interfaces) + iconName: app.interfacesToIcon(discoveryView.thingClass.interfaces) onClicked: { d.thingDescriptor = discoveryProxy.get(index); - d.deviceName = model.name; + d.thingName = model.name; internalPageStack.push(paramsPage) } } @@ -283,7 +281,7 @@ Page { Layout.fillWidth: true Layout.leftMargin: app.margins; Layout.rightMargin: app.margins text: qsTr("Search again") - onClicked: discovery.discoverThings(root.deviceClass.id, d.discoveryParams) + onClicked: discovery.discoverThings(root.thingClass.id, d.discoveryParams) visible: !discovery.busy } @@ -291,7 +289,7 @@ Page { id: manualAddButton Layout.fillWidth: true Layout.leftMargin: app.margins; Layout.rightMargin: app.margins; - visible: root.deviceClass.createMethods.indexOf("CreateMethodUser") >= 0 + visible: root.thingClass.createMethods.indexOf("CreateMethodUser") >= 0 text: qsTr("Add thing manually") onClicked: internalPageStack.push(paramsPage) } @@ -359,7 +357,7 @@ Page { width: parent.width ColumnLayout { -// visible: root.device === null +// visible: root.thing === null Label { Layout.leftMargin: app.margins Layout.rightMargin: app.margins @@ -369,7 +367,7 @@ Page { } TextField { id: nameTextField - text: (d.deviceName ? d.deviceName : root.deviceClass.displayName) + text: (d.thingName ? d.thingName : root.thingClass.displayName) + (root.thingClass.id.toString().match(/\{?f0dd4c03-0aca-42cc-8f34-9902457b05de\}?/) ? " (" + PlatformHelper.machineHostname + ")" : "") Layout.fillWidth: true Layout.leftMargin: app.margins @@ -383,12 +381,12 @@ Page { Repeater { id: paramRepeater - model: engine.jsonRpcClient.ensureServerVersion("1.12") || d.thingDescriptor == null ? root.deviceClass.paramTypes : null + model: engine.jsonRpcClient.ensureServerVersion("1.12") || d.thingDescriptor == null ? root.thingClass.paramTypes : null delegate: ParamDelegate { // Layout.preferredHeight: 60 Layout.fillWidth: true enabled: !model.readOnly - paramType: root.deviceClass.paramTypes.get(index) + paramType: root.thingClass.paramTypes.get(index) //visible: root.thingClass.id.toString().match(/\{?f0dd4c03-0aca-42cc-8f34-9902457b05de\}?/) === null value: { // Discovery, use params from discovered descriptor @@ -423,7 +421,7 @@ Page { text: "OK" onClicked: { - print("setupMethod", root.deviceClass.setupMethod) + print("setupMethod", root.thingClass.setupMethod) var params = [] for (var i = 0; i < paramRepeater.count; i++) { @@ -437,19 +435,19 @@ Page { } } - switch (root.deviceClass.setupMethod) { + switch (root.thingClass.setupMethod) { case 0: - if (root.device) { + if (root.thing) { if (d.thingDescriptor) { - engine.deviceManager.reconfigureDiscoveredDevice(root.device.id, d.thingDescriptor.id, params); + engine.thingManager.reconfigureDiscoveredThing(d.thingDescriptor.id, params); } else { - engine.deviceManager.reconfigureDevice(root.device.id, params); + engine.thingManager.reconfigureThing(root.thing.id, params); } } else { if (d.thingDescriptor) { - engine.deviceManager.addDiscoveredDevice(root.deviceClass.id, d.thingDescriptor.id, nameTextField.text, params); + engine.thingManager.addDiscoveredThing(root.thingClass.id, d.thingDescriptor.id, nameTextField.text, params); } else { - engine.deviceManager.addDevice(root.deviceClass.id, nameTextField.text, params); + engine.thingManager.addThing(root.thingClass.id, nameTextField.text, params); } } break; @@ -458,18 +456,18 @@ Page { case 3: case 4: case 5: - if (root.device) { + if (root.thing) { if (d.thingDescriptor) { - engine.deviceManager.pairDiscoveredDevice(root.deviceClass.id, d.thingDescriptor.id, params, nameTextField.text); + engine.thingManager.pairDiscoveredThing(d.thingDescriptor.id, params, nameTextField.text); } else { - engine.deviceManager.rePairDevice(root.device.id, params, nameTextField.text); + engine.thingManager.rePairThing(root.thing.id, params, nameTextField.text); } return; } else { if (d.thingDescriptor) { - engine.deviceManager.pairDiscoveredDevice(root.deviceClass.id, d.thingDescriptor.id, params, nameTextField.text); + engine.thingManager.pairDiscoveredThing(d.thingDescriptor.id, params, nameTextField.text); } else { - engine.deviceManager.pairDevice(root.deviceClass.id, params, nameTextField.text); + engine.thingManager.pairThing(root.thingClass.id, params, nameTextField.text); } } @@ -532,7 +530,7 @@ Page { Layout.fillWidth: true text: "OK" onClicked: { - engine.deviceManager.confirmPairing(d.pairingTransactionId, pinTextField.password, usernameTextField.displayText); + engine.thingManager.confirmPairing(d.pairingTransactionId, pinTextField.password, usernameTextField.displayText); busyOverlay.shown = true; } } @@ -589,7 +587,7 @@ Page { print("OAUTH URL changed", url) if (url.toString().indexOf("https://127.0.0.1") == 0) { print("Redirect URL detected!"); - engine.deviceManager.confirmPairing(d.pairingTransactionId, url) + engine.thingManager.confirmPairing(d.pairingTransactionId, url) } } } @@ -604,13 +602,13 @@ Page { Page { id: resultsView - property string deviceId - property string deviceError + property string thingId + property int thingError property string message - readonly property bool success: deviceError === "DeviceErrorNoError" + readonly property bool success: thingError === Thing.ThingErrorNoError - readonly property var device: root.device ? root.device : engine.deviceManager.devices.getDevice(deviceId) + readonly property Thing thing: root.thing ? root.thing : engine.thingManager.things.getThing(thingId) ColumnLayout { width: parent.width - app.margins * 2 @@ -620,7 +618,7 @@ Page { Layout.fillWidth: true wrapMode: Text.WordWrap horizontalAlignment: Text.AlignHCenter - text: resultsView.success ? root.device ? qsTr("Thing reconfigured!") : qsTr("Thing added!") : qsTr("Uh oh") + text: resultsView.success ? root.thing ? qsTr("Thing reconfigured!") : qsTr("Thing added!") : qsTr("Uh oh") font.pixelSize: app.largeFont color: Style.accentColor } @@ -628,7 +626,7 @@ Page { Layout.fillWidth: true horizontalAlignment: Text.AlignHCenter wrapMode: Text.WordWrap - text: resultsView.success ? qsTr("All done. You can now start using %1.").arg(resultsView.device.name) : qsTr("Something went wrong setting up this thing..."); + text: resultsView.success ? qsTr("All done. You can now start using %1.").arg(resultsView.thing.name) : qsTr("Something went wrong setting up this thing..."); } Label { diff --git a/nymea-app/ui/thingconfiguration/ThingClassDetailsPage.qml b/nymea-app/ui/thingconfiguration/ThingClassDetailsPage.qml index fdc08bbe..1b46e43d 100644 --- a/nymea-app/ui/thingconfiguration/ThingClassDetailsPage.qml +++ b/nymea-app/ui/thingconfiguration/ThingClassDetailsPage.qml @@ -37,8 +37,8 @@ import "../delegates" SettingsPageBase { id: root - property Device device: null - readonly property DeviceClass thingClass: device ? device.deviceClass : null + property Thing thing: null + readonly property ThingClass thingClass: thing ? thing.thingClass : null header: NymeaHeader { text: root.thingClass.displayName diff --git a/nymea-app/ui/utils/NymeaUtils.qml b/nymea-app/ui/utils/NymeaUtils.qml index e10e8531..a2a8d033 100644 --- a/nymea-app/ui/utils/NymeaUtils.qml +++ b/nymea-app/ui/utils/NymeaUtils.qml @@ -23,9 +23,9 @@ Item { if (interfaceList.indexOf("media") >= 0) { page = "MediaThingPage.qml"; } else if (interfaceList.indexOf("button") >= 0) { - page = "ButtonDevicePage.qml"; + page = "ButtonThingPage.qml"; } else if (interfaceList.indexOf("powerswitch") >= 0) { - page = "ButtonDevicePage.qml"; + page = "ButtonThingPage.qml"; } else if (interfaceList.indexOf("weather") >= 0) { page = "WeatherDevicePage.qml"; } else if (interfaceList.indexOf("heating") >= 0) { @@ -43,7 +43,7 @@ Item { } else if (interfaceList.indexOf("shutter") >= 0 || interfaceList.indexOf("blind") >= 0) { page = "ShutterDevicePage.qml"; } else if (interfaceList.indexOf("awning") >= 0) { - page = "AwningDevicePage.qml"; + page = "AwningThingPage.qml"; } else if (interfaceList.indexOf("notifications") >= 0) { page = "NotificationsDevicePage.qml"; } else if (interfaceList.indexOf("fingerprintreader") >= 0) { From f82fc9056d135c3c284cacf093a8c171df344973 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Wed, 24 Feb 2021 13:23:05 +0100 Subject: [PATCH 3/5] Update min/max required nymea core version --- libnymea-app/jsonrpc/jsonrpcclient.cpp | 12 +++++++++--- libnymea-app/jsonrpc/jsonrpcclient.h | 3 ++- nymea-app/ui/RootItem.qml | 20 +++++++++++++++----- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/libnymea-app/jsonrpc/jsonrpcclient.cpp b/libnymea-app/jsonrpc/jsonrpcclient.cpp index 6e654785..537c86c6 100644 --- a/libnymea-app/jsonrpc/jsonrpcclient.cpp +++ b/libnymea-app/jsonrpc/jsonrpcclient.cpp @@ -644,13 +644,19 @@ void JsonRpcClient::helloReply(int /*commandId*/, const QVariantMap ¶ms) qDebug() << "Handshake reply:" << "Protocol version:" << protoVersionString << "InitRequired:" << m_initialSetupRequired << "AuthRequired:" << m_authenticationRequired << "PushButtonAvailable:" << m_pushButtonAuthAvailable;; - QVersionNumber minimumRequiredVersion = QVersionNumber(1, 10); + QVersionNumber minimumRequiredVersion = QVersionNumber(5, 0); + QVersionNumber maximumMajorVersion = QVersionNumber(5); if (m_jsonRpcVersion < minimumRequiredVersion) { qWarning() << "Nymea core doesn't support minimum required version. Required:" << minimumRequiredVersion << "Found:" << m_jsonRpcVersion; - m_connection->disconnect(); - emit invalidProtocolVersion(m_jsonRpcVersion.toString(), minimumRequiredVersion.toString()); + emit invalidMinimumVersion(m_jsonRpcVersion.toString(), minimumRequiredVersion.toString()); return; } + if (m_jsonRpcVersion.majorVersion() > maximumMajorVersion.majorVersion()) { + qWarning() << "Nymea core has breaking API changes not supported by this app version. Core major version:" << m_jsonRpcVersion.majorVersion() << "Maximum supported major version:" << maximumMajorVersion.majorVersion(); + emit invalidMaximumVersion(m_jsonRpcVersion.toString(), QString("%1.x").arg(maximumMajorVersion.majorVersion())); + return; + } + // Verify SSL certificate if (m_connection->isEncrypted()) { diff --git a/libnymea-app/jsonrpc/jsonrpcclient.h b/libnymea-app/jsonrpc/jsonrpcclient.h index 60726577..59a7c0e0 100644 --- a/libnymea-app/jsonrpc/jsonrpcclient.h +++ b/libnymea-app/jsonrpc/jsonrpcclient.h @@ -129,7 +129,8 @@ signals: void pushButtonAuthAvailableChanged(); void authenticatedChanged(); void tokenChanged(); - void invalidProtocolVersion(const QString &actualVersion, const QString &minimumVersion); + void invalidMinimumVersion(const QString &actualVersion, const QString &minVersion); + void invalidMaximumVersion(const QString &actualVersion, const QString &maxVersion); void authenticationFailed(); void pushButtonAuthFailed(); void createUserSucceeded(); diff --git a/nymea-app/ui/RootItem.qml b/nymea-app/ui/RootItem.qml index f57d2a2d..1c6c2522 100644 --- a/nymea-app/ui/RootItem.qml +++ b/nymea-app/ui/RootItem.qml @@ -366,10 +366,17 @@ Item { init(); } - onInvalidProtocolVersion: { + onInvalidMinimumVersion: { var popup = invalidVersionComponent.createObject(app.contentItem); popup.actualVersion = actualVersion; - popup.minimumVersion = minimumVersion + popup.minVersion = minVersion; + popup.open() + tabSettings.lastConnectedHost = "" + } + onInvalidMaximumVersion: { + var popup = invalidVersionComponent.createObject(app.contentItem); + popup.actualVersion = actualVersion; + popup.maxVersion = maxVersion; popup.open() tabSettings.lastConnectedHost = "" } @@ -421,8 +428,9 @@ Item { Popup { id: popup - property string actualVersion: "0.0" - property string minimumVersion: "1.10" + property string actualVersion: "" + property string minVersion: "" + property string maxVersion: "" width: app.width * .8 height: col.childrenRect.height + app.margins * 2 @@ -439,7 +447,9 @@ Item { font.pixelSize: app.largeFont } Label { - text: qsTr("Sorry, the version of the %1:core you are trying to connect to is too old. This app requires at least version %2 but this %1:core only supports %3").arg(app.systemName).arg(popup.minimumVersion).arg(popup.actualVersion) + text: popup.minVersion != "" + ? qsTr("The version of the %1:core you are trying to connect to is too old. This app requires at least version %2 but this %1:core only supports %3. Please update your %1:core system.").arg(app.systemName).arg(popup.minVersion).arg(popup.actualVersion) + : qsTr("The version of the %1:core you are trying to connect to is too new. This app supports only up to version %2 but this %1:core provides %3. Please update %1:app.").arg(app.systemName).arg(popup.maxVersion).arg(popup.actualVersion) wrapMode: Text.WordWrap Layout.fillWidth: true } From 0c205e3edcbceff6ae36c90c38c39ae935728583 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Sun, 28 Feb 2021 22:17:01 +0100 Subject: [PATCH 4/5] fix androidservice --- androidservice/controlviews/devicecontrolapplication.cpp | 4 ++-- androidservice/nymeaappservice/androidbinder.cpp | 2 +- androidservice/nymeaappservice/nymeaappservice.cpp | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/androidservice/controlviews/devicecontrolapplication.cpp b/androidservice/controlviews/devicecontrolapplication.cpp index a1c0297d..466135b8 100644 --- a/androidservice/controlviews/devicecontrolapplication.cpp +++ b/androidservice/controlviews/devicecontrolapplication.cpp @@ -120,7 +120,7 @@ void DeviceControlApplication::handleNdefMessage(QNdefMessage message, QNearFiel connectToNymea(nymeaId); m_qmlEngine->rootContext()->setContextProperty("controlledThingId", thingId); - connect(m_engine->thingManager(), &DeviceManager::fetchingDataChanged, [this](){ + connect(m_engine->thingManager(), &ThingManager::fetchingDataChanged, [this](){ if (m_engine->jsonRpcClient()->connected() && !m_engine->thingManager()->fetchingData()) { qDebug() << "Ready to process commands"; runNfcAction(); @@ -160,7 +160,7 @@ void DeviceControlApplication::runNfcAction() } QUuid thingId = QUuid(QUrlQuery(url).queryItemValue("t")); - Device *thing = m_engine->thingManager()->things()->getThing(thingId); + Thing *thing = m_engine->thingManager()->things()->getThing(thingId); if (!thing) { qDebug() << "Thing" << thingId.toString() << "from" << url.toString() << "doesn't exist on nymea host" << nymeaId.toString(); return; diff --git a/androidservice/nymeaappservice/androidbinder.cpp b/androidservice/nymeaappservice/androidbinder.cpp index cb81a8cb..41696887 100644 --- a/androidservice/nymeaappservice/androidbinder.cpp +++ b/androidservice/nymeaappservice/androidbinder.cpp @@ -54,7 +54,7 @@ bool AndroidBinder::onTransact(int code, const QAndroidParcel &data, const QAndr } QVariantList thingsList; for (int i = 0; i < engine->thingManager()->things()->rowCount(); i++) { - Device *thing = engine->thingManager()->things()->get(i); + Thing *thing = engine->thingManager()->things()->get(i); QVariantMap thingMap; thingMap.insert("id", thing->id()); thingMap.insert("name", thing->name()); diff --git a/androidservice/nymeaappservice/nymeaappservice.cpp b/androidservice/nymeaappservice/nymeaappservice.cpp index d2c673ff..59713651 100644 --- a/androidservice/nymeaappservice/nymeaappservice.cpp +++ b/androidservice/nymeaappservice/nymeaappservice.cpp @@ -42,7 +42,7 @@ NymeaAppService::NymeaAppService(int argc, char **argv): m_engines.insert(host->uuid(), engine); - QObject::connect(engine->thingManager(), &DeviceManager::thingStateChanged, [=](const QUuid &thingId, const QUuid &stateTypeId, const QVariant &value){ + QObject::connect(engine->thingManager(), &ThingManager::thingStateChanged, [=](const QUuid &thingId, const QUuid &stateTypeId, const QVariant &value){ QVariantMap params; params.insert("nymeaId", engine->jsonRpcClient()->currentHost()->uuid()); params.insert("thingId", thingId); @@ -51,7 +51,7 @@ NymeaAppService::NymeaAppService(int argc, char **argv): sendNotification("ThingStateChanged", params); }); - connect(engine->thingManager(), &DeviceManager::fetchingDataChanged, [=]() { + connect(engine->thingManager(), &ThingManager::fetchingDataChanged, [=]() { qDebug() << "Fetching data changed"; QVariantMap params; params.insert("nymeaId", engine->jsonRpcClient()->currentHost()->uuid()); From 3032e5f2dffe88d1a05a1f8cfcd9ebe4ad4b9515 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Sat, 6 Mar 2021 01:20:10 +0100 Subject: [PATCH 5/5] some more device -> thing --- libnymea-app/models/logsmodelng.cpp | 2 +- libnymea-app/thingclasses.cpp | 5 ----- libnymea-app/thingclasses.h | 7 +++---- libnymea-app/thingdiscovery.cpp | 10 +++++----- libnymea-app/thingmanager.cpp | 20 +++++-------------- libnymea-app/thingmanager.h | 6 +----- libnymea-app/things.cpp | 2 -- libnymea-app/things.h | 1 - libnymea-app/types/interface.cpp | 2 +- libnymea-app/types/interface.h | 2 +- libnymea-app/types/rule.cpp | 6 +++--- libnymea-app/types/thing.cpp | 5 ----- libnymea-app/types/thing.h | 3 --- nymea-app/ui/delegates/InterfaceTile.qml | 8 ++++---- nymea-app/ui/experiences/heating/Main.qml | 10 +++++----- .../ui/thingconfiguration/SetupWizard.qml | 5 ++--- 16 files changed, 31 insertions(+), 63 deletions(-) diff --git a/libnymea-app/models/logsmodelng.cpp b/libnymea-app/models/logsmodelng.cpp index 2a9c921f..9708dfd2 100644 --- a/libnymea-app/models/logsmodelng.cpp +++ b/libnymea-app/models/logsmodelng.cpp @@ -450,7 +450,7 @@ void LogsModelNg::newLogEntryReceived(const QVariantMap &data) m_list.prepend(entry); if (m_graphSeries) { - Thing *dev = m_engine->thingManager()->devices()->getThing(entry->thingId()); + Thing *dev = m_engine->thingManager()->things()->getThing(entry->thingId()); StateType *entryStateType = dev->thingClass()->stateTypes()->getStateType(entry->typeId()); diff --git a/libnymea-app/thingclasses.cpp b/libnymea-app/thingclasses.cpp index cf6c36b8..a50fa0aa 100644 --- a/libnymea-app/thingclasses.cpp +++ b/libnymea-app/thingclasses.cpp @@ -96,11 +96,6 @@ ThingClass *ThingClasses::getThingClass(QUuid thingClassId) const return nullptr; } -ThingClass *ThingClasses::getDeviceClass(QUuid thingClassId) const -{ - return getThingClass(thingClassId); -} - void ThingClasses::addThingClass(ThingClass *thingClass) { thingClass->setParent(this); diff --git a/libnymea-app/thingclasses.h b/libnymea-app/thingclasses.h index 9f3e572e..9149be7b 100644 --- a/libnymea-app/thingclasses.h +++ b/libnymea-app/thingclasses.h @@ -28,8 +28,8 @@ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -#ifndef DEVICECLASSMODEL_H -#define DEVICECLASSMODEL_H +#ifndef THINGCLASSES_H +#define THINGCLASSES_H #include @@ -60,7 +60,6 @@ public: Q_INVOKABLE int count() const; Q_INVOKABLE ThingClass *get(int index) const; Q_INVOKABLE ThingClass *getThingClass(QUuid thingClassId) const; - Q_INVOKABLE ThingClass *getDeviceClass(QUuid thingClassId) const; void addThingClass(ThingClass *thingClass); @@ -77,4 +76,4 @@ private: }; -#endif // DEVICECLASSMODEL_H +#endif // THINGCLASSES_H diff --git a/libnymea-app/thingdiscovery.cpp b/libnymea-app/thingdiscovery.cpp index 0bda1130..087e2d6d 100644 --- a/libnymea-app/thingdiscovery.cpp +++ b/libnymea-app/thingdiscovery.cpp @@ -69,7 +69,7 @@ QHash ThingDiscovery::roleNames() const return roles; } -void ThingDiscovery::discoverThings(const QUuid &deviceClassId, const QVariantList &discoveryParams) +void ThingDiscovery::discoverThings(const QUuid &thingClassId, const QVariantList &discoveryParams) { if (m_busy) { qWarning() << "Busy... not restarting discovery"; @@ -81,20 +81,20 @@ void ThingDiscovery::discoverThings(const QUuid &deviceClassId, const QVariantLi emit countChanged(); if (!m_engine) { - qWarning() << "Cannot discover devices. No Engine set"; + qWarning() << "Cannot discover things. No Engine set"; return; } if (!m_engine->jsonRpcClient()->connected()) { - qWarning() << "Cannot discover devices. Not connected."; + qWarning() << "Cannot discover things. Not connected."; return; } QVariantMap params; - params.insert("deviceClassId", deviceClassId.toString()); + params.insert("thingClassId", thingClassId.toString()); if (!discoveryParams.isEmpty()) { params.insert("discoveryParams", discoveryParams); } - m_engine->jsonRpcClient()->sendCommand("Devices.GetDiscoveredDevices", params, this, "discoverThingsResponse"); + m_engine->jsonRpcClient()->sendCommand("Integrations.DiscoverThings", params, this, "discoverThingsResponse"); m_busy = true; m_displayMessage.clear(); emit busyChanged(); diff --git a/libnymea-app/thingmanager.cpp b/libnymea-app/thingmanager.cpp index 199128b1..67c34324 100644 --- a/libnymea-app/thingmanager.cpp +++ b/libnymea-app/thingmanager.cpp @@ -87,11 +87,6 @@ Plugins *ThingManager::plugins() const return m_plugins; } -Things *ThingManager::devices() const -{ - return m_things; -} - Things *ThingManager::things() const { return m_things; @@ -102,11 +97,6 @@ ThingClasses *ThingManager::thingClasses() const return m_thingClasses; } -ThingClasses *ThingManager::deviceClasses() const -{ - return m_thingClasses; -} - IOConnections *ThingManager::ioConnections() const { return m_ioConnections; @@ -241,9 +231,9 @@ void ThingManager::getVendorsResponse(int /*commandId*/, const QVariantMap ¶ void ThingManager::getThingClassesResponse(int /*commandId*/, const QVariantMap ¶ms) { if (params.keys().contains("thingClasses")) { - QVariantList deviceClassList = params.value("thingClasses").toList(); - foreach (QVariant deviceClassVariant, deviceClassList) { - ThingClass *thingClass = unpackThingClass(deviceClassVariant.toMap()); + QVariantList thingClassList = params.value("thingClasses").toList(); + foreach (QVariant thingClassVariant, thingClassList) { + ThingClass *thingClass = unpackThingClass(thingClassVariant.toMap()); m_thingClasses->addThingClass(thingClass); } } @@ -325,7 +315,7 @@ void ThingManager::getThingsResponse(int /*commandId*/, const QVariantMap ¶m thing->setStateValue(stateTypeId, value); // qDebug() << "Set thing state value:" << thing->stateValue(stateTypeId) << value; } - devices()->addThing(thing); + things()->addThing(thing); } } qDebug() << "Initializing thing manager took" << m_connectionBenchmark.msecsTo(QDateTime::currentDateTime()) << "ms"; @@ -422,7 +412,7 @@ int ThingManager::savePluginConfig(const QUuid &pluginId) ThingGroup *ThingManager::createGroup(Interface *interface, ThingsProxy *things) { - ThingGroup* group = new ThingGroup(this, interface->createDeviceClass(), things, this); + ThingGroup* group = new ThingGroup(this, interface->createThingClass(), things, this); group->setSetupStatus(Thing::ThingSetupStatusComplete, QString()); return group; } diff --git a/libnymea-app/thingmanager.h b/libnymea-app/thingmanager.h index 88f6ddff..7f2587a5 100644 --- a/libnymea-app/thingmanager.h +++ b/libnymea-app/thingmanager.h @@ -55,9 +55,7 @@ class ThingManager : public JsonHandler Q_PROPERTY(Vendors* vendors READ vendors CONSTANT) Q_PROPERTY(Plugins* plugins READ plugins CONSTANT) Q_PROPERTY(Things* things READ things CONSTANT) - Q_PROPERTY(Things* devices READ devices CONSTANT) Q_PROPERTY(ThingClasses* thingClasses READ thingClasses CONSTANT) - Q_PROPERTY(ThingClasses* deviceClasses READ thingClasses CONSTANT) Q_PROPERTY(IOConnections* ioConnections READ ioConnections CONSTANT) Q_PROPERTY(bool fetchingData READ fetchingData NOTIFY fetchingDataChanged) @@ -80,10 +78,8 @@ public: Vendors* vendors() const; Plugins* plugins() const; - Things* devices() const; Things* things() const; ThingClasses* thingClasses() const; - ThingClasses* deviceClasses() const; IOConnections* ioConnections() const; bool fetchingData() const; @@ -158,7 +154,7 @@ signals: private: static Vendor *unpackVendor(const QVariantMap &vendorMap); static Plugin *unpackPlugin(const QVariantMap &pluginMap, QObject *parent); - static ThingClass *unpackThingClass(const QVariantMap &deviceClassMap); + static ThingClass *unpackThingClass(const QVariantMap &thingClassMap); static void unpackParam(const QVariantMap ¶mMap, Param *param); static ParamType *unpackParamType(const QVariantMap ¶mTypeMap, QObject *parent); static StateType *unpackStateType(const QVariantMap &stateTypeMap, QObject *parent); diff --git a/libnymea-app/things.cpp b/libnymea-app/things.cpp index cd4b7811..47ac1430 100644 --- a/libnymea-app/things.cpp +++ b/libnymea-app/things.cpp @@ -78,7 +78,6 @@ QVariant Things::data(const QModelIndex &index, int role) const return thing->name(); case RoleId: return thing->id().toString(); - case RoleDeviceClass: case RoleThingClass: return thing->thingClassId().toString(); case RoleParentId: @@ -145,7 +144,6 @@ QHash Things::roleNames() const QHash roles; roles[RoleName] = "name"; roles[RoleId] = "id"; - roles[RoleDeviceClass] = "deviceClassId"; roles[RoleThingClass] = "thingClassId"; roles[RoleParentId] = "parentId"; roles[RoleSetupStatus] = "setupStatus"; diff --git a/libnymea-app/things.h b/libnymea-app/things.h index 213eefe7..f6b518a1 100644 --- a/libnymea-app/things.h +++ b/libnymea-app/things.h @@ -45,7 +45,6 @@ public: RoleName, RoleId, RoleParentId, - RoleDeviceClass, RoleThingClass, RoleSetupStatus, RoleSetupDisplayMessage, diff --git a/libnymea-app/types/interface.cpp b/libnymea-app/types/interface.cpp index 350c6b62..d4c9160e 100644 --- a/libnymea-app/types/interface.cpp +++ b/libnymea-app/types/interface.cpp @@ -71,7 +71,7 @@ ActionTypes* Interface::actionTypes() const return m_actionTypes; } -ThingClass *Interface::createDeviceClass() +ThingClass *Interface::createThingClass() { ThingClass* dc = new ThingClass(); dc->setName(m_name); diff --git a/libnymea-app/types/interface.h b/libnymea-app/types/interface.h index 1b387b7c..63a19426 100644 --- a/libnymea-app/types/interface.h +++ b/libnymea-app/types/interface.h @@ -56,7 +56,7 @@ public: StateTypes* stateTypes() const; ActionTypes* actionTypes() const; - ThingClass* createDeviceClass(); + ThingClass* createThingClass(); private: QString m_name; diff --git a/libnymea-app/types/rule.cpp b/libnymea-app/types/rule.cpp index cff395ee..e55529ab 100644 --- a/libnymea-app/types/rule.cpp +++ b/libnymea-app/types/rule.cpp @@ -263,7 +263,7 @@ QDebug operator <<(QDebug &dbg, Rule *rule) RuleAction *ra = rule->actions()->get(i); dbg << " " << i << ":"; if (!ra->thingId().isNull() && !ra->actionTypeId().isNull()) { - dbg << "Device ID:" << ra->thingId() << "Action Type ID:" << ra->actionTypeId() << endl; + dbg << "Thing ID:" << ra->thingId() << "Action Type ID:" << ra->actionTypeId() << endl; } else { dbg << "Interface Name:" << ra->interfaceName() << "Action Name:" << ra->interfaceAction() << endl; } @@ -284,7 +284,7 @@ QDebug operator <<(QDebug &dbg, Rule *rule) RuleAction *ra = rule->exitActions()->get(i); dbg << " " << i << ":"; if (!ra->thingId().isNull() && !ra->actionTypeId().isNull()) { - dbg << "Device ID:" << ra->thingId() << "Action Type ID:" << ra->actionTypeId() << endl;; + dbg << "Thing ID:" << ra->thingId() << "Action Type ID:" << ra->actionTypeId() << endl;; } else { dbg << "Interface Name:" << ra->interfaceName() << "Action Name:" << ra->interfaceAction() << endl;; } @@ -306,7 +306,7 @@ QDebug printStateEvaluator(QDebug &dbg, StateEvaluator *stateEvaluator, int inde for (int i = 0; i < indentLevel; i++) { dbg << " "; } dbg << "State Descriptor:"; if (!stateEvaluator->stateDescriptor()->thingId().isNull() && !stateEvaluator->stateDescriptor()->stateTypeId().isNull()) { - dbg << "Device ID:" << stateEvaluator->stateDescriptor()->thingId().toString() << "State Type ID:" << stateEvaluator->stateDescriptor()->stateTypeId().toString(); + dbg << "Thing ID:" << stateEvaluator->stateDescriptor()->thingId().toString() << "State Type ID:" << stateEvaluator->stateDescriptor()->stateTypeId().toString(); } else { dbg << "Interface name:" << stateEvaluator->stateDescriptor()->interfaceName() << "State Name:" << stateEvaluator->stateDescriptor()->interfaceState(); } diff --git a/libnymea-app/types/thing.cpp b/libnymea-app/types/thing.cpp index d577cf5a..9a544b9b 100644 --- a/libnymea-app/types/thing.cpp +++ b/libnymea-app/types/thing.cpp @@ -69,11 +69,6 @@ void Thing::setId(const QUuid &id) m_id = id; } -QUuid Thing::deviceClassId() const -{ - return m_thingClass->id(); -} - QUuid Thing::thingClassId() const { return m_thingClass->id(); diff --git a/libnymea-app/types/thing.h b/libnymea-app/types/thing.h index 8c022958..2580a3e1 100644 --- a/libnymea-app/types/thing.h +++ b/libnymea-app/types/thing.h @@ -45,7 +45,6 @@ class Thing : public QObject { Q_OBJECT Q_PROPERTY(QUuid id READ id CONSTANT) - Q_PROPERTY(QUuid deviceClassId READ deviceClassId CONSTANT) Q_PROPERTY(QUuid thingClassId READ thingClassId CONSTANT) Q_PROPERTY(QUuid parentId READ parentId CONSTANT) Q_PROPERTY(bool isChild READ isChild CONSTANT) @@ -55,7 +54,6 @@ class Thing : public QObject Q_PROPERTY(Params *params READ params NOTIFY paramsChanged) Q_PROPERTY(Params *settings READ settings NOTIFY settingsChanged) Q_PROPERTY(States *states READ states NOTIFY statesChanged) - Q_PROPERTY(ThingClass *deviceClass READ thingClass CONSTANT) Q_PROPERTY(ThingClass *thingClass READ thingClass CONSTANT) public: @@ -106,7 +104,6 @@ public: QString name() const; void setName(const QString &name); - QUuid deviceClassId() const; QUuid thingClassId() const; QUuid parentId() const; bool isChild() const; diff --git a/nymea-app/ui/delegates/InterfaceTile.qml b/nymea-app/ui/delegates/InterfaceTile.qml index adcf9b15..ce09a64b 100644 --- a/nymea-app/ui/delegates/InterfaceTile.qml +++ b/nymea-app/ui/delegates/InterfaceTile.qml @@ -217,15 +217,15 @@ MainPageTile { property int currentDeviceIndex: 0 readonly property Thing currentDevice: thingsProxy.get(currentDeviceIndex) - readonly property StateType playbackStateType: currentDevice.deviceClass.stateTypes.findByName("playbackStatus") + readonly property StateType playbackStateType: currentDevice.thingClass.stateTypes.findByName("playbackStatus") readonly property State playbackState: currentDevice.states.getState(playbackStateType.id) - readonly property StateType artworkStateType: currentDevice.deviceClass.stateTypes.findByName("artwork") + readonly property StateType artworkStateType: currentDevice.thingClass.stateTypes.findByName("artwork") readonly property State artworkState: artworkStateType ? currentDevice.states.getState(artworkStateType.id) : null Component.onCompleted: { for (var i = 0; i < thingsProxy.count; i++) { var d = thingsProxy.get(i); - var st = d.deviceClass.stateTypes.findByName("playbackStatus") + var st = d.thingClass.stateTypes.findByName("playbackStatus") var s = d.states.getState(st.id) s.valueChanged.connect(function() {inlineMediaControl.updateTile()}) } @@ -237,7 +237,7 @@ MainPageTile { var pausedIndex = -1; for (var i = 0; i < thingsProxy.count; i++) { var d = thingsProxy.get(i); - var st = d.deviceClass.stateTypes.findByName("playbackStatus"); + var st = d.thingClass.stateTypes.findByName("playbackStatus"); if (!st) continue; var s = d.states.getState(st.id); if (playingIndex === -1 && s.value === "Playing") { diff --git a/nymea-app/ui/experiences/heating/Main.qml b/nymea-app/ui/experiences/heating/Main.qml index b49b5ae0..db991a41 100644 --- a/nymea-app/ui/experiences/heating/Main.qml +++ b/nymea-app/ui/experiences/heating/Main.qml @@ -44,11 +44,11 @@ Item { readonly property Thing duwWpDevice: duwWpFilterModel.count > 0 ? duwWpFilterModel.get(0) : null readonly property Thing duwLuDevice: duwLuFilterModel.count > 0 ? duwLuFilterModel.get(0) : null - readonly property State temperatureState: duwWpDevice ? duwWpDevice.states.getState(duwWpDevice.deviceClass.stateTypes.findByName("temperature").id) : null - readonly property State targetTemperatureState: duwWpDevice ? duwWpDevice.states.getState(duwWpDevice.deviceClass.stateTypes.findByName("targetTemperature").id) : null - readonly property State co2LevelState: duwLuDevice ? duwLuDevice.states.getState(duwLuDevice.deviceClass.stateTypes.findByName("co2").id) : null - readonly property State ventilationModeState: duwLuDevice ? duwLuDevice.states.getState(duwLuDevice.deviceClass.stateTypes.findByName("ventilationMode").id) : null - readonly property State ventilationLevelState: duwLuDevice ? duwLuDevice.states.getState(duwLuDevice.deviceClass.stateTypes.findByName("activeVentilationLevel").id) : null + readonly property State temperatureState: duwWpDevice ? duwWpDevice.states.getState(duwWpDevice.thingClass.stateTypes.findByName("temperature").id) : null + readonly property State targetTemperatureState: duwWpDevice ? duwWpDevice.states.getState(duwWpDevice.thingClass.stateTypes.findByName("targetTemperature").id) : null + readonly property State co2LevelState: duwLuDevice ? duwLuDevice.states.getState(duwLuDevice.thingClass.stateTypes.findByName("co2").id) : null + readonly property State ventilationModeState: duwLuDevice ? duwLuDevice.states.getState(duwLuDevice.thingClass.stateTypes.findByName("ventilationMode").id) : null + readonly property State ventilationLevelState: duwLuDevice ? duwLuDevice.states.getState(duwLuDevice.thingClass.stateTypes.findByName("activeVentilationLevel").id) : null function ventilationModeToSliderValue(ventilationMode) { switch (ventilationMode) { diff --git a/nymea-app/ui/thingconfiguration/SetupWizard.qml b/nymea-app/ui/thingconfiguration/SetupWizard.qml index 36bd1835..c2eb1923 100644 --- a/nymea-app/ui/thingconfiguration/SetupWizard.qml +++ b/nymea-app/ui/thingconfiguration/SetupWizard.qml @@ -44,7 +44,6 @@ Page { // Optional: If set, it will be reconfigred, otherwise a new one will be created property Thing thing: null - property alias device: root.thing // Transitional, use thing instead signal done(); @@ -89,14 +88,14 @@ Page { } } else if (root.thingClass.createMethods.indexOf("CreateMethodUser") !== -1) { print("CreateMethodUser") - // Setting up a new device + // Setting up a new thing if (!root.thing) { print("New thing setup") internalPageStack.push(paramsPage) // Reconfigure } else if (root.thing) { - print("Existing device") + print("Existing thing") // There are params. Open params page in any case if (root.thingClass.paramTypes.count > 0) { print("Params:", root.thingClass.paramTypes.count)