/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Copyright (C) 2015 Simon Stürz * * * * This file is part of nymea. * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; If not, see * * . * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /*! \page genericelements.html \title Generic elements \brief Common elements to test the rule engine. \ingroup plugins \ingroup nymea-tests The generic elements plugin allows you create virtual buttons, which can be connected with a rule. This gives you the possibility to execute multiple \l{Action}{Actions} with one signal. Without a rule this generic elements are useless. \chapter Toggle Button With the "Toggle Button" \l{DeviceClass} you can create a button with one \l{Action} \unicode{0x2192} toggle. In the \tt state \l{State} you can find out, what happens if the button will be pressed. The states can be true or false. \chapter Button With the "Button" \l{DeviceClass} you can create a button with one \l{Action} \unicode{0x2192} press. This button just creates one \l{Event}. \chapter ON/OFF Button With the "ON/OFF Button" \l{DeviceClass} you create a button pair with the \l{Action}{Actions} \unicode{0x2192} ON and OFF. \chapter Plugin properties Following JSON file contains the definition and the description of all available \l{DeviceClass}{DeviceClasses} and \l{Vendor}{Vendors} of this \l{DevicePlugin}. For more details how to read this JSON file please check out the documentation for \l{The plugin JSON File}. \quotefile plugins/deviceplugins/genericelements/deviceplugingenericelements.json */ #include "deviceplugingenericelements.h" #include "plugininfo.h" #include DevicePluginGenericElements::DevicePluginGenericElements() { } Device::DeviceSetupStatus DevicePluginGenericElements::setupDevice(Device *device) { // Toggle Button if (device->deviceClassId() == toggleButtonDeviceClassId) { return Device::DeviceSetupStatusSuccess; } // Button if (device->deviceClassId() == buttonDeviceClassId) { return Device::DeviceSetupStatusSuccess; } // ON/OFF Button if (device->deviceClassId() == onOffButtonDeviceClassId) { return Device::DeviceSetupStatusSuccess; } return Device::DeviceSetupStatusFailure; } Device::DeviceError DevicePluginGenericElements::executeAction(Device *device, const Action &action) { // Toggle Button if (device->deviceClassId() == toggleButtonDeviceClassId ) { if (action.actionTypeId() == toggleButtonStateActionTypeId) { device->setStateValue(toggleButtonStateStateTypeId, !device->stateValue(toggleButtonStateStateTypeId).toBool()); return Device::DeviceErrorNoError; } return Device::DeviceErrorActionTypeNotFound; } // Button if (device->deviceClassId() == buttonDeviceClassId ) { if (action.actionTypeId() == buttonButtonPressActionTypeId) { emit emitEvent(Event(buttonButtonPressedEventTypeId, device->id())); return Device::DeviceErrorNoError; } return Device::DeviceErrorActionTypeNotFound; } // ON/OFF Button if (device->deviceClassId() == onOffButtonDeviceClassId ) { if (action.actionTypeId() == onOffButtonOnActionTypeId) { emit emitEvent(Event(onOffButtonOnEventTypeId, device->id())); return Device::DeviceErrorNoError; } if (action.actionTypeId() == onOffButtonOffActionTypeId) { emit emitEvent(Event(onOffButtonOffEventTypeId, device->id())); return Device::DeviceErrorNoError; } return Device::DeviceErrorActionTypeNotFound; } return Device::DeviceErrorDeviceClassNotFound; }