Skip to content

Commit

Permalink
feat(accessory): remove outdated services on create
Browse files Browse the repository at this point in the history
  • Loading branch information
duddu committed May 4, 2024
1 parent 5023e26 commit 59723aa
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/accessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ export class HSBAccessory {
}

private addShortcutsServices() {
const activeServicesSubtypes: Set<string | undefined> = new Set();

for (const serviceConfig of this.platform.config.services) {
const subtype = this.platform.api.hap.uuid.generate(JSON.stringify(serviceConfig));

Expand All @@ -57,6 +59,8 @@ export class HSBAccessory {
logServiceOrigin,
);

activeServicesSubtypes.add(service.subtype);

new HSBService(
this.platform.log,
service,
Expand All @@ -66,6 +70,17 @@ export class HSBAccessory {
this.Characteristic,
);
}

for (const service of this.accessory.services) {
if (typeof service.subtype === 'string' && !activeServicesSubtypes.has(service.subtype)) {
this.accessory.removeService(service);
this.platform.log.debug(
'Accessory::addShortcutsServices',
`Service(${service.displayName})`,
'Removed as outdated',
);
}
}
}

private getShortcutsServiceType(): HSBServiceType {
Expand Down

0 comments on commit 59723aa

Please sign in to comment.