How to coalesce multiple requests to a device?
See original GitHub issueHi there!
I am writing a platform to control a single phisical device with 48 individuals light bulbs (declared as distinct accessories inside the platform). I started from homebridge-samplePlatform.
Everything work as expected when I turn the lights individually by the Home app. But when I activate a scene with more than 10 lights, it hangs the Home app with “no response” statuses. The plugin sends several individual requests (one for each light) at the same time, flooding the device.
Here’s part of the log:
EventedHTTPServer [::ffff:192.168.11.19] HTTP request: /characteristics +5s
HAPServer [CC:22:3D:E3:CE:31] HAP Request: PUT /characteristics +0ms
Accessory [Homebridge Mac] Processing characteristic set: [{"aid":10,"iid":9,"value":false},{"aid":11,"iid":9,"value":false},{"aid":3,"iid":9,"value":1},{"aid":2,"iid":9,"value":1},{"aid":12,"iid":9,"value":1},{"aid":14,"iid":9,"value":1},{"aid":13,"iid":9,"value":1},{"aid":9,"iid":9,"value":1},{"aid":8,"iid":9,"value":false},{"aid":7,"iid":9,"value":1},{"aid":4,"iid":9,"value":1},{"aid":5,"iid":9,"value":false},{"aid":6,"iid":9,"value":1},{"aid":15,"iid":9,"value":1}] +2ms
It shows that homebridge receive just one request from HAPServer but split in several individual requests to the device (not in the log).
I guess it should coalesce all these separated requests into a single request to the device but I have no idea how to do that, I mean, which events to implement. Can anybody help me? Examples will be welcome.
Thanks in advance!
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (2 by maintainers)
Top GitHub Comments
1, 2: I really don’t know - I’ve only ever used homebridge, never native HAP-NodeJS. I do think the Service and Characteristic stuff is HAP-NodeJS, though.
3: My solution consists of the following:
SetOn()
that are called by HAP-NodeJS when the corresponding characteristic is changed from HomeKit, https://github.com/ebaauw/homebridge-hue/blob/73ff16c2e2871cd5fceaa30af1ba3a5af6869aa9/lib/HueLight.js#L225;request()
to store the new value, https://github.com/ebaauw/homebridge-hue/blob/73ff16c2e2871cd5fceaa30af1ba3a5af6869aa9/lib/HueLight.js#L883;request()
stores/adds the new value todesiredState
. When this is the first invocation ofrequest()
(since the lastput()
), it sets a timeout to callput()
, https://github.com/ebaauw/homebridge-hue/blob/73ff16c2e2871cd5fceaa30af1ba3a5af6869aa9/lib/HueLight.js#L979;put()
callsbridge.request()
withdesiredState
, possibly containing multiple new values, https://github.com/ebaauw/homebridge-hue/blob/73ff16c2e2871cd5fceaa30af1ba3a5af6869aa9/lib/HueLight.js#L999;bridge.request()
usesdeferred
to throttle calls tobridge._request()
, https://github.com/ebaauw/homebridge-hue/blob/73ff16c2e2871cd5fceaa30af1ba3a5af6869aa9/lib/HueBridge.js#L157;bridge._request()
usesrequest
to send the REST API call to the Hue bridge, https://github.com/ebaauw/homebridge-hue/blob/73ff16c2e2871cd5fceaa30af1ba3a5af6869aa9/lib/HueBridge.js#L865.This issue has been automatically marked as stale because it has not had recent activity, and will be closed if no further activity occurs. If this issue was overlooked, forgotten, or should remain open for any other reason, please reply here to call attention to it and remove the stale status. Thank you for your contributions.