-
-
Notifications
You must be signed in to change notification settings - Fork 288
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
deviceState createByDeviceTypeIdentifier
- Loading branch information
1 parent
4b36ce6
commit b5a4027
Showing
5 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
api/core/devicestate/deviceState.createByDeviceTypeIdentifier.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
var queries = require('./deviceState.queries.js'); | ||
|
||
module.exports = function(identifier, service, state){ | ||
|
||
// we get the devicetype | ||
return gladys.utils.sqlUnique(queries.getDeviceTypeByIdentifierAndService, [identifier, service]) | ||
.then(function(deviceType){ | ||
|
||
// we create the deviceState | ||
state.devicetype = deviceType.id; | ||
return gladys.deviceState.create(state); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
|
||
module.exports.create = require('./deviceState.create.js'); | ||
module.exports.createByIdentifier = require('./deviceState.createByIdentifier.js'); | ||
module.exports.createByDeviceTypeIdentifier = require('./deviceState.createByDeviceTypeIdentifier.js'); | ||
module.exports.get = require('./deviceState.get.js'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
test/unit/api/core/devicestate/deviceState.createByDeviceTypeIdentifier.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
var should = require('should'); | ||
var validateDeviceState = require('../../validator/deviceStateValidator.js'); | ||
|
||
describe('DeviceState', function() { | ||
|
||
describe('createByDeviceTypeIdentifier', function() { | ||
|
||
it('should return correct deviceState created', function (done) { | ||
|
||
var state = { | ||
value: 12.1 | ||
}; | ||
|
||
gladys.deviceState.createByDeviceTypeIdentifier('UNIQUE_IDENTIFIER', 'test', state) | ||
.then(function(result){ | ||
validateDeviceState(result); | ||
result.value.should.equal(state.value); | ||
result.devicetype.should.equal(1); | ||
done(); | ||
}).catch(function(err){ | ||
done(err); | ||
}); | ||
|
||
}); | ||
|
||
|
||
}); | ||
|
||
}); |