From d9a679faccd10a81e67a463b246c5b38d0569aad Mon Sep 17 00:00:00 2001 From: "bernhard.trinnes" Date: Mon, 20 Jul 2020 11:10:34 +0200 Subject: [PATCH] Added get status call --- homeconnect/homeconnect.cpp | 20 ++++--- homeconnect/homeconnect.h | 6 +++ homeconnect/integrationpluginhomeconnect.cpp | 57 +++++++++++++++++--- homeconnect/integrationpluginhomeconnect.h | 2 + 4 files changed, 70 insertions(+), 15 deletions(-) diff --git a/homeconnect/homeconnect.cpp b/homeconnect/homeconnect.cpp index cee8b7b1..1fa9f812 100644 --- a/homeconnect/homeconnect.cpp +++ b/homeconnect/homeconnect.cpp @@ -359,7 +359,7 @@ void HomeConnect::getStatus(const QString &haid) QNetworkReply *reply = m_networkManager->get(request); connect(reply, &QNetworkReply::finished, reply, &QNetworkReply::deleteLater); - connect(reply, &QNetworkReply::finished, this, [this, reply]{ + connect(reply, &QNetworkReply::finished, this, [this, haid, reply]{ // Remote control activation state @@ -371,16 +371,20 @@ void HomeConnect::getStatus(const QString &haid) QJsonParseError error; QJsonDocument data = QJsonDocument::fromJson(reply->readAll(), &error); if (error.error != QJsonParseError::NoError) { - qCDebug(dcHomeConnect()) << "Get home appliances: Recieved invalide JSON object"; + qCDebug(dcHomeConnect()) << "Get status: Recieved invalide JSON object"; return; } - qCDebug(dcHomeConnect()) << "Get home appliances" << data.toJson(); - if (data.toVariant().toMap().contains("data")) { - QVariantMap dataMap = data.toVariant().toMap().value("data").toMap(); - qCDebug(dcHomeConnect()) << "key" << dataMap.value("key").toString() << "value" << dataMap.value("value").toString() << dataMap.value("unit").toString(); - } else if (data.toVariant().toMap().contains("error")) { - qCWarning(dcHomeConnect()) << "Get home appliences" << data.toVariant().toMap().value("error").toMap().value("description").toString(); + QHash statusList; + qCDebug(dcHomeConnect()) << "Get status" << data.toJson(); + QVariantList statusVariantList= data.toVariant().toMap().value("data").toMap().value("status").toList(); + Q_FOREACH(QVariant status, statusVariantList) { + QVariantMap map = status.toMap(); + if (map.value("key") == "BSH.Common.Status.OperationState") { + qCDebug(dcHomeConnect()) << map.value("value").toString(); + } + statusList.insert(map.value("key").toString(), map.value("value").toString()); } + emit receivedStatus(haid, statusList); }); } diff --git a/homeconnect/homeconnect.h b/homeconnect/homeconnect.h index 3f92593d..e6ed79e6 100644 --- a/homeconnect/homeconnect.h +++ b/homeconnect/homeconnect.h @@ -73,6 +73,10 @@ public: QString unit; }; + struct Status { + + }; + HomeConnect(NetworkAccessManager *networkmanager, const QByteArray &clientKey, const QByteArray &clientSecret, bool simulationMode = false, QObject *parent = nullptr); QByteArray accessToken(); QByteArray refreshToken(); @@ -118,6 +122,8 @@ signals: void authenticationStatusChanged(bool authenticated); void commandExecuted(QUuid commandId,bool success); + void receivedStatus(const QString &haId, const QHash &statusList); void receivedHomeAppliances(const QList &appliances); + void receivedAvailablePrograms(); }; #endif // HOMECONNECT_H diff --git a/homeconnect/integrationpluginhomeconnect.cpp b/homeconnect/integrationpluginhomeconnect.cpp index ba899bea..3d5a02e0 100644 --- a/homeconnect/integrationpluginhomeconnect.cpp +++ b/homeconnect/integrationpluginhomeconnect.cpp @@ -47,14 +47,18 @@ IntegrationPluginHomeConnect::IntegrationPluginHomeConnect() m_idParamTypeIds.insert(washerThingClassId, washerThingIdParamTypeId); m_idParamTypeIds.insert(ovenThingClassId, ovenThingIdParamTypeId); m_idParamTypeIds.insert(cookTopThingClassId, cookTopThingIdParamTypeId); - //TODO add new devices + m_idParamTypeIds.insert(hoodThingClassId, hoodThingIdParamTypeId); + m_idParamTypeIds.insert(cleaningRobotThingClassId, cleaningRobotThingIdParamTypeId); + m_connectedStateTypeIds.insert(fridgeThingClassId, fridgeConnectedStateTypeId); m_connectedStateTypeIds.insert(dryerThingClassId, dryerConnectedStateTypeId); m_connectedStateTypeIds.insert(coffeMakerThingClassId, coffeMakerConnectedStateTypeId); m_connectedStateTypeIds.insert(dishwasherThingClassId, dishwasherConnectedStateTypeId); m_connectedStateTypeIds.insert(washerThingClassId, washerConnectedStateTypeId); m_connectedStateTypeIds.insert(ovenThingClassId, ovenConnectedStateTypeId); - //TODO add new devices + m_connectedStateTypeIds.insert(cookTopThingClassId, cookTopConnectedStateTypeId); + m_connectedStateTypeIds.insert(cleaningRobotThingClassId, cleaningRobotConnectedStateTypeId); + m_connectedStateTypeIds.insert(hoodThingClassId, hoodConnectedStateTypeId); } void IntegrationPluginHomeConnect::startPairing(ThingPairingInfo *info) @@ -158,7 +162,10 @@ void IntegrationPluginHomeConnect::setupThing(ThingSetupInfo *info) (thing->thingClassId() == washerThingClassId) || (thing->thingClassId() == dishwasherThingClassId) || (thing->thingClassId() == coffeMakerThingClassId) || - (thing->thingClassId() == ovenThingClassId)) { + (thing->thingClassId() == ovenThingClassId) || + (thing->thingClassId() == hoodThingClassId) || + (thing->thingClassId() == cleaningRobotThingClassId) || + (thing->thingClassId() == cookTopThingClassId)) { Thing *parentThing = myThings().findById(thing->parentId()); if (parentThing->setupComplete()) { info->finish(Thing::ThingErrorNoError); @@ -218,7 +225,10 @@ void IntegrationPluginHomeConnect::postSetupThing(Thing *thing) (thing->thingClassId() == washerThingClassId) || (thing->thingClassId() == dishwasherThingClassId) || (thing->thingClassId() == coffeMakerThingClassId) || - (thing->thingClassId() == ovenThingClassId)) { + (thing->thingClassId() == ovenThingClassId) || + (thing->thingClassId() == hoodThingClassId) || + (thing->thingClassId() == cleaningRobotThingClassId) || + (thing->thingClassId() == cookTopThingClassId)){ Thing *parentThing = myThings().findById(thing->parentId()); if (!parentThing) qCWarning(dcHomeConnect()) << "Could not find parent with Id" << thing->parentId().toString(); @@ -245,15 +255,20 @@ void IntegrationPluginHomeConnect::executeAction(ThingActionInfo *info) } else if (thing->thingClassId() == ovenThingClassId) { HomeConnect *homeConnect = m_homeConnectConnections.value(myThings().findById(thing->parentId())); QString haid = thing->stateValue(m_idParamTypeIds.value(thing->thingClassId())).toString(); + QUuid requestId; if (action.actionTypeId() == ovenPauseActionTypeId) { - homeConnect->sendCommand(haid, "BSH.Common.Command.PauseProgram"); + requestId = homeConnect->sendCommand(haid, "BSH.Common.Command.PauseProgram"); } else if (action.actionTypeId() == ovenResumeActionTypeId) { - homeConnect->sendCommand(haid, "BSH.Common.Command.ResumeProgram"); + requestId = homeConnect->sendCommand(haid, "BSH.Common.Command.ResumeProgram"); } else { Q_ASSERT_X(false, "executeAction", QString("Unhandled actionTypeId: %1").arg(action.actionTypeId().toString()).toUtf8()); } + m_pendingActions.insert(requestId, info); + connect(info, &ThingActionInfo::aborted, [requestId, this] { + m_pendingActions.remove(requestId); + }); } else { - Q_ASSERT_X(false, "executeAction", QString("Unhandled deviceClassId: %1").arg(thing->thingClassId().toString()).toUtf8()); + Q_ASSERT_X(false, "executeAction", QString("Unhandled thingClassId: %1").arg(thing->thingClassId().toString()).toUtf8()); } } @@ -279,16 +294,31 @@ void IntegrationPluginHomeConnect::thingRemoved(Thing *thing) void IntegrationPluginHomeConnect::browseThing(BrowseResult *result) { Q_UNUSED(result) + Thing *thing = result->thing(); + qCDebug(dcHomeConnect()) << "Browse thing called " << thing->name(); + + if (thing->thingClassId() == ovenThingClassId) { + HomeConnect *homeConnect = m_homeConnectConnections.value(myThings().findById(thing->parentId())); + if (!homeConnect) + return; + QString haid = thing->stateValue(m_idParamTypeIds.value(thing->thingClassId())).toString(); + homeConnect->getProgramsAvailable(haid); + connect(homeConnect, &HomeConnect::re) + } } void IntegrationPluginHomeConnect::browserItem(BrowserItemResult *result) { Q_UNUSED(result) + Thing *thing = result->thing(); + qCDebug(dcHomeConnect()) << "Browse item called " << thing->name(); } void IntegrationPluginHomeConnect::executeBrowserItem(BrowserActionInfo *info) { Q_UNUSED(info) + Thing *thing = info->thing(); + qCDebug(dcHomeConnect()) << "Execute browse item called " << thing->name(); } void IntegrationPluginHomeConnect::onConnectionChanged(bool connected) @@ -408,3 +438,16 @@ void IntegrationPluginHomeConnect::onReceivedHomeAppliances(QList statusList) +{ + HomeConnect *homeConnectConnection = static_cast(sender()); + Thing *parentThing = m_homeConnectConnections.key(homeConnectConnection); + if (!parentThing) + return; + + if (statusList.contains("BSH.Common.Status.LocalControlActive")) { + + } + +} diff --git a/homeconnect/integrationpluginhomeconnect.h b/homeconnect/integrationpluginhomeconnect.h index 537b2997..c4c8ce6b 100644 --- a/homeconnect/integrationpluginhomeconnect.h +++ b/homeconnect/integrationpluginhomeconnect.h @@ -74,11 +74,13 @@ private: QHash m_connectedStateTypeIds; HomeConnect *createHomeConnection(); + private slots: void onConnectionChanged(bool connected); void onAuthenticationStatusChanged(bool authenticated); void onRequestExecuted(QUuid requestId, bool success); void onReceivedHomeAppliances(QList appliances); + void onReceivedStatusList(const QString &haId, const QHash &statusList); }; #endif // INTEGRATIONPLUGINHOMECONNECT_H