aioleafi
Asyncio Python client for the Leafi Nova local TCP API (TLS 1.2 PSK, newline-delimited
JSON-RPC). Used by the leafi Home Assistant integration. Licensed Apache-2.0.
The library implements version 1 of the Nova local API: the TLS-PSK handshake, the per-Nova key format and the encrypted key upload. The source in this repository is the reference for the wire format.
import asyncio
from aioleafi import LeafiClient, parse_key
async def main() -> None:
client = LeafiClient("192.0.2.42", parse_key("1YFA-8W83-AV53-VA3S-4W0Y-SX51-BFR"))
client.add_state_listener(print)
hello = await client.connect() # TLS-PSK handshake, hello, get_state snapshot
print(hello)
await client.open_cover()
await asyncio.sleep(60) # events arrive as they happen; nothing is polled
await client.close()
asyncio.run(main())
client.start() instead of connect() keeps the connection up and reconnects with backoff
(5 s doubling to 20 min; reconnect_now() skips the wait). It stops on a wrong key, wrong
Nova or unsupported API version and reports it through add_error_listener.
Behaviour worth knowing
- No polling. A sleeping Nova answers at its next DTIM beacon (about 0.7 s). State comes from
coverandsensorsevents;get_state()sends a request at most once per 10 s and otherwise returns the current values without sending anything. - A
pinggoes out every 30 minutes; two missed replies mark the connection lost. busyis retried once after 1 s; other error replies raiseNovaErrorsubclasses (NotCalibratedError,UnknownMethodError, ...).- Handshake failure after a successful TCP connect raises
InvalidKeyError; no TCP connection raisesCannotConnectError; a different DSN inhelloraisesWrongNovaError.
TLS-PSK approach
Python 3.13 added ssl.SSLContext.set_psk_client_callback / set_psk_server_callback, so no
third-party TLS library is needed. The client context pins TLS 1.2, cipher
PSK-AES128-GCM-SHA256 and identity ha; it needs an OpenSSL with PSK suites (the python.org
Windows build, OpenSSL 3.0.x, and HA's Python 3.13+ images have them). The handshake runs with
StreamWriter.start_tls after a plain TCP connect, which lets the client tell "no TCP" from
"handshake rejected". Verified against both the fake Nova here and OpenSSL's server side.
Keys and uploads
parse_key, format_key, key_id implement the 27-character Crockford base32 form (mod-37 check
character). parse_key_list validates a leafi-ha-keys list with the spec's per-entry rejection
reasons, and decrypt_key_upload / encrypt_key_upload implement the AES-128-GCM envelope of
the app's POST (Method 3).
Testing
aioleafi.testing.FakeNova is a TLS-PSK fake Nova built from the interface spec.
pip install -e ".[dev]"
pytest
ruff check . && ruff format --check . && mypy src
Metadata
Release files for aioleafi 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| aioleafi-0.0.1.tar.gz | 24.2 kB | Without provenance | Details for aioleafi-0.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| aioleafi-0.0.1-py3-none-any.whl | Python 3 | none | any | Details for aioleafi-0.0.1-py3-none-any.whl |
Total release size: 44.4 kB
Release files / aioleafi-0.0.1.tar.gz
| Download URL | aioleafi-0.0.1.tar.gz |
|---|---|
| Size | 24.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
65c4fe181cc212bbd64d3c149bbc739f154107272919fe7bec032ef0e227e36c
|
|
BLAKE2b-256 checksum How to use checksums |
fb0d582015301593c689d765ee7546982abcc76ed0210779f4dd1390c057b37c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.15
|
Release files / aioleafi-0.0.1-py3-none-any.whl
| Download URL | aioleafi-0.0.1-py3-none-any.whl |
|---|---|
| Size | 20.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bcff73dd35308b7998b9fd971be9740632eeeaec728c455819516cbb354b939f
|
|
BLAKE2b-256 checksum How to use checksums |
edd88ee8e8d90aba1c92479e7f96c7fda1acc6db2201f542d5e4b100ee761526
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.15
|
Security for aioleafi 0.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.