Async Python client for the Homely cloud API, built for Home Assistant but usable anywhere.
Project description
Python-homely
Async Python client for the Homely cloud API and realtime websocket updates.
This package was created for the Homely Home Assistant integration, but it is framework-independent and can be used in any Python project that needs to talk to Homely.
Features
- Login and token refresh
- Location and home-data fetches
- Realtime websocket updates
- Typed exceptions
- Async API built on
aiohttp
Installation
python3 -m pip install python-homely
Quick Start
import aiohttp
from homely import HomelyClient
async def main() -> None:
async with aiohttp.ClientSession() as session:
client = HomelyClient(session)
token = await client.authenticate("user@example.com", "password")
locations = await client.get_locations_or_raise(token.access_token)
location_id = locations[0]["locationId"]
data = await client.get_home_data_or_raise(token.access_token, location_id)
print(data["name"])
Websocket Example
import aiohttp
from homely import HomelyClient, HomelyWebSocket
async def on_update(event: dict) -> None:
print(event)
async def main() -> None:
async with aiohttp.ClientSession() as session:
client = HomelyClient(session)
token = await client.authenticate("user@example.com", "password")
locations = await client.get_locations_or_raise(token.access_token)
location_id = locations[0]["locationId"]
websocket = HomelyWebSocket(
location_id=location_id,
token=token.access_token,
on_data_update=on_update,
context_id="example",
)
await websocket.connect_or_raise()
Main API
authenticate(username, password) -> TokenResponserefresh_access_token(refresh_token) -> TokenResponsefetch_token_details(username, password) -> TokenEndpointResultfetch_refresh_token_details(refresh_token) -> TokenEndpointResultget_locations_or_raise(token) -> list[dict]get_home_data_or_raise(token, location_id) -> dictHomelyWebSocket(...).connect_or_raise()
Legacy compatibility helpers remain available:
fetch_token_with_reason(username, password) -> tuple[dict | None, str | None]fetch_token(username, password) -> dict | Nonefetch_refresh_token(refresh_token) -> dict | None
Main exports:
HomelyClientHomelyWebSocketTokenEndpointResultTokenResponseHomelyConnectionErrorHomelyAuthErrorHomelyResponseErrorHomelyWebSocketError
Exceptions
HomelyConnectionError: network or service unavailableHomelyAuthError: invalid credentials or rejected tokenHomelyResponseError: unexpected response or HTTP failure Carriesstatusandbody_previewwhen available.HomelyWebSocketError: websocket could not be established
Token Diagnostics
If you need more than success/failure, use the detailed token helpers:
result = await client.fetch_refresh_token_details(refresh_token)
if result.ok:
print(result.token.access_token)
else:
print(result.reason, result.status, result.detail, result.body_preview)
TokenEndpointResult.reason can distinguish between invalid credentials, invalid refresh
tokens, network errors, timeouts, malformed JSON, malformed payloads, empty responses, and
unexpected HTTP failures.
Websocket Note
Refreshing an access token does not require forcing an already-connected websocket to reconnect. The websocket token only matters when a new websocket connection is established or re-established.
License
MIT. See LICENSE.
⭐ If you find this package useful, please consider giving it a star on GitHub! ⭐
Project details
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 python_homely-0.1.9.tar.gz.
File metadata
- Download URL: python_homely-0.1.9.tar.gz
- Upload date:
- Size: 17.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
10871a00d6db09fbccd24a707406f4005c6ab903628082cfc6f06bf49d6863ad
|
|
| MD5 |
7e3f6a84b0290dcceba238725aeda0d1
|
|
| BLAKE2b-256 |
361862f56848dc3dd9a9d595fd9f432eabb6ccdc7d8e71d1040ed623fca1f397
|
Provenance
The following attestation bundles were made for python_homely-0.1.9.tar.gz:
Publisher:
publish.yml on ludvikroed/python-homely
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
python_homely-0.1.9.tar.gz -
Subject digest:
10871a00d6db09fbccd24a707406f4005c6ab903628082cfc6f06bf49d6863ad - Sigstore transparency entry: 1954228573
- Sigstore integration time:
-
Permalink:
ludvikroed/python-homely@94f5d2027ebe60eba4924232011977eba72fdb01 -
Branch / Tag:
refs/tags/v0.1.9 - Owner: https://github.com/ludvikroed
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@94f5d2027ebe60eba4924232011977eba72fdb01 -
Trigger Event:
release
-
Statement type:
File details
Details for the file python_homely-0.1.9-py3-none-any.whl.
File metadata
- Download URL: python_homely-0.1.9-py3-none-any.whl
- Upload date:
- Size: 13.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2fb27650792d694a436096e86cabafd6731c22b9d4074c285fcfe173942b07c1
|
|
| MD5 |
7c3fd8a97df60485c264f3d2c5414ff6
|
|
| BLAKE2b-256 |
5b4640c47a8150b1bad17a20626aa5be4b4559b16ff332fd4fac9dc238bdc482
|
Provenance
The following attestation bundles were made for python_homely-0.1.9-py3-none-any.whl:
Publisher:
publish.yml on ludvikroed/python-homely
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
python_homely-0.1.9-py3-none-any.whl -
Subject digest:
2fb27650792d694a436096e86cabafd6731c22b9d4074c285fcfe173942b07c1 - Sigstore transparency entry: 1954228758
- Sigstore integration time:
-
Permalink:
ludvikroed/python-homely@94f5d2027ebe60eba4924232011977eba72fdb01 -
Branch / Tag:
refs/tags/v0.1.9 - Owner: https://github.com/ludvikroed
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@94f5d2027ebe60eba4924232011977eba72fdb01 -
Trigger Event:
release
-
Statement type: