forked from openstf/stf
-
Notifications
You must be signed in to change notification settings - Fork 421
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement enable/disable bluetooth of device (#754)
Signed-off-by: Jussi Vatjus-Anttila <jussiva@gmail.com>
- Loading branch information
Showing
8 changed files
with
163 additions
and
2 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
var syrup = require('stf-syrup') | ||
|
||
var logger = require('../../../util/logger') | ||
var wire = require('../../../wire') | ||
var wireutil = require('../../../wire/util') | ||
|
||
module.exports = syrup.serial() | ||
.dependency(require('./service')) | ||
.dependency(require('../support/router')) | ||
.dependency(require('../support/push')) | ||
.define(function(options, service, router, push) { | ||
var log = logger.createLogger('device:plugins:bluetooth') | ||
|
||
router.on(wire.BluetoothSetEnabledMessage, function(channel, message) { | ||
var reply = wireutil.reply(options.serial) | ||
log.info('Setting Bluetooth "%s"', message.enabled) | ||
service.setBluetoothEnabled(message.enabled) | ||
.timeout(30000) | ||
.then(function() { | ||
push.send([ | ||
channel | ||
, reply.okay() | ||
]) | ||
}) | ||
.catch(function(err) { | ||
log.error('Setting Bluetooth enabled failed', err.stack) | ||
push.send([ | ||
channel | ||
, reply.fail(err.message) | ||
]) | ||
}) | ||
}) | ||
|
||
router.on(wire.BluetoothGetStatusMessage, function(channel) { | ||
var reply = wireutil.reply(options.serial) | ||
log.info('Getting Bluetooth status') | ||
service.getBluetoothStatus() | ||
.timeout(30000) | ||
.then(function(enabled) { | ||
push.send([ | ||
channel | ||
, reply.okay(enabled ? 'bluetooth_enabled' : 'bluetooth_disabled') | ||
]) | ||
}) | ||
.catch(function(err) { | ||
log.error('Getting Bluetooth status failed', err.stack) | ||
push.send([ | ||
channel | ||
, reply.fail(err.message) | ||
]) | ||
}) | ||
}) | ||
}) |
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
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
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