Skip to content

Strixx76/pywam

Repository files navigation

pywam

License PyPi Downloads

Buy Me A Coffee Ko-fi Paypal GitHub Sponsors

pywam is an fast and lightweight python asyncio library without external dependencies for communicating with Samsung Wireless Audio (R) speakers (WAM). It was developed to be used for integrating the speakers in Home Assistant with the Samsung Wireless Audio Integration

Important

This library only supports speakers that can be controlled by the Wireless Audio-Multiroom (Android) or Wireless Audio : Multiroom (iOS). This library will never support speakers not supported by the native Multiroom App. Check src/pywam/device.py to see which speakers are tested and which are believed to work.

Features

  • Control Samsung Multiroom speakers.
  • Keep track of the state of Samsung Multiroom speakers.

Limitations

The SetUrlPlayback API used to get the speakers playing url streams is only partially implemented in the speakers. I have found information that not all speakers accept it, and the one that does will only play the url. The speaker will not report that it is playing a url. This means that as soon as the speakers is asked for current state it will report that it is not playing anything, which this library will pick up and believe to be true.

Installation

pip install pywam

Usage

Set the speaker volume to 50% with python context manager:

from pywam.speaker import Speaker

async with Speaker('192.168.1.100') as speaker:
    await speaker.update()
    await speaker.set_volume(50)

Example of controlling media playback:

# Play
await speaker.cmd_play()
# Pause
await speaker.cmd_pause()
# Shuffle mode
await speaker.set_shuffle(True)

Example of playing a url stream:

from pywam.lib.url import UrlMediaItem

item = UrlMediaItem('http://live-bauerse-fm.sharp-stream.com/retrofm_mp3')
await speaker.play_url(item)

Example of group handling:

from pywam.speaker import Speaker

kitchen = Speaker('192.168.1.50')
await kitchen.connect()
await kitchen.update()

bedroom = Speaker('192.168.1.51')
await bedroom.connect()
await bedroom.update()

bathroom = Speaker('192.168.1.52')
await bathroom.connect()
await bathroom.update()

# Group bathroom with kitchen as master
await kitchen.group([], [bathroom])

# Add bedroom to the group
await kitchen.group([bathroom], [bathroom, bedroom])

# Remove bathroom from group
await kitchen.group([bathroom, bedroom], [bedroom])

# Ungroup
await kitchen.group([bedroom], [])

Get notifications about speakers state changes:

from pywam.speaker import Speaker

def state_receiver(event):
    print(event)

speaker = Speaker('192.168.1.150')
speaker.events.register_subscriber(state_receiver, 2)
await speaker.connect()
await speaker.update()

For more examples please check the Samsung Wireless Audio Integration

Contribute

Roadmap

  • There are some TODO's in the source that should be fixed.
  • Better workaround for play_url to show correct state when url streams are played.
  • I would also like to change all the API keys and values strings in both the event receiver and the state machine to string enums.
  • Make the code less complex.
  • Add more API calls.

Style guide

PEP8 and Google styled PEP257. But none of them is strictly enforced.

License

The project is licensed under the MIT License.

Disclaimer Notice

I have tested all functions in this library on all of my Samsung Multiroom speakers, and the worst that has happened is that speakers froze when receiving faulty calls. A simple power cycle would solve it. But I CAN’T guarantee that your speaker is compatible with this library, and you can’t hold me responsible if you brick your speaker when using this library.

Versioning and Changelog

This project uses Semantic Versioning. The changelog format is based on Keep a Changelog

Credits

This project would not have been possible without, but not limited to, the following projects:

Support the work

If you find this library useful please consider a small donation to show your appreciation.

Buy Me A Coffee Ko-fi Paypal GitHub Sponsors

About

Library built on AsyncIO for communicating with Samsung Wireless Audio speakers (WAM).

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors