commit c4999e79e4d2ac52f41cf189bd958870044b375d
Author: MFori <forejt.martin97@gmail.com>
Date:   Mon Apr 26 16:35:47 2021 +0200

    Re #8566 - add params passed to start subscriber

diff --git a/aswi2021vochomurka/service/mqtt/mqtt_subscriber.py b/aswi2021vochomurka/service/mqtt/mqtt_subscriber.py
index d8d88b8..0d2bd22 100644
--- a/aswi2021vochomurka/service/mqtt/mqtt_subscriber.py
+++ b/aswi2021vochomurka/service/mqtt/mqtt_subscriber.py
@@ -12,7 +12,9 @@ class MQTTSubscriber(Subscriber):
         self.callback.onConnected()
         # Subscribing in on_connect() means that if we lose the connection and
         # reconnect then subscriptions will be renewed.
-        client.subscribe("#")
+        for topic in self.params.topics:
+            print("Subscribed to topic: " + topic)
+            client.subscribe(topic)
 
     # The callback for when a PUBLISH message is received from the server.
     def on_message(self, client, userdata, message):
@@ -29,10 +31,18 @@ class MQTTSubscriber(Subscriber):
         client.on_message = self.on_message
         client.on_disconnect = self.on_disconnect
 
+        if not self.params.anonymous:
+            client.tls_set()
+            client.username_pw_set(self.params.username, self.params.password)
+
         try:
-            client.connect("localhost", 1883, 60)
+            client.connect(
+                self.params.connection.host,
+                self.params.connection.port,
+                self.params.connection.timeout
+            )
         except Exception as error:
-            self.error.emit(error)
+            self.callback.onError()
             return
 
         client.loop_forever()
diff --git a/aswi2021vochomurka/service/subscriber.py b/aswi2021vochomurka/service/subscriber.py
index 6eee77c..9ac8e6b 100644
--- a/aswi2021vochomurka/service/subscriber.py
+++ b/aswi2021vochomurka/service/subscriber.py
@@ -1,12 +1,13 @@
-from PyQt5.QtCore import pyqtSignal, QObject
-
 from aswi2021vochomurka.service.subscriber_callback import SubscriberCallback
+from aswi2021vochomurka.service.subscriber_params import SubscriberParams
 
 
 class Subscriber:
     callback: SubscriberCallback
+    params: SubscriberParams
 
-    def __init__(self, callback: SubscriberCallback):
+    def __init__(self, callback: SubscriberCallback, params: SubscriberParams):
         self.callback = callback
+        self.params = params
 
     def start(self): raise NotImplementedError
diff --git a/aswi2021vochomurka/service/subscriber_params.py b/aswi2021vochomurka/service/subscriber_params.py
new file mode 100644
index 0000000..7aaa227
--- /dev/null
+++ b/aswi2021vochomurka/service/subscriber_params.py
@@ -0,0 +1,21 @@
+from recordclass import RecordClass
+from typing import List
+
+
+class ConnectionParams(RecordClass):
+    host: str
+    port: int
+    timeout: int
+
+
+class SubscriberParams(RecordClass):
+    # list of topics to subscribe
+    topics: List[str]
+    # close limit in seconds
+    closeLimit: int
+    # connection params
+    connection: ConnectionParams
+    # connect anonymously to broker, otherwise provide username and password
+    anonymous: bool
+    username: str = ""
+    password: str = ""
diff --git a/aswi2021vochomurka/view/main_view.py b/aswi2021vochomurka/view/main_view.py
index bce17cd..60d690b 100644
--- a/aswi2021vochomurka/view/main_view.py
+++ b/aswi2021vochomurka/view/main_view.py
@@ -5,6 +5,7 @@ from aswi2021vochomurka.model.Message import Message
 from aswi2021vochomurka.service.mqtt.mqtt_subscriber import MQTTSubscriber
 from aswi2021vochomurka.service.subscriber import Subscriber
 from aswi2021vochomurka.service.subscriber_callback import SubscriberCallback
+from aswi2021vochomurka.service.subscriber_params import SubscriberParams, ConnectionParams
 
 
 class Worker(QObject, SubscriberCallback):
@@ -14,8 +15,15 @@ class Worker(QObject, SubscriberCallback):
     newMessage = pyqtSignal(str)
     subscriber: Subscriber = None
 
+    params = SubscriberParams(
+        ["/home/1", "/home/2"],
+        120,
+        ConnectionParams("localhost", 1883, 60),
+        True
+    )
+
     def start(self):
-        self.subscriber = MQTTSubscriber(self)
+        self.subscriber = MQTTSubscriber(self, self.params)
         self.subscriber.start()
 
     def onConnected(self):
