batch notifications when possible#66
Conversation
often, HomeKit will will change multiple characteristics at once
(on and set brightness of a dimmable bulb, for example) or change
multiple items at once ("hey siri, close all the shades in the house").
instead of sending a separate event message for every characteristic
of every item that changed, batch them all up, and send as a single
message
|
I like the idea here. I'm going to leave this pending until I have some time to dig into the implementation - should get to it in the next few days. |
|
👍 it's definitely a bit more complex than the other PRs. One thing that could probably use another pass is the thread safety. Like I said, I'm still a Java greenie, so I wasn't sure here. I used a |
|
as first: batch is very useful and actually required by HAP spec. but im wondering whether we should reply with "EVENT" to a subscription immediately (as batch or not). currently we have following sequence of messages (recorded from home app on mac os): Receive GET /characteristics?id=1958124085.9 Receive PUT /characteristics {"characteristics":[{"aid":1958124085,"iid":9,"ev":true}]} so, according to HAP specification, we should first send "no Content" and |
|
This is an interesting point. Technically there's actually a race condition with how the controller gets the current value, then registers for notifications (the value could change between the initial GET, and the notification registration). While the probability is small, it goes up as the number of devices exposed on your bridge goes up, both from more devices, and for it taking longer to process these requests and responses. I read the spec when it says "When the value changes, the accessory sends .. EVENT" as emphasizing not to send EVENTs on a timer or something, but only on actual changes. Not necessarily that you shouldn't send an initial EVENT with the current state of the item. I do agree that the first EVENT for a subscription shouldn't be sent until after we respond 204 to the request to register it. |
I've been running this for several days on my home installation, and it's definitely improved responsiveness when asking Siri to do something that involves multiple accessories.