How to use the soco.discovery.any_soco function in soco

To help you get started, we’ve selected a few soco examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github clinton-hall / nzbToMedia / libs / common / beetsplug / sonosupdate.py View on Github external
def update(self, lib):
        """When the client exists try to send refresh request to a Sonos
        controler.
        """
        self._log.info(u'Requesting a Sonos library update...')

        device = soco.discovery.any_soco()

        if device:
            device.music_library.start_library_update()
        else:
            self._log.warning(u'Could not find a Sonos device.')
            return

        self._log.info(u'Sonos update triggered')
github SoCo / SoCo / soco / music_services / music_service.py View on Github external
def _get_music_services_data_xml(soco=None):
        """Fetch the music services data xml from a Sonos device.

        Args:
            soco (SoCo): a SoCo instance to query. If none is specified, a
            random device will be used. Defaults to `None`.

        Returns:
            str: a string containing the music services data xml
        """
        device = soco or discovery.any_soco()
        log.debug("Fetching music services data from %s", device)
        available_services = device.musicServices.ListAvailableServices()
        descriptor_list_xml = available_services[
            'AvailableServiceDescriptorList']
        log.debug("Services descriptor list: %s", descriptor_list_xml)
        return descriptor_list_xml
github SoCo / SoCo / soco / music_services / music_service.py View on Github external
# Spotify uses gzip. Others may do so as well. Unzipping is handled
        # for us by the requests library. Google Play seems to be very fussy
        #  about the user-agent string. The firmware release number (after
        # 'Sonos/') has to be '26' for some reason to get Google Play to
        # work. Although we have access to a real SONOS user agent
        # string (one is returned, eg, in the SERVER header of discovery
        # packets and looks like this: Linux UPnP/1.0 Sonos/29.5-91030 (
        # ZPS3)) it is a bit too much trouble here to access it, and Google
        # Play does not like it anyway.

        self.http_headers = {
            'Accept-Encoding': 'gzip, deflate',
            'User-Agent': 'Linux UPnP/1.0 Sonos/26.99-12345'
        }
        self._device = discovery.any_soco()
        self._device_id = self._device.systemProperties.GetString(
            [('VariableName', 'R_TrialZPSerial')])['StringValue']
github SoCo / SoCo / soco / music_services / accounts.py View on Github external
def _get_account_xml(soco):
        """Fetch the account data from a Sonos device.

        Args:
            soco (SoCo): a SoCo instance to query. If soco is `None`, a
                random device will be used.

        Returns:
            str: a byte string containing the account data xml
        """
        # It is likely that the same information is available over UPnP as well
        # via a call to
        # systemProperties.GetStringX([('VariableName','R_SvcAccounts')]))
        # This returns an encrypted string, and, so far, we cannot decrypt it
        device = soco or discovery.any_soco()
        log.debug("Fetching account data from %s", device)
        settings_url = "http://{}:1400/status/accounts".format(
            device.ip_address)
        result = requests.get(settings_url).content
        log.debug("Account data: %s", result)
        return result
github SoCo / SoCo / soco / alarms.py View on Github external
"""Get a set of all alarms known to the Sonos system.

    Args:
        zone (`SoCo`, optional): a SoCo instance to query. If None, a random
            instance is used. Defaults to `None`.

    Returns:
        set: A set of `Alarm` instances

    Note:
        Any existing `Alarm` instance will have its attributes updated to those
        currently stored on the Sonos system.
    """
    # Get a soco instance to query. It doesn't matter which.
    if zone is None:
        zone = discovery.any_soco()
    response = zone.alarmClock.ListAlarms()
    alarm_list = response['CurrentAlarmList']
    tree = XML.fromstring(alarm_list.encode('utf-8'))

    # An alarm list looks like this:
    # 
    #     
    #     
github SoCo / SoCo / soco / music_library.py View on Github external
def __init__(self, soco=None):
        """
         Args:
             soco (`SoCo`, optional): A `SoCo` instance to query for music
                 library information. If `None`, or not supplied, a random
                 `SoCo` instance will be used.
        """
        self.soco = soco if soco is not None else discovery.any_soco()
        self.contentDirectory = self.soco.contentDirectory
github beetbox / beets / beetsplug / sonosupdate.py View on Github external
def update(self, lib):
        """When the client exists try to send refresh request to a Sonos
        controler.
        """
        self._log.info(u'Requesting a Sonos library update...')

        device = soco.discovery.any_soco()

        if device:
            device.music_library.start_library_update()
        else:
            self._log.warning(u'Could not find a Sonos device.')
            return

        self._log.info(u'Sonos update triggered')
github SoCo / SoCo / dev_tools / sonosdump.py View on Github external
"If none is supplied, a random device will be used"
    )
    parser.add_argument(
        '-s', '--service',
        default=None,
        help="Dump data relating to services matching this regexp "
             "only, e.g. %(prog)s -s GroupRenderingControl"
    )

    args = parser.parse_args()

    # get a zone player - any one will do
    if args.device:
        device = soco.SoCo(args.device)
    else:
        device = soco.discovery.any_soco()
    print("Querying %s" % device.player_name)
    # loop over each of the available services
    # pylint: disable=no-member
    services = (srv(device) for srv in soco.services.Service.__subclasses__())

    for srv in services:
        if args.service is None or re.search(
                args.service, srv.service_type):
            print_details(srv)