Skip to content

Commit

Permalink
Use automation state for devices used by api
Browse files Browse the repository at this point in the history
  • Loading branch information
vbanthia committed Nov 23, 2016
1 parent 42b5588 commit a62a609
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 10 deletions.
15 changes: 15 additions & 0 deletions lib/db/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ dbapi.saveDeviceInitialState = function(serial, device) {
, reverseForwards: []
, remoteConnect: false
, remoteConnectUrl: null
, usage: null
}
return db.run(r.table('devices').get(serial).update(data))
.then(function(stats) {
Expand Down Expand Up @@ -212,6 +213,20 @@ dbapi.setDeviceAbsent = function(serial) {
}))
}

dbapi.setDeviceUsage = function(serial, usage) {
return db.run(r.table('devices').get(serial).update({
usage: usage
, usageChangedAt: r.now()
}))
}

dbapi.unsetDeviceUsage = function(serial) {
return db.run(r.table('devices').get(serial).update({
usage: null
, usageChangedAt: r.now()
}))
}

dbapi.setDeviceAirplaneMode = function(serial, enabled) {
return db.run(r.table('devices').get(serial).update({
airplaneMode: enabled
Expand Down
2 changes: 2 additions & 0 deletions lib/units/api/controllers/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ function addUserDevice(req, res) {
.handler()

req.options.channelRouter.on(wireutil.global, messageListener)
var usage = 'automation'

req.options.push.send([
device.channel
Expand All @@ -165,6 +166,7 @@ function addUserDevice(req, res) {
, match: 'exact'
}
})
, usage
)
)
])
Expand Down
7 changes: 4 additions & 3 deletions lib/units/device/plugins/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module.exports = syrup.serial()
return currentGroup
})

plugin.join = function(newGroup, timeout, identifier) {
plugin.join = function(newGroup, timeout, usage) {
return plugin.get()
.then(function() {
if (currentGroup.group !== newGroup.group) {
Expand All @@ -57,10 +57,11 @@ module.exports = syrup.serial()
, wireutil.envelope(new wire.JoinGroupMessage(
options.serial
, currentGroup
, usage
))
])

plugin.emit('join', currentGroup, identifier)
plugin.emit('join', currentGroup)

return currentGroup
})
Expand Down Expand Up @@ -113,7 +114,7 @@ module.exports = syrup.serial()
var reply = wireutil.reply(options.serial)
grouputil.match(ident, message.requirements)
.then(function() {
return plugin.join(message.owner, message.timeout)
return plugin.join(message.owner, message.timeout, message.usage)
})
.then(function() {
push.send([
Expand Down
4 changes: 4 additions & 0 deletions lib/units/processor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,14 @@ module.exports = function(options) {
})
.on(wire.JoinGroupMessage, function(channel, message, data) {
dbapi.setDeviceOwner(message.serial, message.owner)
if (message.usage) {
dbapi.setDeviceUsage(message.serial, message.usage)
}
appDealer.send([channel, data])
})
.on(wire.LeaveGroupMessage, function(channel, message, data) {
dbapi.unsetDeviceOwner(message.serial, message.owner)
dbapi.unsetDeviceUsage(message.serial)
appDealer.send([channel, data])
})
.on(wire.DeviceLogMessage, function(channel, message, data) {
Expand Down
1 change: 1 addition & 0 deletions lib/units/websocket/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ module.exports = function(options) {
serial: message.serial
, owner: message.owner
, likelyLeaveReason: 'owner_change'
, usage: message.usage
}
, user
)
Expand Down
2 changes: 2 additions & 0 deletions lib/wire/wire.proto
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ message GroupMessage {
required OwnerMessage owner = 1;
optional uint32 timeout = 2;
repeated DeviceRequirement requirements = 3;
optional string usage = 4;
}

message AutoGroupMessage {
Expand All @@ -275,6 +276,7 @@ message UngroupMessage {
message JoinGroupMessage {
required string serial = 1;
required OwnerMessage owner = 2;
optional string usage = 3;
}

message JoinGroupByAdbFingerprintMessage {
Expand Down
6 changes: 4 additions & 2 deletions res/app/components/stf/device/device-info-filter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ module.exports = angular.module('stf.device-status', [])
ready: gettext('Ready'),
using: gettext('Stop Using'),
busy: gettext('Busy'),
available: gettext('Use')
available: gettext('Use'),
automation: gettext('Stop Automation')
}[text] || gettext('Unknown')
}
})
Expand All @@ -25,7 +26,8 @@ module.exports = angular.module('stf.device-status', [])
ready: gettext('Ready'),
using: gettext('Using'),
busy: gettext('Busy'),
available: gettext('Available')
available: gettext('Available'),
automation: gettext('Automating'),
}[text] || gettext('Unknown')
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ module.exports = function EnhanceDeviceServiceFactory($filter, AppState) {
if (data.ready) {
data.state = 'ready'
if (data.using) {
data.state = 'using'
if (data.usage === 'automation') {
data.state = 'automation'
}
else {
data.state = 'using'
}
}
else {
if (data.owner) {
Expand Down
7 changes: 4 additions & 3 deletions res/app/components/stf/device/state-classes-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ module.exports = function StateClassesService() {
present: 'state-present btn-primary-outline',
preparing: 'state-preparing btn-primary-outline btn-success-outline',
unauthorized: 'state-unauthorized btn-danger-outline',
offline: 'state-offline btn-warning-outline'
offline: 'state-offline btn-warning-outline',
automation: 'state-automation btn-info'
}[state]
if (typeof stateClasses === 'undefined') {
stateClasses = 'btn-default-outline'
Expand All @@ -27,7 +28,8 @@ module.exports = function StateClassesService() {
present: 'state-present',
preparing: 'state-preparing',
unauthorized: 'state-unauthorized',
offline: 'state-offline'
offline: 'state-offline',
automation: 'state-automation'
}[state]
if (typeof stateClasses === 'undefined') {
stateClasses = ''
Expand All @@ -37,4 +39,3 @@ module.exports = function StateClassesService() {

return service
}

1 change: 1 addition & 0 deletions res/app/device-list/column/device-column-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@ function DeviceStatusCell(options) {
, preparing: 'state-preparing btn-primary-outline btn-success-outline'
, unauthorized: 'state-unauthorized btn-danger-outline'
, offline: 'state-offline btn-warning-outline'
, automation: 'state-automation btn-info'
}

return _.defaults(options, {
Expand Down
3 changes: 2 additions & 1 deletion res/app/device-list/icons/device-list-icons-directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ module.exports = function DeviceListIconsDirective(
present: 'state-present btn-primary-outline',
preparing: 'state-preparing btn-primary-outline btn-success-outline',
unauthorized: 'state-unauthorized btn-danger-outline',
offline: 'state-offline btn-warning-outline'
offline: 'state-offline btn-warning-outline',
automation: 'state-automation btn-info'
}[state]
if (typeof stateClasses === 'undefined') {
stateClasses = 'btn-default-outline'
Expand Down

0 comments on commit a62a609

Please sign in to comment.