From e0c73a61525f90fe6420aaeae4ecc0bfd195c8da Mon Sep 17 00:00:00 2001
From: jess <jess@jward.io>
Date: Fri, 31 Aug 2018 23:47:04 +0000
Subject: [PATCH] async loop moved to darkmute file. Minor comment changes:

---
 snap.py | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/snap.py b/snap.py
index 4f59709..d5a3d05 100644
--- a/snap.py
+++ b/snap.py
@@ -1,6 +1,5 @@
 from zeroconf import ServiceBrowser, Zeroconf
 import snapcast.control
-import asyncio
 import ipaddress
 import netifaces
 
@@ -17,7 +16,7 @@ class Scanner:
         self.services.append(info)
 
 
-def get_snapcast_server():
+def get_snapcast_server(loop):
     '''Scan for services then find snapcast server.'''
     zeroconf = Zeroconf()
     listener = Scanner()
@@ -26,8 +25,6 @@ def get_snapcast_server():
     while listener.services == []:
         pass
 
-    # Snapcast library only supports asynchronous so need to wrap in async loop
-    loop = asyncio.get_event_loop()
     server_ip_bytes = listener.services[0].address
     server_ip = str(ipaddress.ip_address(server_ip_bytes))
     # Snapserver.__init__ does not work in snapcast==2.0.8
@@ -37,7 +34,6 @@ def get_snapcast_server():
     create_server_coroutine = snapcast.control.create_server(
         loop, server_ip, reconnect=True)
     server = loop.run_until_complete(create_server_coroutine)
-    loop.close()
 
     return server
 
@@ -66,9 +62,11 @@ def get_mac_addresses():
     return mac_addresses
 
 
-def get_snapcast_client(server):
+def get_snapcast_client(loop):
     '''Scan through list of clients to find correct one.'''
+    server = get_snapcast_server(loop)
+    mac_addresses = get_mac_addresses()
     for client in server.clients:
-        print(client.name)
-        print(client.identifier)
-    # TODO Scroll through list of clients and find right one
+        # print(client.identifier)
+        if client.identifier in mac_addresses:
+            return client
-- 
GitLab