From b6bb9f41f7747e94cbbc5d8e82a774cafef207bd Mon Sep 17 00:00:00 2001 From: Boernsman Date: Mon, 17 Feb 2020 11:04:39 +0500 Subject: [PATCH] made actions async --- doorbird/README.md | 12 +++++++++--- doorbird/deviceplugindoorbird.cpp | 16 ++++++++++------ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/doorbird/README.md b/doorbird/README.md index bba30f16..ab687dc5 100644 --- a/doorbird/README.md +++ b/doorbird/README.md @@ -1,8 +1,14 @@ # DoorBird -This plug-in let'S you capture doorbell pressed and motion events, -you are also able to set the power of the IR and the relays. +This plugin integrates DoorBird video doorbells into nymea. All the communication between nymea and the DoorBird device happens locally and will work without internet connection. -It uses a local connection and will work without Internet. +Currently supported features are: +* Doorbell presses +* Motion events +* Enable/disable IR light +* Switching door relays + +The user must have the permission to act as DoorBird API-operator. +You can check the permissions in the DoorBird app. diff --git a/doorbird/deviceplugindoorbird.cpp b/doorbird/deviceplugindoorbird.cpp index 3668bc5c..70a7c42a 100644 --- a/doorbird/deviceplugindoorbird.cpp +++ b/doorbird/deviceplugindoorbird.cpp @@ -195,21 +195,25 @@ void DevicePluginDoorbird::executeAction(DeviceActionInfo *info) if (device->deviceClassId() == doorBirdDeviceClassId) { Doorbird *doorbird = m_doorbirdConnections.value(device->id()); if (!doorbird) { + qCWarning(dcDoorBird()) << "Doorbird object not found" << device->name(); info->finish(Device::DeviceErrorHardwareFailure); return; } if (action.actionTypeId() == doorBirdOpenDoorActionTypeId) { int number = action.param(doorBirdOpenDoorActionNumberParamTypeId).value().toInt(); - doorbird->openDoor(number); - info->finish(Device::DeviceErrorNoError); + QUuid requestId = doorbird->openDoor(number); + m_asyncActions.insert(requestId, info); + connect(info, &DeviceActionInfo::aborted, this, [requestId, this] {m_asyncActions.remove(requestId);}); return; } else if (action.actionTypeId() == doorBirdLightOnActionTypeId) { - doorbird->lightOn(); - info->finish(Device::DeviceErrorNoError); + QUuid requestId = doorbird->lightOn(); + m_asyncActions.insert(requestId, info); + connect(info, &DeviceActionInfo::aborted, this, [requestId, this] {m_asyncActions.remove(requestId);}); return; } else if (action.actionTypeId() == doorBirdRestartActionTypeId) { - doorbird->restart(); - info->finish(Device::DeviceErrorNoError); + QUuid requestId = doorbird->restart(); + m_asyncActions.insert(requestId, info); + connect(info, &DeviceActionInfo::aborted, this, [requestId, this] {m_asyncActions.remove(requestId);}); return; } else { qCWarning(dcDoorBird()) << "Unhandled ActionTypeId:" << action.actionTypeId();