Skip to content

Commit

Permalink
Update platform.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
donavanbecker committed Dec 30, 2023
1 parent 4c7dfe1 commit a1ec64d
Showing 1 changed file with 61 additions and 61 deletions.
122 changes: 61 additions & 61 deletions src/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export class CloudflaredTunnelPlatform implements DynamicPlatformPlugin {
config!: CloudflaredTunnelPlatformConfig;

constructor(log: Logging, config: CloudflaredTunnelPlatformConfig, api: API) {
this.logs();
this.debugLog(`Finished initializing platform: ${config.name}`);
// this.logs();
//this.debugLog(`Finished initializing platform: ${config.name}`);

this.accessories = [];
this.api = api;
Expand All @@ -50,10 +50,10 @@ export class CloudflaredTunnelPlatform implements DynamicPlatformPlugin {
// verify the config
try {
this.verifyConfig();
this.debugLog('Config OK');
//this.debugLog('Config OK');
} catch (e: any) {
this.errorLog(JSON.stringify(e.message));
this.debugLog(JSON.stringify(e));
//this.errorLog(JSON.stringify(e.message));
//this.debugLog(JSON.stringify(e));
return;
}

Expand All @@ -67,8 +67,8 @@ export class CloudflaredTunnelPlatform implements DynamicPlatformPlugin {
try {
this.discoverDevices();
} catch (e: any) {
this.errorLog(`Failed to Discover Devices ${JSON.stringify(e.message)}`);
this.debugLog(JSON.stringify(e));
//this.errorLog(`Failed to Discover Devices ${JSON.stringify(e.message)}`);
//this.debugLog(JSON.stringify(e));
}
});
}
Expand All @@ -78,7 +78,7 @@ export class CloudflaredTunnelPlatform implements DynamicPlatformPlugin {
* It should be used to setup event handlers for characteristics and update respective values.
*/
configureAccessory(accessory: PlatformAccessory) {
this.infoLog(`Loading accessory from cache: ${accessory.displayName}`);
//this.infoLog(`Loading accessory from cache: ${accessory.displayName}`);

// add the restored accessory to the accessories cache so we can track if it has already been registered
this.accessories.push(accessory);
Expand All @@ -96,13 +96,13 @@ export class CloudflaredTunnelPlatform implements DynamicPlatformPlugin {
throw new Error('Missing one of the following configs: port, hostname, url, protocol, please check your config.json');
}
if (this.config.url && this.config.hostname) {
this.debugLog(`URL: ${this.config.url}`);
this.debugLog(`Hostname: ${this.config.hostname}`);
// this.debugLog(`URL: ${this.config.url}`);
//this.debugLog(`Hostname: ${this.config.hostname}`);
throw new Error('Cannot have both url and hostname in config. Please remove one.');
}
} catch (e: any) {
this.errorLog(JSON.stringify(e.message));
this.debugLog(JSON.stringify(e));
//this.errorLog(JSON.stringify(e.message));
//this.debugLog(JSON.stringify(e));
}
if (!this.config.logging) {
this.config.logging = 'standard';
Expand Down Expand Up @@ -148,7 +148,7 @@ export class CloudflaredTunnelPlatform implements DynamicPlatformPlugin {
}
}

logs() {
/*logs() {
this.debugMode = process.argv.includes('-D') || process.argv.includes('--debug');
if (this.config?.logging === 'debug' || this.config?.logging === 'standard' || this.config?.logging === 'none') {
this.platformLogging = this.config!.logging;
Expand All @@ -166,51 +166,51 @@ export class CloudflaredTunnelPlatform implements DynamicPlatformPlugin {
* If device level logging is turned on, log to log.warn
* Otherwise send debug logs to log.debug
*/
infoLog(...log: any[]): void {
if (this.enablingPlatfromLogging()) {
this.log.info(String(...log));
}
}

warnLog(...log: any[]): void {
if (this.enablingPlatfromLogging()) {
this.log.warn(String(...log));
}
}

debugWarnLog(...log: any[]): void {
if (this.enablingPlatfromLogging()) {
if (this.platformLogging?.includes('debug')) {
this.log.warn('[DEBUG]', String(...log));
}
}
}

errorLog(...log: any[]): void {
if (this.enablingPlatfromLogging()) {
this.log.error(String(...log));
}
}

debugErrorLog(...log: any[]): void {
if (this.enablingPlatfromLogging()) {
if (this.platformLogging?.includes('debug')) {
this.log.error('[DEBUG]', String(...log));
}
}
}

debugLog(...log: any[]): void {
if (this.enablingPlatfromLogging()) {
if (this.platformLogging === 'debugMode') {
this.log.debug(String(...log));
} else if (this.platformLogging === 'debug') {
this.log.info('[DEBUG]', String(...log));
}
}
}

enablingPlatfromLogging(): boolean {
return this.platformLogging?.includes('debug') || this.platformLogging === 'standard';
}
}
/* infoLog(...log: any[]): void {
if (this.enablingPlatfromLogging()) {
this.log.info(String(...log));
}
}
warnLog(...log: any[]): void {
if (this.enablingPlatfromLogging()) {
this.log.warn(String(...log));
}
}
debugWarnLog(...log: any[]): void {
if (this.enablingPlatfromLogging()) {
if (this.platformLogging?.includes('debug')) {
this.log.warn('[DEBUG]', String(...log));
}
}
}
errorLog(...log: any[]): void {
if (this.enablingPlatfromLogging()) {
this.log.error(String(...log));
}
}
debugErrorLog(...log: any[]): void {
if (this.enablingPlatfromLogging()) {
if (this.platformLogging?.includes('debug')) {
this.log.error('[DEBUG]', String(...log));
}
}
}
debugLog(...log: any[]): void {
if (this.enablingPlatfromLogging()) {
if (this.platformLogging === 'debugMode') {
this.log.debug(String(...log));
} else if (this.platformLogging === 'debug') {
this.log.info('[DEBUG]', String(...log));
}
}
}
enablingPlatfromLogging(): boolean {
return this.platformLogging?.includes('debug') || this.platformLogging === 'standard';
}*/
}

0 comments on commit a1ec64d

Please sign in to comment.