Skip to content

Commit

Permalink
Fix linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
chase9 committed Oct 9, 2023
1 parent c7967a0 commit 2b618b2
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 77 deletions.
134 changes: 71 additions & 63 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@
"polling-to-event": "^2.1.0"
},
"devDependencies": {
"@types/node": "^20.5.9",
"@typescript-eslint/eslint-plugin": "^6.5.0",
"@typescript-eslint/parser": "^6.5.0",
"eslint": "8.48.0",
"@types/node": "^20.8.4",
"@typescript-eslint/eslint-plugin": "^6.7.5",
"@typescript-eslint/parser": "^6.7.5",
"eslint": "8.51.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.0.0",
"homebridge": "^1.6.1",
Expand Down
27 changes: 21 additions & 6 deletions src/CustomLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ export class CustomLogger implements Logger {
this.logLevel = logLevel;
}

info(message: string, ...parameters: any[]): void {
info(message: string, ...parameters: unknown[]): void {
if (this.logLevel >= CustomLogLevel.NOTICE) this.logger.info(message, ...parameters);
}

warn(message: string, ...parameters: any[]): void {
warn(message: string, ...parameters: unknown[]): void {
if (this.logLevel >= CustomLogLevel.WARN) this.logger.warn(message, ...parameters);
}

error(message: string, ...parameters: any[]): void {
error(message: string, ...parameters: unknown[]): void {
if (this.logLevel >= CustomLogLevel.ERROR) this.logger.error(message, ...parameters);
}

debug(message: string, ...parameters: any[]): void {
debug(message: string, ...parameters: unknown[]): void {
if (this.logLevel >= CustomLogLevel.VERBOSE) this.logger.debug(message, ...parameters);
}

Expand All @@ -37,8 +37,23 @@ export class CustomLogger implements Logger {
* @param message
* @param parameters
*/
log(level: LogLevel, message: string, ...parameters: any[]): void {
return;
log(level: LogLevel, message: string, ...parameters: unknown[]): void {
switch (level) {
case LogLevel.DEBUG:
this.debug(message, parameters);
break;
case LogLevel.ERROR:
this.error(message, parameters);
break;
case LogLevel.INFO:
this.info(message, parameters);
break;
case LogLevel.WARN:
this.warn(message, parameters);
break;
default:
break;
}
}
}

Expand Down
12 changes: 8 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
LockState,
login,
openGarage,
PartitionActionOptions,
SensorState,
SensorType,
setLightOff,
Expand Down Expand Up @@ -70,6 +71,7 @@ import {
} from './_models/Contexts';
import { CustomLogger, CustomLogLevel } from './CustomLogger';

// eslint-disable-next-line @typescript-eslint/no-unused-vars
let hap: HAP;
const PLUGIN_ID = 'homebridge-node-alarm-dot-com';
const PLUGIN_NAME = 'Alarmdotcom';
Expand Down Expand Up @@ -105,7 +107,7 @@ class ADCPlatform implements DynamicPlatformPlugin {
private authOpts: AuthOpts;
private config: PlatformConfig;
private logLevel: CustomLogLevel;
private armingModes: any;
private armingModes: Record<string, Record<string, boolean>>;
private ignoredDevices: string[];
private useMFA: boolean;
private mfaToken?: string;
Expand Down Expand Up @@ -213,7 +215,7 @@ class ADCPlatform implements DynamicPlatformPlugin {
this.listDevices()
.then((res) => {
this.log.debug('Registering system:');
this.log.debug(res as any);
this.log.debug(JSON.stringify(res));

for (const device in res) {
if (device === 'partitions' && typeof res[device][0] === 'undefined') {
Expand Down Expand Up @@ -656,7 +658,7 @@ class ADCPlatform implements DynamicPlatformPlugin {
): Promise<void> {
const id = accessory.context.accID;
let method: typeof armAway | typeof armStay | typeof disarm;
const opts = {} as any;
const opts = {} as PartitionActionOptions;

switch (value) {
case hapCharacteristic.SecuritySystemTargetState.STAY_ARM:
Expand Down Expand Up @@ -1669,7 +1671,7 @@ class ADCPlatform implements DynamicPlatformPlugin {
if (this.accessories.findIndex((accessory) => accessory.context.accID === id) > -1) {
this.api.registerPlatformAccessories(PLUGIN_ID, PLUGIN_NAME, [accessory]);
} else {
this.log.warn(`Preventing adding existing accessory ${name} with id ${id}`);
this.log.warn(`Preventing adding existing ${model} ${name} with id ${id}`);
}
}

Expand Down Expand Up @@ -1934,6 +1936,7 @@ function convertCtoF(c: number): number {
* @param sensor The type as defined by Alarm.com.
* @returns {} An array with details about its type as defines it.
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function getSensorType(sensor: SensorState): Array<any> {
const state = sensor.attributes.state;
const type = sensor.attributes.deviceType;
Expand Down Expand Up @@ -1977,6 +1980,7 @@ function getSensorType(sensor: SensorState): Array<any> {
* @param model The model as reported by Alarm.com.
* @returns {array} An array with homebridge service and characteristic types.
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function sensorModelToType(model: string): Array<any> {
switch (model) {
case 'Contact Sensor':
Expand Down

0 comments on commit 2b618b2

Please sign in to comment.