Skip to content

Commit

Permalink
lms: update commands and lookup handling
Browse files Browse the repository at this point in the history
  • Loading branch information
onkelandy committed Jan 3, 2025
1 parent 20fa474 commit 5cb115a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 33 deletions.
6 changes: 3 additions & 3 deletions lms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def on_connect(self, by=None):
self.send_command('server.listenmode', True)
if not self.items.match_items('*.database.players'):
self.logger.debug(f"Querying players.")
self.send_command('player.info.playernames', None)
self.send_command('player.info.players', None)


def _transform_send_data(self, data=None, **kwargs):
Expand All @@ -107,7 +107,7 @@ def trigger_read(command):
for player in value.keys():
self._dispatch_callback('player.info.modelname' + CUSTOM_SEP + player, value[player].get('modelname'), by)
self._dispatch_callback('player.info.firmware' + CUSTOM_SEP + player, value[player].get('firmware'), by)
self._dispatch_callback('player.info.playernames' + CUSTOM_SEP + player, value, by)
self._dispatch_callback('player.info.players' + CUSTOM_SEP + player, value, by)

if command == f'database.playlists':
self.logger.debug(f"Got command playlists {command} data {data} value {value} by {by}")
Expand All @@ -118,7 +118,7 @@ def trigger_read(command):
return

if command == f'player.playlist.rename{CUSTOM_SEP}{custom}':
trigger_read('player.info.all_playlists')
trigger_read('player.info.playlists')

# set alarm
if command == f'player.control.alarms{CUSTOM_SEP}{custom}':
Expand Down
16 changes: 6 additions & 10 deletions lms/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
'playlist': {
'rename_current': {'read': False, 'write': True, 'item_type': 'str', 'write_cmd': 'playlists rename playlist_id:{CUSTOM_PARAM1:CURRENT_LIST_ID} newname:{VALUE}', 'dev_datatype': 'str', 'reply_pattern': r'^playlists rename playlist_id:(?:\d+) newname:(.*)', 'custom_disabled': True},
'delete_current': {'read': False, 'write': True, 'write_cmd': 'playlists delete playlist_id:{CUSTOM_PARAM1:CURRENT_LIST_ID}', 'item_type': 'bool', 'dev_datatype': 'str', 'reply_pattern': r'^playlists delete playlist_id:(\d+)', 'custom_disabled': True, 'item_attrs': {'enforce': True, 'attributes': {'autotimer': '1s = 0', 'remark': 'Be careful, instantly deletes the current playlist!'}}},
'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}$', r'^{CUSTOM_PATTERN1} status(?:.*)playlist repeat:{LOOKUP}$'], 'lookup': 'TEST', 'item_attrs': {'initial': True, 'attributes': {'remark': '0 = Off, 1 = Song, 2 = Playlist'}, 'lookup_item': True}},
'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}$', r'^{CUSTOM_PATTERN1} status(?:.*)playlist repeat:{LOOKUP}$'], 'lookup': 'REPEAT', 'item_attrs': {'initial': True, '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}$', r'^{CUSTOM_PATTERN1} status(?:.*)playlist shuffle:{LOOKUP}$'], 'lookup': 'SHUFFLE', 'item_attrs': {'initial': True, '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+)$', r'^{CUSTOM_PATTERN1} status(?:.*)playlist index:(\d*[^\s]+)', r'^{CUSTOM_PATTERN1} prefset server currentSong (\d+)$', r'^{CUSTOM_PATTERN1} playlist jump (\d+)', r'^{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+)$', r'^{CUSTOM_PATTERN1} playlist name (.*[^?])', r'^{CUSTOM_PATTERN1} playlist playlistsinfo id:(?:\d+) name:(.*) modified:']},
Expand All @@ -95,7 +95,7 @@
'customskip': {'read': False, 'write': True, 'item_type': 'str', 'write_cmd': '{CUSTOM_ATTR1} customskip setfilter filter{VALUE}.cs.xml', 'dev_datatype': 'str', 'item_attrs': {'attributes': {'cache': True}}}
},
'info': {
'playernames': {'read': True, 'write': False, 'read_cmd': 'players 0 100', 'item_type': 'dict', 'dev_datatype': 'LMSPlayers', 'reply_pattern': r'^players 0 100 (.*)', 'custom_disabled': True, 'item_attrs': {'initial': False, 'item_template': 'players'}},
'players': {'read': True, 'write': False, 'read_cmd': 'players 0 100', 'item_type': 'dict', 'dev_datatype': 'LMSPlayers', 'reply_pattern': r'^players 0 100 (.*)', 'item_attrs': {'initial': False, 'item_template': 'players'}},
'playlists': {'read': True, 'write': False, 'read_cmd': 'playlists 0 1000 tags:u', 'item_type': 'dict', 'dev_datatype': 'LMSPlaylists', 'reply_pattern': r'^playlists 0 1000(?: tags:[u,s])? (.*)', 'item_attrs': {'initial': False, 'item_template': 'playlists'}},
'status': {'read': True, 'write': False, 'read_cmd': '{CUSTOM_ATTR1} status', 'item_type': 'str', 'dev_datatype': 'raw', 'reply_pattern': r'^{CUSTOM_PATTERN1} status\s+(.*)', 'item_attrs': {'initial': True}},
'connected': {'read': True, 'write': False, 'read_cmd': '{CUSTOM_ATTR1} connected ?', 'item_type': 'bool', 'dev_datatype': 'LMSConnection', 'reply_pattern': [r'^{CUSTOM_PATTERN1} (?:connected|client) (\d|disconnect|reconnect)', r'^{CUSTOM_PATTERN1} status(?:.*)player_connected:([^\s]+)']},
Expand Down Expand Up @@ -128,33 +128,29 @@
'2': 'ALBUM'
},
'TEST': {
'0': 'OFF'
}
}

item_templates = {
'players': {
'lookup':
'on_change': '.lu_names = {key: value["name"] for key, value in sh..self().items()}',
'lu_names':
{
'type': 'dict',
'eval_trigger': '..',
'eval': '{value["name"]: key for key, value in sh...().items()}',
'sqb_lookup@instance': 'TEST#fwd'
}
},
'playlists': {
'on_change': ['.lu_ids = {value["id"]: key for key, value in sh..self().items()}', '.lu_urls = {value["url"]: key for key, value in sh..self().items()}'],
'lu_ids':
{
'type': 'dict',
'eval_trigger': '...',
'eval': '{key: value["id"] for key, value in sh....().items()}',
'sqb_lookup@instance': 'PLAYLIST_IDS#fwd'

},
'lu_urls':
{
'type': 'dict',
'eval_trigger': '...',
'eval': '{key: value["url"] for key, value in sh....().items()}',
'sqb_lookup@instance': 'PLAYLIST_URLS#fwd'
},
},
Expand Down
36 changes: 16 additions & 20 deletions lms/plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ item_structs:

lookup:
type: list
sqb_lookup@instance: TEST#list
sqb_lookup@instance: REPEAT#list

shuffle:
type: str
Expand Down Expand Up @@ -1000,19 +1000,18 @@ item_structs:
enforce_updates: true
sqb_read_group_trigger@instance: player.info

playernames:
players:
type: dict
sqb_command@instance: player.info.playernames
sqb_command@instance: player.info.players
sqb_read@instance: true
sqb_write@instance: false
sqb_read_group@instance:
- player
- player.info
on_change: '.lu_names = {key: value["name"] for key, value in sh..self().items()}'

lookup:
lu_names:
type: dict
eval_trigger: '..'
eval: '{value["name"]: key for key, value in sh...().items()}'
sqb_lookup@instance: TEST#fwd

playlists:
Expand All @@ -1023,17 +1022,16 @@ item_structs:
sqb_read_group@instance:
- player
- player.info
on_change:
- '.lu_ids = {value["id"]: key for key, value in sh..self().items()}'
- '.lu_urls = {value["url"]: key for key, value in sh..self().items()}'

lu_ids:
type: dict
eval_trigger: '...'
eval: '{key: value["id"] for key, value in sh....().items()}'
sqb_lookup@instance: PLAYLIST_IDS#fwd

lu_urls:
type: dict
eval_trigger: '...'
eval: '{key: value["url"] for key, value in sh....().items()}'
sqb_lookup@instance: PLAYLIST_URLS#fwd

status:
Expand Down Expand Up @@ -1714,7 +1712,7 @@ item_structs:

lookup:
type: list
sqb_lookup@instance: TEST#list
sqb_lookup@instance: REPEAT#list

shuffle:
type: str
Expand Down Expand Up @@ -1925,20 +1923,19 @@ item_structs:
enforce_updates: true
sqb_read_group_trigger@instance: ALL.player.info

playernames:
players:
type: dict
sqb_command@instance: player.info.playernames
sqb_command@instance: player.info.players
sqb_read@instance: true
sqb_write@instance: false
sqb_read_group@instance:
- ALL
- ALL.player
- ALL.player.info
on_change: '.lu_names = {key: value["name"] for key, value in sh..self().items()}'

lookup:
lu_names:
type: dict
eval_trigger: '..'
eval: '{value["name"]: key for key, value in sh...().items()}'
sqb_lookup@instance: TEST#fwd

playlists:
Expand All @@ -1950,17 +1947,16 @@ item_structs:
- ALL
- ALL.player
- ALL.player.info
on_change:
- '.lu_ids = {value["id"]: key for key, value in sh..self().items()}'
- '.lu_urls = {value["url"]: key for key, value in sh..self().items()}'

lu_ids:
type: dict
eval_trigger: '...'
eval: '{key: value["id"] for key, value in sh....().items()}'
sqb_lookup@instance: PLAYLIST_IDS#fwd

lu_urls:
type: dict
eval_trigger: '...'
eval: '{key: value["url"] for key, value in sh....().items()}'
sqb_lookup@instance: PLAYLIST_URLS#fwd

status:
Expand Down

0 comments on commit 5cb115a

Please sign in to comment.