From 1b4c67c776497d588749246e705d0197df549567 Mon Sep 17 00:00:00 2001 From: jess <jess@jward.io> Date: Tue, 12 Jun 2018 17:50:31 +0000 Subject: [PATCH] put zeroconf into function, added get_client logic --- snapcast.py | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/snapcast.py b/snapcast.py index 34297ab..0aecb22 100644 --- a/snapcast.py +++ b/snapcast.py @@ -1,27 +1,35 @@ from zeroconf import ServiceBrowser, Zeroconf +import snapcast.control class Scanner: + services = [] + def remove_service(self, zeroconf, type, name): print("Service %s removed" % (name,)) def add_service(self, zeroconf, type, name): - snapcast_server = [] info = zeroconf.get_service_info(type, name) - snapcast_server.append(name, info) + self.services.append(info) -zeroconf = Zeroconf() -listener = Scanner() -browser = ServiceBrowser(zeroconf, "_snapcast._tcp.local.", listener) +def get_snapcast_server(services): + '''scan for services then find snapcast server''' + zeroconf = Zeroconf() + listener = Scanner() + ServiceBrowser(zeroconf, "_snapcast._tcp.local.", listener) + server = snapcast.control.Snapserver(services, snapcast.control. + CONTROL.PORT) -try: - input("Press enter to exit...\n\n") -finally: - zeroconf.close() + while services == []: + pass + return server -def get_snapcast_client(): - pass +def get_snapcast_client(server): + '''scan through list of clients to find correct one''' + for client in server.clients: + print(client.name) + print(client.identifier) # TODO Scroll through list of clients and find right one -- GitLab