Skip to content

Commit

Permalink
Housekeeping - deviceUUID checks
Browse files Browse the repository at this point in the history
* [Housekeeping] Check if device exists based on `deviceUUID` rather than `serial` for consistency with cache restore checks. `deviceUUID` used as basis for Homebridge `UUID`.
* [Logging] Add accType to logging messages added in v5.9.7 so that UUIDs can be more easily tracked.
  • Loading branch information
DMBlakeley committed Jun 9, 2022
1 parent 4548fe7 commit 2f33d04
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

All notable changes to this project will be documented in this file. This project uses [Semantic Versioning](https://semver.org/).

## v5.9.8
* [Housekeeping] Check if device exists based on `deviceUUID` rather than `serial` for consistency with cache restore checks. `deviceUUID` used as basis for Homebridge `UUID`.
* [Logging] Add accType to logging messages added in v5.9.7 so that UUIDs can be more easily tracked.

## v5.9.7
* [Debugging] Add additional logging for homebridge accessory UUID during addition of new Awair device and recovery from cache for existing Awair devices.
* [Logging] Add additional logging for homebridge accessory UUID during addition of new Awair device and recovery from cache for existing Awair devices.

## v5.9.6
* [Housekeeping] Plug-in initialization code and logging improvements.
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"private": false,
"displayName": "Homebridge Awair2",
"name": "homebridge-awair2",
"version": "5.9.7",
"version": "5.9.8",
"description": "HomeKit integration of Awair air quality monitor as Dynamic Platform.",
"main": "dist/index.js",
"scripts": {
Expand Down
15 changes: 8 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ class AwairPlatform implements DynamicPlatformPlugin {
*/
configureAccessory(accessory: PlatformAccessory): void {
if(this.config.logging){
this.log(`Restoring cached accessory deviceUUID: ${accessory.context.deviceUUID}, UUID: ${accessory.UUID}`);
// eslint-disable-next-line max-len
this.log(`Restoring cached accessory deviceUUID: ${accessory.context.deviceUUID}, ${accessory.context.accType}, UUID: ${accessory.UUID}`);
}

switch(accessory.context.accType) {
Expand Down Expand Up @@ -557,16 +558,16 @@ class AwairPlatform implements DynamicPlatformPlugin {
this.log(`[${device.macAddress}] Initializing platform accessory ${device.name}...`);
}

// check if IAQ accessory exists
// check if IAQ accessory exists in cache
let accessory = this.accessories.find(cachedAccessory => {
return ((cachedAccessory.context.serial === device.macAddress) && (cachedAccessory.context.accType === 'IAQ'));
return ((cachedAccessory.context.deviceUUID === device.deviceUUID) && (cachedAccessory.context.accType === 'IAQ'));
});

// if IAQ accessory does _not_ exist, initialze as new
// if IAQ accessory does NOT exist in cache, initialze as new
if (!accessory) {
const uuid = hap.uuid.generate(device.deviceUUID);
if(this.config.logging){
this.log(`Adding deviceUUID: ${device.deviceUUID}, UUID: ${uuid}`);
this.log(`Adding deviceUUID: ${device.deviceUUID}, IAQ, UUID: ${uuid}`);
}
accessory = new Accessory(device.name, uuid);

Expand Down Expand Up @@ -1200,7 +1201,7 @@ class AwairPlatform implements DynamicPlatformPlugin {

// check if Awair device 'displayMode' accessory exists
let accessory = this.accessories.find(cachedAccessory => {
return ((cachedAccessory.context.serial === data.macAddress) && (cachedAccessory.context.accType === 'Display'));
return ((cachedAccessory.context.deviceUUID === data.deviceUUID) && (cachedAccessory.context.accType === 'Display'));
});

// if displayMode accessory does not exist in cache, initialze as new
Expand Down Expand Up @@ -1381,7 +1382,7 @@ class AwairPlatform implements DynamicPlatformPlugin {

// check if Awair device 'ledMode' accessory exists
let accessory = this.accessories.find(cachedAccessory => {
return ((cachedAccessory.context.serial === data.macAddress) && (cachedAccessory.context.accType === 'LED'));
return ((cachedAccessory.context.deviceUUID === data.deviceUUID) && (cachedAccessory.context.accType === 'LED'));
});

// if ledMode accessory does not exist in cache, initialze as new
Expand Down

0 comments on commit 2f33d04

Please sign in to comment.