homebridge: Plugin accessories not updating after refresh, need development guidance.
Current Situation
Hello, I am re-writing a security system plugin and what I noticed is that all the accessories don’t update until I close the Home app, or switch pages and have the app refresh itself. I tried a few methods, both with no luck.
Methods I’ve used:
onGet()
on('get')
updateValue()
updateCharacteristic()
A small snippet on how I fetch contact sensors:
this.#services.Primary.getCharacteristic(this.#characteristic.ContactSensorState)
.onGet(async () => this.getSensorStatus('status', context));
A small snippet on how I set the security panel:
this.#services.Primary.getCharacteristic(this.#characteristic.SecuritySystemTargetState)
.onSet(async (value) => this.setPanelStatus(value, context));
If anyone has come across this issue, please do let me know, thanks! Or if you require more code, please do let me know!
Logs
N/A
Configuration
N/A
Environment
- OS: Sonoma 14.2.1
- Homebridge: 1.7.0
- Node: 18.19.0
- npm: 10.2.3
Process Supervisor
not applicable
Additional Context
No response
About this issue
- Original URL
- State: closed
- Created 6 months ago
- Comments: 25 (9 by maintainers)
That is awesome, Tks for adding this to the available plugins
It should be simple, does you plugin pull status updates or does the device push status updates ?
If it pulls, then as part of the pull polling loop you need to updateValue for each change. If it pushes, then as part of the push event listener, once you determine which accessory it is, then updateValue.
onSet is fine
An example - https://github.com/NorthernMan54/homebridge-tasmota/blob/473f4e593ff3d8d92710e9aa4b318f9dd7946f29/src/tasmotaSensorService.ts#L264
@mrjackyliang I use this feature with most of my plugins, and to enable it, do not implement the onGet() and on(‘get’) interface and only use updateValue() or updateCharacteristic()