Skip to content

Commit

Permalink
jshint cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
586837r committed Sep 14, 2019
1 parent 18306d1 commit 7761006
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 105 deletions.
3 changes: 3 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"esversion": 8
}
56 changes: 28 additions & 28 deletions lib/alexa-remote-ext.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const util = require('util');
const tools = require('./common.js');
const known = require('./known-color-values.js');
const convert = require('./color-convert.js');
const deltaE = require('./delta-e.js')
const deltaE = require('./delta-e.js');
const DEBUG_THIS = tools.DEBUG_THIS;

function requireUncached(mod) {
Expand Down Expand Up @@ -481,7 +481,7 @@ class AlexaRemoteExt extends AlexaRemote
continue;
}
this.notificationByIdExt.delete(id);
if(DEBUG_THIS) tools.log(`notification update apply: ${type} ${id} @ ${version} (previous version: ${notification && notification.version})`)
if(DEBUG_THIS) tools.log(`notification update apply: ${type} ${id} @ ${version} (previous version: ${notification && notification.version})`);
this._notificationChange();
}
else {
Expand All @@ -494,7 +494,7 @@ class AlexaRemoteExt extends AlexaRemote
await this.initNotificationsExt();
}
}
}
};

await applyAll().then(() => {
this.notificationUpdatesRunning = false;
Expand All @@ -504,7 +504,7 @@ class AlexaRemoteExt extends AlexaRemote
tools.log(`notification update ended erronously...`);
error.message = `failed to update notifications: ${error.message}`;
this.warnCallback(error);
})
});
}

async refreshExt() {
Expand Down Expand Up @@ -560,13 +560,13 @@ class AlexaRemoteExt extends AlexaRemote
const wrapperNode = {
'@type': 'com.amazon.alexa.behaviors.model.Sequence',
startNode: sequenceNode
}
};

const requestData = {
behaviorId: 'PREVIEW',
sequenceJson: JSON.stringify(wrapperNode),
status: 'ENABLED',
}
};

//tools.log({sequenceNode: sequenceNode});

Expand Down Expand Up @@ -621,7 +621,7 @@ class AlexaRemoteExt extends AlexaRemote

const target = convert.hex2lab(arg);
let closestDelta = Infinity;
let closestName = undefined;
let closestName;

for(const [name, hex] of this.colorNameToHexExt) {
const lab = convert.hex2lab(hex);
Expand Down Expand Up @@ -657,7 +657,7 @@ class AlexaRemoteExt extends AlexaRemote
}

let closestDelta = Infinity;
let closestName = undefined;
let closestName;

for(const [name, kelvin] of this.colorTemperatureNameToKelvinExt) {
const lab = convert.tmp2lab(kelvin);
Expand All @@ -672,7 +672,7 @@ class AlexaRemoteExt extends AlexaRemote
}

// requests like ['Lamp 1', '1234-DEAD-BEEF-5678' }]
async querySmarthomeDevicesExt(requests) {
async querySmarthomeDeviceStatesExt(requests) {
const entities = requests.map(request => this.findSmarthomeEntityExt(request.entity));
const nativeRequests = entities.filter(e => e).map(entity => ({
entityType: entity.type,
Expand Down Expand Up @@ -705,7 +705,7 @@ class AlexaRemoteExt extends AlexaRemote
data: JSON.stringify({
'stateRequests': stateRequests
})
}
};

console.log(util.inspect(flags, false, 10, true));
return this.httpsGetPromise('/api/phoenix/state', flags);
Expand All @@ -731,7 +731,7 @@ class AlexaRemoteExt extends AlexaRemote
data: JSON.stringify({
'controlRequests': controlRequests
})
}
};

console.log(util.inspect(flags, false, 10, true));
return this.httpsGetPromise('/api/phoenix/state', flags);
Expand All @@ -741,27 +741,27 @@ class AlexaRemoteExt extends AlexaRemote
return new Promise((resolve, reject) => {
const entity = this.findSmarthomeEntityExt(id);
if(!entity || entity.type !== 'APPLIANCE') throw new Error(`smarthome device not found: "${id}"`);
this.deleteSmarthomeDevice(entity.applianceId, (err, val) => {
err && err.message !== 'no body' ? reject(err) : resolve(val);
});
this.deleteSmarthomeDevice(entity.applianceId, (err, val) =>
err && err.message !== 'no body' ? reject(err) : resolve(val)
);
});
}

async deleteSmarthomeGroupExt(id) {
return new Promise((resolve, reject) => {
const entity = this.findSmarthomeEntityExt(id);
if(!entity || entity.type !== 'GROUP') throw new Error(`smarthome group not found: "${id}"`);
this.deleteSmarthomeGroup(entity.groupId, (err, val) => {
err && err.message !== 'no body' ? reject(err) : resolve(val);
});
this.deleteSmarthomeGroup(entity.groupId, (err, val) =>
err && err.message !== 'no body' ? reject(err) : resolve(val)
);
});
}

async deleteAllSmarthomeDevicesExt() {
return new Promise((resolve, reject) => {
this.deleteAllSmarthomeDevices((err, val) => {
err && err.message !== 'no body' ? reject(err) : resolve(val);
});
this.deleteAllSmarthomeDevices((err, val) =>
err && err.message !== 'no body' ? reject(err) : resolve(val)
);
});
}

Expand All @@ -781,15 +781,15 @@ class AlexaRemoteExt extends AlexaRemote
createdDate: new Date().getTime(),
completed: false,
deleted: false,
}
};

this.httpsGetPromise(`/api/todos`, {
method: 'POST',
data: JSON.stringify(request),
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
}
})
});
}

findNotificationExt(id) {
Expand All @@ -800,7 +800,7 @@ class AlexaRemoteExt extends AlexaRemote

// type like "Reminder" or "Alarm" or "Timer"
// status like "ON" or "OFF" or "PAUSED"
createNotificationObjectExt(serialOrName, type, label, time, status = 'ON', sound) {
createNotificationObjectExt(serialOrName, type, label, time, status = 'ON', sound = null) {
const device = this.find(serialOrName);
if(!device) throw new Error('device not found');
if(!['Reminder', 'Alarm', 'Timer'].includes(type)) throw new Error(`invalid notification type: "${type}"`);
Expand Down Expand Up @@ -861,7 +861,7 @@ class AlexaRemoteExt extends AlexaRemote
"triggerTime": 0,
"type": type,
"version": '1'
}
};
}

changeNotificationObjectExt(notification, label, time, status, sound) {
Expand Down Expand Up @@ -954,7 +954,7 @@ class AlexaRemoteExt extends AlexaRemote
const found = this.find(device);
if(!found) throw new Error(`device not found: "${device}"`);

return this.httpsGetPromise(`/api/notification/migration/default-sound?deviceSerialNumber=${found.serialNumber}&deviceType=${found.deviceType}&softwareVersion=${found.softwareVersion}&notificationType=${notificationType.toUpperCase()}&_=%t`)
return this.httpsGetPromise(`/api/notification/migration/default-sound?deviceSerialNumber=${found.serialNumber}&deviceType=${found.deviceType}&softwareVersion=${found.softwareVersion}&notificationType=${notificationType.toUpperCase()}&_=%t`);
}

async getDeviceNotificationStatesExt() {
Expand All @@ -971,9 +971,9 @@ class AlexaRemoteExt extends AlexaRemote

async checkAuthenticationExt() {
return new Promise((resolve, reject) => {
this.checkAuthentication((authenticated, error) => {
error ? reject(error) : resolve(authenticated);
});
this.checkAuthentication((authenticated, error) =>
error ? reject(error) : resolve(authenticated)
);
});
}

Expand Down
6 changes: 3 additions & 3 deletions lib/color-convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function hex2rgb(hex) {
// ranges 0..1
function rgb2hex(rgb) {
[r,g,b] = rgb.map(x => Math.round(x*255));
return '#' + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1)
return '#' + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);
}

// ranges 0..1
Expand Down Expand Up @@ -57,7 +57,7 @@ function rgb2hsv([r,g,b]) {
Math.abs(K + (g-b) / (6.0 * chroma + Number.EPSILON)),
chroma / (r + Number.EPSILON),
r
]
];
}

function clamp(v, min, max) {
Expand Down Expand Up @@ -146,4 +146,4 @@ module.exports = {
tmp2lab: tmp => xyz2lab(rgb2xyz(tmp2rgb(tmp))),

xyz2lab: xyz2lab,
}
};
16 changes: 8 additions & 8 deletions lib/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function isObject(x) {
function mapObject(obj, fun, depth = Infinity) {
if(typeof obj !== 'object' || obj === null || depth === 0) return obj;

for(key of Object.keys(obj)) {
for(const key of Object.keys(obj)) {
val = obj[key];
mapObject(val, fun, depth - 1);
res = fun(key, val);
Expand Down Expand Up @@ -179,7 +179,7 @@ function nodeEvaluateProperties(RED, node, msg, obj, depth = Infinity) {
if(!typeEqual(obj, { type: '', value: '' })) {
const clone = {};
for(const key of Object.keys(obj)) {
clone[key] = nodeEvaluateProperties(RED, node, msg, obj[key], depth - 1)
clone[key] = nodeEvaluateProperties(RED, node, msg, obj[key], depth - 1);
}
return clone;
}
Expand Down Expand Up @@ -223,7 +223,7 @@ function flatten(arr) {
}

function tryParseJson(json) {
let obj = undefined;
let obj;

try {
obj = JSON.parse(json);
Expand Down Expand Up @@ -298,7 +298,7 @@ function assignEvalTyped(RED, node, msg, dest, keys) {
function assignEvalTypedStruct(RED, node, msg, dest, keys) {
return assignBase((dst, src, key) => {
const inp = src[key];
dst[key] = RED.util.evaluateNodeProperty(inp && inp.value, inp && inp.type, node, msg)
dst[key] = RED.util.evaluateNodeProperty(inp && inp.value, inp && inp.type, node, msg);
},
...[...arguments].slice(3));
}
Expand Down Expand Up @@ -396,13 +396,13 @@ function nodeSetup(node, input, statusReport = false) {
this.blinkInterval = null;
}
this.status({});
}
};
node._startBlinking = function(a, b) {
this.blinkInterval = setInterval(() => {
this.blinkState = !this.blinkState;
this.status(this.blinkState ? a : b);
}, 300);
}
};

node._onStatus = (code, message) => {
node._stopBlinking();
Expand All @@ -421,7 +421,7 @@ function nodeSetup(node, input, statusReport = false) {
case 'UNINITIALISED': node.status({shape: 'ring', fill: 'grey', text: 'uninitialized' }); break;
default: node.status({shape: 'ring', fill: 'yellow', text: 'unknown status' }); break;
}
}
};

node.account.emitter.removeListener('state', node._onStatus);
node.account.emitter.addListener('state', node._onStatus);
Expand Down Expand Up @@ -505,7 +505,7 @@ async function portAvailable(port) {
socket.pipe(socket);
});
server.on('error', (err) => {
reject(err)
reject(err);
});
server.on('listening', () => {
server.close();
Expand Down
Loading

0 comments on commit 7761006

Please sign in to comment.