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
About
This module implements a Python client for the Stream Magic API used to control Cambridge Audio streamers. The API connects over TCP/IP 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
Release history Release notifications | RSS feed
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.2.4.tar.gz
(8.0 kB
view hashes)
Built Distribution
Close
Hashes for aiostreammagic-2.2.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9da37c994ae62ce20f3c473beff41b106fc582496e26454cf2775e87d00bdbda |
|
MD5 | b2a1dca9010872d81d0bac4ccc7aaaca |
|
BLAKE2b-256 | a78680c8436da9afeac34eca74a71c22fdb14eae6b1020e92068449efbc1dbd7 |