homekit_python icon indicating copy to clipboard operation
homekit_python copied to clipboard

Asyncio support?

Open Jc2k opened this issue 6 years ago • 6 comments
trafficstars

It's been on my long term wishlist for a while to have an asyncio client. I thought it was nice but wouldn't enable new features or have much impact in terms of reliability. But working on #61/#62 has been a bit of a pain because of threading, and it would be nice not to have to deal with threads in HASS.

Do you have any interest in having an asyncio client within homekit_python or would it be better served as a seperate project?

Jc2k avatar Jul 26 '19 08:07 Jc2k

Hey, I never did something with asyncio, so no clue about this topic. But I will not say no without looking at it. Joachim

jlusiardi avatar Jul 26 '19 09:07 jlusiardi

Cool. I will try and make a mockup of what the HTTP client would look like with asyncio, and keep the sync code as is. First pass will be just to get something that works, but definitely lots of opportunity to share code between the two.

If that works, then i'd ditch my prototype from #62 and instead say if you want to multiplex events and request/reply on the same TCP stream like Apple you have to use asyncio.

BLE should be possible too with aioble, but will need to extend that to support descriptors from a cursory glance.

Jc2k avatar Jul 26 '19 10:07 Jc2k

The http aio prototype is nearly ready, got a test that passed but leaves a thread hanging to sort out and events to test out then will port my hass branch to use it and see how it feels.

Jc2k avatar Jul 30 '19 16:07 Jc2k

I will try to have a look at it soon, latest on the weekend in the train!

jlusiardi avatar Jul 31 '19 05:07 jlusiardi

Hanging test fixed, test for auto-reconnect added, going to try and get events working today/tomorrow.

Jc2k avatar Jul 31 '19 07:07 Jc2k

Got it working in HASS with events, though havent tried pairing yet with a real device yet.

Wanted to be able to test events in CI so have added events support to accessory server - see this commit.

I can pull this out as a seperate PR for #51 if you like, or we can keep it together.

Jc2k avatar Aug 01 '19 09:08 Jc2k