Skip to content

Commit

Permalink
lms: re-read players on new client and player (dis)connect as well as…
Browse files Browse the repository at this point in the history
… rename
  • Loading branch information
onkelandy committed Jan 24, 2025
1 parent 3c74366 commit 39d147a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
19 changes: 18 additions & 1 deletion lms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,16 @@ def trigger_read(command):
self.send_command(command + CUSTOM_SEP + custom)

if command == f'server.newclient':
self.logger.debug(f"Got new or removed client connection {command}, re-reading players")
self.logger.debug(f"Got new client connection {command}, re-reading players.")
self.send_command('server.players')
if value in self._custom_values.get(1):
self.logger.debug(f"Subscribing to updates: {value}")
self.send_command('player.info.player.status_subscribe' + CUSTOM_SEP + value, True)
self.read_all_commands('player.info.currentsong' + CUSTOM_SEP + value)
self.read_all_commands('player.control' + CUSTOM_SEP + value)

if command == f'server.forgetclient':
self.logger.debug(f"Got forget client connection {command}: {value}, re-reading players")
self.send_command('server.players')

if command == f'server.players':
Expand Down Expand Up @@ -152,6 +161,14 @@ def find_player_index(target, mac_list):
if not custom:
return

if command == f'player.info.player.connected{CUSTOM_SEP}{custom}':
self.logger.debug(f"Got client (dis)connection {command}: {value}, re-reading players")
self.send_command('server.players')

if command == f'player.info.player.name{CUSTOM_SEP}{custom}':
self.logger.debug(f"Got name {command}: {value}, re-reading players")
self.send_command('server.players')

if command == f'player.playlist.rename_current{CUSTOM_SEP}{custom}':
self.logger.debug(f"Got command rename_current {command}, re-reading playlists")
self.send_command('server.playlists.available')
Expand Down
3 changes: 2 additions & 1 deletion lms/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
'members': {'read': True, 'write': False, 'read_cmd': 'syncgroups ?', 'item_type': 'list', 'dev_datatype': 'LMSSyncmembers', 'reply_pattern': r'^syncgroups\s?(.*)?$', 'custom_disabled': True, 'item_attrs': {'initial': True}},
'names': {'read': True, 'write': False, 'read_cmd': 'syncgroups ?', 'item_type': 'list', 'dev_datatype': 'LMSSyncnames', 'reply_pattern': r'^syncgroups\s?(.*)?$', 'custom_disabled': True, 'item_attrs': {'initial': False}},
},
'newclient': {'read': True, 'write': False, 'item_type': 'str', 'dev_datatype': 'str', 'reply_pattern': [r'^({CUSTOM_PATTERN1}) client new$', r'^({CUSTOM_PATTERN1}) client forget$'], 'custom_disabled': True},
'newclient': {'read': True, 'write': False, 'item_type': 'str', 'dev_datatype': 'str', 'reply_pattern': [r'^({CUSTOM_PATTERN1}) client new$', r'^({CUSTOM_PATTERN1}) client reconnect$'], 'custom_disabled': True},
'forgetclient': {'read': True, 'write': False, 'item_type': 'str', 'dev_datatype': 'str', 'reply_pattern': r'^({CUSTOM_PATTERN1}) client forget$', 'custom_disabled': True},
'players': {'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': True, 'item_template': 'players'}},
'playlists': {
'available': {'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])? (.*)', 'custom_disabled': True, 'item_attrs': {'initial': True, 'item_template': 'playlists'}},
Expand Down
12 changes: 12 additions & 0 deletions lms/plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,12 @@ item_structs:
sqb_read@instance: true
sqb_write@instance: false

forgetclient:
type: str
sqb_command@instance: server.forgetclient
sqb_read@instance: true
sqb_write@instance: false

players:
type: dict
sqb_command@instance: server.players
Expand Down Expand Up @@ -1370,6 +1376,12 @@ item_structs:
sqb_read@instance: true
sqb_write@instance: false

forgetclient:
type: str
sqb_command@instance: server.forgetclient
sqb_read@instance: true
sqb_write@instance: false

players:
type: dict
sqb_command@instance: server.players
Expand Down

0 comments on commit 39d147a

Please sign in to comment.