Skip to content

Commit

Permalink
Fixed: if a service is removed it is now ensured that no existing ser…
Browse files Browse the repository at this point in the history
…vices still link to that removed service
  • Loading branch information
Supereg committed Sep 23, 2020
1 parent 72baab0 commit b9b95d5
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/lib/Accessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -420,17 +420,28 @@ export class Accessory extends EventEmitter<Events> {
if (this.primaryService === service) { // check if we are removing out primary service
this.primaryService = undefined;
}
this.removeLinkedService(service); // remove it from linked service entries on the local accessory

if (!this.bridged) {
this._updateConfiguration();
} else {
this.emit(AccessoryEventTypes.SERVICE_CONFIGURATION_CHANGE, clone({accessory:this, service:service}));

for (const accessory of this.bridgedAccessories) {
accessory.removeLinkedService(service);
}
}

service.removeAllListeners();
}
}

private removeLinkedService(service: Service) {
for (const service of this.services) {
service.removeLinkedService(service);
}
}

getService = <T extends WithUUID<typeof Service>>(name: string | T) => {
for (let index in this.services) {
const service = this.services[index];
Expand Down

0 comments on commit b9b95d5

Please sign in to comment.