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 ifinclude_invisible
isTrue
. Will block for up totimeout
seconds,after which returnNone
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 forsocket.IP_MULTICAST_IF
). IfNone
or not specified, the system default interface for UDP multicast messages will be used. This is probably what you want to happen. Defaults toNone
.
Returns: Return type: 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 ifconfig.SOCO_CLASS
is set, - or
None
if no instances are found
Return type: SoCo - A