import time

from mycroft.messagebus.message import Message


class AudioService():
    def __init__(self, emitter):
        self.emitter = emitter
        self.emitter.on('MycroftAudioServiceTrackInfoReply', self._track_info)
        self.info = None

    def _track_info(self, message=None):
        self.info = message.data

    def play(self, tracks=[], utterance=''):
        self.emitter.emit(Message('MycroftAudioServicePlay',
                                  data={'tracks': tracks,
                                        'utterance': utterance}))

    def track_info(self):
        self.info = None
        self.emitter.emit(Message('MycroftAudioServiceTrackInfo'))
        while self.info is None:
            time.sleep(0.1)
        return self.info

import time

from mycroft.messagebus.message import Message


class AudioService():
    def __init__(self, emitter):
        self.emitter = emitter
        self.emitter.on('MycroftAudioServiceTrackInfoReply', self._track_info)
        self.info = None

    def _track_info(self, message=None):
        self.info = message.data

    def play(self, tracks=[], utterance=''):
        if isinstance(tracks, basestring):
            tracks = [tracks]
        elif not isinstance(tracks, list):
            raise ValueError

        self.emitter.emit(Message('MycroftAudioServicePlay',
                                  data={'tracks': tracks,
                                        'utterance': utterance}))

    def track_info(self):
        self.info = None
        self.emitter.emit(Message('MycroftAudioServiceTrackInfo'))
        while self.info is None:
            time.sleep(0.1)
        return self.info

Add check for valid type of tracks
Add check for valid type of tracks

  import time
  
  from mycroft.messagebus.message import Message
  
  
  class AudioService():
      def __init__(self, emitter):
          self.emitter = emitter
          self.emitter.on('MycroftAudioServiceTrackInfoReply', self._track_info)
          self.info = None
  
      def _track_info(self, message=None):
          self.info = message.data
  
      def play(self, tracks=[], utterance=''):
+         if isinstance(tracks, basestring):
+             tracks = [tracks]
+         elif not isinstance(tracks, list):
+             raise ValueError
+ 
          self.emitter.emit(Message('MycroftAudioServicePlay',
                                    data={'tracks': tracks,
                                          'utterance': utterance}))
  
      def track_info(self):
          self.info = None
          self.emitter.emit(Message('MycroftAudioServiceTrackInfo'))
          while self.info is None:
              time.sleep(0.1)
          return self.info
  
Add check for valid type of tracks
## Code Before:
import time

from mycroft.messagebus.message import Message


class AudioService():
    def __init__(self, emitter):
        self.emitter = emitter
        self.emitter.on('MycroftAudioServiceTrackInfoReply', self._track_info)
        self.info = None

    def _track_info(self, message=None):
        self.info = message.data

    def play(self, tracks=[], utterance=''):
        self.emitter.emit(Message('MycroftAudioServicePlay',
                                  data={'tracks': tracks,
                                        'utterance': utterance}))

    def track_info(self):
        self.info = None
        self.emitter.emit(Message('MycroftAudioServiceTrackInfo'))
        while self.info is None:
            time.sleep(0.1)
        return self.info

## Instruction:
Add check for valid type of tracks
## Code After:
import time

from mycroft.messagebus.message import Message


class AudioService():
    def __init__(self, emitter):
        self.emitter = emitter
        self.emitter.on('MycroftAudioServiceTrackInfoReply', self._track_info)
        self.info = None

    def _track_info(self, message=None):
        self.info = message.data

    def play(self, tracks=[], utterance=''):
        if isinstance(tracks, basestring):
            tracks = [tracks]
        elif not isinstance(tracks, list):
            raise ValueError

        self.emitter.emit(Message('MycroftAudioServicePlay',
                                  data={'tracks': tracks,
                                        'utterance': utterance}))

    def track_info(self):
        self.info = None
        self.emitter.emit(Message('MycroftAudioServiceTrackInfo'))
        while self.info is None:
            time.sleep(0.1)
        return self.info
