An asyncio HomeKit client
Project description
aiohomekit by Parker Industries
This library is still in development. No guarantees are made. Features may be incomplete or buggy, and might change over time.
This library implements the HomeKit protocol for controlling Homekit accessories using asyncio.
This library is a fork of Jc2k/aiohomekit with major refactoring. It is not backwards compatible with the original library and can't be used as a drop-in replacement.
It's primary use is for MajorDom, so python version and code standards are the same as at MajorDom.
Changes
Notes to adapt the new API:
- storage mechanisms (for pairing data and characteristics cache) have been completed to automatically load and save all data, and delegated from controllers to separate injected Storage classes, which provide interface for CRUD operations and manage data persistence
- Pairings and Discoveries no longer have a reference to the controller
- finish_pairing returns PairingData, which can be used to instantiate a Pairing
- async methods marked with
asynckeyword no longer haveasync_prefix - some methods have been renamed for clarity
- arguments for some methods have been changed to correspond to the abstract classes
- redundant methods and arguments have been removed
- files have been restructured to improve organization and maintainability, which may require changes in imports
- to try the library or view the examples, check the renewed
__main__.py - for other details, check the declaration of the classes and methods, it's pretty self-explanatory now
Other changes include:
- added more type hints, comments, and more clear names
- fixed bugs related to data persistence and storage management
- fixed saving of updated pairing data when DHCP changes the IP address of the accessory
Roadmap
- IP discovery, pairing, and control
- Test IP stack
- Update code QA tools
- BLE discovery
- BLE pairing and provisioning of WiFi and Thread credentials
- Device control over BLE and COAP (Thread))
- Tests for the features above
- Fix all errors and warnings from linters and type checkers (most of them due to ignoring optional types)
- Fix all docstrings since they became deprecated before this fork was even created
- Update readme, add docs
Code Quality Analysis (TODO)
This projects uses tool stack by astra.sh:
uvproject manager instead ofpoetryrufflinter+formatter instead ofblack,isort, andflake8tystatic type checker instead ofmypy
Contributing (legacy)
Lots of users are using this library with devices from a wide array of vendors. As a community open source project we do not have the hardware or time resources to certify every device with multiple vendors projects. We may be conservative about larger changes or changes that are low level. We do ask where possible that any changes should be tested with a certified HomeKit implementations of shipping products, not just against emulators or other uncertified implementations.
Please bear in mind that some shipping devices interpret the HAP specification loosely. In general we prefer to match the behaviour of real HAP controllers even where their behaviour is not strictly specified. Here are just some of the kinds of problems we've had to work around:
- Despite the precise formatting of JSON being unspecified, there are devices in the wild that cannot handle spaces when parsing JSON. For example,
{"foo": "bar"}vs{"foo":"bar"}. This means we never use a "pretty" encoding of JSON. - Despite a boolean being explicitly defined as
0,1,trueorfalsein the spec, some devices only support 3 of the 4. This means booleans must be encoded as0or1. - Some devices have shown themselves to be sensitive to headers being missing, in the wrong order or if there are extra headers. So we ensure that only the headers iOS sends are present, and that the casing and ordering is the same.
- Some devices are sensitive to a HTTP message being split into separate TCP packets. So we take care to only write a full message to the network stack.
And so on. As a rule we need to be strict about what we send and loose about what we receive.
Device compatibility (legacy)
aiohomekit is primarily tested with a Phillips Hue bridge and an Eve Extend bridge. It is known to work to some extent with many more devices though these are not currently explicitly documented anywhere at the moment.
You can look at the problems your device has faced in the home-assistant issues list.
FAQ (legacy, TODO)
How do I use this?
Check the main.py file for examples.
Does this support BLE accessories?
No. Eventually we hope to via aioble which provides an asyncio bluetooth abstraction that works on Linux, macOS and Windows.
Can i use this to make a homekit accessory?
No, this is just the client part. You should use one the of other implementations:
- homekit_python (this is used a lot during aiohomekit development)
- HAP-python
Why doesn't aiohomekit use library X instead?
Where possible aiohomekit uses libraries that are easy to install with pip, are ready available as wheels (including on Raspberry Pi via piwheels), are cross platform (including Windows) and are already used by Home Assistant. They should not introduce hard dependencies on uncommon system libraries. The intention here is to avoid any difficulty in the Home Assistant build process.
People are often alarmed at the hand rolled HTTP code and suggest using an existing HTTP library like aiohttp. High level HTTP libraries are pretty much a non-starter because:
- Of the difficulty of adding in HAP session security without monkey patches.
- They don't expect responses without requests (i.e. events).
- As mentioned above, some of these devices are very sensitive. We don't care if your change is compliant with every spec if it still makes a real world device cry. We are not in a position to demand these devices be fixed. So instead we strive for byte-for-byte accuracy on our write path. Any library would need to give us that flexibility.
- Some parts of the responses are actually not HTTP, even though they look it.
We are also just reluctant to make a change that large for something that is working with a lot of devices. There is a big chance of introducing a regression.
Of course a working proof of concept (using a popular well maintained library) that has been tested with something like a Tado internet bridge (including events) would be interesting.
Thanks
This library wouldn't have been possible without homekit_python, a synchronous implementation of both the client and server parts of HAP.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file parker_aiohomekit-4.0.1.tar.gz.
File metadata
- Download URL: parker_aiohomekit-4.0.1.tar.gz
- Upload date:
- Size: 136.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0cf7007f5aaf35eddd84f54987320b2381fc903858fd6757a17181daf9d491e8
|
|
| MD5 |
5bad01fe290529a25d88d255fbd7b124
|
|
| BLAKE2b-256 |
a0d83744fba9370dd9e22bba256e71e620f7b570601493f46f455c3ecea70579
|
Provenance
The following attestation bundles were made for parker_aiohomekit-4.0.1.tar.gz:
Publisher:
release.yml on ParkerIndustries/parker-aiohomekit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
parker_aiohomekit-4.0.1.tar.gz -
Subject digest:
0cf7007f5aaf35eddd84f54987320b2381fc903858fd6757a17181daf9d491e8 - Sigstore transparency entry: 1097378107
- Sigstore integration time:
-
Permalink:
ParkerIndustries/parker-aiohomekit@e7b34e1e39113f07a04d488c025f426b72cc8458 -
Branch / Tag:
refs/heads/develop - Owner: https://github.com/ParkerIndustries
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@e7b34e1e39113f07a04d488c025f426b72cc8458 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file parker_aiohomekit-4.0.1-py3-none-any.whl.
File metadata
- Download URL: parker_aiohomekit-4.0.1-py3-none-any.whl
- Upload date:
- Size: 180.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0781d0fd3b1d5a494e485fc27c9475096783b7ec3d5b2cc3f03034b8318f56e1
|
|
| MD5 |
cdf37acda23c7338917ee1db0593d1e8
|
|
| BLAKE2b-256 |
880263bc325fadc5e8393281d07d51ae9c137e93462fa5835acbe712a4ffd057
|
Provenance
The following attestation bundles were made for parker_aiohomekit-4.0.1-py3-none-any.whl:
Publisher:
release.yml on ParkerIndustries/parker-aiohomekit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
parker_aiohomekit-4.0.1-py3-none-any.whl -
Subject digest:
0781d0fd3b1d5a494e485fc27c9475096783b7ec3d5b2cc3f03034b8318f56e1 - Sigstore transparency entry: 1097378131
- Sigstore integration time:
-
Permalink:
ParkerIndustries/parker-aiohomekit@e7b34e1e39113f07a04d488c025f426b72cc8458 -
Branch / Tag:
refs/heads/develop - Owner: https://github.com/ParkerIndustries
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@e7b34e1e39113f07a04d488c025f426b72cc8458 -
Trigger Event:
workflow_dispatch
-
Statement type: