This module contains methods for discovering Sonos devices on the network.
discover(timeout=5, include_invisible=False, interface_addr=None)¶
Discover Sonos zones on the local network.after which return
Noneif no zones found.
- 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
- interface_addr (str or None) – Discovery operates by sending UDP
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 for
Noneor not specified, the system default interface for UDP multicast messages will be used. This is probably what you want to happen. Defaults to
Returns: Return type:
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]['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
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: Return type: SoCo