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.2.tar.gz (8.2 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.2-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: hegel_ip_client-0.1.2.tar.gz
  • Upload date:
  • Size: 8.2 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.2.tar.gz
Algorithm Hash digest
SHA256 cdd94e651a76df1836f287645a4a2ac38a94322d2ee6b4ed98b554e49fda3cd8
MD5 cf35eebfd3eb6019034a4f4fdbc14d05
BLAKE2b-256 57a092d1b40ba16fb050c6865cfa7fd2d029ddcc9fc5edcf0812bf4cb91414d9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for hegel_ip_client-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ded246accf4fbc0975305d448493e9fcfbd86bc21cd9dcc6e4b965c6606e6fe3
MD5 aacec92b5d0eb0e494183bcf23827be1
BLAKE2b-256 bcb554298c8a0203d511dc96a1554c1653c2c497fb15863634c18ce967f28229

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