soco.discovery module

This module contains methods for discovering Sonos devices on the network.

soco.discovery.discover(timeout=5, include_invisible=False, interface_addr=None)[source]

Discover Sonos zones on the local network.

Return a set of SoCo instances for each zone found. Include invisible zones (bridges and slave zones in stereo pairs if include_invisible is True. Will block for up to timeout seconds,

System Message: ERROR/3 (/home/docs/checkouts/readthedocs.org/user_builds/soco/checkouts/latest/soco/discovery.py:docstring of soco.discovery.discover, line 6)

Unexpected indentation.
after which return None if no zones found.
Parameters:
  • timeout (int, optional) – block for this many seconds, at most. Defaults to 5.
  • include_invisible (bool, optional) – include invisible zones in the return set. Defaults to False.
  • interface_addr (str or None) – Discovery operates by sending UDP multicast datagrams. interface_addr is a string (dotted quad) representation of the network interface address to use as the source of the datagrams (i.e. it is a value for socket.IP_MULTICAST_IF). If None or not specified, the system default interface for UDP multicast messages will be used. This is probably what you want to happen. Defaults to None.
Returns:

a set of SoCo instances, one for each zone found, or else

None.

Return type:

set

Note

There is no easy cross-platform way to find out the addresses of the local machine’s network interfaces. You might try the netifaces module and some code like this:

>>> from netifaces import interfaces, AF_INET, ifaddresses
>>> data = [ifaddresses(i) for i in interfaces()]
>>> [d[AF_INET][0]['addr'] for d in data if d.get(AF_INET)]
['127.0.0.1', '192.168.1.20']

This should provide you with a list of values to try for interface_addr if you are having trouble finding your Sonos devices

soco.discovery.any_soco()[source]

Return any visible soco device, for when it doesn’t matter which.

Try to obtain an existing instance, or use discover if necessary. Note that this assumes that the existing instance has not left the network.

Returns:
A SoCo instance (or subclass if config.SOCO_CLASS is set,
or None if no instances are found
Return type:SoCo
soco.discovery.by_name(name)[source]

Return a device by name.

Parameters:name (str) – The name of the device to return.
Returns:
The first device encountered among all zone with the
given player name. If none are found None is returned.
Return type:SoCo