From 526447c0e3cd5fc3ec22cb095dcede87bad987cc Mon Sep 17 00:00:00 2001 From: kyleboyer Date: Tue, 23 Jul 2024 23:49:36 -0500 Subject: [PATCH] Logging tweaks/consistency --- src/accessory/base.ts | 5 +++++ src/accessory/garage-door.ts | 3 +-- src/accessory/garage-learn-mode.ts | 3 +-- src/accessory/garage-light.ts | 3 +-- src/accessory/garage-lock.ts | 3 +-- src/accessory/garage-motion-sensor.ts | 3 +-- src/accessory/garage-obstruction-sensor.ts | 3 +-- src/accessory/garage-pre-close-warning.ts | 3 +-- 8 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/accessory/base.ts b/src/accessory/base.ts index 6d61d7c..63f5de9 100644 --- a/src/accessory/base.ts +++ b/src/accessory/base.ts @@ -48,6 +48,7 @@ export class BaseBlaQAccessory implements BaseBlaQAccessoryInterface { }: BaseBlaQAccessoryConstructorParams){ this.platform = platform; this.logger = this.platform.logger; + this.logger.debug(`Initializing ${this.getSelfClassName()}...`); this.accessory = accessory; this.friendlyName = friendlyName; this.serialNumber = serialNumber; @@ -66,6 +67,10 @@ export class BaseBlaQAccessory implements BaseBlaQAccessoryInterface { .onGet(this.getFirmwareVersion.bind(this)); } + protected getSelfClassName() { + return Object.getPrototypeOf(this).constructor.name; + } + protected getOrAddService(service: WithUUID | Service): Service{ return this.accessory.getService(service as WithUUID) || this.accessory.addService(service as Service); diff --git a/src/accessory/garage-door.ts b/src/accessory/garage-door.ts index 6a1c4eb..2f46774 100644 --- a/src/accessory/garage-door.ts +++ b/src/accessory/garage-door.ts @@ -37,7 +37,6 @@ export class BlaQGarageDoorAccessory extends BaseBlaQAccessory { constructor(args: BaseBlaQAccessoryConstructorParams) { super(args); - this.logger.debug('Initializing BlaQGarageDoorAccessory...'); this.garageDoorService = this.getOrAddService(this.platform.service.GarageDoorOpener); // Set the service name. This is what is displayed as the name on the Home @@ -67,7 +66,7 @@ export class BlaQGarageDoorAccessory extends BaseBlaQAccessory { this.garageDoorService.getCharacteristic(this.platform.characteristic.LockTargetState) .onSet(this.updateLockState.bind(this)); - this.logger.debug('Initialized BlaQGarageDoorAccessory!'); + this.logger.debug(`Initialized ${this.getSelfClassName()}!`); } private async updateLockState(lockState: CharacteristicValue){ diff --git a/src/accessory/garage-learn-mode.ts b/src/accessory/garage-learn-mode.ts index 94f95e6..3710373 100644 --- a/src/accessory/garage-learn-mode.ts +++ b/src/accessory/garage-learn-mode.ts @@ -20,7 +20,6 @@ export class BlaQGarageLearnModeAccessory extends BaseBlaQAccessory { constructor(args: BaseBlaQAccessoryConstructorParams) { super(args); - this.logger.debug('Initializing BlaQGarageLearnModeAccessory...'); this.switchService = this.getOrAddService(this.platform.service.Switch); // Set the service name. This is what is displayed as the name on the Home @@ -30,7 +29,7 @@ export class BlaQGarageLearnModeAccessory extends BaseBlaQAccessory { this.switchService.getCharacteristic(this.platform.characteristic.On) .onGet(this.getIsOn.bind(this)) .onSet(this.changeIsOn.bind(this)); - this.logger.debug('Initialized BlaQGarageLearnModeAccessory!'); + this.logger.debug(`Initialized ${this.getSelfClassName()}!`); } getIsOn(): CharacteristicValue { diff --git a/src/accessory/garage-light.ts b/src/accessory/garage-light.ts index 0092c1e..ebf665c 100644 --- a/src/accessory/garage-light.ts +++ b/src/accessory/garage-light.ts @@ -24,7 +24,6 @@ export class BlaQGarageLightAccessory extends BaseBlaQAccessory { constructor(args: BaseBlaQAccessoryConstructorParams) { super(args); - this.logger.debug('Initializing BlaQGarageLightAccessory...'); this.lightbulbService = this.getOrAddService(this.platform.service.Lightbulb); // Set the service name. This is what is displayed as the name on the Home @@ -35,7 +34,7 @@ export class BlaQGarageLightAccessory extends BaseBlaQAccessory { .onGet(this.getPowerState.bind(this)) .onSet(this.changePowerState.bind(this)); - this.logger.debug('Initialized BlaQGarageLightAccessory!'); + this.logger.debug(`Initialized ${this.getSelfClassName()}!`); } getPowerState(): CharacteristicValue { diff --git a/src/accessory/garage-lock.ts b/src/accessory/garage-lock.ts index 02d6241..5397d5c 100644 --- a/src/accessory/garage-lock.ts +++ b/src/accessory/garage-lock.ts @@ -24,7 +24,6 @@ export class BlaQGarageLockAccessory extends BaseBlaQAccessory { constructor(args: BaseBlaQAccessoryConstructorParams) { super(args); - this.logger.debug('Initializing BlaQGarageLockAccessory...'); this.lockService = this.getOrAddService(this.platform.service.LockMechanism); // Set the service name. This is what is displayed as the name on the Home @@ -36,7 +35,7 @@ export class BlaQGarageLockAccessory extends BaseBlaQAccessory { this.lockService.getCharacteristic(this.platform.characteristic.LockTargetState) .onSet(this.changeLockState.bind(this)); - this.logger.debug('Initialized BlaQGarageLockAccessory!'); + this.logger.debug(`Initialized ${this.getSelfClassName()}!`); } getLockState(): CharacteristicValue { diff --git a/src/accessory/garage-motion-sensor.ts b/src/accessory/garage-motion-sensor.ts index e39579e..fafbfd9 100644 --- a/src/accessory/garage-motion-sensor.ts +++ b/src/accessory/garage-motion-sensor.ts @@ -20,7 +20,6 @@ export class BlaQGarageMotionSensorAccessory extends BaseBlaQAccessory { constructor(args: BaseBlaQAccessoryConstructorParams) { super(args); - this.logger.debug('Initializing BlaQGarageMotionSensorAccessory...'); this.motionSensorService = this.getOrAddService(this.platform.service.MotionSensor); // Set the service name. This is what is displayed as the name on the Home @@ -30,7 +29,7 @@ export class BlaQGarageMotionSensorAccessory extends BaseBlaQAccessory { this.motionSensorService.getCharacteristic(this.platform.characteristic.MotionDetected) .onGet(this.getMotionDetected.bind(this)); - this.logger.debug('Initialized BlaQGarageMotionSensorAccessory!'); + this.logger.debug(`Initialized ${this.getSelfClassName()}!`); } getMotionDetected(): CharacteristicValue { diff --git a/src/accessory/garage-obstruction-sensor.ts b/src/accessory/garage-obstruction-sensor.ts index 6f20a09..2bbbb86 100644 --- a/src/accessory/garage-obstruction-sensor.ts +++ b/src/accessory/garage-obstruction-sensor.ts @@ -19,7 +19,6 @@ export class BlaQGarageObstructionSensorAccessory extends BaseBlaQAccessory { constructor(args: BaseBlaQAccessoryConstructorParams) { super(args); - this.logger.debug('Initializing BlaQGarageObstructionSensorAccessory...'); this.occupancySensorService = this.getOrAddService(this.platform.service.OccupancySensor); // Set the service name. This is what is displayed as the name on the Home @@ -32,7 +31,7 @@ export class BlaQGarageObstructionSensorAccessory extends BaseBlaQAccessory { this.occupancySensorService.getCharacteristic(this.platform.characteristic.OccupancyDetected) .onGet(this.getObstructionDetected.bind(this)); - this.logger.debug('Initialized BlaQGarageObstructionSensorAccessory!'); + this.logger.debug(`Initialized ${this.getSelfClassName()}!`); } getObstructionDetected(): CharacteristicValue { diff --git a/src/accessory/garage-pre-close-warning.ts b/src/accessory/garage-pre-close-warning.ts index e94e652..bc8b60d 100644 --- a/src/accessory/garage-pre-close-warning.ts +++ b/src/accessory/garage-pre-close-warning.ts @@ -20,7 +20,6 @@ export class BlaQGaragePreCloseWarningAccessory extends BaseBlaQAccessory { constructor(args: BaseBlaQAccessoryConstructorParams) { super(args); - this.logger.debug('Initializing BlaQGaragePreCloseWarningAccessory...'); this.outletService = this.getOrAddService(this.platform.service.Outlet); // Set the service name. This is what is displayed as the name on the Home @@ -30,7 +29,7 @@ export class BlaQGaragePreCloseWarningAccessory extends BaseBlaQAccessory { this.outletService.getCharacteristic(this.platform.characteristic.On) .onGet(this.getIsOn.bind(this)) .onSet(this.changeIsOn.bind(this)); - this.logger.debug('Initialized BlaQGaragePreCloseWarningAccessory!'); + this.logger.debug(`Initialized ${this.getSelfClassName()}!`); } getIsOn(): CharacteristicValue {