reduced API requests

This commit is contained in:
Boernsman 2020-10-27 16:05:55 +01:00
parent 76763ad5d9
commit e79674fb80
4 changed files with 61 additions and 32 deletions

View File

@ -82,6 +82,7 @@ IntegrationPluginHomeConnect::IntegrationPluginHomeConnect()
m_doorStateTypeIds.insert(dryerThingClassId, dryerClosedStateTypeId); m_doorStateTypeIds.insert(dryerThingClassId, dryerClosedStateTypeId);
m_doorStateTypeIds.insert(ovenThingClassId, ovenClosedStateTypeId); m_doorStateTypeIds.insert(ovenThingClassId, ovenClosedStateTypeId);
m_doorStateTypeIds.insert(coffeeMakerThingClassId, coffeeMakerClosedStateTypeId); m_doorStateTypeIds.insert(coffeeMakerThingClassId, coffeeMakerClosedStateTypeId);
m_doorStateTypeIds.insert(fridgeThingClassId, fridgeClosedStateTypeId);
m_operationStateTypeIds.insert(ovenThingClassId, ovenOperationStateStateTypeId); m_operationStateTypeIds.insert(ovenThingClassId, ovenOperationStateStateTypeId);
m_operationStateTypeIds.insert(dryerThingClassId, dryerOperationStateStateTypeId); m_operationStateTypeIds.insert(dryerThingClassId, dryerOperationStateStateTypeId);
@ -248,15 +249,7 @@ void IntegrationPluginHomeConnect::setupThing(ThingSetupInfo *info)
connect(homeConnect, &HomeConnect::receivedSettings, this, &IntegrationPluginHomeConnect::onReceivedSettings); connect(homeConnect, &HomeConnect::receivedSettings, this, &IntegrationPluginHomeConnect::onReceivedSettings);
connect(homeConnect, &HomeConnect::receivedEvents, this, &IntegrationPluginHomeConnect::onReceivedEvents); connect(homeConnect, &HomeConnect::receivedEvents, this, &IntegrationPluginHomeConnect::onReceivedEvents);
} else if ((thing->thingClassId() == dryerThingClassId) || } else if (m_idParamTypeIds.contains(thing->thingClassId())) {
(thing->thingClassId() == fridgeThingClassId) ||
(thing->thingClassId() == washerThingClassId) ||
(thing->thingClassId() == dishwasherThingClassId) ||
(thing->thingClassId() == coffeeMakerThingClassId) ||
(thing->thingClassId() == ovenThingClassId) ||
(thing->thingClassId() == hoodThingClassId) ||
(thing->thingClassId() == cleaningRobotThingClassId) ||
(thing->thingClassId() == cookTopThingClassId)) {
Thing *parentThing = myThings().findById(thing->parentId()); Thing *parentThing = myThings().findById(thing->parentId());
if (parentThing->setupComplete()) { if (parentThing->setupComplete()) {
info->finish(Thing::ThingErrorNoError); info->finish(Thing::ThingErrorNoError);
@ -274,9 +267,9 @@ void IntegrationPluginHomeConnect::setupThing(ThingSetupInfo *info)
void IntegrationPluginHomeConnect::postSetupThing(Thing *thing) void IntegrationPluginHomeConnect::postSetupThing(Thing *thing)
{ {
if (!m_pluginTimer60sec) { if (!m_pluginTimer15min) {
m_pluginTimer60sec = hardwareManager()->pluginTimerManager()->registerTimer(60); m_pluginTimer15min = hardwareManager()->pluginTimerManager()->registerTimer(60*15);
connect(m_pluginTimer60sec, &PluginTimer::timeout, this, [this]() { connect(m_pluginTimer15min, &PluginTimer::timeout, this, [this]() {
Q_FOREACH (Thing *thing, myThings().filterByThingClassId(homeConnectAccountThingClassId)) { Q_FOREACH (Thing *thing, myThings().filterByThingClassId(homeConnectAccountThingClassId)) {
HomeConnect *homeConnect = m_homeConnectConnections.value(thing); HomeConnect *homeConnect = m_homeConnectConnections.value(thing);
if (!homeConnect) { if (!homeConnect) {
@ -301,15 +294,7 @@ void IntegrationPluginHomeConnect::postSetupThing(Thing *thing)
thing->setStateValue(homeConnectAccountConnectedStateTypeId, true); thing->setStateValue(homeConnectAccountConnectedStateTypeId, true);
thing->setStateValue(homeConnectAccountLoggedInStateTypeId, true); thing->setStateValue(homeConnectAccountLoggedInStateTypeId, true);
//TBD Set user name //TBD Set user name
} else if ((thing->thingClassId() == dryerThingClassId) || } else if (m_idParamTypeIds.contains(thing->thingClassId())) {
(thing->thingClassId() == fridgeThingClassId) ||
(thing->thingClassId() == washerThingClassId) ||
(thing->thingClassId() == dishwasherThingClassId) ||
(thing->thingClassId() == coffeeMakerThingClassId) ||
(thing->thingClassId() == ovenThingClassId) ||
(thing->thingClassId() == hoodThingClassId) ||
(thing->thingClassId() == cleaningRobotThingClassId) ||
(thing->thingClassId() == cookTopThingClassId)) {
Thing *parentThing = myThings().findById(thing->parentId()); Thing *parentThing = myThings().findById(thing->parentId());
if (!parentThing) if (!parentThing)
qCWarning(dcHomeConnect()) << "Could not find parent with Id" << thing->parentId().toString(); qCWarning(dcHomeConnect()) << "Could not find parent with Id" << thing->parentId().toString();
@ -432,6 +417,7 @@ void IntegrationPluginHomeConnect::executeAction(ThingActionInfo *info)
} }
} else if (thing->thingClassId() == washerThingClassId) { } else if (thing->thingClassId() == washerThingClassId) {
if (action.actionTypeId() == washerStartActionTypeId) { if (action.actionTypeId() == washerStartActionTypeId) {
if (!m_selectedProgram.contains(thing)) { if (!m_selectedProgram.contains(thing)) {
homeConnect->getProgramsSelected(haid); homeConnect->getProgramsSelected(haid);
return info->finish(Thing::ThingErrorMissingParameter, tr("Please select a program first")); return info->finish(Thing::ThingErrorMissingParameter, tr("Please select a program first"));
@ -496,9 +482,9 @@ void IntegrationPluginHomeConnect::thingRemoved(Thing *thing)
} }
if (myThings().empty()) { if (myThings().empty()) {
if (m_pluginTimer60sec) { if (m_pluginTimer15min) {
hardwareManager()->pluginTimerManager()->unregisterTimer(m_pluginTimer60sec); hardwareManager()->pluginTimerManager()->unregisterTimer(m_pluginTimer15min);
m_pluginTimer60sec = nullptr; m_pluginTimer15min = nullptr;
} }
} }
} }
@ -539,8 +525,10 @@ void IntegrationPluginHomeConnect::browserItem(BrowserItemResult *result)
homeConnect->getProgramsAvailable(haid); homeConnect->getProgramsAvailable(haid);
connect(homeConnect, &HomeConnect::receivedAvailablePrograms, result, [result, this] (const QString &haid, const QStringList &programs) { connect(homeConnect, &HomeConnect::receivedAvailablePrograms, result, [result, this] (const QString &haid, const QStringList &programs) {
if (result->thing()->paramValue(m_idParamTypeIds.value(result->thing()->thingClassId())).toString() == haid) { if (result->thing()->paramValue(m_idParamTypeIds.value(result->thing()->thingClassId())).toString() == haid) {
if (programs.contains(result->item().id())) if (programs.contains(result->item().id())) {
result->item().setDisplayName(result->item().id());
result->finish(Thing::ThingErrorNoError); result->finish(Thing::ThingErrorNoError);
}
} }
}); });
} }
@ -771,6 +759,46 @@ void IntegrationPluginHomeConnect::parseSettingKey(Thing *thing, const QString &
} }
} }
bool IntegrationPluginHomeConnect::checkIfActionIsPossible(ThingActionInfo *info)
{
Thing *thing = info->thing();
if (m_connectedStateTypeIds.contains(thing->thingClassId())) {
if(!thing->stateValue(m_connectedStateTypeIds.value(thing->thingClassId())).toBool()) {
info->finish(Thing::ThingErrorHardwareNotAvailable, tr("Appliance ist not connected."));
return false;
}
}
if (m_remoteStartAllowanceStateTypeIds.contains(thing->thingClassId())) {
if (!thing->stateValue(m_remoteStartAllowanceStateTypeIds.value(thing->thingClassId())).toBool()) {
info->finish(Thing::ThingErrorHardwareNotAvailable, tr("Remote start is not activated."));
return false;
}
}
if (m_remoteControlActivationStateTypeIds.contains(thing->thingClassId())) {
if (!thing->stateValue(m_remoteControlActivationStateTypeIds.value(thing->thingClassId())).toBool()) {
info->finish(Thing::ThingErrorHardwareNotAvailable, tr("Remote control is not activated."));
return false;
}
}
if (m_doorStateTypeIds.contains(thing->thingClassId())) {
if (!thing->stateValue(m_doorStateTypeIds.value(thing->thingClassId())).toBool()) {
info->finish(Thing::ThingErrorHardwareNotAvailable, tr("Door is not closed."));
return false;
}
}
if (m_operationStateTypeIds.contains(thing->thingClassId())) {
if (thing->stateValue(m_operationStateTypeIds.value(thing->thingClassId())).toString() != "Ready") {
info->finish(Thing::ThingErrorHardwareNotAvailable, tr("Appliance not ready."));
return false;
}
}
return true;
}
void IntegrationPluginHomeConnect::onConnectionChanged(bool connected) void IntegrationPluginHomeConnect::onConnectionChanged(bool connected)
{ {
HomeConnect *homeConnect = static_cast<HomeConnect *>(sender()); HomeConnect *homeConnect = static_cast<HomeConnect *>(sender());

View File

@ -60,8 +60,7 @@ public:
void executeBrowserItem(BrowserActionInfo *info) override; void executeBrowserItem(BrowserActionInfo *info) override;
private: private:
PluginTimer *m_pluginTimer5sec = nullptr; PluginTimer *m_pluginTimer15min = nullptr;
PluginTimer *m_pluginTimer60sec = nullptr;
QHash<HomeConnect *, ThingSetupInfo *> m_asyncSetup; QHash<HomeConnect *, ThingSetupInfo *> m_asyncSetup;
@ -93,6 +92,7 @@ private:
void parseKey(Thing *thing, const QString &key, const QVariant &value); void parseKey(Thing *thing, const QString &key, const QVariant &value);
void parseSettingKey(Thing *thing, const QString &key, const QVariant &value); void parseSettingKey(Thing *thing, const QString &key, const QVariant &value);
bool checkIfActionIsPossible(ThingActionInfo *info);
private slots: private slots:
void onConnectionChanged(bool connected); void onConnectionChanged(bool connected);

View File

@ -227,7 +227,7 @@
"id": "bb0fcd0b-9594-4368-99d9-3ad5e5a8136b", "id": "bb0fcd0b-9594-4368-99d9-3ad5e5a8136b",
"name": "dishwasher", "name": "dishwasher",
"displayName": "Dishwasher", "displayName": "Dishwasher",
"interfaces": ["connectable"], "interfaces": ["connectable", "closablesensor"],
"createMethods": ["auto"], "createMethods": ["auto"],
"browsable": true, "browsable": true,
"paramTypes": [ "paramTypes": [
@ -351,7 +351,7 @@
"id": "f6b39ce2-8276-4db7-b2a3-4a04cafacbb9", "id": "f6b39ce2-8276-4db7-b2a3-4a04cafacbb9",
"name": "coffeeMaker", "name": "coffeeMaker",
"displayName": "Coffee Maker", "displayName": "Coffee Maker",
"interfaces": ["connectable"], "interfaces": ["connectable", "closablesensor"],
"createMethods": ["auto"], "createMethods": ["auto"],
"browsable": true, "browsable": true,
"paramTypes": [ "paramTypes": [
@ -518,7 +518,7 @@
"id": "f360cc43-41fc-454a-b6df-09ec0a66c22a", "id": "f360cc43-41fc-454a-b6df-09ec0a66c22a",
"name": "dryer", "name": "dryer",
"displayName": "Dryer", "displayName": "Dryer",
"interfaces": ["connectable"], "interfaces": ["connectable", "closablesensor"],
"createMethods": ["auto"], "createMethods": ["auto"],
"browsable": true, "browsable": true,
"paramTypes": [ "paramTypes": [
@ -656,7 +656,7 @@
"id": "6cbf309d-bde8-4e6e-ad6d-b85c8fc1843f", "id": "6cbf309d-bde8-4e6e-ad6d-b85c8fc1843f",
"name": "fridge", "name": "fridge",
"displayName": "Fridge Freezer", "displayName": "Fridge Freezer",
"interfaces": ["connectable"], "interfaces": ["connectable", "closablesensor"],
"createMethods": ["auto"], "createMethods": ["auto"],
"paramTypes": [ "paramTypes": [
{ {
@ -754,7 +754,7 @@
"id": "aaec390e-a61f-40ea-b42c-80f69428690b", "id": "aaec390e-a61f-40ea-b42c-80f69428690b",
"name": "washer", "name": "washer",
"displayName": "Washer", "displayName": "Washer",
"interfaces": ["connectable"], "interfaces": ["connectable", "closablesensor"],
"createMethods": ["auto"], "createMethods": ["auto"],
"browsable": true, "browsable": true,
"paramTypes": [ "paramTypes": [

View File

@ -8,5 +8,6 @@
"network" "network"
], ],
"categories": [ "categories": [
"online-service"
] ]
} }