Skip to content

Commit

Permalink
Update device with new metadata on package upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
sajmonr committed Mar 4, 2023
1 parent 8511534 commit f2b8382
Showing 1 changed file with 10 additions and 1 deletion.
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

0 comments on commit f2b8382

Please sign in to comment.