Skip to content

Commit

Permalink
Various fixes. Closes #47. Released 0.0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
Hexagon committed Dec 22, 2013
1 parent 0ddddb3 commit 1995bdd
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 21 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{ "name" : "telldus"
, "version" : "0.0.6"
, "version" : "0.0.7"
, "description" : "node wrapper for telldus-core, based on telldus-core-js"
, "keywords": ["telldus", "telldus-core", "TellStick", "home automation"]
, "author": "Robin Nilsson <[email protected]>"
Expand Down
53 changes: 34 additions & 19 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
telldus - Node bindings for telldus-core
===

Latest release is 0.0.6, available at npm using ```npm install telldus```
Latest release is 0.0.7, available at npm using ```npm install telldus```

---

Expand Down Expand Up @@ -37,33 +37,48 @@ Make sure telldusd is running on the same machine.

```javascript
var telldus = require('telldus');
var devices = telldus.getDevicesSync();

telldus.getDevices(function(err,devices) {
if ( err ) {
console.log('Error: ' + err);
} else {
// A list of all configured devices is returned
console.log(deviceList);
}
});
```

If you ever get a returnValue from a method like turnOnSync that is
not equal to 0 (TELLDUS_SUCCESS) you could check what type of error
that is using telldus.getErrorString.


---

API
===

getDevicesSync
getDevices
----------

Returns an array of device dictionary objects.
Only configured devices are returned.

Currently only available as a synchronous function.
Synchronous version: ```javascript var devices = telldus.getDevicesSync();```

Signature:

```javascript
var devices = telldus.getDevicesSync();
telldus.getDevices(function(err,devices) {
if ( err ) {
console.log('Error: ' + err);
} else {
// The list of devices is returned
console.log(devices);
}
});
```


```javascript
[
{
Expand All @@ -90,7 +105,7 @@ Signature:

```javascript
telldus.turnOn(deviceId,function(err) {
console.log('deviceId is now ON');
console.log('deviceId is now ON');
});
```

Expand All @@ -112,7 +127,7 @@ Signature:

```javascript
telldus.turnOff(deviceId,function(err) {
console.log('Device' + deviceId + ' is now OFF');
console.log('Device' + deviceId + ' is now OFF');
});
```

Expand All @@ -134,7 +149,7 @@ Signature:

```javascript
telldus.dim(deviceId, level,function(err) {
console.log('Device ' + deviceId + ' is now dimmed to level ' + level);
console.log('Device ' + deviceId + ' is now dimmed to level ' + level);
});
```

Expand All @@ -149,7 +164,7 @@ Signature:

```javascript
var listener = telldus.addRawDeviceEventListener(function(controllerId, data) {
console.log('Raw device event: ' + data);
console.log('Raw device event: ' + data);
});
```

Expand All @@ -170,7 +185,7 @@ Signature:

```javascript
var listener = telldus.addDeviceEventListener(function(deviceId, status) {
console.log('Device ' + deviceId + ' is now ' + status.status);
console.log('Device ' + deviceId + ' is now ' + status.status);
});
```

Expand All @@ -188,7 +203,7 @@ Signature:

```javascript
var listener = telldus.addSensorEventListener(function(deviceId,protocol,model,type,value,timestamp) {
console.log('New sensor event received: ',deviceId,protocol,model,type,value,timestamp);
console.log('New sensor event received: ',deviceId,protocol,model,type,value,timestamp);
});
```

Expand Down Expand Up @@ -216,13 +231,13 @@ Synchronous version: ```javascript var errStr = telldus.getErrorStringSync(retur
Signature:

```javascript
var returnValue = telldus.turnOnSync(deviceId);
if(returnValue > 0) {
telldus.getErrorString(returnValue, function (err, errStr) {
console.error('turnOn failed for device ' + deviceId + ', error: ' + errStr);
process.exit(0);
});
}
var returnValue = telldus.turnOnSync(deviceId);
if(returnValue > 0) {
telldus.getErrorString(returnValue, function (err, errStr) {
console.error('turnOn failed for device ' + deviceId + ', error: ' + errStr);
process.exit(0);
});
}

```

Expand Down
5 changes: 5 additions & 0 deletions telldus.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ namespace telldus_v8 {
int id;
char *name;
char *model;
char *protocol;
};

Local<Object> GetSupportedMethods(int id, int supportedMethods){
Expand Down Expand Up @@ -122,12 +123,14 @@ namespace telldus_v8 {
obj->Set(String::NewSymbol("id"), Number::New(deviceInternals.id));
obj->Set(String::NewSymbol("methods"), GetSupportedMethods(deviceInternals.id,deviceInternals.supportedMethods));
obj->Set(String::NewSymbol("model"), String::New(deviceInternals.model, strlen(deviceInternals.model)));
obj->Set(String::NewSymbol("protocol"), String::New(deviceInternals.protocol, strlen(deviceInternals.protocol)));
obj->Set(String::NewSymbol("type"), GetDeviceType(deviceInternals.id,deviceInternals.deviceType));
obj->Set(String::NewSymbol("status"), GetDeviceStatus(deviceInternals.id,deviceInternals.lastSentCommand,deviceInternals.level));

// Cleanup
tdReleaseString(deviceInternals.name);
tdReleaseString(deviceInternals.model);
tdReleaseString(deviceInternals.protocol);

return obj;

Expand Down Expand Up @@ -156,6 +159,7 @@ namespace telldus_v8 {
deviceInternals.id = tdGetDeviceId( idx );
deviceInternals.name = tdGetName( deviceInternals.id );
deviceInternals.model = tdGetModel( deviceInternals.id );
deviceInternals.protocol = tdGetProtocol( deviceInternals.id );

deviceInternals.supportedMethods = tdMethods( deviceInternals.id, SUPPORTED_METHODS );
deviceInternals.deviceType = tdGetDeviceType( deviceInternals.id );
Expand Down Expand Up @@ -482,6 +486,7 @@ namespace telldus_v8 {
break;
case 26: // getDevices
work->l = getDevicesRaw();
break;
}

}
Expand Down
2 changes: 1 addition & 1 deletion test/async.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ describe('async methods', function () {
it('getNumberOfDevices', function (done) {
telldus.getNumberOfDevices(function (err, result) {
should.not.exist(err);
result.should.be.within(1, 10);
result.should.be.within(1, 50);
done();
});

Expand Down

0 comments on commit 1995bdd

Please sign in to comment.