From 746f3e41213e33854c7296658a0a28b66cdda502 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Fri, 10 Jul 2020 23:02:06 +0200 Subject: [PATCH] fix actions cleanup --- .../integrations/pythonintegrationplugin.cpp | 5 +- plugins/pymock/integrationpluginpymock.json | 47 +++++++++++++++++++ plugins/pymock/integrationpluginpymock.py | 12 ++++- 3 files changed, 61 insertions(+), 3 deletions(-) diff --git a/libnymea-core/integrations/pythonintegrationplugin.cpp b/libnymea-core/integrations/pythonintegrationplugin.cpp index 8fe0aafb..ee26620c 100644 --- a/libnymea-core/integrations/pythonintegrationplugin.cpp +++ b/libnymea-core/integrations/pythonintegrationplugin.cpp @@ -536,7 +536,10 @@ void PythonIntegrationPlugin::executeAction(ThingActionInfo *info) PyGILState_Release(s); }); - callPluginFunction("executeAction", reinterpret_cast(pyInfo)); + bool success = callPluginFunction("executeAction", reinterpret_cast(pyInfo)); + if (!success) { + info->finish(Thing::ThingErrorUnsupportedFeature); + } } void PythonIntegrationPlugin::thingRemoved(Thing *thing) diff --git a/plugins/pymock/integrationpluginpymock.json b/plugins/pymock/integrationpluginpymock.json index 52e7702e..9ec7c8e9 100644 --- a/plugins/pymock/integrationpluginpymock.json +++ b/plugins/pymock/integrationpluginpymock.json @@ -49,6 +49,21 @@ "displayName": "Python mock thing", "createMethods": ["user"], "setupMethod": "justAdd", + "eventTypes": [ + { + "id": "de6c2425-0dee-413f-8f4c-bb0929e83c0d", + "name": "event1", + "displayName": "Event 1", + "paramTypes": [ + { + "id": "9f6aef52-dcde-4ee1-8ae3-4823594bf153", + "name": "param1", + "displayName": "Event param 1", + "type": "QString" + } + ] + } + ], "stateTypes": [ { "id": "24714828-93ec-41a7-875e-6a0b5b57d25c", @@ -59,6 +74,22 @@ "type": "int", "defaultValue": 0 } + ], + "actionTypes": [ + { + "id": "a504933a-2b86-41c1-b188-8998d445adf8", + "name": "action1", + "displayName": "Action 1", + "paramTypes": [ + { + "id": "5a824a21-3e97-49a5-8b4d-2a5bc3ea99ef", + "name": "param1", + "displayName": "Action param 1", + "type": "QString", + "defaultValue": "hello" + } + ] + } ] }, { @@ -121,6 +152,22 @@ "type": "int", "defaultValue": 0 } + ], + "actionTypes": [ + { + "id": "9bcc17ee-52a4-48ef-9a76-b2df4433dac5", + "name": "action1", + "displayName": "Action 1", + "paramTypes": [ + { + "id": "2e86cb76-e1a9-4afd-8fd3-e900cbb738f5", + "name": "param1", + "displayName": "Action param 1", + "type": "QString", + "defaultValue": "hello" + } + ] + } ] } ] diff --git a/plugins/pymock/integrationpluginpymock.py b/plugins/pymock/integrationpluginpymock.py index 3c4b2cc0..28abe6f1 100644 --- a/plugins/pymock/integrationpluginpymock.py +++ b/plugins/pymock/integrationpluginpymock.py @@ -10,9 +10,14 @@ async def init(): await asyncio.sleep(2); logger.log("Updating stuff") for thing in myThings(): + if thing.thingClassId == pyMockThingClassId: + logger.log("Emitting event 1 for", thing.name, "eventTypeId", pyMockEvent1EventTypeId) + thing.emitEvent(pyMockEvent1EventTypeId, [nymea.Param(pyMockEvent1EventParam1ParamTypeId, "Im an event")]) + logger.log("Setting state 1 for", thing.name, "to", thing.stateValue(pyMockState1StateTypeId) + 1) + thing.setStateValue(pyMockState1StateTypeId, thing.stateValue(pyMockState1StateTypeId) + 1) if thing.thingClassId == pyMockDiscoveryPairingThingClassId: logger.log("Emitting event 1 for", thing.name) -# thing.emitEvent(pyMockDiscoveryPairingEvent1EventTypeId, [nymea.Param(pyMockDiscoveryPairingEvent1EventParam1ParamTypeId, "Im an event")]) + thing.emitEvent(pyMockDiscoveryPairingEvent1EventTypeId, [nymea.Param(pyMockDiscoveryPairingEvent1EventParam1ParamTypeId, "Im an event")]) logger.log("Setting state 1 for", thing.name, "Old value is:", thing.stateValue(pyMockDiscoveryPairingState1StateTypeId)) thing.setStateValue(pyMockDiscoveryPairingState1StateTypeId, thing.stateValue(pyMockDiscoveryPairingState1StateTypeId) + 1) @@ -79,7 +84,6 @@ async def confirmPairing(info, username, secret): async def setupThing(info): -# logger.log("setupThing for", info.thing.name, info.thing.params) logger.log("setupThing for", info.thing.name) info.finish(nymea.ThingErrorNoError) @@ -96,6 +100,10 @@ async def postSetupThing(thing): logger.log("Setting 1 value:", thing.setting(pyMockDiscoveryPairingSettingsSetting1ParamTypeId)) +async def executeAction(info): + logger.log("executeAction for", info.thing.name, info.actionTypeId, "with params", info.params[0].value) + info.finish(nymea.ThingErrorNoError) + def autoThings(): autoThings = []