first version of toggle button

pull/135/head
Simon Stürz 2014-11-05 16:06:59 +01:00 committed by Michael Zanetti
parent ef7458879b
commit 78272ecdd3
7 changed files with 147 additions and 1 deletions

View File

@ -10,3 +10,4 @@ usr/lib/guh/plugins/libguh_devicepluginphilipshue.so
usr/lib/guh/plugins/libguh_devicepluginwakeonlan.so
usr/lib/guh/plugins/libguh_devicepluginwemo.so
usr/lib/guh/plugins/libguh_devicepluginwifidetector.so
usr/lib/guh/plugins/libguh_deviceplugingenericelements.so

View File

@ -11,6 +11,7 @@ SUBDIRS += elro \
mailnotification \
philipshue \
lgsmarttv \
genericelements \

View File

@ -0,0 +1,55 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* This file is part of guh. *
* *
* Guh is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, version 2 of the License. *
* *
* Guh 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 General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with guh. If not, see <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "deviceplugingenericelements.h"
#include "devicemanager.h"
#include <QDebug>
DeviceClassId toggleButtonDeviceClassId = DeviceClassId("c0f511f9-70f5-499b-bd70-2c0e9ddd68c4");
ActionTypeId toggleButtonToggleActionTypeId = ActionTypeId("47bdc15a-b393-4dc2-801b-845420cdfda3");
StateTypeId toggleButtonStatusStateTypeId = StateTypeId("b5e90567-54aa-49bd-a78a-3c19fb38aaf5");
DevicePluginGenericElements::DevicePluginGenericElements()
{
}
DeviceManager::HardwareResources DevicePluginGenericElements::requiredHardware() const
{
return DeviceManager::HardwareResourceNone;
}
DeviceManager::DeviceSetupStatus DevicePluginGenericElements::setupDevice(Device *device)
{
if (device->deviceClassId() == toggleButtonDeviceClassId) {
device->setName(device->paramValue("name").toString() +" (Toggle Button)");
return DeviceManager::DeviceSetupStatusSuccess;
}
return DeviceManager::DeviceSetupStatusFailure;
}
DeviceManager::DeviceError DevicePluginGenericElements::executeAction(Device *device, const Action &action)
{
if (device->deviceClassId() == toggleButtonDeviceClassId
&& action.actionTypeId() == toggleButtonToggleActionTypeId) {
bool currentStatus = device->stateValue(toggleButtonStatusStateTypeId).toBool();
device->setStateValue(toggleButtonStatusStateTypeId, !currentStatus);
return DeviceManager::DeviceErrorNoError;
}
return DeviceManager::DeviceErrorDeviceClassNotFound;
}

View File

@ -0,0 +1,43 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* This file is part of guh. *
* *
* Guh is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, version 2 of the License. *
* *
* Guh 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 General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with guh. If not, see <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#ifndef DEVICEPLUGINGENERICELEMENTS_H
#define DEVICEPLUGINGENERICELEMENTS_H
#include "plugin/deviceplugin.h"
class DevicePluginGenericElements : public DevicePlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "guru.guh.DevicePlugin" FILE "deviceplugingenericelements.json")
Q_INTERFACES(DevicePlugin)
public:
explicit DevicePluginGenericElements();
DeviceManager::HardwareResources requiredHardware() const override;
DeviceManager::DeviceSetupStatus setupDevice(Device *device) override;
public slots:
DeviceManager::DeviceError executeAction(Device *device, const Action &action) override;
};
#endif // DEVICEPLUGINGENERICELEMENTS_H

View File

@ -0,0 +1,36 @@
{
"name": "Generic Elements",
"id": "6e22161e-39b7-4416-8623-39e730721efb",
"vendors": [
{
"name": "guh",
"id": "2062d64d-3232-433c-88bc-0d33c0ba2ba6",
"deviceClasses": [
{
"deviceClassId": "c0f511f9-70f5-499b-bd70-2c0e9ddd68c4",
"name": "Toggle Button",
"createMethods": ["user"],
"paramTypes": [
{
"name": "name",
"type": "QString"
}
],
"stateTypes": [
{
"id": "b5e90567-54aa-49bd-a78a-3c19fb38aaf5",
"name": "status",
"type": "bool",
}
],
"actionTypes": [
{
"id": "47bdc15a-b393-4dc2-801b-845420cdfda3",
"name": "toggle"
}
]
}
]
}
]
}

View File

@ -0,0 +1,11 @@
include(../../plugins.pri)
TARGET = $$qtLibraryTarget(guh_deviceplugingenericelements)
SOURCES += \
deviceplugingenericelements.cpp
HEADERS += \
deviceplugingenericelements.h

View File

@ -169,7 +169,6 @@ def select_stateOperator():
def read_paramDescriptors(paramTypes):
params = []
for paramType in paramTypes:
print paramType['allowedValues']
paramValue = raw_input("Please enter value for parameter <%s> (type: %s): " % (paramType['name'], paramType['type']))
operator = select_valueOperator()
param = {}