python 3.10 type definitions
[oam.git] / code / network-generator / model / python / o_ran_node.py
index e5a819e..f57279d 100644 (file)
 An abstract Class for O-RAN Node
 """
 from abc import abstractmethod
-from typing import Any, Dict
-
+from typing import Any
+import xml.etree.ElementTree as ET
 from model.python.geo_location import GeoLocation
 from model.python.o_ran_object import IORanObject, ORanObject
 import model.python.hexagon as Hexagon
-from model.python.hexagon import Hex, Layout, Point
+from model.python.hexagon import Hex, Layout
+from model.python.point import Point
 from model.python.o_ran_spiral_radius_profile import SpiralRadiusProfile
+from model.python.o_ran_termination_point import ORanTerminationPoint
 from model.python.type_definitions import (
     AddressType,
 )
@@ -40,7 +42,7 @@ class IORanNode(IORanObject):
         position: Hex = None,
         layout: Layout = None,
         spiralRadiusProfile: SpiralRadiusProfile = None,
-        parent  = None,
+        parent=None,
         **kwargs
     ):
         super().__init__(**kwargs)
@@ -49,8 +51,9 @@ class IORanNode(IORanObject):
         self.url = url
         self.position = position
         self.layout = layout
-        self.spiralRadiusProfile  = spiralRadiusProfile,
-        self.parent  = parent
+        self.spiralRadiusProfile = (spiralRadiusProfile,)
+        self.parent = parent
+
 
 # Define an abstract O-RAN Node class
 class ORanNode(ORanObject, IORanNode):
@@ -61,74 +64,82 @@ class ORanNode(ORanObject, IORanNode):
             of["geoLocation"] if of and "geoLocation" in of else GeoLocation()
         )
         self.url = of["url"] if of and "url" in of else self.id
-        self.position = of["position"] if of and "position" in of else Hex(0,0,0)
-        self.layout = of["layout"] if of and "layout" in of else Layout(Hexagon.layout_flat, Point(1,1), Point(0,0))
-        self.spiralRadiusProfile = of["spiralRadiusProfile"] if of and "spiralRadiusProfile" in of else SpiralRadiusProfile()
+        self.position = of["position"] if of and "position" in of else Hex(0, 0, 0)
+        self.layout = (
+            of["layout"]
+            if of and "layout" in of
+            else Layout(Hexagon.layout_flat, Point(1, 1), Point(0, 0))
+        )
+        self.spiralRadiusProfile = (
+            of["spiralRadiusProfile"]
+            if of and "spiralRadiusProfile" in of
+            else SpiralRadiusProfile()
+        )
         self.parent = of["parent"] if of and "parent" in of else None
         self._terminationPoints = []
 
     @property
-    def address(self):
+    def address(self) -> str:
         return self._address
 
     @address.setter
-    def address(self, value):
+    def address(self, value: str):
         self._address = value
 
     @property
-    def geoLocation(self):
+    def geoLocation(self) -> GeoLocation:
         return self._geographicalLocation
 
     @geoLocation.setter
-    def geoLocation(self, value):
+    def geoLocation(self, value: GeoLocation):
         self._geographicalLocation = value
 
     @property
-    def url(self):
+    def url(self) -> str:
         return self._url
 
     @url.setter
-    def url(self, value):
+    def url(self, value: str):
         self._url = value
 
     @property
-    def position(self):
+    def position(self) -> Hex:
         return self._position
 
     @position.setter
-    def position(self, value):
+    def position(self, value: Hex):
         self._position = value
 
     @property
-    def layout(self):
+    def layout(self) -> Layout:
         return self._layout
 
     @layout.setter
-    def layout(self, value):
+    def layout(self, value: Layout):
         self._layout = value
 
     @property
-    def spiralRadiusProfile(self):
+    def spiralRadiusProfile(self) -> SpiralRadiusProfile:
         return self._spiralRadiusProfile
 
     @spiralRadiusProfile.setter
-    def spiralRadiusProfile(self, value):
+    def spiralRadiusProfile(self, value: SpiralRadiusProfile):
         self._spiralRadiusProfile = value
 
     @property
-    def parent(self):
+    def parent(self) -> Any:  # expected are ORanNodes and all inherits for ORanNode
         return self._parent
 
     @parent.setter
-    def parent(self, value):
+    def parent(self, value: Any):
         self._parent = value
 
     @property
-    def terminationPoints(self):
+    def terminationPoints(self) -> list[ORanTerminationPoint]:
         return self._terminationPoints
 
-    def json(self):
-        result: Dict = super().json()
+    def json(self) -> dict[str, Any]:
+        result: dict = super().json()
         result["address"] = self.address
         result["geoLocation"] = self.geoLocation
         result["url"] = self.url
@@ -137,17 +148,17 @@ class ORanNode(ORanObject, IORanNode):
         result["parent"] = self.parent
         return result
 
-    def toTopology(self):
-        result:Dict[str, Any] = {
+    def toTopology(self) -> dict[str, Any]:
+        result: dict[str, Any] = {
             "node-id": self.name,
-            "ietf-network-topology:termination-point": self.terminationPoints
+            "ietf-network-topology:termination-point": self.terminationPoints,
         }
         return result
 
     @abstractmethod
-    def toKml(self):
+    def toKml(self) -> ET.Element | None:
         pass
 
     @abstractmethod
-    def toSvg(self):
-        pass
\ No newline at end of file
+    def toSvg(self) -> ET.Element | None:
+        pass