Skip to main content

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) -> TokenResponse
  • refresh_access_token(refresh_token) -> TokenResponse
  • fetch_token_details(username, password) -> TokenEndpointResult
  • fetch_refresh_token_details(refresh_token) -> TokenEndpointResult
  • get_locations_or_raise(token) -> list[dict]
  • get_home_data_or_raise(token, location_id) -> dict
  • HomelyWebSocket(...).connect_or_raise()

Legacy compatibility helpers remain available:

  • fetch_token_with_reason(username, password) -> tuple[dict | None, str | None]
  • fetch_token(username, password) -> dict | None
  • fetch_refresh_token(refresh_token) -> dict | None

Main exports:

  • HomelyClient
  • HomelyWebSocket
  • TokenEndpointResult
  • TokenResponse
  • HomelyConnectionError
  • HomelyAuthError
  • HomelyResponseError
  • HomelyWebSocketError

Exceptions

  • HomelyConnectionError: network or service unavailable
  • HomelyAuthError: invalid credentials or rejected token
  • HomelyResponseError: unexpected response or HTTP failure Carries status and body_preview when 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

python_homely-0.1.2.tar.gz (14.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_homely-0.1.2-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

Details for the file python_homely-0.1.2.tar.gz.

File metadata

  • Download URL: python_homely-0.1.2.tar.gz
  • Upload date:
  • Size: 14.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for python_homely-0.1.2.tar.gz
Algorithm Hash digest
SHA256 ca5c9918e817a07703c4aa9e47c56d63fe0c44adadeef80f4b16c87fe355f7de
MD5 db1bcaa4223fffc6a9a87da59813ef14
BLAKE2b-256 67dfb7b8e4015e76906443ac2f5b2205de6eb16bb54cfc6619b7d391b96c48d0

See more details on using hashes here.

Provenance

The following attestation bundles were made for python_homely-0.1.2.tar.gz:

Publisher: publish.yml on ludvikroed/python-homely

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file python_homely-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: python_homely-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 12.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for python_homely-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4b751a855e5af600f304aa1e70f2d4d7a2f3a2a3b80e6da46ec8252f929ca7cd
MD5 35b462ea0224e22036ee4290eea00bfc
BLAKE2b-256 a315c8bd87dd931fd7c22b20aa0c9c9a3fe1beec3cfa297d02cf1e20f10a3409

See more details on using hashes here.

Provenance

The following attestation bundles were made for python_homely-0.1.2-py3-none-any.whl:

Publisher: publish.yml on ludvikroed/python-homely

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page