1
0
Fork 0
mirror of https://github.com/openstf/stf synced 2025-10-04 10:19:30 +02:00

Use automation state for devices used by api

This commit is contained in:
Vishal Banthia 2016-11-23 06:45:36 +05:30
parent 42b55889ae
commit a62a6094e4
11 changed files with 45 additions and 10 deletions

View file

@ -153,6 +153,7 @@ dbapi.saveDeviceInitialState = function(serial, device) {
, reverseForwards: [] , reverseForwards: []
, remoteConnect: false , remoteConnect: false
, remoteConnectUrl: null , remoteConnectUrl: null
, usage: null
} }
return db.run(r.table('devices').get(serial).update(data)) return db.run(r.table('devices').get(serial).update(data))
.then(function(stats) { .then(function(stats) {
@ -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) { dbapi.setDeviceAirplaneMode = function(serial, enabled) {
return db.run(r.table('devices').get(serial).update({ return db.run(r.table('devices').get(serial).update({
airplaneMode: enabled airplaneMode: enabled

View file

@ -148,6 +148,7 @@ function addUserDevice(req, res) {
.handler() .handler()
req.options.channelRouter.on(wireutil.global, messageListener) req.options.channelRouter.on(wireutil.global, messageListener)
var usage = 'automation'
req.options.push.send([ req.options.push.send([
device.channel device.channel
@ -165,6 +166,7 @@ function addUserDevice(req, res) {
, match: 'exact' , match: 'exact'
} }
}) })
, usage
) )
) )
]) ])

View file

@ -30,7 +30,7 @@ module.exports = syrup.serial()
return currentGroup return currentGroup
}) })
plugin.join = function(newGroup, timeout, identifier) { plugin.join = function(newGroup, timeout, usage) {
return plugin.get() return plugin.get()
.then(function() { .then(function() {
if (currentGroup.group !== newGroup.group) { if (currentGroup.group !== newGroup.group) {
@ -57,10 +57,11 @@ module.exports = syrup.serial()
, wireutil.envelope(new wire.JoinGroupMessage( , wireutil.envelope(new wire.JoinGroupMessage(
options.serial options.serial
, currentGroup , currentGroup
, usage
)) ))
]) ])
plugin.emit('join', currentGroup, identifier) plugin.emit('join', currentGroup)
return currentGroup return currentGroup
}) })
@ -113,7 +114,7 @@ module.exports = syrup.serial()
var reply = wireutil.reply(options.serial) var reply = wireutil.reply(options.serial)
grouputil.match(ident, message.requirements) grouputil.match(ident, message.requirements)
.then(function() { .then(function() {
return plugin.join(message.owner, message.timeout) return plugin.join(message.owner, message.timeout, message.usage)
}) })
.then(function() { .then(function() {
push.send([ push.send([

View file

@ -175,10 +175,14 @@ module.exports = function(options) {
}) })
.on(wire.JoinGroupMessage, function(channel, message, data) { .on(wire.JoinGroupMessage, function(channel, message, data) {
dbapi.setDeviceOwner(message.serial, message.owner) dbapi.setDeviceOwner(message.serial, message.owner)
if (message.usage) {
dbapi.setDeviceUsage(message.serial, message.usage)
}
appDealer.send([channel, data]) appDealer.send([channel, data])
}) })
.on(wire.LeaveGroupMessage, function(channel, message, data) { .on(wire.LeaveGroupMessage, function(channel, message, data) {
dbapi.unsetDeviceOwner(message.serial, message.owner) dbapi.unsetDeviceOwner(message.serial, message.owner)
dbapi.unsetDeviceUsage(message.serial)
appDealer.send([channel, data]) appDealer.send([channel, data])
}) })
.on(wire.DeviceLogMessage, function(channel, message, data) { .on(wire.DeviceLogMessage, function(channel, message, data) {

View file

@ -174,6 +174,7 @@ module.exports = function(options) {
serial: message.serial serial: message.serial
, owner: message.owner , owner: message.owner
, likelyLeaveReason: 'owner_change' , likelyLeaveReason: 'owner_change'
, usage: message.usage
} }
, user , user
) )

View file

@ -261,6 +261,7 @@ message GroupMessage {
required OwnerMessage owner = 1; required OwnerMessage owner = 1;
optional uint32 timeout = 2; optional uint32 timeout = 2;
repeated DeviceRequirement requirements = 3; repeated DeviceRequirement requirements = 3;
optional string usage = 4;
} }
message AutoGroupMessage { message AutoGroupMessage {
@ -275,6 +276,7 @@ message UngroupMessage {
message JoinGroupMessage { message JoinGroupMessage {
required string serial = 1; required string serial = 1;
required OwnerMessage owner = 2; required OwnerMessage owner = 2;
optional string usage = 3;
} }
message JoinGroupByAdbFingerprintMessage { message JoinGroupByAdbFingerprintMessage {

View file

@ -10,7 +10,8 @@ module.exports = angular.module('stf.device-status', [])
ready: gettext('Ready'), ready: gettext('Ready'),
using: gettext('Stop Using'), using: gettext('Stop Using'),
busy: gettext('Busy'), busy: gettext('Busy'),
available: gettext('Use') available: gettext('Use'),
automation: gettext('Stop Automation')
}[text] || gettext('Unknown') }[text] || gettext('Unknown')
} }
}) })
@ -25,7 +26,8 @@ module.exports = angular.module('stf.device-status', [])
ready: gettext('Ready'), ready: gettext('Ready'),
using: gettext('Using'), using: gettext('Using'),
busy: gettext('Busy'), busy: gettext('Busy'),
available: gettext('Available') available: gettext('Available'),
automation: gettext('Automating'),
}[text] || gettext('Unknown') }[text] || gettext('Unknown')
} }
}) })

View file

@ -19,7 +19,12 @@ module.exports = function EnhanceDeviceServiceFactory($filter, AppState) {
if (data.ready) { if (data.ready) {
data.state = 'ready' data.state = 'ready'
if (data.using) { if (data.using) {
data.state = 'using' if (data.usage === 'automation') {
data.state = 'automation'
}
else {
data.state = 'using'
}
} }
else { else {
if (data.owner) { if (data.owner) {

View file

@ -10,7 +10,8 @@ module.exports = function StateClassesService() {
present: 'state-present btn-primary-outline', present: 'state-present btn-primary-outline',
preparing: 'state-preparing btn-primary-outline btn-success-outline', preparing: 'state-preparing btn-primary-outline btn-success-outline',
unauthorized: 'state-unauthorized btn-danger-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] }[state]
if (typeof stateClasses === 'undefined') { if (typeof stateClasses === 'undefined') {
stateClasses = 'btn-default-outline' stateClasses = 'btn-default-outline'
@ -27,7 +28,8 @@ module.exports = function StateClassesService() {
present: 'state-present', present: 'state-present',
preparing: 'state-preparing', preparing: 'state-preparing',
unauthorized: 'state-unauthorized', unauthorized: 'state-unauthorized',
offline: 'state-offline' offline: 'state-offline',
automation: 'state-automation'
}[state] }[state]
if (typeof stateClasses === 'undefined') { if (typeof stateClasses === 'undefined') {
stateClasses = '' stateClasses = ''
@ -37,4 +39,3 @@ module.exports = function StateClassesService() {
return service return service
} }

View file

@ -571,6 +571,7 @@ function DeviceStatusCell(options) {
, preparing: 'state-preparing btn-primary-outline btn-success-outline' , preparing: 'state-preparing btn-primary-outline btn-success-outline'
, unauthorized: 'state-unauthorized btn-danger-outline' , unauthorized: 'state-unauthorized btn-danger-outline'
, offline: 'state-offline btn-warning-outline' , offline: 'state-offline btn-warning-outline'
, automation: 'state-automation btn-info'
} }
return _.defaults(options, { return _.defaults(options, {

View file

@ -66,7 +66,8 @@ module.exports = function DeviceListIconsDirective(
present: 'state-present btn-primary-outline', present: 'state-present btn-primary-outline',
preparing: 'state-preparing btn-primary-outline btn-success-outline', preparing: 'state-preparing btn-primary-outline btn-success-outline',
unauthorized: 'state-unauthorized btn-danger-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] }[state]
if (typeof stateClasses === 'undefined') { if (typeof stateClasses === 'undefined') {
stateClasses = 'btn-default-outline' stateClasses = 'btn-default-outline'