diff --git a/pyharmony/discovery.py b/pyharmony/discovery.py old mode 100644 new mode 100755 index 5dd6d6d..9b61315 --- a/pyharmony/discovery.py +++ b/pyharmony/discovery.py @@ -49,7 +49,7 @@ def deserialize_response(self, response): pairs[key_value[0]] = key_value[1] return pairs - def discover(self, scan_attempts, scan_interval): + def discover(self, scan_attempts, scan_interval, broadcast_ip): # https://ruslanspivak.com/lsbaws-part1/ listen_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) listen_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) @@ -79,7 +79,7 @@ def discover(self, scan_attempts, scan_interval): for scan in range(0, scan_attempts): try: logger.debug('Pinging network on port %s', PORT_TO_ANNOUNCE) - ping_sock.sendto(MESSAGE, ('255.255.255.255', 5224)) + ping_sock.sendto(MESSAGE, (broadcast_ip, 5224)) except Exception as e: logger.error('Error pinging network: %s', e) @@ -94,7 +94,7 @@ def discover(self, scan_attempts, scan_interval): return [hubs[h] for h in hubs] -def discover(scan_attempts=10, scan_interval=1): +def discover(scan_attempts=10, scan_interval=1, broadcast_ip='255.255.255.255'): """Creates a Harmony client and initializes session. Args: @@ -104,4 +104,4 @@ def discover(scan_attempts=10, scan_interval=1): Returns: A list of Hub devices found and their configs """ - return Discovery().discover(scan_attempts, scan_interval) + return Discovery().discover(scan_attempts, scan_interval, broadcast_ip)