# Path: extras/python/iotsaControl/consts.py
# class UserIntervention(Exception):
#     pass
# 
# VERBOSE=[]


from future import standard_library
from builtins import str
from builtins import object
from .consts import UserIntervention, VERBOSE
import sys
import time
    import zeroconf
from __future__ import unicode_literals
standard_library.install_aliases()


class PlatformMDNSCollector(object):
    """Default mDNS handling: ask the user"""
    def __init__(self):
        pass
        
    def run(self, timeout=5):
        """Run for a short while (5 seconds default) and collect all iotsa devices found. Return list."""
        raise UserIntervention("Please browse for mDNS services _iotsa._tcp.local")
 
if sys.platform in ('darwin', 'linux2', 'linux'):
    
    class PlatformMDNSCollector(object):
        def __init__(self):
            self.found = []
            if VERBOSE: print('Start mDNS browser for _iotsa._tcp.local.')
            self.zeroconf = zeroconf.Zeroconf()
            self.browsers = []
            self.browsers.append(zeroconf.ServiceBrowser(self.zeroconf, "_iotsa._tcp.local.", self))
            self.browsers.append(zeroconf.ServiceBrowser(self.zeroconf, "_iotsa._http._tcp.local.", self))
            self.browsers.append(zeroconf.ServiceBrowser(self.zeroconf, "_iotsa._https._tcp.local.", self))
            self.browsers.append(zeroconf.ServiceBrowser(self.zeroconf, "_iotsa._coap._tcp.local.", self))
        
        def remove_service(self, zc, type, name):
            pass
        
        def add_service(self, zc, type, name):

# Path: extras/python/iotsaControl/consts.py
# class UserIntervention(Exception):
#     pass
# 
# VERBOSE=[]


# Path: extras/python/iotsaControl/mdns.py
from future import standard_library
from builtins import str
from builtins import object
from .consts import UserIntervention, VERBOSE
import sys
import time
    import zeroconf

from __future__ import unicode_literals
standard_library.install_aliases()


class PlatformMDNSCollector(object):
    """Default mDNS handling: ask the user"""
    def __init__(self):
        pass
        
    def run(self, timeout=5):
        """Run for a short while (5 seconds default) and collect all iotsa devices found. Return list."""
        raise UserIntervention("Please browse for mDNS services _iotsa._tcp.local")
 
if sys.platform in ('darwin', 'linux2', 'linux'):
    
    class PlatformMDNSCollector(object):
        def __init__(self):
            self.found = []
            if VERBOSE: print('Start mDNS browser for _iotsa._tcp.local.')
            self.zeroconf = zeroconf.Zeroconf()
            self.browsers = []
            self.browsers.append(zeroconf.ServiceBrowser(self.zeroconf, "_iotsa._tcp.local.", self))
            self.browsers.append(zeroconf.ServiceBrowser(self.zeroconf, "_iotsa._http._tcp.local.", self))
            self.browsers.append(zeroconf.ServiceBrowser(self.zeroconf, "_iotsa._https._tcp.local.", self))
            self.browsers.append(zeroconf.ServiceBrowser(self.zeroconf, "_iotsa._coap._tcp.local.", self))
        
        def remove_service(self, zc, type, name):
            pass
        
        def add_service(self, zc, type, name):

            if VERBOSE: print('Found mDNS entry for', name, 'type:', type)