Skip to content

Commit

Permalink
Remove unusable accessories from cache
Browse files Browse the repository at this point in the history
  • Loading branch information
raymondelooff committed Apr 23, 2017
1 parent 01f154d commit 5fe4810
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
3 changes: 0 additions & 3 deletions lib/HueAccessory/Factory.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict';

const PLATFORM_VERSION = require('../../package.json').version;

const HueError = require('../HueError');

let Accessory;
Expand Down Expand Up @@ -29,7 +27,6 @@ class Factory {
const uuid = UUIDGen.generate(hueAccessory.uniqueId);
const accessory = new Accessory(hueAccessory.name, uuid);
accessory.context.uniqueId = hueAccessory.uniqueId;
accessory.context.platformVersion = PLATFORM_VERSION;
accessory.context.cached = false;

return accessory;
Expand Down
12 changes: 11 additions & 1 deletion lib/HuePlatform.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,27 @@ class HuePlatform {
}

_removeUnusableCachedAccessories() {
const usableCachedAccessories = [];

for (const accessory of this.cachedAccessories) {
if (accessory.context.uniqueId === undefined || accessory.context.platformVersion === undefined || accessory.context.platformVersion !== PLATFORM_VERSION) {
if (accessory.context.uniqueId === undefined) {
this.log.debug(`Unregistering accessory '${accessory.displayName}'...`);
this.api.unregisterPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);

continue;
}

if (this.config.ignoreAccessories.indexOf(accessory.context.uniqueId) !== -1) {
this.log.info(`Ignoring accessory with ID ${accessory.context.uniqueId}...`);
this.api.unregisterPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);

continue;
}

usableCachedAccessories.push(accessory);
}

this.cachedAccessories = usableCachedAccessories;
}

_loadAccessories() {
Expand Down

0 comments on commit 5fe4810

Please sign in to comment.