Bouke / HAP

Swift implementation of the Homekit Accessory Protocol
https://boukehaarsma.nl/HAP/
MIT License
364 stars 50 forks source link

Ensure access to characteristics happen on the main queue. #79

Closed gbrooker closed 5 years ago

gbrooker commented 5 years ago

Two small changes.

First change corrects the precondition on set characteristic value.

Secondly, the characteristic endpoint is currently running on a NIO queue, causing thread safety issues.

This PR performs the endpoint on the main queue, to ensure a single queue access the HAP characteristics. A future improvement could be to restructure the entire endpoint architecture to use promises, which would avoid a synchronous call across queues.

gbrooker commented 5 years ago

Added workaround mentioned in #77 to ensure a minimum buffer size larger than 1155 for messages from HK.

Also added the debug message in root() to log the message sent to HomeKit to help fix issues in communications or configuration. The original version has a spelling mistake ("messagea") which was useful for locating it in the logs, so I preserved the spelling mistake !

gbrooker commented 5 years ago

The Tests were running on the main queue, which doesn't happen under normal operations. I've modified the characteristic tests to run from a separate queue, simulating a NIO thread.