diff --git a/src/services/discovery.service.ts b/src/services/discovery.service.ts index 8b142a2..6c2c0fe 100644 --- a/src/services/discovery.service.ts +++ b/src/services/discovery.service.ts @@ -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'; @@ -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{ diff --git a/src/settings.ts b/src/settings.ts index 0071b16..4d8a1be 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -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'; \ No newline at end of file +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; \ No newline at end of file