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
SoCoinstances for each zone found. Include invisible zones (bridges and slave zones in stereo pairs ifinclude_invisibleisTrue. Will block for up totimeoutseconds,after which return
Noneif 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_addris 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). IfNoneor not specified, the system default interface for UDP multicast messages will be used. This is probably what you want to happen. Defaults toNone.
- Returns
- a set of
SoCoinstances, one for each zone found, or else None.
- a set of
- 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
discoverif necessary. Note that this assumes that the existing instance has not left the network.- Returns
- A
SoCoinstance (or subclass ifconfig.SOCO_CLASSis set, or
Noneif no instances are found
- A
- Return type