Skip to content

Commit

Permalink
Logging update
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleBoyer committed Jul 24, 2024
1 parent c515191 commit 862496c
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 88 deletions.
111 changes: 40 additions & 71 deletions package-lock.json

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

13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"private": false,
"displayName": "Konnected BlaQ",
"name": "homebridge-blaq",
"version": "0.2.20",
"version": "0.2.21",
"description": "Control and view your garage door(s) remotely with real-time updates using Konnected's BlaQ hardware",
"license": "Apache-2.0",
"type": "module",
Expand Down Expand Up @@ -37,7 +37,8 @@
"dependencies": {
"bonjour-service": "^1.2.1",
"eventsource": "^2.0.2",
"node-fetch": "^3.3.2"
"node-fetch": "^3.3.2",
"strip-ansi": "^7.1.0"
},
"devDependencies": {
"@types/eventsource": "^1.1.15",
Expand All @@ -57,12 +58,12 @@
"author": "Kyle Boyer",
"funding": [
{
"type" : "github",
"url" : "https://github.com/sponsors/my-account"
"type": "github",
"url": "https://github.com/sponsors/my-account"
},
{
"type" : "paypal",
"url" : "https://paypal.me/kylemboyer"
"type": "paypal",
"url": "https://paypal.me/kylemboyer"
}
]
}
21 changes: 11 additions & 10 deletions src/hub.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { AutoReconnectingEventSource, LogMessageEvent, PingMessageEvent, StateUpdateMessageEvent } from './utils/eventsource.js';
import { Logger, PlatformAccessory, PlatformConfig } from 'homebridge';
import stripAnsi from 'strip-ansi';
import { BlaQTextSensorEvent, ConfigDevice } from './types.js';
import { BaseBlaQAccessoryInterface } from './accessory/base.js';
import { BlaQHomebridgePluginPlatform } from './platform.js';
Expand Down Expand Up @@ -96,7 +97,7 @@ export class BlaQHub {

private possiblyFinalizeInit(){
if(!this.initialized && this.friendlyName && this.deviceMac){
this.logger.info('[init] Publishing accessories with device model:', this.friendlyName);
this.logger.info(`[${this.configDevice.displayName}] [init] Publishing accessories with device model:`, this.friendlyName);
this.initAccessories({
friendlyName: this.friendlyName,
serialNumber: this.deviceMac,
Expand All @@ -116,7 +117,7 @@ export class BlaQHub {
});
});
this.eventsBeforeAccessoryInit = [];
this.logger.debug('[init] Accessories initialized!');
this.logger.debug(`[${this.configDevice.displayName}] [init] Accessories initialized!`);
}
}

Expand All @@ -132,12 +133,12 @@ export class BlaQHub {
}
this.possiblyFinalizeInit();
} catch (e) {
this.logger.debug('[init] Got event:', msg);
this.logger.debug('[init] Got event data:', msg.data);
this.logger.error('[init] Cannot parse BlaQTextSensorEvent', e);
this.logger.debug(`[${this.configDevice.displayName}] [init] Got event:`, msg);
this.logger.debug(`[${this.configDevice.displayName}] [init] Got event data:`, msg.data);
this.logger.error(`[${this.configDevice.displayName}] [init] Cannot parse BlaQTextSensorEvent`, e);
}
}
this.logger.debug('Processing state event:', msg.data);
this.logger.debug(`[${this.configDevice.displayName}] Processing state event:`, msg.data);
this.accessories.forEach(accessory => {
if(accessory.handleStateEvent){
accessory.handleStateEvent(msg);
Expand All @@ -149,7 +150,7 @@ export class BlaQHub {
if(!this.initialized){
this.eventsBeforeAccessoryInit.push({ type: 'log', event: msg });
}
this.logger.debug('BlaQ log:', msg.data);
this.logger.debug(`[${this.configDevice.displayName}] GDO blaQ log:`, stripAnsi(msg.data));
this.accessories.forEach(accessory => {
if(accessory.handleLogEvent){
accessory.handleLogEvent(msg);
Expand Down Expand Up @@ -236,9 +237,9 @@ export class BlaQHub {
this.friendlyName = b.title;
this.possiblyFinalizeInit();
} catch (e) {
this.logger.debug('[init] Got event:', msg);
this.logger.debug('[init] Got event data:', msg.data);
this.logger.error('[init] Cannot parse BlaQPingEvent', e);
this.logger.debug(`[${this.configDevice.displayName}] [init] Got event:`, msg);
this.logger.debug(`[${this.configDevice.displayName}] [init] Got event data:`, msg.data);
this.logger.error(`[${this.configDevice.displayName}] [init] Cannot parse BlaQPingEvent`, e);
}
}
this.accessories.forEach(accessory => {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/formatters.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export const formatMAC = (str?: string) =>
str?.toUpperCase()?.replaceAll(/[^A-F0-9]/g, '')?.match(/.{2}/g)?.join(':');
str?.toUpperCase()?.replaceAll(/[^A-F0-9]/g, '')?.match(/.{2}/g)?.join(':');

0 comments on commit 862496c

Please sign in to comment.