homebridge / homebridge-plugin-template

A template you can use to create your own Homebridge plugins.
https://developers.homebridge.io/
Apache License 2.0
315 stars 133 forks source link

Remove existing accessory from cache #73

Open mkz212 opened 4 months ago

mkz212 commented 4 months ago

Great template. But there is no function that removes existing accessories from the cache when they are no longer in the setup. Currently, there are only two options: get from cache or add new ones.

mkz212 commented 3 months ago

Here is example: https://github.com/mkz212/homebridge-virtual-device/blob/master/src/platform.ts

uswong commented 2 months ago

Hey @mkz212,

Will this work for you? https://github.com/uswong/homebridge-plugin-template/blob/latest/src/platform.ts

The lines I have added to remove those existing accessories not restored from cache are as follow: https://github.com/uswong/homebridge-plugin-template/commit/8358c8cb7f454a759569959782121171d3d4ade6

mkz212 commented 2 months ago

Hey @mkz212,

Will this work for you? https://github.com/uswong/homebridge-plugin-template/blob/latest/src/platform.ts

The lines I have added to remove those existing accessories not restored from cache are as follow: uswong@8358c8c

For me it seems to be ok, but @bwp91 should take a look, he maintain this and knows it best.

bwp91 commented 5 days ago

i just updated the template with some example code of doing this