From 27738d1de147b8109fc4c489eadaf33ea983f9a1 Mon Sep 17 00:00:00 2001 From: kyleboyer Date: Sun, 14 Jul 2024 23:23:50 -0500 Subject: [PATCH] Display name updates --- package-lock.json | 4 +- package.json | 2 +- src/accessory/garage-learn-mode.ts | 4 +- src/accessory/garage-light.ts | 4 +- src/accessory/garage-lock.ts | 4 +- src/accessory/garage-motion-sensor.ts | 4 +- src/accessory/garage-obstruction-sensor.ts | 4 +- src/accessory/garage-pre-close-warning.ts | 4 +- src/hub.ts | 143 ++++++++------------- 9 files changed, 74 insertions(+), 99 deletions(-) diff --git a/package-lock.json b/package-lock.json index cddb8e9..bb98dbc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "homebridge-blaq", - "version": "0.2.9", + "version": "0.2.10", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "homebridge-blaq", - "version": "0.2.9", + "version": "0.2.10", "license": "Apache-2.0", "dependencies": { "bonjour-service": "^1.2.1", diff --git a/package.json b/package.json index ba8216d..f8c1871 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "private": false, "displayName": "Konnected BlaQ", "name": "homebridge-blaq", - "version": "0.2.9", + "version": "0.2.10", "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-learn-mode.ts b/src/accessory/garage-learn-mode.ts index 90e33f4..6e67177 100644 --- a/src/accessory/garage-learn-mode.ts +++ b/src/accessory/garage-learn-mode.ts @@ -28,6 +28,8 @@ type BlaQGarageLearnModeAccessoryConstructorParams = { apiBaseURL: string; }; +export const label = 'Learn/Pair Mode'; + /** * Platform Accessory * An instance of this class is created for each accessory your platform registers @@ -73,7 +75,7 @@ export class BlaQGarageLearnModeAccessory implements BaseBlaQAccessory { // Set the service name. This is what is displayed as the name on the Home // app. We use what we stored in `accessory.context` in `discoverDevices`. - this.switchService.setCharacteristic(this.platform.characteristic.Name, accessory.context.device.displayName); + this.switchService.setCharacteristic(this.platform.characteristic.Name, accessory.context.device.displayName + ' ' + label); this.switchService.getCharacteristic(this.platform.characteristic.On) .onGet(this.getIsOn.bind(this)) diff --git a/src/accessory/garage-light.ts b/src/accessory/garage-light.ts index ebfe54e..84392b9 100644 --- a/src/accessory/garage-light.ts +++ b/src/accessory/garage-light.ts @@ -31,6 +31,8 @@ type BlaQGarageLightAccessoryConstructorParams = { apiBaseURL: string; }; +export const label = 'Light'; + /** * Platform Accessory * An instance of this class is created for each accessory your platform registers @@ -77,7 +79,7 @@ export class BlaQGarageLightAccessory implements BaseBlaQAccessory { // Set the service name. This is what is displayed as the name on the Home // app. We use what we stored in `accessory.context` in `discoverDevices`. - this.lightbulbService.setCharacteristic(this.platform.characteristic.Name, accessory.context.device.displayName); + this.lightbulbService.setCharacteristic(this.platform.characteristic.Name, accessory.context.device.displayName + ' ' + label); this.lightbulbService.getCharacteristic(this.platform.characteristic.On) .onGet(this.getPowerState.bind(this)) diff --git a/src/accessory/garage-lock.ts b/src/accessory/garage-lock.ts index 1ab5b1d..14d8af1 100644 --- a/src/accessory/garage-lock.ts +++ b/src/accessory/garage-lock.ts @@ -31,6 +31,8 @@ type BlaQGarageLockAccessoryConstructorParams = { apiBaseURL: string; }; +export const label = 'Lock Remotes'; + /** * Platform Accessory * An instance of this class is created for each accessory your platform registers @@ -77,7 +79,7 @@ export class BlaQGarageLockAccessory implements BaseBlaQAccessory { // Set the service name. This is what is displayed as the name on the Home // app. We use what we stored in `accessory.context` in `discoverDevices`. - this.lockService.setCharacteristic(this.platform.characteristic.Name, accessory.context.device.displayName); + this.lockService.setCharacteristic(this.platform.characteristic.Name, accessory.context.device.displayName + ' ' + label); this.lockService.getCharacteristic(this.platform.characteristic.LockCurrentState) .onGet(this.getLockState.bind(this)); diff --git a/src/accessory/garage-motion-sensor.ts b/src/accessory/garage-motion-sensor.ts index 3580a26..739359c 100644 --- a/src/accessory/garage-motion-sensor.ts +++ b/src/accessory/garage-motion-sensor.ts @@ -27,6 +27,8 @@ type BlaQGarageMotionSensorAccessoryConstructorParams = { apiBaseURL: string; }; +export const label = 'Motion Sensor'; + /** * Platform Accessory * An instance of this class is created for each accessory your platform registers @@ -72,7 +74,7 @@ export class BlaQGarageMotionSensorAccessory implements BaseBlaQAccessory { // Set the service name. This is what is displayed as the name on the Home // app. We use what we stored in `accessory.context` in `discoverDevices`. - this.motionSensorService.setCharacteristic(this.platform.characteristic.Name, accessory.context.device.displayName); + this.motionSensorService.setCharacteristic(this.platform.characteristic.Name, accessory.context.device.displayName + ' ' + label); this.motionSensorService.getCharacteristic(this.platform.characteristic.MotionDetected) .onGet(this.getMotionDetected.bind(this)); diff --git a/src/accessory/garage-obstruction-sensor.ts b/src/accessory/garage-obstruction-sensor.ts index 0499720..9e1706e 100644 --- a/src/accessory/garage-obstruction-sensor.ts +++ b/src/accessory/garage-obstruction-sensor.ts @@ -27,6 +27,8 @@ type BlaQGarageObstructionSensorAccessoryConstructorParams = { apiBaseURL: string; }; +export const label = 'Obstruction Sensor'; + /** * Platform Accessory * An instance of this class is created for each accessory your platform registers @@ -72,7 +74,7 @@ export class BlaQGarageObstructionSensorAccessory implements BaseBlaQAccessory { // Set the service name. This is what is displayed as the name on the Home // app. We use what we stored in `accessory.context` in `discoverDevices`. - this.occupancySensorService.setCharacteristic(this.platform.characteristic.Name, accessory.context.device.displayName); + this.occupancySensorService.setCharacteristic(this.platform.characteristic.Name, accessory.context.device.displayName + ' ' + label); this.occupancySensorService.getCharacteristic(this.platform.characteristic.OccupancyDetected) .onGet(this.getObstructionDetected.bind(this)); diff --git a/src/accessory/garage-pre-close-warning.ts b/src/accessory/garage-pre-close-warning.ts index ffd4c60..7922977 100644 --- a/src/accessory/garage-pre-close-warning.ts +++ b/src/accessory/garage-pre-close-warning.ts @@ -28,6 +28,8 @@ type BlaQGaragePreCloseWarningAccessoryConstructorParams = { apiBaseURL: string; }; +export const label = 'Pre-close Warning'; + /** * Platform Accessory * An instance of this class is created for each accessory your platform registers @@ -73,7 +75,7 @@ export class BlaQGaragePreCloseWarningAccessory implements BaseBlaQAccessory { // Set the service name. This is what is displayed as the name on the Home // app. We use what we stored in `accessory.context` in `discoverDevices`. - this.outletService.setCharacteristic(this.platform.characteristic.Name, accessory.context.device.displayName); + this.outletService.setCharacteristic(this.platform.characteristic.Name, accessory.context.device.displayName + ' ' + label); this.outletService.getCharacteristic(this.platform.characteristic.On) .onGet(this.getIsOn.bind(this)) diff --git a/src/hub.ts b/src/hub.ts index 5410e93..bde0de6 100644 --- a/src/hub.ts +++ b/src/hub.ts @@ -24,6 +24,11 @@ type ModelAndSerialNumber = { serialNumber: string; }; +type InitAccessoryParams = ModelAndSerialNumber & { + platform: BlaQHomebridgePluginPlatform; + accessory: PlatformAccessory; +}; + export type BlaQInitAccessoryCallback = (configDevice: ConfigDevice, Model: string, SerialNumber: string) => { platform: BlaQHomebridgePluginPlatform; accessory: PlatformAccessory; @@ -99,115 +104,73 @@ export class BlaQHub { }); } - private initGarageDoorAccessory({ model, serialNumber }: ModelAndSerialNumber){ - const {platform, accessory} = this.initAccessoryCallback( - this.configDevice, - model, - serialNumber, - ); + private initGarageDoorAccessory({ platform, accessory, model, serialNumber}: InitAccessoryParams){ this.accessories.push(new BlaQGarageDoorAccessory({ platform, accessory, model, serialNumber, apiBaseURL: this.getAPIBaseURL(), })); } - private initGarageLightAccessory({ model, serialNumber }: ModelAndSerialNumber){ - const baseDisplayName = this.configDevice.displayName || 'Garage Door'; - const displayName = `${baseDisplayName} Light`; - const {platform, accessory} = this.initAccessoryCallback( - { ...this.configDevice, displayName }, - model, - serialNumber, - ); - this.accessories.push(new BlaQGarageLightAccessory({ - platform, accessory, model, serialNumber, apiBaseURL: this.getAPIBaseURL(), - })); + private initGarageLightAccessory({ platform, accessory, model, serialNumber}: InitAccessoryParams){ + if(this.pluginConfig.enableLight) { + this.accessories.push(new BlaQGarageLightAccessory({ + platform, accessory, model, serialNumber, apiBaseURL: this.getAPIBaseURL(), + })); + } } - private initGarageLockAccessory({ model, serialNumber }: ModelAndSerialNumber){ - const baseDisplayName = this.configDevice.displayName || 'Garage Door'; - const displayName = `${baseDisplayName} Remote Lock`; - const {platform, accessory} = this.initAccessoryCallback( - { ...this.configDevice, displayName }, - model, - serialNumber, - ); - this.accessories.push(new BlaQGarageLockAccessory({ - platform, accessory, model, serialNumber, apiBaseURL: this.getAPIBaseURL(), - })); + private initGarageLockAccessory({ platform, accessory, model, serialNumber}: InitAccessoryParams){ + if(this.pluginConfig.enableLockRemotes){ + this.accessories.push(new BlaQGarageLockAccessory({ + platform, accessory, model, serialNumber, apiBaseURL: this.getAPIBaseURL(), + })); + } } - private initGarageMotionSensorAccessory({ model, serialNumber }: ModelAndSerialNumber){ - const baseDisplayName = this.configDevice.displayName || 'Garage Door'; - const displayName = `${baseDisplayName} Motion Sensor`; - const {platform, accessory} = this.initAccessoryCallback( - { ...this.configDevice, displayName }, - model, - serialNumber, - ); - this.accessories.push(new BlaQGarageMotionSensorAccessory({ - platform, accessory, model, serialNumber, apiBaseURL: this.getAPIBaseURL(), - })); + private initGarageMotionSensorAccessory({ platform, accessory, model, serialNumber}: InitAccessoryParams){ + if(this.pluginConfig.enableMotionSensor){ + this.accessories.push(new BlaQGarageMotionSensorAccessory({ + platform, accessory, model, serialNumber, apiBaseURL: this.getAPIBaseURL(), + })); + } } - private initGaragePreCloseWarningAccessory({ model, serialNumber }: ModelAndSerialNumber){ - const baseDisplayName = this.configDevice.displayName || 'Garage Door'; - const displayName = `${baseDisplayName} Pre Close Warning`; - const {platform, accessory} = this.initAccessoryCallback( - { ...this.configDevice, displayName }, - model, - serialNumber, - ); - this.accessories.push(new BlaQGaragePreCloseWarningAccessory({ - platform, accessory, model, serialNumber, apiBaseURL: this.getAPIBaseURL(), - })); + private initGaragePreCloseWarningAccessory({ platform, accessory, model, serialNumber}: InitAccessoryParams){ + if(this.pluginConfig.enablePreCloseWarning){ + this.accessories.push(new BlaQGaragePreCloseWarningAccessory({ + platform, accessory, model, serialNumber, apiBaseURL: this.getAPIBaseURL(), + })); + } } - private initGarageLearnModeAccessory({ model, serialNumber }: ModelAndSerialNumber){ - const baseDisplayName = this.configDevice.displayName || 'Garage Door'; - const displayName = `${baseDisplayName} Learn/Pair Mode`; - const {platform, accessory} = this.initAccessoryCallback( - { ...this.configDevice, displayName }, - model, - serialNumber, - ); - this.accessories.push(new BlaQGarageLearnModeAccessory({ - platform, accessory, model, serialNumber, apiBaseURL: this.getAPIBaseURL(), - })); + private initGarageLearnModeAccessory({ platform, accessory, model, serialNumber}: InitAccessoryParams){ + if(this.pluginConfig.enableLearnMode){ + this.accessories.push(new BlaQGarageLearnModeAccessory({ + platform, accessory, model, serialNumber, apiBaseURL: this.getAPIBaseURL(), + })); + } } - private initGarageObstructionSensorAccessory({ model, serialNumber }: ModelAndSerialNumber){ - const baseDisplayName = this.configDevice.displayName || 'Garage Door'; - const displayName = `${baseDisplayName} Obstruction Sensor`; + private initGarageObstructionSensorAccessory({ platform, accessory, model, serialNumber}: InitAccessoryParams){ + if(this.pluginConfig.enableSeparateObstructionSensor){ + this.accessories.push(new BlaQGarageObstructionSensorAccessory({ + platform, accessory, model, serialNumber, apiBaseURL: this.getAPIBaseURL(), + })); + } + } + + private initAccessories({ model, serialNumber }: ModelAndSerialNumber){ const {platform, accessory} = this.initAccessoryCallback( - { ...this.configDevice, displayName }, + this.configDevice, model, serialNumber, ); - this.accessories.push(new BlaQGarageObstructionSensorAccessory({ - platform, accessory, model, serialNumber, apiBaseURL: this.getAPIBaseURL(), - })); - } - - private initAccessories({ model, serialNumber }: ModelAndSerialNumber){ - this.initGarageDoorAccessory({ model, serialNumber }); - if(this.pluginConfig.enableLight) { - this.initGarageLightAccessory({ model, serialNumber }); - } - if(this.pluginConfig.enableLockRemotes){ - this.initGarageLockAccessory({ model, serialNumber }); - } - if(this.pluginConfig.enableMotionSensor){ - this.initGarageMotionSensorAccessory({ model, serialNumber }); - } - if(this.pluginConfig.enablePreCloseWarning){ - this.initGaragePreCloseWarningAccessory({ model, serialNumber }); - } - if(this.pluginConfig.enableLearnMode){ - this.initGarageLearnModeAccessory({ model, serialNumber }); - } - if(this.pluginConfig.enableSeparateObstructionSensor){ - this.initGarageObstructionSensorAccessory({ model, serialNumber }); - } + this.initGarageDoorAccessory({ platform, accessory, model, serialNumber }); + this.initGarageLightAccessory({ platform, accessory, model, serialNumber }); + this.initGarageLockAccessory({ platform, accessory, model, serialNumber }); + this.initGarageMotionSensorAccessory({ platform, accessory, model, serialNumber }); + this.initGaragePreCloseWarningAccessory({ platform, accessory, model, serialNumber }); + this.initGarageLearnModeAccessory({ platform, accessory, model, serialNumber }); + this.initGarageObstructionSensorAccessory({ platform, accessory, model, serialNumber }); } private handlePingUpdate(msg: PingMessageEvent){