Skip to content

Commit

Permalink
Merge pull request #17 from noahhusby/docs/examples
Browse files Browse the repository at this point in the history
Include example files
  • Loading branch information
noahhusby authored Sep 11, 2024
2 parents 50d1a4b + 2e00e6a commit c405b91
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,3 @@ cython_debug/

# PyCharm
.idea/
/examples/
23 changes: 23 additions & 0 deletions examples/basic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
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())
29 changes: 29 additions & 0 deletions examples/subscribe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
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())

0 comments on commit c405b91

Please sign in to comment.