From cd9fe821d58d9c39a7ad6185b987a4e61938c84c Mon Sep 17 00:00:00 2001 From: kyleboyer Date: Thu, 1 Aug 2024 21:44:16 -0500 Subject: [PATCH] More debug logging around target/current door state --- package-lock.json | 4 ++-- package.json | 2 +- src/accessory/garage-door.ts | 27 +++++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index c1eb218..286abdf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "homebridge-blaq", - "version": "0.2.25", + "version": "0.2.26", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "homebridge-blaq", - "version": "0.2.25", + "version": "0.2.26", "funding": [ { "type": "github", diff --git a/package.json b/package.json index b93bfc8..29e821f 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "private": false, "displayName": "Konnected BlaQ", "name": "homebridge-blaq", - "version": "0.2.25", + "version": "0.2.26", "description": "Control and view your garage door(s) remotely with real-time updates using Konnected's BlaQ hardware", "license": "Apache-2.0", "type": "module", diff --git a/src/accessory/garage-door.ts b/src/accessory/garage-door.ts index 2e39f87..970329e 100644 --- a/src/accessory/garage-door.ts +++ b/src/accessory/garage-door.ts @@ -128,14 +128,30 @@ export class BlaQGarageDoorAccessory extends BaseBlaQAccessory { if(this.preClosing || this.currentOperation === 'CLOSING' || ( this.position !== undefined && this.targetPosition !== undefined && this.targetPosition < this.position )){ + let closingReason = 'current operation is CLOSING'; + if(this.preClosing){ + closingReason = 'the pre-close warning is active'; + } else if(this.position !== undefined && this.targetPosition !== undefined && this.targetPosition < this.position){ + closingReason = `the target position (${this.targetPosition}) is less than the current position (${this.position})`; + } + this.logger.debug(`Returning current state CLOSING because: ${closingReason}`); return this.platform.characteristic.CurrentDoorState.CLOSING; } else if(this.currentOperation === 'OPENING' || ( this.position !== undefined && this.targetPosition !== undefined && this.targetPosition > this.position )){ + const openingReason = + this.currentOperation === 'OPENING' ? + 'current operation is OPENING' : + `the target position (${this.targetPosition}) is greater than the current position (${this.position})`; + this.logger.debug(`Returning current state OPENING because: ${openingReason}`); return this.platform.characteristic.CurrentDoorState.OPENING; } else if (this.state === 'OPEN' || (this.position !== undefined && this.position > 0)) { + const openReason = this.state === 'OPEN' ? 'the current state is OPEN' : 'the current position is greater than zero'; + this.logger.debug(`Returning current state OPENING because: ${openReason}`); return this.platform.characteristic.CurrentDoorState.OPEN; } else if (this.state === 'CLOSED' || (this.position !== undefined && this.position <= 0)) { + const closedReason = this.state === 'CLOSED' ? 'the current state is CLOSED' : 'the current position is less than or equal to zero'; + this.logger.debug(`Returning current state OPENING because: ${closedReason}`); return this.platform.characteristic.CurrentDoorState.CLOSED; } throw new Error(`Invalid door state: ${this.state}`); @@ -220,13 +236,24 @@ export class BlaQGarageDoorAccessory extends BaseBlaQAccessory { getTargetDoorState(): CharacteristicValue { if(this.currentOperation === 'CLOSING' || this.preClosing || (this.targetPosition !== undefined && this.targetPosition <= 0)){ + let closedReason = 'current operation is CLOSING'; + if(this.preClosing){ + closedReason = 'the pre-close warning is active'; + }else if(this.targetPosition !== undefined && this.targetPosition <= 0){ + closedReason = 'target position is less than or equal to zero'; + } + this.logger.debug(`Returning target state CLOSED because: ${closedReason}`); return this.platform.characteristic.TargetDoorState.CLOSED; } else if(this.currentOperation === 'OPENING' || (this.targetPosition !== undefined && this.targetPosition > 0)){ + const openReason = this.currentOperation === 'OPENING' ? 'current operation is OPENING' : 'target position is greater than zero'; + this.logger.debug(`Returning target state OPEN because: ${openReason}`); return this.platform.characteristic.TargetDoorState.OPEN; } else if(this.currentOperation === 'IDLE'){ if(this.state === 'CLOSED'){ + this.logger.debug('Returning target state CLOSED because: current operation is IDLE and current state is CLOSED'); return this.platform.characteristic.TargetDoorState.CLOSED; }else if(this.state === 'OPEN'){ + this.logger.debug('Returning target state CLOSED because: current operation is IDLE and current state is OPEN'); return this.platform.characteristic.TargetDoorState.OPEN; } }