Skip to content

Commit

Permalink
Integrate EsLint + Prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
jason-fox committed Nov 30, 2019
1 parent d47bba7 commit 7028300
Show file tree
Hide file tree
Showing 136 changed files with 18,865 additions and 12,353 deletions.
11 changes: 11 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "tamia",
"parserOptions": {
"sourceType": "module"
},
"plugins": ["prettier"],
"rules": {
"prettier/prettier": "error",
"valid-jsdoc": 0
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
.project
.metadata
npm-debug.log
.eslintcache

31 changes: 0 additions & 31 deletions .jshintrc

This file was deleted.

9 changes: 9 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"arrowParens": "always",
"bracketSpacing": true,
"singleQuote": true,
"parser": "flow",
"printWidth": 120,
"trailingComma": "none",
"tabWidth": 4
}
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -459,8 +459,8 @@ in the database model.
| entity_name | name | Name of the entity representing the device in the Context Broker | ParkLamplight12 |
| entity_type | type | Type of the entity in the Context Broker | Lamplights |
| timezone | timezone | Time zone of the sensor if it has any | America/Santiago |
| timestamp | timestamp | Optional flag about add or not the TimeInstant attribute to devide entity created, as well as a TimeInstant metadata to each attribute, with the current timestamp | true |
| apikey | apikey | Optional Apikey key string to use instead of group apikey
| timestamp. | timestamp | Optional flag about add or not the TimeInstant attribute to devide entity created, as well as a TimeInstant metadata to each attribute, with the current timestamp | true |
| apikey | apikey | Optional Apikey key string to use instead of group apikey
| 9n4hb1vpwbjozzmw9f0flf9c2 |
| endpoint | endpoint | Endpoint where the device is going to receive commands, if any. | http://theDeviceUrl:1234/commands |
| protocol | protocol | Name of the device protocol, for its use with an IoT Manager. | IoTA-UL |
Expand Down Expand Up @@ -1477,17 +1477,17 @@ version 3](./LICENSE).

### Are there any legal issues with AGPL 3.0? Is it safe for me to use?

There is absolutely no problem in using a product licensed under AGPL 3.0. Issues with GPL
(or AGPL) licenses are mostly related with the fact that different people assign different
There is absolutely no problem in using a product licensed under AGPL 3.0. Issues with GPL
(or AGPL) licenses are mostly related with the fact that different people assign different
interpretations on the meaning of the term “derivate work” used in these licenses. Due to this,
some people believe that there is a risk in just _using_ software under GPL or AGPL licenses
(even without _modifying_ it).

For the avoidance of doubt, the owners of this software licensed under an AGPL-3.0 license
For the avoidance of doubt, the owners of this software licensed under an AGPL-3.0 license
wish to make a clarifying public statement as follows:

> Please note that software derived as a result of modifying the source code of this
> software in order to fix a bug or incorporate enhancements is considered a derivative
> work of the product. Software that merely uses or aggregates (i.e. links to) an otherwise
> software in order to fix a bug or incorporate enhancements is considered a derivative
> work of the product. Software that merely uses or aggregates (i.e. links to) an otherwise
> unmodified version of existing software is not considered a derivative work, and therefore
> it does not need to be released as under the same license, or even released as open source.
137 changes: 79 additions & 58 deletions bin/agentConsole.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,79 +23,84 @@
* please contact with::[[email protected]]
*/

var readline = require('readline'),
iotAgentLib = require('../lib/fiware-iotagent-lib'),
commandUtils = require('command-shell-lib'),
config = require('../config'),
logger = require('logops'),
async = require('async'),
separator = '\n\n\t';

var commands = {
'start': {
/* eslint-disable no-unused-vars */
/* eslint-disable no-console */

const readline = require('readline');
const iotAgentLib = require('../lib/fiware-iotagent-lib');
const commandUtils = require('command-shell-lib');
let config = require('../config');
const logger = require('logops');
const async = require('async');
const separator = '\n\n\t';

const commands = {
start: {
parameters: [],
description: '\tStart the IoT Agent',
handler: startApp
},
'stop': {
stop: {
parameters: [],
description: '\tStop the IoT Agent',
handler: stopApp
},
'register': {
register: {
parameters: ['id', 'type'],
description: '\tRegister a new device in the IoT Agent. The attributes to register will be extracted from the\n' +
description:
'\tRegister a new device in the IoT Agent. The attributes to register will be extracted from the\n' +
'\ttype configuration',
handler: registerDevice
},
'unregister': {
unregister: {
parameters: ['id', 'type'],
description: '\tUnregister the selected device',
handler: unregisterDevice
},
'showConfig': {
showConfig: {
parameters: [],
description: '\tShow the current configuration file',
handler: showConfig
},
'config': {
config: {
parameters: ['newConfig'],
description: '\tChange the configuration file to a new one',
handler: changeConfig
},
'updatevalue': {
updatevalue: {
parameters: ['deviceId', 'deviceType', 'attributes'],
description: '\tUpdate a device value in the Context Broker. The attributes should be triads with the following\n' +
description:
'\tUpdate a device value in the Context Broker. The attributes should be triads with the following\n' +
'\tformat: "name/type/value" sepparated by commas.',
handler: updateDeviceValue
},
'listdevices': {
listdevices: {
parameters: [],
description: '\tList all the devices that have been registered in this IoT Agent session\n',
handler: listDevices
}
};

function handleError(message) {
return function (error) {
return function(error) {
if (error) {
console.log('\n\033[31mERROR:\033[0m %s', error.message);
console.log('\n\\033[31mERROR:\\033[0m %s', error.message);
} else {
console.log(message)
console.log(message);
}

commandUtils.prompt();
};
}

function listDevices() {
iotAgentLib.listDevices(config.service, config.subservice, function (error, devices) {
iotAgentLib.listDevices(config.service, config.subservice, function(error, devices) {
if (error) {
console.log('\n\033[31mERROR:\033[0m %s', error.message);
console.log('\n\\033[31mERROR:\\033[0m %s', error.message);
} else {
var keys = Object.keys(devices);
const keys = Object.keys(devices);

for (var i = 0; i < keys.length; i++) {
for (let i = 0; i < keys.length; i++) {
console.log('\n\n%s\n', JSON.stringify(devices[keys[i]], null, 4));
}

Expand All @@ -105,16 +110,15 @@ function listDevices() {
}

function extractAttributes(attributeString, callback) {
var attributes = attributeString.split(','),
attributesResult = [];

for (var i = 0; i < attributes.length; i++) {
var fields = attributes[i].split('/'),
attribute = {
name: fields[0],
type: fields[1]
};
const attributes = attributeString.split(',');
const attributesResult = [];

for (let i = 0; i < attributes.length; i++) {
const fields = attributes[i].split('/');
const attribute = {
name: fields[0],
type: fields[1]
};

if (fields[2]) {
attribute.value = fields[2];
Expand All @@ -135,24 +139,32 @@ function changeConfig(command) {
}

function writeHandler(id, type, attributes, callback) {
console.log('\n\nFake WRITE handler for update in entity [%s] with type [%s]\n%s\n',
id, type, JSON.stringify(attributes, null, 4));
console.log(
'\n\nFake WRITE handler for update in entity [%s] with type [%s]\n%s\n',
id,
type,
JSON.stringify(attributes, null, 4)
);

callback(null, {
id: id,
type: type,
attributes: attributes
id,
type,
attributes
});
}

function readHandler(id, type, attributes, callback) {
console.log('\n\nFake READ handler for update in entity [%s] with type [%s]\n%s\n'
, id, type, JSON.stringify(attributes, null, 4));

var sensorData = {
id: id,
console.log(
'\n\nFake READ handler for update in entity [%s] with type [%s]\n%s\n',
id,
type,
JSON.stringify(attributes, null, 4)
);

const sensorData = {
id,
isPattern: false,
type: type,
type,
attributes: [
{
name: 'luminance',
Expand Down Expand Up @@ -181,7 +193,7 @@ function exitAgent(command) {
}

function registerDevice(command) {
var device = {
const device = {
id: command[0],
type: command[1]
};
Expand All @@ -199,14 +211,23 @@ function updateDeviceValue(command) {
iotAgentLib.getDevice(command[0], function(error, device) {
if (device) {
extractAttributes(command[2], function(error, attributes) {
iotAgentLib.update(device.name, device.type, '', attributes, device,
handleError('Device value updated'));
iotAgentLib.update(
device.name,
device.type,
'',
attributes,
device,
handleError('Device value updated')
);
});
} else {
async.waterfall([
async.apply(extractAttributes, command[2]),
async.apply(iotAgentLib.update, command[0], command[1], '')
], handleError('Device value updated'));
async.waterfall(
[
async.apply(extractAttributes, command[2]),
async.apply(iotAgentLib.update, command[0], command[1], '')
],
handleError('Device value updated')
);
}
});
}
Expand All @@ -215,20 +236,20 @@ function queryHandler(id, type, attributes, callback) {
console.log('Handling query for [%s] of type [%s]:\n%s', JSON.stringify(attributes));

callback(null, {
type: type,
type,
isPattern: false,
id: id,
id,
attributes: []
});
}

function updateHandler(id, type, attributes, callback) {
console.log("Update message received for device with id [%s] and type [%s]", id, type);
console.log('Update message received for device with id [%s] and type [%s]', id, type);

callback(null, {
type: type,
type,
isPattern: false,
id: id,
id,
attributes: []
});
}
Expand Down
33 changes: 16 additions & 17 deletions bin/iotAgentTester.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,23 @@
* For those usages not covered by the GNU Affero General Public License
* please contact with::[[email protected]]
*/
'use strict';

var commandLine = require('../lib/command/commandLine'),
clUtils = require('command-shell-lib'),
configCb = {
host: 'localhost',
port: 1026,
service: 'tester',
subservice: '/test'
},
configIot = {
host: 'localhost',
port: 4041,
name: 'default',
service: 'tester',
subservice: '/test'
};
const commandLine = require('../lib/command/commandLine');
const clUtils = require('command-shell-lib');
const configCb = {
host: 'localhost',
port: 1026,
service: 'tester',
subservice: '/test'
};
const configIot = {
host: 'localhost',
port: 4041,
name: 'default',
service: 'tester',
subservice: '/test'
};

commandLine.init(configCb, configIot);

clUtils.initialize(commandLine.commands, 'IoT Agent tester> ');
clUtils.initialize(commandLine.commands, 'IoT Agent tester> ');
3 changes: 1 addition & 2 deletions config-blank.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ var config = {
deviceRegistry: {
type: 'memory'
},
types: {
},
types: {},
service: 'tester',
subservice: '/test',
providerUrl: 'http://192.168.56.1:4041',
Expand Down
Loading

0 comments on commit 7028300

Please sign in to comment.