Skip to content
Snippets Groups Projects
Commit e0c73a61 authored by Jess Ward's avatar Jess Ward
Browse files

async loop moved to darkmute file.

Minor comment changes:
parent a61eadd7
No related branches found
No related tags found
No related merge requests found
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment