How to use the soco.exceptions.SoCoUPnPException 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 SoCo / SoCo / tests / test_integration.py View on Github external
def test_remove_playlist_bad_id(self, soco):
        """Test attempting to remove a Sonos playlist using a bad id."""
        # junky bad
        with pytest.raises(SoCoUPnPException):
            soco.remove_sonos_playlist('SQ:-7')
        # realistic non-existing
        hpl_i = max([int(x.item_id.split(':')[1])
                     for x in soco.get_sonos_playlists()])
        with pytest.raises(SoCoUPnPException):
            soco.remove_sonos_playlist('SQ:{}'.format(hpl_i + 1))
github tdamdouni / Pythonista / automation / SoCoSono / unittest / test_core.py View on Github external
def test_search_track_no_result(self, moco):
        moco.contentDirectory.reset_mock()
        # Browse returns an exception if the artist can't be found
        # s:ClientUPnPError701
        moco.contentDirectory.Browse.side_effect = SoCoUPnPException("No such object", "701", "error XML")

        result = moco.search_track("artist")

        assert len(result) == 0

        moco.contentDirectory.Browse.assert_called_once_with([
            ('ObjectID', 'A:ALBUMARTIST/artist/'),
            ('BrowseFlag', 'BrowseDirectChildren'),
            ('Filter', '*'),
            ('StartingIndex', 0),
            ('RequestedCount', 100000),
            ('SortCriteria', '')
        ])
github SoCo / SoCo / tests / test_music_library.py View on Github external
def test_search_track_no_result(self, moco):
        moco.contentDirectory.reset_mock()
        # Browse returns an exception if the artist can't be found
        # s:ClientUPnPError701
        moco.contentDirectory.Browse.side_effect = SoCoUPnPException(
            "No such object", "701", "error XML")

        result = moco.music_library.search_track("artist")

        assert len(result) == 0

        moco.contentDirectory.Browse.assert_called_once_with([
            ('ObjectID', 'A:ALBUMARTIST/artist/'),
            ('BrowseFlag', 'BrowseDirectChildren'),
            ('Filter', '*'),
            ('StartingIndex', 0),
            ('RequestedCount', 100000),
            ('SortCriteria', '')
        ])
github SoCo / SoCo / soco / core.py View on Github external
# Note: A value of None for sleep_time_seconds is valid, and needs to
        # be preserved distinctly separate from 0. 0 means go to sleep now,
        # which will immediately start the sound tappering, and could be a
        # useful feature, while None means cancel the current timer
        try:
            if sleep_time_seconds is None:
                sleep_time = ''
            else:
                sleep_time = format(
                    datetime.timedelta(seconds=int(sleep_time_seconds))
                )
            self.avTransport.ConfigureSleepTimer([
                ('InstanceID', 0),
                ('NewSleepTimerDuration', sleep_time),
            ])
        except SoCoUPnPException as err:
            if 'Error 402 received' in str(err):
                raise ValueError('invalid sleep_time_seconds, must be integer \
                    value between 0 and 86399 inclusive or None')
            raise
        except ValueError:
            raise ValueError('invalid sleep_time_seconds, must be integer \
                value between 0 and 86399 inclusive or None')
github SoCo / SoCo / soco / services.py View on Github external
#       
        #   
        # 
        #
        # All that matters for our purposes is the errorCode.
        # errorDescription is not required, and Sonos does not seem to use it.

        # NB need to encode unicode strings before passing to ElementTree
        xml_error = xml_error.encode('utf-8')
        error = XML.fromstring(xml_error)
        log.debug("Error %s", xml_error)
        error_code = error.findtext(
            './/{urn:schemas-upnp-org:control-1-0}errorCode')
        if error_code is not None:
            description = self.UPNP_ERRORS.get(int(error_code), '')
            raise SoCoUPnPException(
                message='UPnP Error {} received: {} from {}'.format(
                    error_code, description, self.soco.ip_address),
                error_code=error_code,
                error_description=description,
                error_xml=xml_error
                )
        else:
            # Unknown error, so just return the entire response
            log.error("Unknown error received from %s", self.soco.ip_address)
            raise UnknownSoCoException(xml_error)
github SoCo / socos / socos / core.py View on Github external
def previous(self, sonos):
        """Play the previous track"""
        try:
            sonos.previous()
        except SoCoUPnPException:
            raise SoCoIllegalSeekException('No such track')
        return self.get_current_track_info(sonos)
github SoCo / SoCo / soco / exceptions.py View on Github external
def __init__(self, message, error_code, error_xml, error_description=""):
        """
        Args:
            message (str): The message from the server.
            error_code (str): The UPnP Error Code as a string.
            error_xml (str): The xml containing the error, as a utf-8
                encoded string.
            error_description (str): A description of the error. Default is ""
        """
        super(SoCoUPnPException, self).__init__()
        self.message = message
        self.error_code = error_code
        self.error_description = error_description
        self.error_xml = error_xml
github NAStools / homeassistant / homeassistant / components / media_player / sonos.py View on Github external
def play_media(self, media_type, media_id, **kwargs):
        """
        Send the play_media command to the media player.

        If ATTR_MEDIA_ENQUEUE is True, add `media_id` to the queue.
        """
        if self._coordinator:
            self._coordinator.play_media(media_type, media_id, **kwargs)
        else:
            if kwargs.get(ATTR_MEDIA_ENQUEUE):
                from soco.exceptions import SoCoUPnPException
                try:
                    self._player.add_uri_to_queue(media_id)
                except SoCoUPnPException:
                    _LOGGER.error('Error parsing media uri "%s", '
                                  "please check it's a valid media resource "
                                  'supported by Sonos', media_id)
            else:
                self._player.play_uri(media_id)
github SoCo / socos / socos / core.py View on Github external
def play_next(sonos):
    """ Play the next track """
    try:
        sonos.next()
    except SoCoUPnPException:
        raise SoCoIllegalSeekException('No such track')
    return get_current_track_info(sonos)