Skip to content

Commit

Permalink
Merge pull request #938 from onkelandy/lms
Browse files Browse the repository at this point in the history
LMS plugin: some fixes
  • Loading branch information
onkelandy committed Jun 1, 2024
2 parents 979c751 + fea3f53 commit 9a71c89
Show file tree
Hide file tree
Showing 3 changed files with 654 additions and 655 deletions.
22 changes: 11 additions & 11 deletions lms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@ def trigger_read(command):
if not custom:
return

if command == 'player.info.playlists.names':
if command == f'player.info.playlists.names{CUSTOM_SEP}{custom}':
self.logger.debug(f"Got command playlist names {command} data {data} value {value} custom {custom} by {by}")
trigger_read('player.playlist.id')
trigger_read('player.playlist.name')

if command == 'playlist.rename':
trigger_read('info.playlists.names')
# set alarm
if command == 'player.control.alarms':
if command == f'player.control.alarms{CUSTOM_SEP}{custom}':
# This does not really work currently. The created string is somehow correct.
# However, much more logic has to be included to add/update/delete alarms, etc.
try:
Expand All @@ -118,7 +118,7 @@ def trigger_read(command):
self.logger.error(f"Error setting alarm: {e}")

# set album art URL
if command == 'player.info.album':
if command == f'player.info.album{CUSTOM_SEP}{custom}':
self.logger.debug(f"Got command album {command} data {data} value {value} custom {custom} by {by}")
host = self._parameters['web_host']
port = self._parameters['web_port']
Expand All @@ -130,17 +130,17 @@ def trigger_read(command):
self._dispatch_callback('player.info.albumarturl' + CUSTOM_SEP + custom, url, by)

# set playlist ID
if command == 'player.playlist.load':
if command == f'player.playlist.load{CUSTOM_SEP}{custom}':
self.logger.debug(f"Got command load {command} data {data} value {value} custom {custom} by {by}")
trigger_read('player.playlist.id')
trigger_read('player.control.playmode')

if command == 'player.playlist.id':
if command == f'player.playlist.id{CUSTOM_SEP}{custom}':
self.logger.debug(f"Got command id {command} data {data} value {value} custom {custom} by {by}")
trigger_read('player.playlist.name')

# update on new song
if command == 'player.info.title':
if command == f'player.info.title{CUSTOM_SEP}{custom}':
# trigger_read('player.control.playmode')
# trigger_read('player.playlist.index')
trigger_read('player.info.duration')
Expand All @@ -150,7 +150,7 @@ def trigger_read(command):
trigger_read('player.info.path')

# update on new song
if command == 'player.control.playpause' and value:
if command == f'player.control.playpause{CUSTOM_SEP}{custom}' and value:
trigger_read('player.control.playmode')
trigger_read('player.info.duration')
trigger_read('player.info.album')
Expand All @@ -159,7 +159,7 @@ def trigger_read(command):
trigger_read('player.info.path')

# update on new song
if command == 'player.playlist.index':
if command == f'player.playlist.index{CUSTOM_SEP}{custom}':
self.logger.debug(f"Got command index {command} data {data} value {value} custom {custom} by {by}")
trigger_read('player.control.playmode')
trigger_read('player.info.duration')
Expand All @@ -170,12 +170,12 @@ def trigger_read(command):
trigger_read('player.info.title')

# update current time info
if command in ['player.control.forward', 'player.control.rewind']:
if command in [f'player.control.forward{CUSTOM_SEP}{custom}', f'player.control.rewind{CUSTOM_SEP}{custom}']:
self.logger.debug(f"Got command forward/rewind {command} data {data} value {value} custom {custom} by {by}")
trigger_read('player.control.time')

# update play and stop items based on playmode
if command == 'player.control.playmode':
if command == f'player.control.playmode{CUSTOM_SEP}{custom}':
self.logger.debug(f"Got command playmode {command} data {data} value {value} custom {custom} by {by}")
mode = data.split("mode")[-1].strip()
mode = mode.split("playlist")[-1].strip()
Expand All @@ -186,7 +186,7 @@ def trigger_read(command):
trigger_read('player.control.time')

# update play and stop items based on playmode
if command == 'player.control.stop' or (command == 'player.control.playpause' and not value):
if command == f'player.control.stop{CUSTOM_SEP}{custom}' or (command == f'player.control.playpause{CUSTOM_SEP}{custom}' and not value):
self.logger.debug(f"Got command stop or pause {command} data {data} value {value} custom {custom} by {by}")
trigger_read('player.control.playmode')

Expand Down
8 changes: 4 additions & 4 deletions lms/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@
'rename': {'read': False, 'write': False, 'item_type': 'str', 'dev_datatype': 'raw', 'reply_pattern': r'{CUSTOM_PATTERN1} playlists rename\s+(.*)'},
'repeat': {'read': True, 'write': True, 'read_cmd': '{CUSTOM_ATTR1} playlist repeat ?', 'item_type': 'str', 'write_cmd': '{CUSTOM_ATTR1} playlist repeat {VALUE}', 'dev_datatype': 'str', 'reply_pattern': [r'{CUSTOM_PATTERN1} playlist repeat {LOOKUP}', '{CUSTOM_PATTERN1} status(?:.*)playlist repeat:{LOOKUP}'], 'lookup': 'REPEAT', 'item_attrs': {'attributes': {'remark': '0 = Off, 1 = Song, 2 = Playlist'}, 'lookup_item': True}},
'shuffle': {'read': True, 'write': True, 'read_cmd': '{CUSTOM_ATTR1} playlist shuffle ?', 'item_type': 'str', 'write_cmd': '{CUSTOM_ATTR1} playlist shuffle {VALUE}', 'dev_datatype': 'str', 'reply_pattern': [r'{CUSTOM_PATTERN1} playlist shuffle {LOOKUP}', '{CUSTOM_PATTERN1} status(?:.*)playlist shuffle:{LOOKUP}'], 'lookup': 'SHUFFLE', 'item_attrs': {'attributes': {'remark': '0 = Off, 1 = Song, 2 = Album'}, 'lookup_item': True}},
'index': {'read': True, 'write': True, 'read_cmd': '{CUSTOM_ATTR1} playlist index ?', 'write_cmd': '{CUSTOM_ATTR1} playlist index {VALUE}', 'item_type': 'str', 'dev_datatype': 'str', 'reply_pattern': [r'{CUSTOM_PATTERN1} playlist (?:index|newsong .*) (\d+)$', '{CUSTOM_PATTERN1} status(?:.*)playlist index:(\d*[^\s]+)', '{CUSTOM_PATTERN1} prefset server currentSong (\d+)$', '{CUSTOM_PATTERN1} playlist jump (\d*)', '{CUSTOM_PATTERN1} play (\d*)'], 'item_attrs': {'initial': True}},
'name': {'read': True, 'write': True, 'read_cmd': '{CUSTOM_ATTR1} playlist name ?', 'write_cmd': '{CUSTOM_ATTR1} playlist name {VALUE}', 'item_type': 'str', 'dev_datatype': 'str', 'reply_pattern': [r'{CUSTOM_PATTERN1} playlistcontrol cmd:load playlist_name:(.*) count:(?:\d*)', '{CUSTOM_PATTERN1} playlist name (.*[^?])'], 'item_attrs': {'initial': True}},
'id': {'read': True, 'write': True, 'read_cmd': '{CUSTOM_ATTR1} playlist playlistsinfo', 'write_cmd': '{CUSTOM_ATTR1} playlistcontrol cmd:load playlist_id:{VALUE}', 'item_type': 'num', 'dev_datatype': 'str', 'reply_pattern': [r'{CUSTOM_PATTERN1} (?:status - 1 .*|playlist playlistsinfo |playlistcontrol cmd:load playlist_)id:(\d*)', '{CUSTOM_PATTERN1} playlist loadtracks playlist.id=(\d*)\s']},
'index': {'read': True, 'write': True, 'read_cmd': '{CUSTOM_ATTR1} playlist index ?', 'write_cmd': '{CUSTOM_ATTR1} playlist index {VALUE}', 'item_type': 'str', 'dev_datatype': 'str', 'reply_pattern': [r'{CUSTOM_PATTERN1} playlist (?:index|newsong .*) (\d+)$', '{CUSTOM_PATTERN1} status(?:.*)playlist index:(\d*[^\s]+)', '{CUSTOM_PATTERN1} prefset server currentSong (\d+)$', '{CUSTOM_PATTERN1} playlist jump (\d+)', '{CUSTOM_PATTERN1} play (\d*)'], 'item_attrs': {'initial': True}},
'name': {'read': True, 'write': True, 'read_cmd': '{CUSTOM_ATTR1} playlist name ?', 'write_cmd': '{CUSTOM_ATTR1} playlist name {VALUE}', 'item_type': 'str', 'dev_datatype': 'str', 'reply_pattern': [r'{CUSTOM_PATTERN1} playlistcontrol cmd:load playlist_name:(.*) count:(?:\d+)', '{CUSTOM_PATTERN1} playlist name (.*[^?])'], 'item_attrs': {'initial': True}},
'id': {'read': True, 'write': True, 'read_cmd': '{CUSTOM_ATTR1} playlist playlistsinfo', 'write_cmd': '{CUSTOM_ATTR1} playlistcontrol cmd:load playlist_id:{VALUE}', 'item_type': 'num', 'dev_datatype': 'str', 'reply_pattern': [r'{CUSTOM_PATTERN1} (?:status - 1 .*|playlist playlistsinfo |playlistcontrol cmd:load playlist_)id:(\d+)', '{CUSTOM_PATTERN1} playlist loadtracks playlist.id=(\d+)\s']},
'save': {'read': True, 'write': True, 'write_cmd': '{CUSTOM_ATTR1} playlist save {VALUE}', 'item_type': 'str', 'dev_datatype': 'str', 'reply_pattern': '{CUSTOM_PATTERN1} playlist save (.*)', 'item_attrs': {'enforce': True}},
'load': {'read': True, 'write': True, 'write_cmd': '{CUSTOM_ATTR1} playlistcontrol cmd:load playlist_name:{VALUE}', 'item_type': 'str', 'dev_datatype': 'str', 'reply_pattern': ['{CUSTOM_PATTERN1} playlist resume (.*)', '{CUSTOM_PATTERN1} playlist loadtracks playlist.name:(.*)\s'], 'item_attrs': {'enforce': True}},
'loadalbum': {'read': True, 'write': True, 'write_cmd': '{CUSTOM_ATTR1} playlist loadalbum {VALUE}', 'item_type': 'str', 'dev_datatype': 'str', 'reply_pattern': '{CUSTOM_PATTERN1} playlist loadalbum (.*)', 'item_attrs': {'enforce': True}},
Expand All @@ -68,7 +68,7 @@
'addtracks': {'read': True, 'write': True, 'write_cmd': '{CUSTOM_ATTR1} playlist addtracks {VALUE}', 'item_type': 'str', 'dev_datatype': 'str', 'reply_pattern': '{CUSTOM_PATTERN1} playlist addtracks (.*)', 'item_attrs': {'enforce': True}},
'insertalbum': {'read': True, 'write': True, 'write_cmd': '{CUSTOM_ATTR1} playlist insertalbum {VALUE}', 'item_type': 'str', 'dev_datatype': 'str', 'reply_pattern': '{CUSTOM_PATTERN1} playlist insertalbum (.*)', 'item_attrs': {'enforce': True}},
'inserttracks': {'read': True, 'write': True, 'write_cmd': '{CUSTOM_ATTR1} playlist insert {VALUE}', 'item_type': 'str', 'dev_datatype': 'str', 'reply_pattern': '{CUSTOM_PATTERN1} playlist insert (.*)', 'item_attrs': {'enforce': True}},
'tracks': {'read': True, 'write': False, 'read_cmd': '{CUSTOM_ATTR1} playlist tracks ?', 'item_type': 'num', 'dev_datatype': 'str', 'reply_pattern': [r'{CUSTOM_PATTERN1} playlistcontrol cmd:load .* count:(\d*)', '{CUSTOM_PATTERN1} playlist_tracks (\d*[^?])', '{CUSTOM_PATTERN1} status(?:.*)playlist tracks:(\d*[^\s]+)']},
'tracks': {'read': True, 'write': False, 'read_cmd': '{CUSTOM_ATTR1} playlist tracks ?', 'item_type': 'num', 'dev_datatype': 'str', 'reply_pattern': [r'{CUSTOM_PATTERN1} playlistcontrol cmd:load .* count:(\d+)', '{CUSTOM_PATTERN1} playlist_tracks (\d+[^?])', '{CUSTOM_PATTERN1} status(?:.*)playlist tracks:(\d*[^\s]+)']},
'clear': {'read': True, 'write': True, 'write_cmd': '{CUSTOM_ATTR1} playlist clear', 'item_type': 'bool', 'dev_datatype': 'str', 'reply_pattern': '{CUSTOM_PATTERN1} playlist clear$', 'item_attrs': {'enforce': True, 'attributes': {'eval': 'True if value else None'}}},
'delete': {'read': True, 'write': True, 'write_cmd': '{CUSTOM_ATTR1} playlist delete {VALUE}', 'item_type': 'str', 'dev_datatype': 'str', 'reply_pattern': '{CUSTOM_PATTERN1} playlist delete (.*)', 'item_attrs': {'enforce': True}},
'deleteitem': {'read': True, 'write': True, 'write_cmd': '{CUSTOM_ATTR1} playlist deleteitem {VALUE}', 'item_type': 'str', 'dev_datatype': 'str', 'reply_pattern': '{CUSTOM_PATTERN1} playlist deleteitem (.*)', 'item_attrs': {'enforce': True}},
Expand Down
Loading

0 comments on commit 9a71c89

Please sign in to comment.