Skip to main content

Async API client for Prana heat recovery ventilator.

Project description

Prana Local API Client

Prana Local API Client is a small asynchronous Python library to interact with a local HTTP API exposed by a Prana device. It uses aiohttp and provides a simple interface to read device state and send control commands.

Requirements

  • Python 3.9+
  • aiohttp

Install dependencies:

pip install aiohttp

Overview

Primary class: PranaLocalApiClient

Constructor:

  • PranaLocalApiClient(host: str, port: int = 80)

Behavior summary:

  • Uses an aiohttp ClientSession. You can provide/retain a session by using the client as an async context manager (async with) or let the client create and close a temporary session for each call.
  • Requests use a total timeout of 10 seconds.
  • Non-200 HTTP responses raise PranaApiUpdateFailed.
  • Network errors and timeouts raise PranaApiCommunicationError.

API (async)

  • async def get_state() -> dict[str, Any] | None

    • GET /getState
    • Returns parsed JSON when the server responds with application/json. Returns None for responses without JSON body.
  • async def set_speed(speed: int, fan_type: str) -> None

    • POST /setSpeed
    • JSON body: {"speed": speed, "fanType": fan_type}
  • async def set_switch(switch_type: str, value: bool) -> None

    • POST /setSwitch
    • JSON body: {"switchType": switch_type, "value": value}
  • async def set_brightness(brightness: int) -> None

    • POST /setBrightness
    • JSON body: {"brightness": brightness}

Notes:

  • All methods call a shared internal _async_request which handles creating/closing sessions when needed, error handling and JSON parsing.

Exceptions

The library exposes a small exception hierarchy in prana_local_api_client.exceptions:

  • PranaApiClientException — base exception class.
  • PranaApiCommunicationError — network-level issues (wrapping aiohttp ClientError / timeout).
  • PranaApiUpdateFailed(status: int) — HTTP request completed but device returned non-200 status.

Example of catching errors:

from prana_local_api_client.exceptions import PranaApiCommunicationError, PranaApiUpdateFailed

try:
    state = await client.get_state()
except PranaApiUpdateFailed as e:
    # HTTP-level error (server returned non-200)
    print("Device returned error status:", getattr(e, "status", None))
except PranaApiCommunicationError as e:
    # Network/timeout/etc.
    print("Communication error:", e)

Usage examples

Using the client as a context manager (recommended when performing multiple requests):

import asyncio
from prana_local_api_client.prana_api_client import PranaLocalApiClient

async def main():
    async with PranaLocalApiClient("192.168.1.100", 80) as client:
        state = await client.get_state()
        await client.set_speed(3, fan_type="main")
        await client.set_switch("power", True)
        await client.set_brightness(70)

asyncio.run(main())

Using the client without context manager (client will create and close a session per call):

from prana_local_api_client.prana_api_client import PranaLocalApiClient
import asyncio

async def short_run():
    client = PranaLocalApiClient("192.168.1.100")
    # session will be created internally for each call and closed afterwards
    state = await client.get_state()
    print(state)

asyncio.run(short_run())

Logging and debugging

The module uses a logger under its package name. Enable debugging in your application to see detailed logs:

import logging
logging.basicConfig(level=logging.DEBUG)

Timeouts and retries

  • Default request timeout is 10 seconds (ClientTimeout(total=10)).
  • This library does not implement automatic retries. If you need retries, implement them in your caller code (e.g., with tenacity) or wrap calls in retry logic.

Type hints

The client uses Python 3.9+ type hints (dict[str, Any]). Adjust your type checks accordingly.

Contributing

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

prana_api_client-0.7.0.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

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

prana_api_client-0.7.0-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file prana_api_client-0.7.0.tar.gz.

File metadata

  • Download URL: prana_api_client-0.7.0.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for prana_api_client-0.7.0.tar.gz
Algorithm Hash digest
SHA256 8ac71791bece9f09734a12b2289d83d862b7253ead554a61ade1452af080ffe0
MD5 d9b0c3772bc7d86f737e1bdd3633f7b2
BLAKE2b-256 1c33ae3dab1d2d2b2ed6c2c00c81854fa12fbd1c982bc827242d7b28b6668491

See more details on using hashes here.

File details

Details for the file prana_api_client-0.7.0-py3-none-any.whl.

File metadata

File hashes

Hashes for prana_api_client-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6cde184aa9d2b14cb7683ebe7918e9e85e77d91ebf88b72e4a2cd171c94ddb28
MD5 787639bdf44b03a0e69fdc69a4c1833f
BLAKE2b-256 c5c6e3f64ad85d9c2625955bfb58ff1c3c0acc15b5223a43a3151a067d91e830

See more details on using hashes here.

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