Added get status call

master
bernhard.trinnes 2020-07-20 11:10:34 +02:00 committed by Boernsman
parent 1ed1306e50
commit d9a679facc
4 changed files with 70 additions and 15 deletions

View File

@ -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<QString, QString> 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);
});
}

View File

@ -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<QString, QVariant> &statusList);
void receivedHomeAppliances(const QList<HomeAppliance> &appliances);
void receivedAvailablePrograms();
};
#endif // HOMECONNECT_H

View File

@ -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<HomeConnect::H
if (!desciptors.isEmpty())
emit autoThingsAppeared(desciptors);
}
void IntegrationPluginHomeConnect::onReceivedStatusList(QHash<QString, QString> statusList)
{
HomeConnect *homeConnectConnection = static_cast<HomeConnect *>(sender());
Thing *parentThing = m_homeConnectConnections.key(homeConnectConnection);
if (!parentThing)
return;
if (statusList.contains("BSH.Common.Status.LocalControlActive")) {
}
}

View File

@ -74,11 +74,13 @@ private:
QHash<ThingClassId, StateTypeId> m_connectedStateTypeIds;
HomeConnect *createHomeConnection();
private slots:
void onConnectionChanged(bool connected);
void onAuthenticationStatusChanged(bool authenticated);
void onRequestExecuted(QUuid requestId, bool success);
void onReceivedHomeAppliances(QList<HomeConnect::HomeAppliance> appliances);
void onReceivedStatusList(const QString &haId, const QHash<QString, QVariant> &statusList);
};
#endif // INTEGRATIONPLUGINHOMECONNECT_H