commit 523382c19daeef1d2eeec6e3ec868b24b011d36f
Author: MFori <forejt.martin97@gmail.com>
Date:   Fri May 28 00:21:07 2021 +0200

    Re: #8997 - refactoring, comments

diff --git a/aswi2021vochomurka/model/Message.py b/aswi2021vochomurka/model/Message.py
index 3e70281..9da2d52 100644
--- a/aswi2021vochomurka/model/Message.py
+++ b/aswi2021vochomurka/model/Message.py
@@ -2,6 +2,9 @@ from recordclass import RecordClass
 
 
 class Message(RecordClass):
+    """
+    Message wrapper
+    """
     topic: str
     index: int
     date: str
diff --git a/aswi2021vochomurka/service/file_manager.py b/aswi2021vochomurka/service/file_manager.py
index 7f29c4a..b9e2b29 100644
--- a/aswi2021vochomurka/service/file_manager.py
+++ b/aswi2021vochomurka/service/file_manager.py
@@ -15,17 +15,32 @@ trans = str.maketrans({
     ".": "_"})
 
 
-def create_filename(message: Message):
+def create_filename(message: Message) -> str:
+    """
+    Create file name based on message data
+    :param message: message
+    :return: filename
+    """
     name = "data/" + message.topic.translate(trans) + "/" + message.date + "_" + message.time + ".csv"
     return name
 
 
 class FileManager:
+    """
+    Helper class for writing incoming message to files
+    Each topic has created own instance of this class
+    """
     topic: str
     lastUpdate: float
     file: TextIO
 
     def __init__(self, topic: str, message: Message):
+        """
+        Constructing new FileManager will create new file and write first message
+        :param topic: topic
+        :param message: message
+        :except when creating new file fails
+        """
         self.topic = topic
         logging.debug('opening file ' + self.topic)
 
@@ -39,10 +54,17 @@ class FileManager:
         self.write(message)
 
     def write(self, message: Message):
+        """
+        Append message to file
+        :param message: message
+        """
         self.file.write(message.date + ";" + message.time + ";" + str(message.index) + ";" + str(message.value) + "\n")
         self.lastUpdate = time.time()
 
     def close(self):
+        """
+        Close file
+        """
         logging.debug('closing file ' + self.topic)
         self.file.flush()
         self.file.close()
diff --git a/aswi2021vochomurka/service/message_parser.py b/aswi2021vochomurka/service/message_parser.py
index 7c9a81a..9787dd3 100644
--- a/aswi2021vochomurka/service/message_parser.py
+++ b/aswi2021vochomurka/service/message_parser.py
@@ -6,10 +6,19 @@ from aswi2021vochomurka.model.Message import Message
 
 
 class ParseException(Exception):
+    """
+    May be throw when message has incorrect format
+    """
     pass
 
 
 def parse_mqtt_message(message: MQTTMessage) -> Message:
+    """
+    Parse MQTTMessage to Message
+    :param message: messsage
+    :return: message
+    :except: when message has incorrect format
+    """
     data = message.payload.decode("utf-8")
     parts = data.split(";")
     logging.debug('Parsing message: ' + data + ', parts: ' + str(len(parts)))
diff --git a/aswi2021vochomurka/service/mqtt/mqtt_subscriber.py b/aswi2021vochomurka/service/mqtt/mqtt_subscriber.py
index fb07edb..3466137 100644
--- a/aswi2021vochomurka/service/mqtt/mqtt_subscriber.py
+++ b/aswi2021vochomurka/service/mqtt/mqtt_subscriber.py
@@ -7,10 +7,16 @@ from aswi2021vochomurka.service.subscriber import Subscriber
 
 
 class MQTTSubscriber(Subscriber):
+    """
+    MQTT subscriber, implementation of Subscriber over MQTT protocol
+    """
     client: mqtt.Client = None
 
-    # The callback for when the client receives a CONNACK response from the server.
     def on_connect(self, client, userdata, flags, rc, properties=None):
+        """
+        The callback for when the client receives a CONNACK response from the server.
+        See: mqtt.Client.on_connect for info about params
+        """
         logging.info('Connected with result code ' + str(rc))
         self.callback.onConnected()
 
@@ -20,8 +26,11 @@ class MQTTSubscriber(Subscriber):
             logging.info('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: mqtt.MQTTMessage):
+        """
+        The callback for when a PUBLISH message is received from the server.
+        See: mqtt.Client.on_message for info about params
+        """
         try:
             m = parse_mqtt_message(message)
             logging.info('Message: ' + str(m))
@@ -34,11 +43,18 @@ class MQTTSubscriber(Subscriber):
             pass
 
     def on_disconnect(self, client, userdata, rc):
+        """
+        The callback for when the client disconnects from the server.
+        See: mqtt.Client.on_disconnect for info about params
+        """
         logging.info('Disconnected')
         self.callback.onDisconnected()
         self.stop()
 
     def start(self):
+        """
+        Start mqtt client
+        """
         super().start()
         client = mqtt.Client()
         self.client = client
@@ -66,6 +82,9 @@ class MQTTSubscriber(Subscriber):
         client.loop_forever()
 
     def stop(self):
+        """
+        Stop mqtt client
+        """
         super().stop()
         if self.client is not None:
             logging.info("Disconnecting from broker")
diff --git a/aswi2021vochomurka/service/subscriber.py b/aswi2021vochomurka/service/subscriber.py
index 25ce50b..82ad578 100644
--- a/aswi2021vochomurka/service/subscriber.py
+++ b/aswi2021vochomurka/service/subscriber.py
@@ -11,6 +11,11 @@ from aswi2021vochomurka.service.subscriber_params import SubscriberParams
 
 
 class Subscriber:
+    """
+    Subscriber is responsible for establishing communication with broker and notifying
+    about new message via callback
+    Subscriber must be started via 'start' method and stopped via 'stop' method
+    """
     callback: SubscriberCallback
     params: SubscriberParams
 
@@ -18,26 +23,43 @@ class Subscriber:
     files: Dict[str, FileManager] = {}
 
     def __init__(self, callback: SubscriberCallback, params: SubscriberParams):
+        """
+        Constructor
+        :param callback: callback
+        :param params: params
+        """
         self.callback = callback
         self.params = params
 
     def start(self):
+        """
+        Start subscriber
+        """
         # start scheduler to check closed topics
         self.scheduler = BackgroundScheduler()
         self.scheduler.add_job(self.check_closed_topics, 'interval', seconds=self.params.closeLimit)
         self.scheduler.start()
 
     def stop(self):
+        """
+        Stop subscriber
+        """
         if self.scheduler.state != STATE_STOPPED:
             self.scheduler.shutdown()
         self.close_files()
 
     def close_files(self):
+        """
+        Close all open files
+        """
         for topic in self.files:
             self.files.get(topic).close()
         self.files.clear()
 
     def check_closed_topics(self):
+        """
+        May be called periodically for checking for expired timeout for closing topic
+        """
         t = time.time()
         for topic in list(self.files):
             file = self.files.get(topic)
@@ -47,8 +69,14 @@ class Subscriber:
                 self.files.pop(topic)
 
     def write_to_file(self, message: Message):
+        """
+        Write message to file
+        :param message: message
+        """
         if message.topic in self.files:
+            # file exist, just append message
             self.files.get(message.topic).write(message)
         else:
+            # new message for this topic, create new file
             fm = FileManager(message.topic, message)
             self.files[message.topic] = fm
diff --git a/aswi2021vochomurka/service/subscriber_params.py b/aswi2021vochomurka/service/subscriber_params.py
index 7aaa227..e9af434 100644
--- a/aswi2021vochomurka/service/subscriber_params.py
+++ b/aswi2021vochomurka/service/subscriber_params.py
@@ -3,12 +3,18 @@ from typing import List
 
 
 class ConnectionParams(RecordClass):
+    """
+    Connection params to connect to broker
+    """
     host: str
     port: int
     timeout: int
 
 
 class SubscriberParams(RecordClass):
+    """
+    Params for Subscriber
+    """
     # list of topics to subscribe
     topics: List[str]
     # close limit in seconds
