From 6094d29ce7300c8bab7a26bbc2a32ae66cabcb58 Mon Sep 17 00:00:00 2001
From: jess <jess@jward.io>
Date: Fri, 14 Sep 2018 16:15:15 +0000
Subject: [PATCH] mute status tracking to clean logs

---
 darkmute/dark_mute.py | 12 +++++++-----
 setup.py              |  2 +-
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/darkmute/dark_mute.py b/darkmute/dark_mute.py
index d51369a..358c639 100644
--- a/darkmute/dark_mute.py
+++ b/darkmute/dark_mute.py
@@ -4,7 +4,7 @@ import time
 import RPi.GPIO as GPIO
 from .snap import get_snapcast_client
 
-
+logging.basicConfig(level=logging.INFO)
 SENSOR_PIN = 7
 MUTE_BRIGHTNESS = 0.1
 
@@ -12,22 +12,24 @@ MUTE_BRIGHTNESS = 0.1
 def dark_mute():
     '''Uses brighness level to mute or unmute device'''
     # Snapcast library only supports asynchronous so need to wrap in async loop
+    logger = logging.getLogger('darkmute')
     loop = asyncio.new_event_loop()
     client = get_snapcast_client(loop)
-    logger = logging.getLogger('darkmute')
-    logging.basicConfig(level=logging.INFO)
     GPIO.setmode(GPIO.BOARD)
+    is_muted = client.muted
     try:
         while True:
             brightness = measure_brightness(SENSOR_PIN)
-            if brightness < MUTE_BRIGHTNESS:
+            if brightness < MUTE_BRIGHTNESS and not is_muted:
                 # client.muted did not work so need client.set_muted
                 # loop used here and also passed into snap.py to get server
                 logger.info('muting client')
                 loop.run_until_complete(client.set_muted(True))
-            else:
+                is_muted = client.muted
+            elif brightness > MUTE_BRIGHTNESS and is_muted:
                 logger.info('unmuting client')
                 loop.run_until_complete(client.set_muted(False))
+                is_muted = client.muted
     except KeyboardInterrupt:
         pass
     finally:
diff --git a/setup.py b/setup.py
index 8cdcc99..1141efd 100644
--- a/setup.py
+++ b/setup.py
@@ -5,7 +5,7 @@ with open("README.md", "r") as fh:
 
 setup(
     name="DarkMute",
-    version="0.1.7",
+    version="0.1.8",
     author="Jessica Ward",
     description="Mute snapcast client playing on raspi3",
     long_description=long_description,
-- 
GitLab