66from  __future__ import  annotations 
77
88import  typing 
9+ from  abc  import  ABC , abstractmethod 
910from  dataclasses  import  dataclass 
1011from  enum  import  Enum 
1112from  typing  import  Optional 
1415import  frequenz .api .microgrid .grid_pb2  as  grid_pb 
1516import  frequenz .api .microgrid .inverter_pb2  as  inverter_pb 
1617
18+ from  ...timeseries  import  Current 
19+ from  ..fuse  import  Fuse 
20+ 
1721
1822class  ComponentType (Enum ):
1923    """A base class from which individual component types are derived.""" 
@@ -108,29 +112,41 @@ def _component_category_from_protobuf(
108112    return  ComponentCategory (component_category )
109113
110114
111- class  ComponentMetadata :
115+ class  ComponentMetadata ( ABC ) :
112116    """Base class for component metadata classes.""" 
113117
118+     @property  
119+     @abstractmethod  
120+     def  fuse (self ) ->  Optional [Fuse ]:
121+         """Get the fuse associated with this component. 
122+ 
123+         Returns: 
124+             The fuse associated with this component. 
125+         """ 
126+ 
114127
115128class  GridMetadata (ComponentMetadata ):
116129    """Metadata for a grid connection point.""" 
117130
118-     def  __init__ (self , max_current :  float ) ->  None :
131+     def  __init__ (self , fuse :  Fuse ) ->  None :
119132        """Create a new instance. 
120133
121134        Args: 
122-             max_current: maximum current rating of  the grid connection point in amps . 
135+             fuse: The fuse at  the grid connection point. 
123136        """ 
124-         self ._max_current  =  max_current 
137+         self ._fuse  =  fuse 
125138
126139    @property  
127-     def  max_current (self ) ->  float :
128-         """Get the maximum current rating of  the grid connection point. 
140+     def  fuse (self ) ->  Optional [ Fuse ] :
141+         """Get the fuse at  the grid connection point. 
129142
130143        Returns: 
131-             Maximum current rating in amps . 
144+             The fuse at the grid connection point . 
132145        """ 
133-         return  self ._max_current 
146+         if  not  isinstance (self , GridMetadata ):
147+             return  None 
148+ 
149+         return  self ._fuse 
134150
135151    def  __eq__ (self , other : typing .Any ) ->  bool :
136152        """Check if this instance is equal to another. 
@@ -139,21 +155,23 @@ def __eq__(self, other: typing.Any) -> bool:
139155            other: object to compare to. 
140156
141157        Returns: 
142-             `True` if `other` is a `GridMetadata` instance and `max_current ` is equal, 
158+             `True` if `other` is a `GridMetadata` instance and `fuse ` is equal, 
143159                `False` otherwise. 
144160        """ 
145161        if  not  isinstance (other , GridMetadata ):
146162            return  False 
147163
148-         return  self .max_current  ==  other .max_current 
164+         return  self .fuse  ==  other .fuse 
149165
150166
151167def  _component_metadata_from_protobuf (
152168    component_category : components_pb .ComponentCategory .ValueType ,
153169    component_metadata : grid_pb .Metadata ,
154170) ->  Optional [GridMetadata ]:
155171    if  component_category  ==  components_pb .ComponentCategory .COMPONENT_CATEGORY_GRID :
156-         return  GridMetadata (float (component_metadata .rated_fuse_current ))
172+         max_current  =  Current .from_amperes (component_metadata .rated_fuse_current )
173+         fuse  =  Fuse (max_current )
174+         return  GridMetadata (fuse )
157175
158176    return  None 
159177
0 commit comments