From: 
Subject: Debian changes

The Debian packaging of python-pilight is maintained in git, using a workflow
similar to the one described in dgit-maint-merge(7).
The Debian delta is represented by this one combined patch; there isn't a
patch queue that can be represented as a quilt series.

A detailed breakdown of the changes is available from their canonical
representation -- git commits in the packaging repository.
For example, to see the changes made by the Debian maintainer in the first
upload of upstream version 1.2.3, you could use:

    % git clone https://git.dgit.debian.org/python-pilight
    % cd python-pilight
    % git log --oneline 1.2.3..debian/1.2.3-1 -- . ':!debian'

(If you have dgit, use `dgit clone python-pilight`, rather than plain `git clone`.)

We don't use debian/source/options single-debian-patch because it has bugs.
Therefore, NMUs etc. may nevertheless have made additional patches.

---

diff --git a/pilight/__init__.py b/pilight/__init__.py
index 612f4b7..d540704 100644
--- a/pilight/__init__.py
+++ b/pilight/__init__.py
@@ -1,12 +1,12 @@
 # http://stackoverflow.com/questions/17583443/what-is-the-correct-way-to-share-package-version-with-setup-py-and-the-package
-from pkg_resources import get_distribution, DistributionNotFound
+from importlib.metadata import PackageNotFoundError, version
 
 __project__ = 'pilight'
 __version__ = None  # required for initial installation
 
 try:
-    __version__ = get_distribution(__project__).version
-except DistributionNotFound:
+    __version__ = version(__project__)
+except PackageNotFoundError:
     VERSION = __project__ + '-' + '(local)'
 else:
-    VERSION = __project__ + '-' + __version__
\ No newline at end of file
+    VERSION = __project__ + '-' + __version__
diff --git a/pilight/test/pilight_daemon.py b/pilight/test/pilight_daemon.py
index 51bea7f..6639a8c 100644
--- a/pilight/test/pilight_daemon.py
+++ b/pilight/test/pilight_daemon.py
@@ -22,7 +22,7 @@ else:
 
 # Settings for the pilight-daemon simulation
 HOST = '127.0.0.1'
-PORT = 5000
+PORT = 0  # Let the operating system allocate an available port.
 
 SEND_DELAY = 0.1  # How often a fake code is send in seconds
 
@@ -93,6 +93,7 @@ class PilightDeamonSim(threading.Thread):
         else:  # Called when for loop not breaked
             raise RuntimeError('Cannot create socket connection')
 
+        self.port = self.server_socket.getsockname()[1]
         self.server_socket.listen(2)  # Allow 2 connections
         self.client_sockets = []
 
diff --git a/pilight/test/test_client.py b/pilight/test/test_client.py
index a39d36e..f35fc67 100644
--- a/pilight/test/test_client.py
+++ b/pilight/test/test_client.py
@@ -27,8 +27,8 @@ class TestClient(unittest.TestCase):
 
     def test_client_connection(self):
         """Test for successfull pilight daemon connection."""
-        with pilight_daemon.PilightDaemon():
-            pilight.Client(host=pilight_daemon.HOST, port=pilight_daemon.PORT)
+        with pilight_daemon.PilightDaemon() as my_daemon:
+            pilight.Client(host=pilight_daemon.HOST, port=my_daemon.port)
 
     def test_client_connection_fail(self):
         """Test for failing pilight daemon connection."""
@@ -39,7 +39,7 @@ class TestClient(unittest.TestCase):
     def test_send_code(self):
         """Test for successfull code send."""
         with pilight_daemon.PilightDaemon() as my_daemon:
-            pilight_client = pilight.Client(host=pilight_daemon.HOST, port=pilight_daemon.PORT)
+            pilight_client = pilight.Client(host=pilight_daemon.HOST, port=my_daemon.port)
             pilight_client.send_code(data={'protocol': 'daycom'})
             time.sleep(1)
 
@@ -47,8 +47,8 @@ class TestClient(unittest.TestCase):
 
     def test_send_code_fail(self):
         """Tests for failed code send."""
-        with pilight_daemon.PilightDaemon():
-            pilight_client = pilight.Client(host=pilight_daemon.HOST, port=pilight_daemon.PORT)
+        with pilight_daemon.PilightDaemon() as my_daemon:
+            pilight_client = pilight.Client(host=pilight_daemon.HOST, port=my_daemon.port)
 
             # Test 1: Use unknows protocol
             with self.assertRaises(IOError):
@@ -67,8 +67,8 @@ class TestClient(unittest.TestCase):
                 "receiver": 1  # To receive the RF data received by pilight
             }
         }
-        with pilight_daemon.PilightDaemon(send_codes=True):
-            pilight_client = pilight.Client(host=pilight_daemon.HOST, port=pilight_daemon.PORT,
+        with pilight_daemon.PilightDaemon(send_codes=True) as my_daemon:
+            pilight_client = pilight.Client(host=pilight_daemon.HOST, port=my_daemon.port,
                                             recv_ident=recv_ident, recv_codes_only=False)
             pilight_client.set_callback(_callback)
             pilight_client.start()
@@ -79,8 +79,8 @@ class TestClient(unittest.TestCase):
     def test_receive_code(self, mock):
         """Test for successfull code received."""
 
-        with pilight_daemon.PilightDaemon(send_codes=True):
-            pilight_client = pilight.Client(host=pilight_daemon.HOST, port=pilight_daemon.PORT)
+        with pilight_daemon.PilightDaemon(send_codes=True) as my_daemon:
+            pilight_client = pilight.Client(host=pilight_daemon.HOST, port=my_daemon.port)
             pilight_client.set_callback(_callback)
             pilight_client.start()
             time.sleep(2)
@@ -92,8 +92,8 @@ class TestClient(unittest.TestCase):
     @patch('pilight.test.test_client._callback')
     def test_no_receive_filter(self, mock):
         """Test for successfull code received."""
-        with pilight_daemon.PilightDaemon(send_codes=True):
-            pilight_client = pilight.Client(host=pilight_daemon.HOST, port=pilight_daemon.PORT, veto_repeats=False)
+        with pilight_daemon.PilightDaemon(send_codes=True) as my_daemon:
+            pilight_client = pilight.Client(host=pilight_daemon.HOST, port=my_daemon.port, veto_repeats=False)
             pilight_client.set_callback(_callback)
             pilight_client.start()
             time.sleep(2)
@@ -115,13 +115,13 @@ class TestClient(unittest.TestCase):
         }
 
         with self.assertRaises(IOError):
-            with pilight_daemon.PilightDaemon(send_codes=True):
-                pilight.Client(host=pilight_daemon.HOST, port=pilight_daemon.PORT, recv_ident=recv_ident)
+            with pilight_daemon.PilightDaemon(send_codes=True) as my_daemon:
+                pilight.Client(host=pilight_daemon.HOST, port=my_daemon.port, recv_ident=recv_ident)
 
     def test_no_callback(self):
         """Test for no callback defined."""
-        with pilight_daemon.PilightDaemon(send_codes=True):
-            pilight_client = pilight.Client(host=pilight_daemon.HOST, port=pilight_daemon.PORT)
+        with pilight_daemon.PilightDaemon(send_codes=True) as my_daemon:
+            pilight_client = pilight.Client(host=pilight_daemon.HOST, port=my_daemon.port)
             pilight_client.start()
             time.sleep(1)  # Give time to set thread status
 
