def __str__(self): """Convert this playing object to a readable string.""" output = [] mtype = convert.media_type_str(self.media_type) output.append('Media type: {0} ({1})'.format(mtype, self.media_type)) pyatv_api.javaHandler.statusEvent("media_type", str(mtype)) output.append('Play state: {0} ({1})'.format( convert.playstate_str(self.play_state), self.play_state)) pyatv_api.javaHandler.statusEvent( "play_state", str(convert.playstate_str(self.play_state))) if self.title is not None: title = self.title.strip("\0") output.append(' Title: {0}'.format(title)) pyatv_api.javaHandler.statusEvent("title", str(self.title)) if self.artist is not None: artist = self.artist.strip("\0") output.append(' Artist: {0}'.format(artist)) pyatv_api.javaHandler.statusEvent("artist", str(artist)) if self.album is not None: album = self.album.strip("\0") output.append(' Album: {0}'.format(album)) pyatv_api.javaHandler.statusEvent("album", str(album)) if self.genre is not None: genre = self.genre.strip("\0") output.append(' Genre: {0}'.format(genre)) pyatv_api.javaHandler.statusEvent("genre", str(genre)) position = self.position total_time = self.total_time if position is not None and total_time is not None and total_time != 0: output.append(' Position: {0}/{1}s ({2:.1%})'.format( position, total_time, float(position) / float(total_time))) elif position is not None and position != 0: output.append(' Position: {0}s'.format(position)) elif total_time is not None and position != 0: output.append('Total time: {0}s'.format(total_time)) if position is not None: pyatv_api.javaHandler.statusEvent("position", str(position)) if total_time is not None: pyatv_api.javaHandler.statusEvent("total_time", str(total_time)) if self.repeat is not None: output.append(' Repeat: {0}'.format(convert.repeat_str( self.repeat))) pyatv_api.javaHandler.statusEvent( "repeat", str(convert.repeat_str(self.repeat))) if self.shuffle is not None: output.append(' Shuffle: {0}'.format(self.shuffle)) pyatv_api.javaHandler.statusEvent("shuffle", str(self.shuffle)) return '\n'.join(output)
def __str__(self): """Convert this playing object to a readable string.""" output = [] output.append('Media type: {0}'.format( convert.media_type_str(self.media_type))) output.append('Play state: {0}'.format( convert.playstate_str(self.play_state))) if self.title is not None: output.append(' Title: {0}'.format(self.title)) if self.artist is not None: output.append(' Artist: {0}'.format(self.artist)) if self.album is not None: output.append(' Album: {0}'.format(self.album)) position = self.position total_time = self.total_time if position is not None and total_time is not None and total_time != 0: output.append(' Position: {0}/{1}s ({2:.1%})'.format( position, total_time, float(position)/float(total_time))) elif position is not None and position != 0: output.append(' Position: {0}s'.format(position)) elif total_time is not None and position != 0: output.append('Total time: {0}s'.format(total_time)) if self.repeat is not None: output.append(' Repeat: {0}'.format( convert.repeat_str(self.repeat))) if self.shuffle is not None: output.append(' Shuffle: {0}'.format(self.shuffle)) return '\n'.join(output)
def test_playstate_str(self): self.assertEqual('Idle', convert.playstate_str(DeviceState.Idle)) self.assertEqual('Loading', convert.playstate_str(DeviceState.Loading)) self.assertEqual('Stopped', convert.playstate_str(DeviceState.Stopped)) self.assertEqual('Paused', convert.playstate_str(DeviceState.Paused)) self.assertEqual('Playing', convert.playstate_str(DeviceState.Playing)) self.assertEqual('Seeking', convert.playstate_str(DeviceState.Seeking))
def test_playstate_str(self): self.assertEqual('No media', convert.playstate_str(const.PLAY_STATE_NO_MEDIA)) self.assertEqual('Idle', convert.playstate_str(const.PLAY_STATE_IDLE)) self.assertEqual('Loading', convert.playstate_str(const.PLAY_STATE_LOADING)) self.assertEqual('Paused', convert.playstate_str(const.PLAY_STATE_PAUSED)) self.assertEqual('Playing', convert.playstate_str(const.PLAY_STATE_PLAYING)) self.assertEqual('Fast forward', convert.playstate_str(const.PLAY_STATE_FAST_FORWARD)) self.assertEqual('Fast backward', convert.playstate_str(const.PLAY_STATE_FAST_BACKWARD))
def test_playing_media_type_and_playstate(self): out = str(PlayingDummy()) self.assertIn(convert.media_type_str(const.MEDIA_TYPE_VIDEO), out) self.assertIn(convert.playstate_str(const.PLAY_STATE_PLAYING), out)
def test_unsupported_playstate_str(self): self.assertEqual('Unsupported', convert.playstate_str(999))
def test_playing_media_type_and_playstate(self): out = str(PlayingDummy()) self.assertIn(convert.media_type_str(MediaType.Video), out) self.assertIn(convert.playstate_str(DeviceState.Playing), out)