Skip to content

Commit

Permalink
Prettified Code!
Browse files Browse the repository at this point in the history
  • Loading branch information
daniep01 authored and actions-user committed Mar 17, 2022
1 parent 4e506d6 commit cc55c78
Showing 1 changed file with 34 additions and 29 deletions.
63 changes: 34 additions & 29 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ instance.prototype.init = function () {
self.nodes = []
self.currentChannel = ''
self.accessToken = ''

self.setupVariables()
self.getAccessToken()
self.getNodes()
Expand Down Expand Up @@ -72,7 +72,8 @@ instance.prototype.config_fields = function () {
id: 'info',
width: 12,
label: 'Information',
value: 'This module is for the Adder XDIP Receiver. Add a new module connection for each receiver in your system. The Receiver Access Password is required to change channels.',
value:
'This module is for the Adder XDIP Receiver. Add a new module connection for each receiver in your system. The Receiver Access Password is required to change channels.',
},
{
type: 'textinput',
Expand Down Expand Up @@ -150,7 +151,7 @@ instance.prototype.action = function (action) {
self.switchChannel(cmd)
self.getCurrentChannel()
} else {
self.log('warn','Unable to find channel number for ' + opt.channelUuid)
self.log('warn', 'Unable to find channel number for ' + opt.channelUuid)
}
break
}
Expand Down Expand Up @@ -189,7 +190,7 @@ instance.prototype.switchChannel = function (cmd) {

if (self.accessToken == '') {
console.log('missing access token')
self.log('warn','Unable to switch channel, missing access token')
self.log('warn', 'Unable to switch channel, missing access token')
return
}

Expand All @@ -213,13 +214,14 @@ instance.prototype.switchChannel = function (cmd) {
self.status(self.STATUS_OK)
} else {
console.log('error ' + result.response.statusCode)
self.log('warn','Unable to switch to channel')
self.log('warn', 'Unable to switch to channel')
}
},
header,
{ connection: {
rejectUnauthorized: false,
}
{
connection: {
rejectUnauthorized: false,
},
}
)
}
Expand Down Expand Up @@ -262,9 +264,10 @@ instance.prototype.getChannels = function () {
}
},
header,
{ connection: {
rejectUnauthorized: false,
}
{
connection: {
rejectUnauthorized: false,
},
}
)
}
Expand All @@ -278,7 +281,7 @@ instance.prototype.getNodes = function () {
var header = []
header['Content-Type'] = 'application/json'
console.log(cmd)

self.system.emit(
'rest_get',
cmd,
Expand All @@ -297,7 +300,7 @@ instance.prototype.getNodes = function () {
if (name.length == 0) {
name = 'Name not set! ' + i
}
description = result.data[i].description.trim()
description = result.data[i].description.trim()
// console.log(uuid)
//if (uuid != 'self') {
self.nodes.splice(i, 0, {
Expand All @@ -316,9 +319,10 @@ instance.prototype.getNodes = function () {
}
},
header,
{ connection: {
rejectUnauthorized: false,
}
{
connection: {
rejectUnauthorized: false,
},
}
)
}
Expand Down Expand Up @@ -363,17 +367,18 @@ instance.prototype.getCurrentChannel = function () {
}
},
header,
{ connection: {
rejectUnauthorized: false,
}
{
connection: {
rejectUnauthorized: false,
},
}
)
}

instance.prototype.getAccessToken = function (cmd) {
var self = this
var header = []
header['Content-Type'] = 'application/json'
header['Content-Type'] = 'application/json'

try {
authData = JSON.parse('{"accessPassword":"' + self.config.password.toString() + '"}')
Expand All @@ -387,7 +392,7 @@ instance.prototype.getAccessToken = function (cmd) {
console.log(cmd)

self.system.emit(
'rest',
'rest',
cmd,
authData,
function (err, result) {
Expand All @@ -402,7 +407,7 @@ instance.prototype.getAccessToken = function (cmd) {
self.accessToken = result.data.accessToken.toString()
console.log(self.accessToken)
self.setVariable('tokenStatus', 'Valid')
self.log('debug','Access Token received')
self.log('debug', 'Access Token received')
}
}
} else {
Expand All @@ -413,9 +418,10 @@ instance.prototype.getAccessToken = function (cmd) {
}
},
header,
{ connection: {
rejectUnauthorized: false,
}
{
connection: {
rejectUnauthorized: false,
},
}
)
}
Expand All @@ -425,7 +431,7 @@ instance.prototype.lookupChannel = function (lookupUuid) {
console.log('Lookup channel for: ' + lookupUuid)

try {
let obj = self.channels.find(o => o.uuid == lookupUuid)
let obj = self.channels.find((o) => o.uuid == lookupUuid)
console.log(lookupUuid + ' is channel ' + obj.channel)
return obj.channel
} catch (e) {
Expand All @@ -445,7 +451,7 @@ instance.prototype.lookupName = function (lookupCh) {
}

try {
let obj = self.channels.find(o => o.channel == lookupCh)
let obj = self.channels.find((o) => o.channel == lookupCh)
uuid = obj.uuid
console.log('Lookup uuid for channel: ' + lookupCh + ' = ' + uuid)
} catch (e) {
Expand All @@ -454,7 +460,7 @@ instance.prototype.lookupName = function (lookupCh) {
}

try {
let obj = self.nodes.find(p => p.id == uuid)
let obj = self.nodes.find((p) => p.id == uuid)
name = obj.label
console.log('Lookup name for channel: ' + lookupCh + ' = ' + name)
} catch (e) {
Expand All @@ -467,4 +473,3 @@ instance.prototype.lookupName = function (lookupCh) {

instance_skel.extendedBy(instance)
exports = module.exports = instance

0 comments on commit cc55c78

Please sign in to comment.