From a3e09bab2ac377ecda9aea8172e93aceb05f6d62 Mon Sep 17 00:00:00 2001 From: Jan-Philipp Litza Date: Mon, 8 Nov 2021 22:12:31 +0100 Subject: [PATCH] Set MPD output state based on client mute Before, we simply toggled the output enabled state, assuming that the mute state changed. --- main.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index 953429d..8706941 100644 --- a/main.py +++ b/main.py @@ -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