Skip to main content

An async python package for interfacing with Cambridge Audio / Stream Magic compatible streamers.

Project description

aiostreammagic

An async python package for interfacing with Cambridge Audio / Stream Magic compatible streamers

📖 Read the docs »

GitHub Release Python Versions Downloads Project Maintenance License

About

This module implements a Python client for the Stream Magic API used to control Cambridge Audio streamers. The API connects over websockets and supports several streamers, receivers, and pre-amps.

Supported Devices

  • Cambridge Audio Evo 75
  • Cambridge Audio Evo 150
  • Cambridge Audio CXN
  • Cambridge Audio CXN (v2)
  • Cambridge Audio CXR120
  • Cambridge Audio CXR200
  • Cambridge Audio 851N
  • Cambridge Audio Edge NQ

If your model is not on the list of supported devices, and everything works correctly then add it to the list by opening a pull request.

Installation

pip install aiostreammagic

Examples

Basic Example

import asyncio

from aiostreammagic import StreamMagicClient, Source, Info

HOST = "192.168.20.218"


async def main():
    """Basic demo entrypoint."""
    client = StreamMagicClient("192.168.20.218")
    await client.connect()

    info: Info = await client.get_info()
    sources: list[Source] = await client.get_sources()

    print(f"Model: {info.model}")
    for source in sources:
        print(f"Name: {source.id} ({source.id})")

    await client.disconnect()

if __name__ == '__main__':
    asyncio.run(main())

Subscription Example

The Cambridge Audio StreamMagic API can automatically notify the client of changes instead of the need for polling. Register a callback to be called whenver new information is available.

import asyncio

from aiostreammagic import StreamMagicClient

HOST = "192.168.20.218"


async def on_state_change(client: StreamMagicClient):
    """Called when new information is received."""
    print(f"System info: {client.get_info()}")
    print(f"Sources: {client.get_sources()}")
    print(f"State: {client.get_state()}")
    print(f"Play State: {client.get_play_state()}")
    print(f"Now Playing: {client.get_now_playing()}")

async def main():
    """Subscribe demo entrypoint."""
    client = StreamMagicClient("192.168.20.218")
    await client.register_state_update_callbacks(on_state_change)
    await client.connect()

    # Play media using the unit's front controls or StreamMagic app
    await asyncio.sleep(60)

    await client.disconnect()


if __name__ == '__main__':
    asyncio.run(main())

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

aiostreammagic-2.11.0.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

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

aiostreammagic-2.11.0-py3-none-any.whl (11.1 kB view details)

Uploaded Python 3

File details

Details for the file aiostreammagic-2.11.0.tar.gz.

File metadata

  • Download URL: aiostreammagic-2.11.0.tar.gz
  • Upload date:
  • Size: 10.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.9

File hashes

Hashes for aiostreammagic-2.11.0.tar.gz
Algorithm Hash digest
SHA256 21c4a079b79acc816ff7b7a1ffbf3ea4c5f4cc2cae74f31949bf5e2e77da02e6
MD5 be23d57fcace8bffb92cee9a1ffde9e3
BLAKE2b-256 04e62a03dd70c81f64526899608fe264236644ac06a590e61144d42b81dbadd6

See more details on using hashes here.

File details

Details for the file aiostreammagic-2.11.0-py3-none-any.whl.

File metadata

File hashes

Hashes for aiostreammagic-2.11.0-py3-none-any.whl
Algorithm Hash digest
SHA256 683eecfbd782e819c9ad5666185797e81d26d479f019833370152a19d3462d65
MD5 e422451391136dd49a1ad4a355812348
BLAKE2b-256 3ef3d5d12d61a4c7b4e9e0c644745bb5614a8dd75ead81f3fa32798f4b7bc7ce

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