Skip to content

Commit

Permalink
Enabled scanning for multiple mDNS types
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel Collins committed Jun 17, 2020
1 parent 9c8002b commit f3d871b
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions labthings_client/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@

from pprint import pprint

from thing import FoundThing
from .thing import FoundThing

class Browser:
def __init__(self, service="labthing", protocol="tcp"):
self.service_record = f"_{service}._{protocol}.local."
def __init__(self, types=["labthing", "webthing"], protocol="tcp"):
self.service_types = [f"_{service_type}._{protocol}.local." for service_type in types]

self.services = {}

self.add_service_callbacks = set()
self.remove_service_callbacks = set()

self._zeroconf = Zeroconf()
self._browser = None
self._browsers = set()

def __enter__(self):
self.open()
Expand All @@ -27,7 +27,8 @@ def __exit__(self ,type, value, traceback):
return self.close()

def open(self):
self._browser = ServiceBrowser(self._zeroconf, self.service_record, self)
for service_type in self.service_types:
self._browsers.add(ServiceBrowser(self._zeroconf, service_type, self))
return self

def close(self, *args, **kwargs):
Expand Down

0 comments on commit f3d871b

Please sign in to comment.