diff --git a/homeconnect/homeconnect.cpp b/homeconnect/homeconnect.cpp index 3ecf3098..358143ff 100644 --- a/homeconnect/homeconnect.cpp +++ b/homeconnect/homeconnect.cpp @@ -309,8 +309,6 @@ void HomeConnect::getPrograms(const QString &haId) checkStatusCode(status, rawData); QVariantMap dataMap = QJsonDocument::fromJson(rawData).toVariant().toMap().value("data").toMap(); - - qCDebug(dcHomeConnect()) << "Get programs available" << rawData; QVariantList programList = dataMap.value("programs").toList(); QStringList programs; Q_FOREACH(QVariant var, programList) { @@ -341,8 +339,6 @@ void HomeConnect::getProgramsAvailable(const QString &haId) checkStatusCode(status, rawData); QVariantMap dataMap = QJsonDocument::fromJson(rawData).toVariant().toMap().value("data").toMap(); - - qCDebug(dcHomeConnect()) << "Get programs available" << rawData; QVariantList programList = dataMap.value("programs").toList(); QStringList programs; Q_FOREACH(QVariant var, programList) { @@ -372,19 +368,17 @@ void HomeConnect::getProgramsActive(const QString &haId) QByteArray rawData = reply->readAll(); checkStatusCode(status, rawData); - qCDebug(dcHomeConnect()) << "Get programs active" << rawData; QVariantMap map = QJsonDocument::fromJson(rawData).toVariant().toMap(); - QHash options; if (map.contains("data")) { QString key = map.value("data").toMap().value("key").toString(); Q_FOREACH(QVariant var, map.value("data").toMap().value("options").toList()) { options.insert(var.toMap().value("key").toString(), var.toMap().value("value")); } - emit receivedSelectedProgram(haId, key, options); + emit receivedActiveProgram(haId, key, options); } else if (map.contains("error")) { QString key = map.value("error").toMap().value("key").toString(); - emit receivedSelectedProgram(haId, key, options); + emit receivedActiveProgram(haId, key, options); } }); } @@ -406,9 +400,7 @@ void HomeConnect::getProgramsSelected(const QString &haId) QByteArray rawData = reply->readAll(); checkStatusCode(status, rawData); - qCDebug(dcHomeConnect()) << "Get program selected" << rawData; QVariantMap map = QJsonDocument::fromJson(rawData).toVariant().toMap(); - QHash options; if (map.contains("data")) { QString key = map.value("data").toMap().value("key").toString(); @@ -511,7 +503,6 @@ void HomeConnect::getStatus(const QString &haid) checkStatusCode(status, rawData); QVariantMap dataMap = QJsonDocument::fromJson(rawData).toVariant().toMap().value("data").toMap(); - QHash statusList; QVariantList statusVariantList= dataMap.value("status").toList(); Q_FOREACH(QVariant status, statusVariantList) { @@ -548,7 +539,6 @@ void HomeConnect::getSettings(const QString &haid) int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); QByteArray rawData = reply->readAll(); checkStatusCode(status, rawData); - qCDebug(dcHomeConnect()) << "Get settings" << rawData; QVariantMap dataMap = QJsonDocument::fromJson(rawData).toVariant().toMap().value("data").toMap(); QVariantList settingsList = dataMap.value("settings").toList(); QHash settings; @@ -581,8 +571,6 @@ void HomeConnect::connectEventStream() QJsonDocument data; QString haId; EventType eventType; - - qCDebug(dcHomeConnect()) << "Event reveived" << rawData; Q_FOREACH(QByteArray line, rawData) { if (line.startsWith("data")) { if (checkStatusCode(status, line.remove(0,6))) diff --git a/homeconnect/integrationpluginhomeconnect.cpp b/homeconnect/integrationpluginhomeconnect.cpp index 59b57720..81ad7f88 100644 --- a/homeconnect/integrationpluginhomeconnect.cpp +++ b/homeconnect/integrationpluginhomeconnect.cpp @@ -37,6 +37,7 @@ #include #include #include +#include IntegrationPluginHomeConnect::IntegrationPluginHomeConnect() { @@ -96,40 +97,28 @@ IntegrationPluginHomeConnect::IntegrationPluginHomeConnect() m_doorStateTypeIds.insert(ovenThingClassId, ovenDoorStateStateTypeId); m_operationStateTypeIds.insert(ovenThingClassId, ovenOperationStateStateTypeId); - //m_operationStateTypeIds.insert(fridgeThingClassId, fridgeOperationStateStateTypeId); m_operationStateTypeIds.insert(dryerThingClassId, dryerOperationStateStateTypeId); m_operationStateTypeIds.insert(coffeeMakerThingClassId, coffeeMakerOperationStateStateTypeId); m_operationStateTypeIds.insert(dishwasherThingClassId, dishwasherOperationStateStateTypeId); m_operationStateTypeIds.insert(washerThingClassId, washerOperationStateStateTypeId); - //m_operationStateTypeIds.insert(cookTopThingClassId, cookTopOperationStateStateTypeId); - //m_operationStateTypeIds.insert(cleaningRobotThingClassId, cleaningRobotOperationStateStateTypeId); - //m_operationStateTypeIds.insert(hoodThingClassId, hoodOperationStateStateTypeId); m_selectedProgramStateTypeIds.insert(ovenThingClassId, ovenSelectedProgramStateTypeId); - //m_selectedProgramStateTypeIds.insert(fridgeThingClassId, fridgeSelectedProgramStateTypeId); m_selectedProgramStateTypeIds.insert(dryerThingClassId, dryerSelectedProgramStateTypeId); m_selectedProgramStateTypeIds.insert(coffeeMakerThingClassId, coffeeMakerSelectedProgramStateTypeId); m_selectedProgramStateTypeIds.insert(dishwasherThingClassId, dishwasherSelectedProgramStateTypeId); m_selectedProgramStateTypeIds.insert(washerThingClassId, washerSelectedProgramStateTypeId); - //m_selectedProgramStateTypeIds.insert(cookTopThingClassId, cookTopSelectedProgramStateTypeId); - //m_selectedProgramStateTypeIds.insert(cleaningRobotThingClassId, cleaningRobotSelectedProgramStateTypeId); - //m_selectedProgramStateTypeIds.insert(hoodThingClassId, hoodSelectedProgramStateTypeId); - - m_activeProgramStateTypeIds.insert(ovenThingClassId, ovenActiveProgramStateTypeId); - //m_activeProgramStateTypeIds.insert(fridgeThingClassId, fridgeActiveProgramStateTypeId); - m_activeProgramStateTypeIds.insert(dryerThingClassId, dryerActiveProgramStateTypeId); - m_activeProgramStateTypeIds.insert(coffeeMakerThingClassId, coffeeMakerActiveProgramStateTypeId); - m_activeProgramStateTypeIds.insert(dishwasherThingClassId, dishwasherActiveProgramStateTypeId); - m_activeProgramStateTypeIds.insert(washerThingClassId, washerActiveProgramStateTypeId); - //m_activeProgramStateTypeIds.insert(cookTopThingClassId, cookTopActiveProgramStateTypeId); - //m_activeProgramStateTypeIds.insert(cleaningRobotThingClassId, cleaningRobotActiveProgramStateTypeId); - //m_activeProgramStateTypeIds.insert(hoodThingClassId, hoodActiveProgramStateTypeId); m_progressStateTypeIds.insert(ovenThingClassId, ovenProgressStateTypeId); m_progressStateTypeIds.insert(dryerThingClassId, dryerProgressStateTypeId); m_progressStateTypeIds.insert(dishwasherThingClassId, dishwasherProgressStateTypeId); m_progressStateTypeIds.insert(washerThingClassId, washerProgressStateTypeId); m_progressStateTypeIds.insert(coffeeMakerThingClassId, coffeeMakerProgressStateTypeId); + + m_endTimerStateTypeIds.insert(ovenThingClassId, ovenEndTimeStateTypeId); + + m_pauseActionTypeIds.insert(ovenThingClassId, ovenPauseActionTypeId); + m_resumeActionTypeIds.insert(ovenThingClassId, ovenResumeActionTypeId); + } void IntegrationPluginHomeConnect::startPairing(ThingPairingInfo *info) @@ -224,7 +213,6 @@ void IntegrationPluginHomeConnect::setupThing(ThingSetupInfo *info) connect(homeConnect, &HomeConnect::authenticationStatusChanged, this, &IntegrationPluginHomeConnect::onAuthenticationStatusChanged); connect(homeConnect, &HomeConnect::receivedHomeAppliances, this, &IntegrationPluginHomeConnect::onReceivedHomeAppliances); connect(homeConnect, &HomeConnect::receivedStatusList, this, &IntegrationPluginHomeConnect::onReceivedStatusList); - connect(homeConnect, &HomeConnect::receivedActiveProgram, this, &IntegrationPluginHomeConnect::onReceivedActiveProgram); connect(homeConnect, &HomeConnect::receivedSelectedProgram, this, &IntegrationPluginHomeConnect::onReceivedSelectedProgram); connect(homeConnect, &HomeConnect::receivedSettings, this, &IntegrationPluginHomeConnect::onReceivedSettings); connect(homeConnect, &HomeConnect::receivedEvents, this, &IntegrationPluginHomeConnect::onReceivedEvents); @@ -287,7 +275,6 @@ void IntegrationPluginHomeConnect::postSetupThing(Thing *thing) QString haId = childThing->paramValue(m_idParamTypeIds.value(childThing->thingClassId())).toString(); homeConnect->getStatus(haId); homeConnect->getSettings(haId); - homeConnect->getProgramsActive(haId); homeConnect->getProgramsSelected(haId); } } @@ -320,7 +307,6 @@ void IntegrationPluginHomeConnect::postSetupThing(Thing *thing) } else { homeConnect->getStatus(haId); homeConnect->getSettings(haId); - homeConnect->getProgramsActive(haId); homeConnect->getProgramsSelected(haId); } } else { @@ -332,24 +318,30 @@ void IntegrationPluginHomeConnect::executeAction(ThingActionInfo *info) { Thing *thing = info->thing(); Action action = info->action(); - if (thing->thingClassId() == homeConnectConnectionThingClassId) { - Q_ASSERT_X(false, "executeAction", QString("Unhandled actionTypeId: %1").arg(action.actionTypeId().toString()).toUtf8()); + HomeConnect *homeConnect = m_homeConnectConnections.value(myThings().findById(thing->parentId())); + if (!homeConnect) { + return info->finish(Thing::ThingErrorHardwareNotAvailable); + } + QString haid = thing->paramValue(m_idParamTypeIds.value(thing->thingClassId())).toString(); - } else if (thing->thingClassId() == ovenThingClassId) { - HomeConnect *homeConnect = m_homeConnectConnections.value(myThings().findById(thing->parentId())); - QString haid = thing->stateValue(m_idParamTypeIds.value(thing->thingClassId())).toString(); + if (m_pauseActionTypeIds.values().contains(action.actionTypeId())) { QUuid requestId; - if (action.actionTypeId() == ovenPauseActionTypeId) { - requestId = homeConnect->sendCommand(haid, "BSH.Common.Command.PauseProgram"); - } else if (action.actionTypeId() == ovenResumeActionTypeId) { - requestId = homeConnect->sendCommand(haid, "BSH.Common.Command.ResumeProgram"); - } else { - Q_ASSERT_X(false, "executeAction", QString("Unhandled actionTypeId: %1").arg(action.actionTypeId().toString()).toUtf8()); - } + requestId = homeConnect->sendCommand(haid, "BSH.Common.Command.PauseProgram"); m_pendingActions.insert(requestId, info); connect(info, &ThingActionInfo::aborted, [requestId, this] { m_pendingActions.remove(requestId); }); + } else if (m_resumeActionTypeIds.values().contains(action.actionTypeId())) { + QUuid requestId; + requestId = homeConnect->sendCommand(haid, "BSH.Common.Command.ResumeProgram"); + m_pendingActions.insert(requestId, info); + connect(info, &ThingActionInfo::aborted, [requestId, this] { + m_pendingActions.remove(requestId); + }); + } else if (thing->thingClassId() == ovenThingClassId) { + //set temperature + } else if (thing->thingClassId() == coffeeMakerThingClassId) { + } else { Q_ASSERT_X(false, "executeAction", QString("Unhandled thingClassId: %1").arg(thing->thingClassId().toString()).toUtf8()); } @@ -436,9 +428,10 @@ void IntegrationPluginHomeConnect::parseKey(Thing *thing, const QString &key, co qCDebug(dcHomeConnect()) << thing->name() << key.split('.').last() << value; // PROGRAM CHANGES if (key == "BSH.Common.Root.SelectedProgram") { - thing->setStateValue(m_selectedProgramStateTypeIds.value(thing->thingClassId()), value.toString().split('.').last()); + if (m_selectedProgramStateTypeIds.contains(thing->thingClassId())) { + thing->setStateValue(m_selectedProgramStateTypeIds.value(thing->thingClassId()), value.toString().split('.').last()); + } } else if (key == "BSH.Common.Root.ActiveProgram") { - thing->setStateValue(m_activeProgramStateTypeIds.value(thing->thingClassId()), value.toString().split('.').last()); // Option Changes } else if (key == "Cooking.Oven.Option.SetpointTemperature") { @@ -464,6 +457,8 @@ void IntegrationPluginHomeConnect::parseKey(Thing *thing, const QString &key, co // Program Progress Changes } else if (key == "BSH.Common.Option.ElapsedProgramTime") { } else if (key == "BSH.Common.Option.RemainingProgramTime") { + QString time = QDateTime::fromMSecsSinceEpoch(QDateTime::currentMSecsSinceEpoch()+(value.toInt()*1000)).time().toString(); + thing->setStateValue(m_endTimerStateTypeIds.value(thing->thingClassId()), time); } else if (key == "BSH.Common.Option.ProgramProgress") { if (m_progressStateTypeIds.contains(thing->thingClassId())) { thing->setStateValue(m_progressStateTypeIds.value(thing->thingClassId()), value); @@ -674,7 +669,6 @@ void IntegrationPluginHomeConnect::onReceivedEvents(HomeConnect::EventType event case HomeConnect::EventTypeEvent: case HomeConnect::EventTypeNotify: { Q_FOREACH(HomeConnect::Event event, events) { - qCDebug(dcHomeConnect()) << "Received event" << event.key << event.uri << event.name; parseKey(thing, event.key, event.value); } } break; @@ -690,55 +684,6 @@ void IntegrationPluginHomeConnect::onReceivedEvents(HomeConnect::EventType event } } -void IntegrationPluginHomeConnect::onReceivedActiveProgram(const QString &haId, const QString &key, const QHash &options) -{ - HomeConnect *homeConnectConnection = static_cast(sender()); - Thing *parentThing = m_homeConnectConnections.key(homeConnectConnection); - if (!parentThing) - return; - - Q_FOREACH(Thing *thing, myThings().filterByParentId(parentThing->id())) { - if (thing->paramValue(m_idParamTypeIds.value(thing->thingClassId())).toString() == haId) { - - Q_FOREACH(QString key, options.keys()) { - parseKey(thing, key, options.value(key)); - } - if (thing->thingClassId() == ovenThingClassId) { - if (key.contains("Cooking.Oven.Program.HeatingMode")) { - thing->setStateValue(ovenActiveProgramStateTypeId, key.split('.').last()); - } else { - qCWarning(dcHomeConnect()) << "Oven unhandled program type" << key; - } - } else if (thing->thingClassId() == washerThingClassId) { - if (key.contains("LaundryCare.Washer.Program")) { - thing->setStateValue(washerActiveProgramStateTypeId, key.split('.').last()); - } else { - qCWarning(dcHomeConnect()) << "Washer unhandled program type" << key; - } - } else if (thing->thingClassId() == dishwasherThingClassId) { - if (key.contains("Dishcare.Dishwasher.Program")) { - thing->setStateValue(dishwasherActiveProgramStateTypeId, key.split('.').last()); - } else { - qCWarning(dcHomeConnect()) << "Dishwasher unhandled program type" << key; - } - } else if (thing->thingClassId() == dryerThingClassId) { - if (key.contains("LaundryCare.Dryer.Program")) { - thing->setStateValue(dryerActiveProgramStateTypeId, key.split('.').last()); - } else { - qCWarning(dcHomeConnect()) << "Dryer unhandled program type" << key; - } - } else if (thing->thingClassId() == coffeeMakerThingClassId) { - if (key.contains("ConsumerProducts.CoffeeMaker.Program")) { - thing->setStateValue(coffeeMakerActiveProgramStateTypeId, key.split('.').last()); - } else { - qCWarning(dcHomeConnect()) << "Coffee maker unhandled program type" << key; - } - } - break; - } - } -} - void IntegrationPluginHomeConnect::onReceivedSelectedProgram(const QString &haId, const QString &key, const QHash &options) { Q_UNUSED(options) diff --git a/homeconnect/integrationpluginhomeconnect.h b/homeconnect/integrationpluginhomeconnect.h index ddd606a4..548ece7f 100644 --- a/homeconnect/integrationpluginhomeconnect.h +++ b/homeconnect/integrationpluginhomeconnect.h @@ -71,6 +71,7 @@ private: QHash m_pendingActions; QHash m_idParamTypeIds; + QHash m_connectedStateTypeIds; QHash m_doorStateStateTypeIds; QHash m_localControlStateTypeIds; @@ -78,9 +79,12 @@ private: QHash m_remoteStartAllowanceStateTypeIds; QHash m_operationStateTypeIds; QHash m_doorStateTypeIds; - QHash m_activeProgramStateTypeIds; QHash m_selectedProgramStateTypeIds; QHash m_progressStateTypeIds; + QHash m_endTimerStateTypeIds; + + QHash m_resumeActionTypeIds; + QHash m_pauseActionTypeIds; HomeConnect *createHomeConnection(); diff --git a/homeconnect/integrationpluginhomeconnect.json b/homeconnect/integrationpluginhomeconnect.json index c811003f..1ddcc47b 100644 --- a/homeconnect/integrationpluginhomeconnect.json +++ b/homeconnect/integrationpluginhomeconnect.json @@ -184,11 +184,11 @@ "type": "QString" }, { - "id": "474d9ca0-6842-4a1b-9655-e147df923459", - "name": "activeProgram", - "displayName": "Active program", - "displayNameEvent": "Active program changed", - "defaultValue": "None", + "id": "6e828e48-3634-4d92-9dee-2c03a51c7189", + "name": "endTime", + "displayName": "End time", + "displayNameEvent": "End time changed", + "defaultValue": "00:00:00", "type": "QString" } ], @@ -292,14 +292,6 @@ "displayNameEvent": "Selected program changed", "defaultValue": "None", "type": "QString" - }, - { - "id": "5f4cc1a2-a9d9-4358-9fcd-d09078a38638", - "name": "activeProgram", - "displayName": "Active program", - "displayNameEvent": "Active program changed", - "defaultValue": "None", - "type": "QString" } ] }, @@ -392,12 +384,51 @@ "type": "QString" }, { - "id": "52ce0862-aa9d-41fa-8d14-6fdb11b82d89", - "name": "activeProgram", - "displayName": "Active program", - "displayNameEvent": "Active program changed", - "defaultValue": "None", - "type": "QString" + "id": "714a12bc-63a5-4423-aad9-47d77f41ae47", + "name": "strength", + "displayName": "Strength", + "displayNameEvent": "Strength changed", + "displayNameAction": "Set strength", + "defaultValue": "Normal", + "writable": true, + "type": "QString", + "possibleValues": [ + "Very Mild", + "Mild", + "Normal", + "Strong", + "Very Strong", + "Double Shot", + "Double Shot+", + "Double Shot++" + ] + }, + { + "id": "b3aea372-bc51-4e92-b92f-5b9613c20a9c", + "name": "fillQuantity", + "displayName": "Fill quantity", + "displayNameEvent": "Fill quantity changed", + "displayNameAction": "Set fill quantity", + "defaultValue": "60", + "type": "int", + "minValue": 35, + "maxValue": 60, + "writable": true + }, + { + "id": "29dc7edb-c34f-41da-9d2a-e46bda34885b", + "name": "temperature", + "displayName": "Temperature", + "displayNameEvent": "Temperature changed", + "displayNameAction": "Set temperature", + "defaultValue": "Normal", + "possibleValues": [ + "Normal", + "High", + "Very high" + ], + "type": "QString", + "writable": true } ] }, @@ -499,14 +530,6 @@ "displayNameEvent": "Selected program changed", "defaultValue": "None", "type": "QString" - }, - { - "id": "cde9357e-5e6c-49ff-82d5-a69150b64978", - "name": "activeProgram", - "displayName": "Active program", - "displayNameEvent": "Active program changed", - "defaultValue": "None", - "type": "QString" } ], "actionTypes": [ @@ -708,14 +731,6 @@ "defaultValue": "None", "type": "QString" }, - { - "id": "d4abaabe-933f-4b55-8065-ba1f612dce90", - "name": "activeProgram", - "displayName": "Active program", - "displayNameEvent": "Active program changed", - "defaultValue": "None", - "type": "QString" - }, { "id": "29ed9597-2ace-48f5-91bc-171ac2601bfc", "name": "temperature",