Skip to content
This repository has been archived by the owner on Nov 24, 2023. It is now read-only.

Commit

Permalink
#64 Remove accessory from bridge when device is removed from pimatic
Browse files Browse the repository at this point in the history
  • Loading branch information
michbeck100 committed Sep 14, 2017
1 parent efca3a2 commit 911375c
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions hap.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ module.exports = (env) =>
'tradfridimmer-temp': DimmerAccessory
}

accessories: {}

init: (app, @framework, @config) =>
env.logger.info("Starting homekit bridge")

Expand All @@ -76,8 +78,15 @@ module.exports = (env) =>
for accessory in newAccessories
if accessory? && !accessory.exclude()
bridge.addBridgedAccessory(accessory)
if !@accessories.hasOwnProperty(device.id)
@accessories[device.id] = []
@accessories[device.id].push accessory
env.logger.debug("successfully added device " + accessory.displayName)

@framework.on 'deviceRemoved', (device) =>
if device.id in @accessories
bridge.removeBridgedAccessory(entry.id, false) for entry in accessories[device.id]

@framework.once "after init", =>
# publish homekit bridge
env.logger.debug("publishing homekit bridge on port " + @config.port)
Expand Down

0 comments on commit 911375c

Please sign in to comment.