From 5bb60a60c90e2653e7f3ae77fdf9e90911f5eb3c Mon Sep 17 00:00:00 2001 From: Micke Prag Date: Thu, 29 Dec 2011 17:36:41 +0100 Subject: [PATCH] Implement our new type of command messages and also handle the ACK. This requires us to bump the protocol version. Closes #151 --- telldus-gui/Plugins/Live/LiveObject.cpp | 12 ++++++++++-- telldus-gui/Plugins/Live/__init__.js | 24 +++++++++++++++--------- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/telldus-gui/Plugins/Live/LiveObject.cpp b/telldus-gui/Plugins/Live/LiveObject.cpp index 126f14d2..27b73280 100644 --- a/telldus-gui/Plugins/Live/LiveObject.cpp +++ b/telldus-gui/Plugins/Live/LiveObject.cpp @@ -127,6 +127,14 @@ void LiveObject::readyRead() { s.setValue("Live/UUID", d->uuid); emit notRegistered(); emit errorChanged("Not registered"); + } else if (msg->name() == "command") { + if (msg->arg(0).valueType == LiveMessageToken::Dictionary && msg->arg(0).dictVal.contains("ACK")) { + int ack = msg->arg(0).dictVal["ACK"].intVal; + LiveMessage msg("ACK"); + msg.append(ack); + this->sendMessage(msg); + } + emit messageReceived(msg.data()); } else { emit messageReceived(msg.data()); } @@ -137,7 +145,7 @@ void LiveObject::refreshServerList() { emit statusChanged("Discover servers"); d->serverList.clear(); QUrl url(TELLDUS_LIVE_URI); - QPair version("protocolVersion", "1"); + QPair version("protocolVersion", "2"); QList > query; query.append(version); url.setQueryItems(query); @@ -286,7 +294,7 @@ QByteArray LiveObject::signatureForMessage( const QByteArray &message ) { LiveMessageToken LiveObject::generateVersionToken() { LiveMessageToken token; token.valueType = LiveMessageToken::Dictionary; - token.dictVal["protocol"] = LiveMessageToken("1"); + token.dictVal["protocol"] = LiveMessageToken(2); token.dictVal["version"] = LiveMessageToken(TELLDUS_CENTER_VERSION); #if defined(Q_WS_WIN) token.dictVal["os"] = LiveMessageToken("windows"); diff --git a/telldus-gui/Plugins/Live/__init__.js b/telldus-gui/Plugins/Live/__init__.js index 4f292f7e..2c3f5653 100644 --- a/telldus-gui/Plugins/Live/__init__.js +++ b/telldus-gui/Plugins/Live/__init__.js @@ -45,16 +45,22 @@ com.telldus.live = function() { } function messageReceived(msg) { - if (msg.name() == "turnon") { - com.telldus.core.turnOn( msg.argument(0).intVal() ); - } else if (msg.name() == "turnoff") { - com.telldus.core.turnOff( msg.argument(0).intVal() ); - } else if (msg.name() == "dim") { - com.telldus.core.dim( msg.argument(0).intVal(), msg.argument(1).intVal() ); - } else if (msg.name() == "bell") { - com.telldus.core.bell( msg.argument(0).intVal() ); + if (msg.name() == "command") { + handleCommand(msg.argument(0)); + } + } + + function handleCommand(msg) { + var action = msg.getString('action'); + if (action == "turnon") { + com.telldus.core.turnOn( msg.getInt('id') ); + } else if (action == "turnoff") { + com.telldus.core.turnOff( msg.getInt('id') ); + } else if (action == "dim") { + com.telldus.core.dim( msg.getInt('id'), msg.getInt('value') ); + } else if (action == "bell") { + com.telldus.core.bell( msg.getInt('id') ); } - print("Received: " + msg.name()); } function registered(msg) {