Skip to main content

Python client library for Hegel amplifiers

Project description

hegel-ip-client

Python client library for Hegel amplifiers with async support and push notifications.

Features

  • Async/await support - Built on asyncio for non-blocking I/O
  • Push notifications - Real-time state updates from the amplifier
  • Automatic reconnection - Resilient connection management with exponential backoff
  • Command queuing - FIFO queue for command responses
  • Full protocol support - Power, volume, mute, input selection, and more

Installation

pip install hegel-ip-client

Quick Start

import asyncio
from hegel_ip_client import HegelClient, COMMANDS

async def main():
    # Create client
    client = HegelClient("192.168.1.100", 50001)

    # Register callback for push messages
    def on_push(message):
        print(f"Received push: {message}")

    client.add_push_callback(on_push)

    # Start connection manager
    await client.start()

    # Send commands
    power_state = await client.send(COMMANDS["power_query"])
    print(f"Power state: {power_state.power}")

    # Set volume
    await client.send(COMMANDS["volume_set"](50), expect_reply=False)

    # Stop client when done
    await client.stop()

asyncio.run(main())

API Reference

HegelClient

__init__(host: str, port: int = 50001)

Create a new Hegel client.

async start()

Start the connection manager. Automatically handles reconnection.

async stop()

Stop the client and close the connection.

async send(command: str, expect_reply: bool = True, timeout: float = 5.0) -> Optional[HegelStateUpdate]

Send a command to the amplifier.

  • command: Command string (use COMMANDS dict for convenience)
  • expect_reply: Whether to wait for a reply
  • timeout: Maximum time to wait for reply
  • Returns: HegelStateUpdate with parsed state changes, or None if expect_reply=False

add_push_callback(callback: Callable[[str], None])

Register a callback for push messages from the amplifier.

HegelStateUpdate

Dataclass representing state changes from the amplifier:

  • power: Optional[bool] - Power state (True=on, False=off)
  • volume: Optional[float] - Volume level (0.0 to 1.0)
  • mute: Optional[bool] - Mute state (True=muted)
  • input: Optional[int] - Selected input number (1-20)
  • reset: Optional[str] - Reset/heartbeat message

COMMANDS

Dictionary of pre-defined commands:

  • power_on, power_off, power_query
  • volume_set(level), volume_query, volume_up, volume_down
  • mute_on, mute_off, mute_query
  • input_set(idx), input_query
  • reset_query

Protocol Details

The Hegel TCP protocol uses carriage return (\r) as the line terminator. Commands and replies are text-based.

Example Commands

  • -p.? - Query power state
  • -p.1 - Power on
  • -p.0 - Power off
  • -v.? - Query volume
  • -v.50 - Set volume to 50
  • -v.u - Volume up
  • -v.d - Volume down
  • -m.1 - Mute on
  • -m.0 - Mute off
  • -i.? - Query input
  • -i.1 - Select input 1

License

MIT License

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Support

For issues and feature requests, please use the GitHub issue tracker.

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

hegel_ip_client-0.1.4.tar.gz (9.6 kB view details)

Uploaded Source

Built Distribution

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

hegel_ip_client-0.1.4-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file hegel_ip_client-0.1.4.tar.gz.

File metadata

  • Download URL: hegel_ip_client-0.1.4.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for hegel_ip_client-0.1.4.tar.gz
Algorithm Hash digest
SHA256 566293211fc0ecdf9845e55c5bc0b6ae8348678031b49776889605fd628db65e
MD5 d82eedfe700f045a6c36737e6474c82e
BLAKE2b-256 8c12528a5ea6319a42a5e815d3cbd1110f0408ad5afe92e7b2906a1ae20258c1

See more details on using hashes here.

File details

Details for the file hegel_ip_client-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for hegel_ip_client-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 11ff755d6d937d04b06f88be1e39bc74d2d392639b5c4ed530b89c7722446bbb
MD5 7daf6cc00fa1b967d80d3ad1dfac7627
BLAKE2b-256 de5e9ed120ae88f022b08933a0bdd674a5a1cc6dfb83594e2bb73a87b3bffa65

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