some more device -> thing

This commit is contained in:
Michael Zanetti 2021-03-06 01:20:10 +01:00
parent 0c205e3edc
commit 3032e5f2df
16 changed files with 31 additions and 63 deletions

View File

@ -450,7 +450,7 @@ void LogsModelNg::newLogEntryReceived(const QVariantMap &data)
m_list.prepend(entry); m_list.prepend(entry);
if (m_graphSeries) { 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()); StateType *entryStateType = dev->thingClass()->stateTypes()->getStateType(entry->typeId());

View File

@ -96,11 +96,6 @@ ThingClass *ThingClasses::getThingClass(QUuid thingClassId) const
return nullptr; return nullptr;
} }
ThingClass *ThingClasses::getDeviceClass(QUuid thingClassId) const
{
return getThingClass(thingClassId);
}
void ThingClasses::addThingClass(ThingClass *thingClass) void ThingClasses::addThingClass(ThingClass *thingClass)
{ {
thingClass->setParent(this); thingClass->setParent(this);

View File

@ -28,8 +28,8 @@
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#ifndef DEVICECLASSMODEL_H #ifndef THINGCLASSES_H
#define DEVICECLASSMODEL_H #define THINGCLASSES_H
#include <QAbstractListModel> #include <QAbstractListModel>
@ -60,7 +60,6 @@ public:
Q_INVOKABLE int count() const; Q_INVOKABLE int count() const;
Q_INVOKABLE ThingClass *get(int index) const; Q_INVOKABLE ThingClass *get(int index) const;
Q_INVOKABLE ThingClass *getThingClass(QUuid thingClassId) const; Q_INVOKABLE ThingClass *getThingClass(QUuid thingClassId) const;
Q_INVOKABLE ThingClass *getDeviceClass(QUuid thingClassId) const;
void addThingClass(ThingClass *thingClass); void addThingClass(ThingClass *thingClass);
@ -77,4 +76,4 @@ private:
}; };
#endif // DEVICECLASSMODEL_H #endif // THINGCLASSES_H

View File

@ -69,7 +69,7 @@ QHash<int, QByteArray> ThingDiscovery::roleNames() const
return roles; return roles;
} }
void ThingDiscovery::discoverThings(const QUuid &deviceClassId, const QVariantList &discoveryParams) void ThingDiscovery::discoverThings(const QUuid &thingClassId, const QVariantList &discoveryParams)
{ {
if (m_busy) { if (m_busy) {
qWarning() << "Busy... not restarting discovery"; qWarning() << "Busy... not restarting discovery";
@ -81,20 +81,20 @@ void ThingDiscovery::discoverThings(const QUuid &deviceClassId, const QVariantLi
emit countChanged(); emit countChanged();
if (!m_engine) { if (!m_engine) {
qWarning() << "Cannot discover devices. No Engine set"; qWarning() << "Cannot discover things. No Engine set";
return; return;
} }
if (!m_engine->jsonRpcClient()->connected()) { if (!m_engine->jsonRpcClient()->connected()) {
qWarning() << "Cannot discover devices. Not connected."; qWarning() << "Cannot discover things. Not connected.";
return; return;
} }
QVariantMap params; QVariantMap params;
params.insert("deviceClassId", deviceClassId.toString()); params.insert("thingClassId", thingClassId.toString());
if (!discoveryParams.isEmpty()) { if (!discoveryParams.isEmpty()) {
params.insert("discoveryParams", discoveryParams); params.insert("discoveryParams", discoveryParams);
} }
m_engine->jsonRpcClient()->sendCommand("Devices.GetDiscoveredDevices", params, this, "discoverThingsResponse"); m_engine->jsonRpcClient()->sendCommand("Integrations.DiscoverThings", params, this, "discoverThingsResponse");
m_busy = true; m_busy = true;
m_displayMessage.clear(); m_displayMessage.clear();
emit busyChanged(); emit busyChanged();

View File

@ -87,11 +87,6 @@ Plugins *ThingManager::plugins() const
return m_plugins; return m_plugins;
} }
Things *ThingManager::devices() const
{
return m_things;
}
Things *ThingManager::things() const Things *ThingManager::things() const
{ {
return m_things; return m_things;
@ -102,11 +97,6 @@ ThingClasses *ThingManager::thingClasses() const
return m_thingClasses; return m_thingClasses;
} }
ThingClasses *ThingManager::deviceClasses() const
{
return m_thingClasses;
}
IOConnections *ThingManager::ioConnections() const IOConnections *ThingManager::ioConnections() const
{ {
return m_ioConnections; return m_ioConnections;
@ -241,9 +231,9 @@ void ThingManager::getVendorsResponse(int /*commandId*/, const QVariantMap &para
void ThingManager::getThingClassesResponse(int /*commandId*/, const QVariantMap &params) void ThingManager::getThingClassesResponse(int /*commandId*/, const QVariantMap &params)
{ {
if (params.keys().contains("thingClasses")) { if (params.keys().contains("thingClasses")) {
QVariantList deviceClassList = params.value("thingClasses").toList(); QVariantList thingClassList = params.value("thingClasses").toList();
foreach (QVariant deviceClassVariant, deviceClassList) { foreach (QVariant thingClassVariant, thingClassList) {
ThingClass *thingClass = unpackThingClass(deviceClassVariant.toMap()); ThingClass *thingClass = unpackThingClass(thingClassVariant.toMap());
m_thingClasses->addThingClass(thingClass); m_thingClasses->addThingClass(thingClass);
} }
} }
@ -325,7 +315,7 @@ void ThingManager::getThingsResponse(int /*commandId*/, const QVariantMap &param
thing->setStateValue(stateTypeId, value); thing->setStateValue(stateTypeId, value);
// qDebug() << "Set thing state value:" << thing->stateValue(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"; 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 *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()); group->setSetupStatus(Thing::ThingSetupStatusComplete, QString());
return group; return group;
} }

View File

@ -55,9 +55,7 @@ class ThingManager : public JsonHandler
Q_PROPERTY(Vendors* vendors READ vendors CONSTANT) Q_PROPERTY(Vendors* vendors READ vendors CONSTANT)
Q_PROPERTY(Plugins* plugins READ plugins CONSTANT) Q_PROPERTY(Plugins* plugins READ plugins CONSTANT)
Q_PROPERTY(Things* things READ things 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* thingClasses READ thingClasses CONSTANT)
Q_PROPERTY(ThingClasses* deviceClasses READ thingClasses CONSTANT)
Q_PROPERTY(IOConnections* ioConnections READ ioConnections CONSTANT) Q_PROPERTY(IOConnections* ioConnections READ ioConnections CONSTANT)
Q_PROPERTY(bool fetchingData READ fetchingData NOTIFY fetchingDataChanged) Q_PROPERTY(bool fetchingData READ fetchingData NOTIFY fetchingDataChanged)
@ -80,10 +78,8 @@ public:
Vendors* vendors() const; Vendors* vendors() const;
Plugins* plugins() const; Plugins* plugins() const;
Things* devices() const;
Things* things() const; Things* things() const;
ThingClasses* thingClasses() const; ThingClasses* thingClasses() const;
ThingClasses* deviceClasses() const;
IOConnections* ioConnections() const; IOConnections* ioConnections() const;
bool fetchingData() const; bool fetchingData() const;
@ -158,7 +154,7 @@ signals:
private: private:
static Vendor *unpackVendor(const QVariantMap &vendorMap); static Vendor *unpackVendor(const QVariantMap &vendorMap);
static Plugin *unpackPlugin(const QVariantMap &pluginMap, QObject *parent); 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 &paramMap, Param *param); static void unpackParam(const QVariantMap &paramMap, Param *param);
static ParamType *unpackParamType(const QVariantMap &paramTypeMap, QObject *parent); static ParamType *unpackParamType(const QVariantMap &paramTypeMap, QObject *parent);
static StateType *unpackStateType(const QVariantMap &stateTypeMap, QObject *parent); static StateType *unpackStateType(const QVariantMap &stateTypeMap, QObject *parent);

View File

@ -78,7 +78,6 @@ QVariant Things::data(const QModelIndex &index, int role) const
return thing->name(); return thing->name();
case RoleId: case RoleId:
return thing->id().toString(); return thing->id().toString();
case RoleDeviceClass:
case RoleThingClass: case RoleThingClass:
return thing->thingClassId().toString(); return thing->thingClassId().toString();
case RoleParentId: case RoleParentId:
@ -145,7 +144,6 @@ QHash<int, QByteArray> Things::roleNames() const
QHash<int, QByteArray> roles; QHash<int, QByteArray> roles;
roles[RoleName] = "name"; roles[RoleName] = "name";
roles[RoleId] = "id"; roles[RoleId] = "id";
roles[RoleDeviceClass] = "deviceClassId";
roles[RoleThingClass] = "thingClassId"; roles[RoleThingClass] = "thingClassId";
roles[RoleParentId] = "parentId"; roles[RoleParentId] = "parentId";
roles[RoleSetupStatus] = "setupStatus"; roles[RoleSetupStatus] = "setupStatus";

View File

@ -45,7 +45,6 @@ public:
RoleName, RoleName,
RoleId, RoleId,
RoleParentId, RoleParentId,
RoleDeviceClass,
RoleThingClass, RoleThingClass,
RoleSetupStatus, RoleSetupStatus,
RoleSetupDisplayMessage, RoleSetupDisplayMessage,

View File

@ -71,7 +71,7 @@ ActionTypes* Interface::actionTypes() const
return m_actionTypes; return m_actionTypes;
} }
ThingClass *Interface::createDeviceClass() ThingClass *Interface::createThingClass()
{ {
ThingClass* dc = new ThingClass(); ThingClass* dc = new ThingClass();
dc->setName(m_name); dc->setName(m_name);

View File

@ -56,7 +56,7 @@ public:
StateTypes* stateTypes() const; StateTypes* stateTypes() const;
ActionTypes* actionTypes() const; ActionTypes* actionTypes() const;
ThingClass* createDeviceClass(); ThingClass* createThingClass();
private: private:
QString m_name; QString m_name;

View File

@ -263,7 +263,7 @@ QDebug operator <<(QDebug &dbg, Rule *rule)
RuleAction *ra = rule->actions()->get(i); RuleAction *ra = rule->actions()->get(i);
dbg << " " << i << ":"; dbg << " " << i << ":";
if (!ra->thingId().isNull() && !ra->actionTypeId().isNull()) { 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 { } else {
dbg << "Interface Name:" << ra->interfaceName() << "Action Name:" << ra->interfaceAction() << endl; 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); RuleAction *ra = rule->exitActions()->get(i);
dbg << " " << i << ":"; dbg << " " << i << ":";
if (!ra->thingId().isNull() && !ra->actionTypeId().isNull()) { 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 { } else {
dbg << "Interface Name:" << ra->interfaceName() << "Action Name:" << ra->interfaceAction() << endl;; 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 << " "; } for (int i = 0; i < indentLevel; i++) { dbg << " "; }
dbg << "State Descriptor:"; dbg << "State Descriptor:";
if (!stateEvaluator->stateDescriptor()->thingId().isNull() && !stateEvaluator->stateDescriptor()->stateTypeId().isNull()) { 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 { } else {
dbg << "Interface name:" << stateEvaluator->stateDescriptor()->interfaceName() << "State Name:" << stateEvaluator->stateDescriptor()->interfaceState(); dbg << "Interface name:" << stateEvaluator->stateDescriptor()->interfaceName() << "State Name:" << stateEvaluator->stateDescriptor()->interfaceState();
} }

View File

@ -69,11 +69,6 @@ void Thing::setId(const QUuid &id)
m_id = id; m_id = id;
} }
QUuid Thing::deviceClassId() const
{
return m_thingClass->id();
}
QUuid Thing::thingClassId() const QUuid Thing::thingClassId() const
{ {
return m_thingClass->id(); return m_thingClass->id();

View File

@ -45,7 +45,6 @@ class Thing : public QObject
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(QUuid id READ id CONSTANT) Q_PROPERTY(QUuid id READ id CONSTANT)
Q_PROPERTY(QUuid deviceClassId READ deviceClassId CONSTANT)
Q_PROPERTY(QUuid thingClassId READ thingClassId CONSTANT) Q_PROPERTY(QUuid thingClassId READ thingClassId CONSTANT)
Q_PROPERTY(QUuid parentId READ parentId CONSTANT) Q_PROPERTY(QUuid parentId READ parentId CONSTANT)
Q_PROPERTY(bool isChild READ isChild 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 *params READ params NOTIFY paramsChanged)
Q_PROPERTY(Params *settings READ settings NOTIFY settingsChanged) Q_PROPERTY(Params *settings READ settings NOTIFY settingsChanged)
Q_PROPERTY(States *states READ states NOTIFY statesChanged) Q_PROPERTY(States *states READ states NOTIFY statesChanged)
Q_PROPERTY(ThingClass *deviceClass READ thingClass CONSTANT)
Q_PROPERTY(ThingClass *thingClass READ thingClass CONSTANT) Q_PROPERTY(ThingClass *thingClass READ thingClass CONSTANT)
public: public:
@ -106,7 +104,6 @@ public:
QString name() const; QString name() const;
void setName(const QString &name); void setName(const QString &name);
QUuid deviceClassId() const;
QUuid thingClassId() const; QUuid thingClassId() const;
QUuid parentId() const; QUuid parentId() const;
bool isChild() const; bool isChild() const;

View File

@ -217,15 +217,15 @@ MainPageTile {
property int currentDeviceIndex: 0 property int currentDeviceIndex: 0
readonly property Thing currentDevice: thingsProxy.get(currentDeviceIndex) readonly property Thing currentDevice: thingsProxy.get(currentDeviceIndex)
readonly property StateType playbackStateType: currentDevice.deviceClass.stateTypes.findByName("playbackStatus") readonly property StateType playbackStateType: currentDevice.thingClass.stateTypes.findByName("playbackStatus")
readonly property State playbackState: currentDevice.states.getState(playbackStateType.id) readonly property State playbackState: currentDevice.states.getState(playbackStateType.id)
readonly property StateType artworkStateType: currentDevice.deviceClass.stateTypes.findByName("artwork") readonly property StateType artworkStateType: currentDevice.thingClass.stateTypes.findByName("artwork")
readonly property State artworkState: artworkStateType ? currentDevice.states.getState(artworkStateType.id) : null readonly property State artworkState: artworkStateType ? currentDevice.states.getState(artworkStateType.id) : null
Component.onCompleted: { Component.onCompleted: {
for (var i = 0; i < thingsProxy.count; i++) { for (var i = 0; i < thingsProxy.count; i++) {
var d = thingsProxy.get(i); var d = thingsProxy.get(i);
var st = d.deviceClass.stateTypes.findByName("playbackStatus") var st = d.thingClass.stateTypes.findByName("playbackStatus")
var s = d.states.getState(st.id) var s = d.states.getState(st.id)
s.valueChanged.connect(function() {inlineMediaControl.updateTile()}) s.valueChanged.connect(function() {inlineMediaControl.updateTile()})
} }
@ -237,7 +237,7 @@ MainPageTile {
var pausedIndex = -1; var pausedIndex = -1;
for (var i = 0; i < thingsProxy.count; i++) { for (var i = 0; i < thingsProxy.count; i++) {
var d = thingsProxy.get(i); var d = thingsProxy.get(i);
var st = d.deviceClass.stateTypes.findByName("playbackStatus"); var st = d.thingClass.stateTypes.findByName("playbackStatus");
if (!st) continue; if (!st) continue;
var s = d.states.getState(st.id); var s = d.states.getState(st.id);
if (playingIndex === -1 && s.value === "Playing") { if (playingIndex === -1 && s.value === "Playing") {

View File

@ -44,11 +44,11 @@ Item {
readonly property Thing duwWpDevice: duwWpFilterModel.count > 0 ? duwWpFilterModel.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 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 temperatureState: duwWpDevice ? duwWpDevice.states.getState(duwWpDevice.thingClass.stateTypes.findByName("temperature").id) : null
readonly property State targetTemperatureState: duwWpDevice ? duwWpDevice.states.getState(duwWpDevice.deviceClass.stateTypes.findByName("targetTemperature").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.deviceClass.stateTypes.findByName("co2").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.deviceClass.stateTypes.findByName("ventilationMode").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.deviceClass.stateTypes.findByName("activeVentilationLevel").id) : null readonly property State ventilationLevelState: duwLuDevice ? duwLuDevice.states.getState(duwLuDevice.thingClass.stateTypes.findByName("activeVentilationLevel").id) : null
function ventilationModeToSliderValue(ventilationMode) { function ventilationModeToSliderValue(ventilationMode) {
switch (ventilationMode) { switch (ventilationMode) {

View File

@ -44,7 +44,6 @@ Page {
// Optional: If set, it will be reconfigred, otherwise a new one will be created // Optional: If set, it will be reconfigred, otherwise a new one will be created
property Thing thing: null property Thing thing: null
property alias device: root.thing // Transitional, use thing instead
signal done(); signal done();
@ -89,14 +88,14 @@ Page {
} }
} else if (root.thingClass.createMethods.indexOf("CreateMethodUser") !== -1) { } else if (root.thingClass.createMethods.indexOf("CreateMethodUser") !== -1) {
print("CreateMethodUser") print("CreateMethodUser")
// Setting up a new device // Setting up a new thing
if (!root.thing) { if (!root.thing) {
print("New thing setup") print("New thing setup")
internalPageStack.push(paramsPage) internalPageStack.push(paramsPage)
// Reconfigure // Reconfigure
} else if (root.thing) { } else if (root.thing) {
print("Existing device") print("Existing thing")
// There are params. Open params page in any case // There are params. Open params page in any case
if (root.thingClass.paramTypes.count > 0) { if (root.thingClass.paramTypes.count > 0) {
print("Params:", root.thingClass.paramTypes.count) print("Params:", root.thingClass.paramTypes.count)