Add function com.telldus.core.sensorValue() to script as wrapper for tdSensorValue(). See #96

This commit is contained in:
Micke Prag 2011-10-26 15:55:03 +02:00
parent 486753d411
commit b9fbd3a909
2 changed files with 14 additions and 0 deletions

View file

@ -1,4 +1,5 @@
#include "tellduscoreobject.h"
#include <QDateTime>
#include <QDebug>
TelldusCoreObject::TelldusCoreObject( QObject * parent )
@ -123,6 +124,18 @@ QVariant TelldusCoreObject::sensor() const {
return retval;
}
QVariant TelldusCoreObject::sensorValue(const QString &protocol, const QString &model, int id, int dataType) const {
const int DATA_LENGTH = 20;
char value[DATA_LENGTH];
time_t timestamp = 0;
tdSensorValue(protocol.toUtf8(), model.toUtf8(), id, dataType, value, DATA_LENGTH, (int *)&timestamp);
QVariantMap retval;
retval["value"] = value;
retval["timestamp"] = QDateTime::fromTime_t(timestamp);
return retval;
}
void TelldusCoreObject::triggerError(int deviceId, int errorId) {
char *errorString = tdGetErrorString( errorId );
QString message = QString::fromUtf8( errorString );

View file

@ -29,6 +29,7 @@ public slots:
int methods( int deviceId, int methodsSupported );
QVariant sensor() const;
QVariant sensorValue(const QString &protocol, const QString &model, int id, int dataType) const;
int turnOn( int deviceId );
int turnOff( int deviceId );