Update service alias to use config name

pull/433/head
Åke Forslund 2016-12-18 22:23:19 +01:00
parent 06a9eb7ee5
commit 8686cade3b
3 changed files with 15 additions and 23 deletions

View File

@ -30,15 +30,13 @@ for b in config['backends']:
class Mpg123Service():
def __init__(self, config, emitter):
def __init__(self, config, emitter, name='mpg123'):
self.config = config
self.process = None
self.emitter = emitter
self.emitter.on('Mpg123ServicePlay', self._play)
self.emitter = emitter
self.name = name
@property
def name(self):
return self.config.get('audio.mpg123.name', 'mpg123')
self.emitter.on('Mpg123ServicePlay', self._play)
def supported_uris(self):
return ['file', 'http']
@ -107,18 +105,18 @@ class PlaybackControlSkill(MediaSkill):
super(PlaybackControlSkill, self).initialize()
self.load_data_files(dirname(__file__))
for b in config['backends']:
b = config['backends'][b]
for name in config['backends']:
b = config['backends'][name]
logger.debug(b)
if b['type'] == 'vlc' and b.get('active', False):
logger.info('starting VLC service')
self.service.append(VlcService(b, self.emitter))
self.service.append(VlcService(b, self.emitter, name))
if b['type'] == 'mopidy' and b.get('active', False):
logger.info('starting Mopidy service')
self.service.append(MopidyService(config, self.emitter))
self.service.append(MopidyService(config, self.emitter, name))
if b['type'] == 'mpg123' and b.get('active', False):
logger.info('starting Mpg123 service')
self.service.append(Mpg123Service(config, self.emitter))
self.service.append(Mpg123Service(config, self.emitter, name))
if b.get('default', False):
# Last added service is the default
@ -158,7 +156,7 @@ class PlaybackControlSkill(MediaSkill):
# Find if the user wants to use a specific backend
for s in self.service:
logger.info(s)
logger.info(s.name)
if s.name in message.data['utterance']:
prefered_service = s
logger.info(s.name + ' would be prefered')

View File

@ -28,19 +28,16 @@ class MopidyService():
logger.info('Connected to mopidy server')
def __init__(self, config, emitter):
def __init__(self, config, emitter, name='mopidy'):
self.connection_attempts = 0
self.emitter = emitter
self.emitter = emitter
self.config = config
self.name = name
self.mopidy = None
self.emitter.on('MopidyServiceConnect', self._connect)
self._connect(None)
@property
def name(self):
return self.config.get('audio.mopidy.name', 'mopidy')
def supported_uris(self):
if self.mopidy:
return ['file', 'http', 'https', 'local', 'spotify', 'gmusic']

View File

@ -6,7 +6,7 @@ logger = getLogger(abspath(__file__).split('/')[-2])
import vlc
class VlcService():
def __init__(self, config, emitter=None):
def __init__(self, config, emitter=None, name='vlc'):
self.instance = vlc.Instance()
self.list_player = self.instance.media_list_player_new()
self.player = self.instance.media_player_new()
@ -14,10 +14,7 @@ class VlcService():
self.config = config
self.emitter = emitter
@property
def name(self):
return self.config.get('audio.vlc.name', 'vlc')
self.name = name
def supported_uris(self):
return ['file', 'http']