diff --git a/package-lock.json b/package-lock.json index 8d67ea5..150c7c5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "homebridge-blaq", - "version": "0.2.20", + "version": "0.2.21", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "homebridge-blaq", - "version": "0.2.20", + "version": "0.2.21", "funding": [ { "type": "github", @@ -21,7 +21,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", @@ -212,33 +213,6 @@ "node": ">=12" } }, - "node_modules/@isaacs/cliui/node_modules/ansi-regex": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.0.1.tgz", - "integrity": "sha512-n5M855fKb2SsfMIiFFoVrABHJC8QtHwVx+mHWP3QcEqBHYienj5dHSgjbxtC0WEZXYt4wcD6zrQElDPhFuZgfA==", - "dev": true, - "engines": { - "node": ">=12" - }, - "funding": { - "url": "https://github.com/chalk/ansi-regex?sponsor=1" - } - }, - "node_modules/@isaacs/cliui/node_modules/strip-ansi": { - "version": "7.1.0", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.1.0.tgz", - "integrity": "sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ==", - "dev": true, - "dependencies": { - "ansi-regex": "^6.0.1" - }, - "engines": { - "node": ">=12" - }, - "funding": { - "url": "https://github.com/chalk/strip-ansi?sponsor=1" - } - }, "node_modules/@jridgewell/resolve-uri": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.1.tgz", @@ -1247,6 +1221,18 @@ "url": "https://opencollective.com/eslint" } }, + "node_modules/eslint/node_modules/strip-ansi": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "dev": true, + "dependencies": { + "ansi-regex": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/espree": { "version": "9.6.1", "resolved": "https://registry.npmjs.org/espree/-/espree-9.6.1.tgz", @@ -3207,23 +3193,22 @@ "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", "dev": true }, - "node_modules/string-width/node_modules/ansi-regex": { + "node_modules/string-width-cjs/node_modules/strip-ansi": { "version": "6.0.1", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.0.1.tgz", - "integrity": "sha512-n5M855fKb2SsfMIiFFoVrABHJC8QtHwVx+mHWP3QcEqBHYienj5dHSgjbxtC0WEZXYt4wcD6zrQElDPhFuZgfA==", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", "dev": true, - "engines": { - "node": ">=12" + "dependencies": { + "ansi-regex": "^5.0.1" }, - "funding": { - "url": "https://github.com/chalk/ansi-regex?sponsor=1" + "engines": { + "node": ">=8" } }, - "node_modules/string-width/node_modules/strip-ansi": { + "node_modules/strip-ansi": { "version": "7.1.0", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.1.0.tgz", "integrity": "sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ==", - "dev": true, "dependencies": { "ansi-regex": "^6.0.1" }, @@ -3234,7 +3219,8 @@ "url": "https://github.com/chalk/strip-ansi?sponsor=1" } }, - "node_modules/strip-ansi": { + "node_modules/strip-ansi-cjs": { + "name": "strip-ansi", "version": "6.0.1", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", @@ -3246,17 +3232,15 @@ "node": ">=8" } }, - "node_modules/strip-ansi-cjs": { - "name": "strip-ansi", + "node_modules/strip-ansi/node_modules/ansi-regex": { "version": "6.0.1", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", - "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", - "dev": true, - "dependencies": { - "ansi-regex": "^5.0.1" - }, + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.0.1.tgz", + "integrity": "sha512-n5M855fKb2SsfMIiFFoVrABHJC8QtHwVx+mHWP3QcEqBHYienj5dHSgjbxtC0WEZXYt4wcD6zrQElDPhFuZgfA==", "engines": { - "node": ">=8" + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/ansi-regex?sponsor=1" } }, "node_modules/strip-json-comments": { @@ -3604,16 +3588,16 @@ "node": ">=8" } }, - "node_modules/wrap-ansi/node_modules/ansi-regex": { + "node_modules/wrap-ansi-cjs/node_modules/strip-ansi": { "version": "6.0.1", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.0.1.tgz", - "integrity": "sha512-n5M855fKb2SsfMIiFFoVrABHJC8QtHwVx+mHWP3QcEqBHYienj5dHSgjbxtC0WEZXYt4wcD6zrQElDPhFuZgfA==", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", "dev": true, - "engines": { - "node": ">=12" + "dependencies": { + "ansi-regex": "^5.0.1" }, - "funding": { - "url": "https://github.com/chalk/ansi-regex?sponsor=1" + "engines": { + "node": ">=8" } }, "node_modules/wrap-ansi/node_modules/ansi-styles": { @@ -3628,21 +3612,6 @@ "url": "https://github.com/chalk/ansi-styles?sponsor=1" } }, - "node_modules/wrap-ansi/node_modules/strip-ansi": { - "version": "7.1.0", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.1.0.tgz", - "integrity": "sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ==", - "dev": true, - "dependencies": { - "ansi-regex": "^6.0.1" - }, - "engines": { - "node": ">=12" - }, - "funding": { - "url": "https://github.com/chalk/strip-ansi?sponsor=1" - } - }, "node_modules/wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", diff --git a/package.json b/package.json index 9ad8c7b..b78fd84 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", @@ -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" } ] } diff --git a/src/hub.ts b/src/hub.ts index 9e6b47f..9bfa4a7 100644 --- a/src/hub.ts +++ b/src/hub.ts @@ -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'; @@ -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, @@ -116,7 +117,7 @@ export class BlaQHub { }); }); this.eventsBeforeAccessoryInit = []; - this.logger.debug('[init] Accessories initialized!'); + this.logger.debug(`[${this.configDevice.displayName}] [init] Accessories initialized!`); } } @@ -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); @@ -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); @@ -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 => { diff --git a/src/utils/formatters.ts b/src/utils/formatters.ts index fc2fc61..4cd291c 100644 --- a/src/utils/formatters.ts +++ b/src/utils/formatters.ts @@ -1,2 +1,2 @@ export const formatMAC = (str?: string) => - str?.toUpperCase()?.replaceAll(/[^A-F0-9]/g, '')?.match(/.{2}/g)?.join(':'); \ No newline at end of file + str?.toUpperCase()?.replaceAll(/[^A-F0-9]/g, '')?.match(/.{2}/g)?.join(':');