66from  __future__ import  annotations 
77
88import  typing 
9+ from  abc  import  ABC 
910from  dataclasses  import  dataclass 
1011from  enum  import  Enum 
1112
1213import  frequenz .api .common .components_pb2  as  components_pb 
1314import  frequenz .api .microgrid .grid_pb2  as  grid_pb 
1415import  frequenz .api .microgrid .inverter_pb2  as  inverter_pb 
1516
17+ from  ...timeseries  import  Current 
18+ from  ..fuse  import  Fuse 
19+ 
1620
1721class  ComponentType (Enum ):
1822    """A base class from which individual component types are derived.""" 
@@ -107,29 +111,41 @@ def _component_category_from_protobuf(
107111    return  ComponentCategory (component_category )
108112
109113
110- class  ComponentMetadata :
114+ class  ComponentMetadata ( ABC ) :
111115    """Base class for component metadata classes.""" 
112116
117+     @property  
118+     def  fuse (self ) ->  Fuse  |  None :
119+         """Get the fuse associated with this component. 
120+ 
121+         Returns: 
122+             The fuse associated with this component. 
123+         """ 
124+         return  None 
125+ 
113126
114127class  GridMetadata (ComponentMetadata ):
115128    """Metadata for a grid connection point.""" 
116129
117-     def  __init__ (self , max_current :  float ) ->  None :
130+     def  __init__ (self , fuse :  Fuse ) ->  None :
118131        """Create a new instance. 
119132
120133        Args: 
121-             max_current: maximum current rating of  the grid connection point in amps . 
134+             fuse: The fuse at  the grid connection point. 
122135        """ 
123-         self ._max_current  =  max_current 
136+         self ._fuse  =  fuse 
124137
125138    @property  
126-     def  max_current (self ) ->  float :
127-         """Get the maximum current rating of  the grid connection point. 
139+     def  fuse (self ) ->  Fuse   |   None :
140+         """Get the fuse at  the grid connection point. 
128141
129142        Returns: 
130-             Maximum current rating in amps . 
143+             None, by default . 
131144        """ 
132-         return  self ._max_current 
145+         if  not  isinstance (self , GridMetadata ):
146+             return  None 
147+ 
148+         return  self ._fuse 
133149
134150    def  __eq__ (self , other : typing .Any ) ->  bool :
135151        """Check if this instance is equal to another. 
@@ -138,21 +154,23 @@ def __eq__(self, other: typing.Any) -> bool:
138154            other: object to compare to. 
139155
140156        Returns: 
141-             `True` if `other` is a `GridMetadata` instance and `max_current ` is equal, 
157+             `True` if `other` is a `GridMetadata` instance and `fuse ` is equal, 
142158                `False` otherwise. 
143159        """ 
144160        if  not  isinstance (other , GridMetadata ):
145161            return  False 
146162
147-         return  self .max_current  ==  other .max_current 
163+         return  self .fuse  ==  other .fuse 
148164
149165
150166def  _component_metadata_from_protobuf (
151167    component_category : components_pb .ComponentCategory .ValueType ,
152168    component_metadata : grid_pb .Metadata ,
153169) ->  GridMetadata  |  None :
154170    if  component_category  ==  components_pb .ComponentCategory .COMPONENT_CATEGORY_GRID :
155-         return  GridMetadata (float (component_metadata .rated_fuse_current ))
171+         max_current  =  Current .from_amperes (component_metadata .rated_fuse_current )
172+         fuse  =  Fuse (max_current )
173+         return  GridMetadata (fuse )
156174
157175    return  None 
158176
0 commit comments