Skip to content

Commit

Permalink
Set MPD output state based on client mute
Browse files Browse the repository at this point in the history
Before, we simply toggled the output enabled state, assuming that the
mute state changed.
  • Loading branch information
jplitza committed Nov 8, 2021
1 parent 88a3f4a commit a3e09ba
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,20 @@ async def async_snapcast_client_changed(self, client: snapcast.control.client.Sn
self._logger.debug('Ignoring change of snapcast client %s: No matching MPD output' % name)
return

if output.enabled != client.muted:
# If the output is not enabled and the client is muted (or vice
# versa), everything is fine.
return

self._logger.info('Turning %s MPD output %s' % (
'off' if self.mpd_outputs[name].enabled else 'on',
'off' if client.muted else 'on',
name
))

# determine which method to call
actor = self.mpd.disableoutput if output.enabled else self.mpd.enableoutput
actor = self.mpd.disableoutput if client.muted else self.mpd.enableoutput

# invert stored state of the output to avoid calling
# fake stored state of the output to avoid calling
# mpd_output_changed() from mpd_outputs_changed() when MPD notifies us
# about our own change
self.mpd_outputs[name].enabled = not self.mpd_outputs[name].enabled
Expand Down

0 comments on commit a3e09ba

Please sign in to comment.