Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Python clients for HNAP devices

GitHub Release

Upload Python Package CodeQL Code style: black

Buy Me A Coffee

Generic HNAP client and specialized clients for motion sensors, sirens, routers, water detectors and more.

Async devices

All network operations are asynchronous. Pass a DeviceType to construct a known device without querying it first, or omit the type to discover the concrete device:

import asyncio

import aiohttp
from hnap import DeviceConfig, DeviceFactory, DeviceType

config = DeviceConfig(hostname="192.0.2.10", password="secret")


async def main():
    async with aiohttp.ClientSession() as http_client:
        siren = await DeviceFactory(
            DeviceType.SIREN, config=config, http_client=http_client
        )
        await siren.authenticate()
        await siren.soap_client.call("GetSirenAlarmSettings")

        discovered = await DeviceFactory(config=config)
        async with discovered:
            await discovered.authenticate()


asyncio.run(main())

DeviceConfig retains connection settings independently of authentication state. Operations are not retried after transport errors because the device may have completed an action even if its response was lost.

SoapClient creates an aiohttp.ClientSession when await client.start() is called, when the client or device is entered as an async context manager, or before its first network request. Sessions created by HNAP are closed by await client.close() or on context-manager exit. You can instead supply an existing session via http_client; caller-supplied sessions remain caller-owned and are not closed by the SOAP client or device.

Device operations such as is_playing(), play(), beep(), and get_clients() must be awaited. Cached device information is retrieved with await device.get_info().

Command-line interface

The hnap command requires a hostname and password (or HNAP_PASSWORD) and provides three subcommands:

hnap --hostname 192.0.2.10 --password secret inspect
hnap --hostname 192.0.2.10 --password secret monitor --seconds 10
hnap --hostname 192.0.2.10 --password secret call GetDeviceSettings --param Module 1

inspect reports the device's module types and settings. monitor calls IsDeviceReady immediately and repeats every 30 seconds by default; use --seconds to change the interval. call invokes a raw SOAP action and accepts repeated --param NAME VALUE arguments.

Useful links

Metadata

Release files for hnap 2.0.0rc0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hnap 2.0.0rc0
File Size Uploaded Provenance
hnap-2.0.0rc0.tar.gz 23.5 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for hnap 2.0.0rc0
File Interpreter ABI Platform
hnap-2.0.0rc0-py3-none-any.whl Python 3 none any Details

Total release size: 50.0 kB

Release files / hnap-2.0.0rc0.tar.gz

Download URL hnap-2.0.0rc0.tar.gz
Size 23.5 kB
Tags Source
SHA-256 checksum
How to use checksums
621969bec8c48933b6fc15010240c975f0d3c1add22cb30cb240acac1db80b96
BLAKE2b-256 checksum
How to use checksums
fa7fc6a90bc252132f273262ea9c2cea7054d98f5792fb351803dbea314d5ac6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release files / hnap-2.0.0rc0-py3-none-any.whl

Download URL hnap-2.0.0rc0-py3-none-any.whl
Size 26.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
111d1309321444d3fb9a51625edbbc0e36e0dc357437ff42f2bf3a156d3ab085
BLAKE2b-256 checksum
How to use checksums
cfa4a9fc1076806e650b66a095268cf220571f6a50d8e9f2485ff5353cb94050
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Security for hnap 2.0.0rc0

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page