thing-it-device-wtec
Advanced tools
Comparing version 0.0.4 to 0.0.5
@@ -9,3 +9,6 @@ "use strict"; | ||
deviceTypes: ["wtec/smartengine"], | ||
services: [], | ||
services: [{ | ||
id: "update", | ||
label: "Update" | ||
}], | ||
state: [ | ||
@@ -136,2 +139,8 @@ { | ||
}) | ||
/* | ||
this.interval = setInterval(function() { | ||
this.update(); | ||
}.bind(this), 5000); | ||
*/ | ||
} | ||
@@ -182,3 +191,17 @@ | ||
"use strict"; | ||
this.state = state; | ||
var promise; | ||
if (this.isSimulated()) { | ||
this.state = state; | ||
promise = q(); | ||
} else { | ||
if (state && state.activeSceneName) { | ||
return this.setScene({name: state.activeSceneName}); | ||
} else { | ||
this.logError('Cannot set state:', state); | ||
return q(); | ||
} | ||
} | ||
return promise; | ||
}; | ||
@@ -207,3 +230,3 @@ | ||
} else { | ||
return this.device.get('/rApi/location/' + this.configuration.locationId) | ||
promise = this.device.get('/rApi/location/' + this.configuration.locationId) | ||
.then(function (response) { | ||
@@ -250,2 +273,5 @@ this.logDebug('Received update by request.'); | ||
}.bind(this)) | ||
.then(function(){ | ||
this.update(); | ||
}.bind(this)) | ||
}; | ||
@@ -252,0 +278,0 @@ |
{ | ||
"name": "thing-it-device-wtec", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "[thing-it-node] Device Plugin for wtec devices.", | ||
@@ -5,0 +5,0 @@ "authors": "Klaus Berberich", |
@@ -38,28 +38,65 @@ var q = require('q'); | ||
describe.skip('subscribe to updates', function () { | ||
this.timeout(20000); | ||
describe('#setState', function () { | ||
this.timeout(6000); | ||
it('should receive updates to values', | ||
it('should set the scene to 0', | ||
function (done) { | ||
setTimeout(function () { | ||
assert.ok(testDriver.smartengine.location.state.name !== '', 'location name not received'); | ||
done(); | ||
}, 18000); | ||
var desiredState = JSON.parse(JSON.stringify(initialState)); | ||
desiredState.activeSceneName = '0%'; | ||
testDriver.smartengine.location.setScene({name: desiredState.activeSceneName}) | ||
.delay(4000) | ||
.then(function () { | ||
var resultingState = testDriver.smartengine.location.getState(); | ||
assert.equal(resultingState.activeSceneName, desiredState.activeSceneName); | ||
lastState = resultingState; | ||
done(); | ||
}) | ||
.fail(function (error) { | ||
done(error); | ||
}); | ||
}); | ||
}); | ||
describe('#setScene', function () { | ||
this.timeout(3000); | ||
this.timeout(8000); | ||
it('should set the scene to 100%', | ||
it('should set the scene to 100% and the power value should be increased', | ||
function (done) { | ||
var desiredState = JSON.parse(JSON.stringify(initialState)); | ||
var desiredState = JSON.parse(JSON.stringify(lastState)); | ||
desiredState.activeSceneName = '100%'; | ||
testDriver.smartengine.location.setScene({name: '100%', order: 4}) | ||
.delay(2000) | ||
.then(function () { | ||
var resultingState = testDriver.smartengine.location.getState(); | ||
assert.equal(resultingState.activeSceneName, desiredState.activeSceneName); | ||
}) | ||
.delay(6000) | ||
.then(function () { | ||
return testDriver.smartengine.location.update(); | ||
}.bind(this)) | ||
.then(function () { | ||
var resultingState = testDriver.smartengine.location.getState(); | ||
assert.ok(desiredState.power < resultingState.power, 'power not increased as expected - des: ' + | ||
desiredState.power + ' - res: ' + resultingState.power); | ||
done(); | ||
}.bind(this)) | ||
.fail(function (error) { | ||
done(error); | ||
}); | ||
}); | ||
}); | ||
describe('#setState', function () { | ||
this.timeout(3000); | ||
it('should set the scene back to the original', | ||
function (done) { | ||
var desiredState = JSON.parse(JSON.stringify(initialState)); | ||
desiredState.activeSceneName = initialState.activeSceneName; | ||
testDriver.smartengine.location.setState(initialState) | ||
.then(function () { | ||
var resultingState = testDriver.smartengine.location.getState(); | ||
assert.equal(resultingState.activeSceneName, desiredState.activeSceneName); | ||
lastState = resultingState; | ||
@@ -66,0 +103,0 @@ done(); |
67140
1525