Skip to content

Commit

Permalink
Merge pull request #10 from sajmonr/9-update-cached-accessories-betwe…
Browse files Browse the repository at this point in the history
…en-plug

9 Update cached accessories between plugin updates
  • Loading branch information
sajmonr authored Mar 4, 2023
2 parents d530d05 + f2b8382 commit 1b7942e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/services/discovery.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { PlatformAccessory } from 'homebridge';
import { HubspacePlatform } from '../platform';
import { DeviceResponse } from '../responses/devices-response';
import { PLATFORM_NAME, PLUGIN_NAME } from '../settings';
import { PACKAGE_VERSION, PLATFORM_NAME, PLUGIN_NAME } from '../settings';
import { Endpoints } from '../api/endpoints';
import { createHttpClientWithBearerInterceptor } from '../api/http-client-factory';
import { getDeviceTypeForKey } from '../models/device-type';
Expand Down Expand Up @@ -75,6 +75,15 @@ export class DiscoveryService{

private registerCachedAccessory(accessory: PlatformAccessory, device: Device): void{
createAccessoryForDevice(device, this._platform, accessory);

// If the accessory has been discovered previously and package number has changed
// then update the metadata as things might have changed.
if(!accessory.context.discoveredIn || accessory.context.discoveredIn !== PACKAGE_VERSION){
accessory.context.discoveredIn = PACKAGE_VERSION;
accessory.context.device = device;

this._platform.api.updatePlatformAccessories([ accessory ]);
}
}

private registerNewAccessory(device: Device): void{
Expand Down
8 changes: 7 additions & 1 deletion src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,10 @@ export const PLATFORM_NAME = 'Hubspace';
/**
* This must match the name of your plugin as defined the package.json
*/
export const PLUGIN_NAME = 'homebridge-hubspace';
export const PLUGIN_NAME = 'homebridge-hubspace';

/**
* Current NPM package version
*/
// eslint-disable-next-line @typescript-eslint/no-var-requires
export const PACKAGE_VERSION: string = require('../package.json').version;

0 comments on commit 1b7942e

Please sign in to comment.