From 3e84e4eb04a2a0d25ac891cb8d8ec1f85a78818a Mon Sep 17 00:00:00 2001
From: Johannes Kung <johku144@student.liu.se>
Date: Mon, 17 Jun 2024 11:54:09 +0200
Subject: [PATCH] Refactor signal

---
 src/simudator/core/signal.py | 89 +++++++++++++++++++++++-------------
 1 file changed, 56 insertions(+), 33 deletions(-)

diff --git a/src/simudator/core/signal.py b/src/simudator/core/signal.py
index cfd6de1..cbf9505 100644
--- a/src/simudator/core/signal.py
+++ b/src/simudator/core/signal.py
@@ -5,54 +5,77 @@ from typing import Any
 
 class Signal:
     """
-    Handles datatransportation between modules in the processor.
-    Each signal has one source module and can have multiple
-    destination modules.
+    Signal class to send data between modules in a processor.
+
+    Parameters
+    ----------
+    processor : Processor
+        Processor that the signal belongs to. Needed to queue processor modules
+        for update.
+    name : str
+        Name of the signal.
+    value : Any
+        Initial value of the signal.
     """
-    def __init__(self, processor: Processor, name: str = "Signal", value = None):
-        self.processor = processor
-        self.name = name
-        self.source = None
-        self.destinations = set()
-        self.value = value
+
+    def __init__(self, processor: Processor, name: str = "Signal", value=None):
+        self._processor = processor
+        self._name = name
+        self._source = None
+        self._destinations = set()
+        self._value = value
 
     def add_destination(self, module: Module) -> None:
-        """
-        Add a destination module that the signal will send new
+        """Add a module as a destination that the signal will send new
         values to.
         """
-        self.destinations.add(module)
-
-    def set_source(self, module: Module) -> None:
-        """
-        Set source module that will send values through the signal.
-        """
-        self.source = module
+        self._destinations.add(module)
 
     def update_value(self, value) -> None:
         """
-        Sets value in signal and queues destination moduels for update.
+        Set the value of the signal and queue destination modules for update.
+
+        Parameters
+        ----------
+        value : Any
+            Value to set the signal to.
         """
-        if value != self.value:
-            self.value = value
+        if value != self._value:
+            self._value = value
             # Inform the processor on what modules have been given
             # signal so they can update
-            for destination in self.destinations:
-                self.processor.add_modules_to_update(destination)
+            for destination in self._destinations:
+                self._processor.add_modules_to_update(destination)
 
     def get_value(self) -> Any:
-        """
-        Get the signals current value.
-        """
-        return self.value
+        """Get the current value of the signal.
 
-    def set_value(self, value) -> None:
+        Returns
+        -------
+        Any
+            Value of the signal.
         """
-        Set the value of the signal without queuing the destination
-        modules of the signal for update. This method should not
-        be called by a module.
+        return self._value
+
+    def set_value(self, value: Any) -> None:
+        """Set the value of the signal without queuing the destination
+        modules of the signal for update.
+
+        This method should not be called by a module.
+
+        Parameters
+        ----------
+        value : any
+            Value to set the signal to.
         """
-        self.value = value
+        self._value = value
 
     def get_name(self) -> str:
-        return self.name
+        """Return the name of the signal.
+
+        Returns
+        -------
+        str
+            Name of the signal.
+        """
+        return self._name
-- 
GitLab