Skip to content

Commit

Permalink
Tidying up the lint
Browse files Browse the repository at this point in the history
  • Loading branch information
kiwi-cam committed Jun 18, 2023
1 parent a8da388 commit cd9e9c6
Show file tree
Hide file tree
Showing 61 changed files with 12,011 additions and 12,011 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Expand Up @@ -45,7 +45,7 @@
"no-autofix/prefer-const": "warn",

"indent": ["error", 2, { "SwitchCase": 1 }],
"linebreak-style": ["error", "unix"],
"linebreak-style": ["error", "windows"],
"curly": 1
}
}
252 changes: 126 additions & 126 deletions accessories/accessory.js
@@ -1,126 +1,126 @@
const uuid = require('uuid');

const { HomebridgeAccessory } = require('../base');

const sendData = require('../helpers/sendData');
const delayForDuration = require('../helpers/delayForDuration');
const catchDelayCancelError = require('../helpers/catchDelayCancelError');

class BroadlinkRMAccessory extends HomebridgeAccessory {

constructor (log, config = {}, serviceManagerType) {
if (!config.name) {config.name = "Unknown Accessory"}

config.resendDataAfterReload = config.resendHexAfterReload;
if (config.host) {
//Clean up MAC address formatting
config.host = config.host.toLowerCase();
if (!config.host.includes(".") && !config.host.includes(":") && config.host.length === 12){
config.host = config.host.match(/[\s\S]{1,2}/g).join(':');
}
}

super(log, config, serviceManagerType);
if (config.debug) {this.debug = true}

this.manufacturer = 'Broadlink';
this.model = 'RM Mini or Pro';
this.serialNumber = uuid.v4();

//Set LogLevel
switch(this.config.logLevel){
case 'none':
this.logLevel = 6;
break;
case 'critical':
this.logLevel = 5;
break;
case 'error':
this.logLevel = 4;
break;
case 'warning':
this.logLevel = 3;
break;
case 'info':
this.logLevel = 2;
break;
case 'debug':
this.logLevel = 1;
break;
case 'trace':
this.logLevel = 0;
break;
default:
//default to 'info':
if(this.config.logLevel !== undefined) {log(`\x1b[31m[CONFIG ERROR] \x1b[33mlogLevel\x1b[0m should be one of: trace, debug, info, warning, error, critical, or none.`);}
this.logLevel = 2;
break;
}
if(this.config.debug) {this.logLevel = Math.min(1, this.logLevel);}
if(this.config.disableLogs) {this.logLevel = 6;}
}

performSetValueAction ({ host, data, log, name, logLevel }) {
sendData({ host, hexData: data, log, name, logLevel });
}

reset () {
// Clear Multi-hex timeouts
if (this.intervalTimeoutPromise) {
this.intervalTimeoutPromise.cancel();
this.intervalTimeoutPromise = null;
}

if (this.pauseTimeoutPromise) {
this.pauseTimeoutPromise.cancel();
this.pauseTimeoutPromise = null;
}
}

async performSend (data, actionCallback) {
const { logLevel, config, host, log, name } = this;

//Error catch
if(data === undefined){return}

if (typeof data === 'string') {
sendData({ host, hexData: data, log, name, logLevel });

return;
}

await catchDelayCancelError(async () => {
// Itterate through each hex config in the array
for (let index = 0; index < data.length; index++) {
const { pause } = data[index];

await this.performRepeatSend(data[index], actionCallback);

if (pause) {
this.pauseTimeoutPromise = delayForDuration(pause);
await this.pauseTimeoutPromise;
}
}
});
}

async performRepeatSend (parentData, actionCallback) {
const { host, log, name, logLevel } = this;
let { data, interval, sendCount } = parentData;

sendCount = sendCount || 1
if (sendCount > 1) {interval = interval || 0.1;}

// Itterate through each hex config in the array
for (let index = 0; data && index < sendCount; index++) {
sendData({ host, hexData: data, log, name, logLevel });

if (interval && index < sendCount - 1) {
this.intervalTimeoutPromise = delayForDuration(interval);
await this.intervalTimeoutPromise;
}
}
}
}

module.exports = BroadlinkRMAccessory;
const uuid = require('uuid');

const { HomebridgeAccessory } = require('../base');

const sendData = require('../helpers/sendData');
const delayForDuration = require('../helpers/delayForDuration');
const catchDelayCancelError = require('../helpers/catchDelayCancelError');

class BroadlinkRMAccessory extends HomebridgeAccessory {

constructor (log, config = {}, serviceManagerType) {
if (!config.name) {config.name = "Unknown Accessory"}

config.resendDataAfterReload = config.resendHexAfterReload;
if (config.host) {
//Clean up MAC address formatting
config.host = config.host.toLowerCase();
if (!config.host.includes(".") && !config.host.includes(":") && config.host.length === 12){
config.host = config.host.match(/[\s\S]{1,2}/g).join(':');
}
}

super(log, config, serviceManagerType);
if (config.debug) {this.debug = true}

this.manufacturer = 'Broadlink';
this.model = 'RM Mini or Pro';
this.serialNumber = uuid.v4();

//Set LogLevel
switch(this.config.logLevel){
case 'none':
this.logLevel = 6;
break;
case 'critical':
this.logLevel = 5;
break;
case 'error':
this.logLevel = 4;
break;
case 'warning':
this.logLevel = 3;
break;
case 'info':
this.logLevel = 2;
break;
case 'debug':
this.logLevel = 1;
break;
case 'trace':
this.logLevel = 0;
break;
default:
//default to 'info':
if(this.config.logLevel !== undefined) {log(`\x1b[31m[CONFIG ERROR] \x1b[33mlogLevel\x1b[0m should be one of: trace, debug, info, warning, error, critical, or none.`);}
this.logLevel = 2;
break;
}
if(this.config.debug) {this.logLevel = Math.min(1, this.logLevel);}
if(this.config.disableLogs) {this.logLevel = 6;}
}

performSetValueAction ({ host, data, log, name, logLevel }) {
sendData({ host, hexData: data, log, name, logLevel });
}

reset () {
// Clear Multi-hex timeouts
if (this.intervalTimeoutPromise) {
this.intervalTimeoutPromise.cancel();
this.intervalTimeoutPromise = null;
}

if (this.pauseTimeoutPromise) {
this.pauseTimeoutPromise.cancel();
this.pauseTimeoutPromise = null;
}
}

async performSend (data, actionCallback) {
const { logLevel, config, host, log, name } = this;

//Error catch
if(data === undefined){return}

if (typeof data === 'string') {
sendData({ host, hexData: data, log, name, logLevel });

return;
}

await catchDelayCancelError(async () => {
// Itterate through each hex config in the array
for (let index = 0; index < data.length; index++) {
const { pause } = data[index];

await this.performRepeatSend(data[index], actionCallback);

if (pause) {
this.pauseTimeoutPromise = delayForDuration(pause);
await this.pauseTimeoutPromise;
}
}
});
}

async performRepeatSend (parentData, actionCallback) {
const { host, log, name, logLevel } = this;
let { data, interval, sendCount } = parentData;

Check warning on line 109 in accessories/accessory.js

View workflow job for this annotation

GitHub Actions / Build and Test on Node 16 and ubuntu-latest

'data' is never reassigned. Use 'const' instead

Check warning on line 109 in accessories/accessory.js

View workflow job for this annotation

GitHub Actions / Build and Test on Node 20 and ubuntu-latest

'data' is never reassigned. Use 'const' instead

Check warning on line 109 in accessories/accessory.js

View workflow job for this annotation

GitHub Actions / Build and Test on Node 18 and ubuntu-latest

'data' is never reassigned. Use 'const' instead

Check warning on line 109 in accessories/accessory.js

View workflow job for this annotation

GitHub Actions / Build and Test on Node 16 and macOS-latest

'data' is never reassigned. Use 'const' instead

Check warning on line 109 in accessories/accessory.js

View workflow job for this annotation

GitHub Actions / Build and Test on Node 18 and macOS-latest

'data' is never reassigned. Use 'const' instead

Check warning on line 109 in accessories/accessory.js

View workflow job for this annotation

GitHub Actions / Build and Test on Node 20 and windows-latest

'data' is never reassigned. Use 'const' instead

Check warning on line 109 in accessories/accessory.js

View workflow job for this annotation

GitHub Actions / Build and Test on Node 20 and macOS-latest

'data' is never reassigned. Use 'const' instead

Check warning on line 109 in accessories/accessory.js

View workflow job for this annotation

GitHub Actions / Build and Test on Node 16 and windows-latest

'data' is never reassigned. Use 'const' instead

Check warning on line 109 in accessories/accessory.js

View workflow job for this annotation

GitHub Actions / Build and Test on Node 18 and windows-latest

'data' is never reassigned. Use 'const' instead

sendCount = sendCount || 1
if (sendCount > 1) {interval = interval || 0.1;}

// Itterate through each hex config in the array
for (let index = 0; data && index < sendCount; index++) {
sendData({ host, hexData: data, log, name, logLevel });

if (interval && index < sendCount - 1) {
this.intervalTimeoutPromise = delayForDuration(interval);
await this.intervalTimeoutPromise;
}
}
}
}

module.exports = BroadlinkRMAccessory;

0 comments on commit cd9e9c6

Please sign in to comment.