Implement our new type of command messages and also handle the ACK. This
requires us to bump the protocol version. Closes #151
This commit is contained in:
parent
c56fa6c6f8
commit
5bb60a60c9
2 changed files with 25 additions and 11 deletions
|
@ -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<QString, QString> version("protocolVersion", "1");
|
||||
QPair<QString, QString> version("protocolVersion", "2");
|
||||
QList<QPair<QString, QString> > 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");
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue