domotz-remote-pawn
Version:
Domotz Agent
67 lines (56 loc) • 2.16 kB
JavaScript
/** This file is part of Domotz Agent.
* Copyright (C) 2016 Domotz Ltd
*
* Domotz Agent is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Domotz Agent is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Domotz Agent. If not, see <http://www.gnu.org/licenses/>.
**/
/**
* Created by Tommaso Latini <tommaso@domotz.com> on 14/12/15.
*/
function getNdtServerMessage() {
return {
correlationId: "EVENT",
payload: {
timeout: 3,
maximum_attempts: 10
}
};
}
function getSpeedTestMessage(server) {
return {
correlationId: "EVENT",
payload: {
server_id: server.id
},
non_interactive: true
};
}
var speedTest = function(resourceLocator) {
console.info('Handler: speedTest');
var status = resourceLocator.status;
if (status.get() === status.RESTRICTED || status.get() === status.UPDATING) {
console.warn('Pawn in restricted or updating mode. Cannot perform Speed Test');
return;
}
var executeCommand = resourceLocator.utils.command.execute;
var join = resourceLocator.path.join;
var commandNetworkRoot = join(__dirname, '..', '..', 'commands', 'network');
var ndtServerModulePath = join(commandNetworkRoot, 'detectNearestNDTServer.js');
var speedTestModulePath = join(commandNetworkRoot, 'speedTest.js');
executeCommand(ndtServerModulePath, getNdtServerMessage(), resourceLocator,
function callback(server) {
var speedTestMessage = getSpeedTestMessage(server);
executeCommand(speedTestModulePath, speedTestMessage, resourceLocator);
});
};
module.exports.handler = speedTest;