From e6129d0ceac790142e94b11eae093297d38bfa17 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Fri, 3 Jan 2014 23:49:40 +0100 Subject: [PATCH] some fixes. successfully switching an elro switch using an intertechno remote with this revision --- libhive/devicemanager.cpp | 12 +++++++++ libhive/devicemanager.h | 1 + libhive/radio433.cpp | 5 ++-- .../devicepluginintertechno.cpp | 4 ++- server/jsonrpcserver.cpp | 7 ++--- server/ruleengine.cpp | 3 ++- tests/addconfigureddevice.sh | 27 ++++++++++++++----- tests/addrule.sh | 4 +-- 8 files changed, 47 insertions(+), 16 deletions(-) diff --git a/libhive/devicemanager.cpp b/libhive/devicemanager.cpp index 823b71a2..7ec45d39 100644 --- a/libhive/devicemanager.cpp +++ b/libhive/devicemanager.cpp @@ -89,6 +89,18 @@ QList DeviceManager::findConfiguredDevices(const QUuid &deviceClassId) return ret; } +DeviceClass DeviceManager::findDeviceClassforTrigger(const QUuid &triggerTypeId) +{ + foreach (const DeviceClass &deviceClass, m_supportedDevices) { + foreach (const TriggerType &triggerType, deviceClass.triggers()) { + if (triggerType.id() == triggerTypeId) { + return deviceClass; + } + } + } + return DeviceClass(QUuid(), QUuid()); +} + DeviceClass DeviceManager::findDeviceClass(const QUuid &deviceClassId) { foreach (const DeviceClass &deviceClass, m_supportedDevices) { diff --git a/libhive/devicemanager.h b/libhive/devicemanager.h index 20ca5b97..e5993db9 100644 --- a/libhive/devicemanager.h +++ b/libhive/devicemanager.h @@ -37,6 +37,7 @@ public: Device* findConfiguredDevice(const QUuid &id) const; QList findConfiguredDevices(const QUuid &deviceClassId); + DeviceClass findDeviceClassforTrigger(const QUuid &triggerTypeId); DeviceClass findDeviceClass(const QUuid &deviceClassId); signals: diff --git a/libhive/radio433.cpp b/libhive/radio433.cpp index 423851cd..20180608 100644 --- a/libhive/radio433.cpp +++ b/libhive/radio433.cpp @@ -14,9 +14,9 @@ Radio433::Radio433(QObject *parent) : // Set up transmitter m_transmitter = new Gpio(this,22); m_transmitter->setDirection(OUTPUT); - m_transmitter->setValue(HIGH); + m_transmitter->setValue(LOW); - connect(m_receiver,SIGNAL(pinInterrupt()),this,SLOT(handleInterrupt())); + connect(m_receiver, &Gpio::pinInterrupt, this, &Radio433::handleInterrupt); m_receiver->start(); } @@ -48,6 +48,7 @@ void Radio433::sendData(QList rawData) //qDebug() << "signal sent." << rawData; // re-enable it + m_transmitter->setValue(LOW); m_receiver->start(); } diff --git a/plugins/deviceplugins/devicepluginintertechno/devicepluginintertechno.cpp b/plugins/deviceplugins/devicepluginintertechno/devicepluginintertechno.cpp index 8fa4b821..8fa2c58f 100644 --- a/plugins/deviceplugins/devicepluginintertechno/devicepluginintertechno.cpp +++ b/plugins/deviceplugins/devicepluginintertechno/devicepluginintertechno.cpp @@ -195,7 +195,9 @@ void DevicePluginIntertechno::executeAction(Device *device, const Action &action } void DevicePluginIntertechno::receiveData(QList rawData) -{ +{ + + // filter right here a wrong signal length if(rawData.length() != 49){ return; diff --git a/server/jsonrpcserver.cpp b/server/jsonrpcserver.cpp index 25deb4fc..ba283d57 100644 --- a/server/jsonrpcserver.cpp +++ b/server/jsonrpcserver.cpp @@ -120,9 +120,10 @@ void JsonRPCServer::handleRulesMessage(int clientId, int commandId, const QStrin QVariantMap triggerParams = triggerMap.value("params").toMap(); Trigger trigger(triggerTypeId, triggerDeviceId, triggerParams); - Action action(params.value("deviceId").toString()); - action.setName(params.value("name").toString()); - action.setParams(params.value("params").toMap()); + QVariantMap actionMap = params.value("action").toMap(); + Action action(actionMap.value("deviceId").toString()); + action.setName(actionMap.value("name").toString()); + action.setParams(actionMap.value("params").toMap()); switch(HiveCore::instance()->ruleEngine()->addRule(trigger, action)) { case RuleEngine::RuleErrorNoError: diff --git a/server/ruleengine.cpp b/server/ruleengine.cpp index ac818bb0..707d400a 100644 --- a/server/ruleengine.cpp +++ b/server/ruleengine.cpp @@ -51,13 +51,14 @@ QList RuleEngine::evaluateTrigger(const Trigger &trigger) RuleEngine::RuleError RuleEngine::addRule(const Trigger &trigger, const Action &action) { - + qDebug() << "adding rule: Trigger:" << trigger.triggerTypeId() << "deviceid:" << action.deviceId(); Device *device = HiveCore::instance()->deviceManager()->findConfiguredDevice(trigger.deviceId()); if (!device) { qWarning() << "Cannot create rule. No configured device for triggerTypeId" << trigger.triggerTypeId(); return RuleErrorDeviceNotFound; } DeviceClass deviceClass = HiveCore::instance()->deviceManager()->findDeviceClass(device->deviceClassId()); + qDebug() << "found deviceClass" << deviceClass.name(); bool triggerTypeFound = false; foreach (const TriggerType &triggerType, deviceClass.triggers()) { diff --git a/tests/addconfigureddevice.sh b/tests/addconfigureddevice.sh index 067f5777..5ede2594 100755 --- a/tests/addconfigureddevice.sh +++ b/tests/addconfigureddevice.sh @@ -2,13 +2,26 @@ # Creates a Mumbi remote if [ -z $1 ]; then - echo "usage $0 host" + echo "usage $0 host device" +elif [ $1 == "list" ]; then + echo "elroremote elroswitch intertechnoremote meisteranker" +elif [ -z $2 ]; then + echo "usage $0 host device" else - # Adds an ELRO remote control on channel 00000 - (echo '{"id":1, "method":"Devices.AddConfiguredDevice", "params":{"deviceClass": "{d85c1ef4-197c-4053-8e40-707aa671d302}","params":{"channel1":"false", "channel2":"false", "channel3":"false", "channel4": "false", "channel5":"false" }}}'; sleep 1) | nc $1 1234 - # Adds a ELRO power switch on channel 00000 and group E - (echo '{"id":1, "method":"Devices.AddConfiguredDevice", "params":{"deviceClass": "{308ae6e6-38b3-4b3a-a513-3199da2764f8}","params":{"channel1":"false","channel2":"false", "channel3":"false", "channel4": "false","channel5":"false","A":"false","B":"true","C":"false","D":"false","E":"false" }}}'; sleep 1) | nc $1 1234 - # Adds an intertechno remote control - (echo '{"id":1, "method":"Devices.AddConfiguredDevice", "params":{"deviceClass": "{ab73ad2f-6594-45a3-9063-8f72d365c5e5}","params":{"familycode":"J"}}}'; sleep 1) | nc $1 1234 + + if [ $2 == "elroremote" ]; then + # Adds an ELRO remote control on channel 00000 + (echo '{"id":1, "method":"Devices.AddConfiguredDevice", "params":{"deviceClass": "{d85c1ef4-197c-4053-8e40-707aa671d302}","params":{"channel1":"false", "channel2":"false", "channel3":"false", "channel4": "false", "channel5":"false" }}}'; sleep 1) | nc $1 1234 + elif [ $2 == "elroswitch" ]; then + # Adds a ELRO power switch on channel 00000 and group E + (echo '{"id":1, "method":"Devices.AddConfiguredDevice", "params":{"deviceClass": "{308ae6e6-38b3-4b3a-a513-3199da2764f8}","params":{"channel1":"false","channel2":"false", "channel3":"false", "channel4": "false","channel5":"false","A":"false","B":"true","C":"false","D":"false","E":"false" }}}'; sleep 1) | nc $1 1234 + elif [ $2 == "intertechnoremote" ]; then + # Adds an intertechno remote control + (echo '{"id":1, "method":"Devices.AddConfiguredDevice", "params":{"deviceClass": "{ab73ad2f-6594-45a3-9063-8f72d365c5e5}","params":{"familycode":"J"}}}'; sleep 1) | nc $1 1234 + elif [ $2 == "meisteranker" ]; then + # Adds an intertechno remote control + (echo '{"id":1, "method":"Devices.AddConfiguredDevice", "params":{"deviceClass": "{e37e9f34-95b9-4a22-ae4f-e8b874eec871}","params":{"id":"1"}}}'; sleep 1) | nc $1 1234 + fi + fi diff --git a/tests/addrule.sh b/tests/addrule.sh index 1edce044..300ec9ab 100755 --- a/tests/addrule.sh +++ b/tests/addrule.sh @@ -3,6 +3,6 @@ if test -z $3; then echo "usage: $1 host triggerId actionId" else - (echo '{"id":1, "method":"Rules.AddRule", "params":{"triggerTypeId": "'$2'", "action":{ "deviceId":"'$3'", "name":"rule 1", "actionParams":{"power":"true"}}}}'; sleep 1) | nc $1 1234 - (echo '{"id":2, "method":"Rules.AddRule", "params":{"triggerTypeId": "'$2'", "action":{ "deviceId":"'$3'", "name":"rule 2", "actionParams":{"power":"false"}}}}'; sleep 1) | nc $1 1234 + (echo '{"id":1, "method":"Rules.AddRule", "params":{"trigger": {"triggerTypeId": "'$2'", "deviceId":"'$3'", "params":{"power":"true"}}, "action":{ "deviceId":"'$4'", "name":"rule 1", "params":{"power":"true"}}}}'; sleep 1) | nc $1 1234 + (echo '{"id":1, "method":"Rules.AddRule", "params":{"trigger": {"triggerTypeId": "'$2'", "deviceId":"'$3'", "params":{"power":"false"}}, "action":{ "deviceId":"'$4'", "name":"rule 1", "params":{"power":"false"}}}}'; sleep 1) | nc $1 1234 fi