soco.snapshot module

Functionality to support saving and restoring the current Sonos state.

This is useful for scenarios such as when you want to switch to radio or an announcement and then back again to what was playing previously.

Warning

Sonos has introduced control via Amazon Alexa. A new cloud queue is created and at present there appears no way to restart this queue from snapshot. Currently if a cloud queue was playing it will not restart.

Warning

This class is designed to be created used and destroyed. It is not designed to be reused or long lived. The init sets up defaults for one use.

class soco.snapshot.Snapshot(device, snapshot_queue=False)[source]

A snapshot of the current state.

Note

This does not change anything to do with the configuration such as which group the speaker is in, just settings that impact what is playing, or how it is played.

List of sources that may be playing using root of media_uri:

x-rincon-queue: playing from Queue
x-sonosapi-stream: playing a stream (eg radio)
x-file-cifs: playing file
x-rincon: slave zone (only change volume etc. rest from coordinator)
Parameters:
  • device (SoCo) – The device to snapshot

  • snapshot_queue (bool) – Whether the queue should be snapshotted. Defaults to False.

Warning

It is strongly advised that you do not snapshot the queue unless you really need to as it takes a very long time to restore large queues as it is done one track at a time.

snapshot()[source]

Record and store the current state of a device.

Returns:

True if the device is a coordinator, False otherwise. Useful for determining whether playing an alert on a device will ungroup it.

Return type:

bool

restore(fade=False)[source]

Restore the state of a device to that which was previously saved.

For coordinator devices restore everything. For slave devices only restore volume etc., not transport info (transport info comes from the slave’s coordinator).

Parameters:

fade (bool) – Whether volume should be faded up on restore.