55
66
77from collections .abc import Mapping
8+ from dataclasses import dataclass
89from datetime import datetime
910
1011from frequenz .client .microgrid import ComponentMetricId
1112
1213
14+ @dataclass (frozen = True , eq = False )
1315class ComponentMetricsData :
1416 """Store values of the component metrics."""
1517
16- def __init__ (
17- self ,
18- component_id : int ,
19- timestamp : datetime ,
20- metrics : Mapping [ComponentMetricId , float ],
21- ) -> None :
22- """Create class instance.
18+ component_id : int
19+ """The component ID the data is for."""
2320
24- Args:
25- component_id: component id
26- timestamp: timestamp the same for all metrics
27- metrics: map between metrics and its values.
28- """
29- self ._component_id = component_id
30- self ._timestamp = timestamp
31- self ._metrics : Mapping [ComponentMetricId , float ] = metrics
32-
33- @property
34- def component_id (self ) -> int :
35- """Get component id of the given metrics.
21+ timestamp : datetime
22+ """The timestamp for all the metrics."""
3623
37- Returns:
38- Component id
39- """
40- return self ._component_id
41-
42- @property
43- def timestamp (self ) -> datetime :
44- """Get timestamp of the given metrics.
45-
46- Returns:
47- Timestamp (one for all metrics).
48- """
49- return self ._timestamp
24+ metrics : Mapping [ComponentMetricId , float ]
25+ """The values for each metric."""
5026
5127 def get (self , metric : ComponentMetricId ) -> float | None :
5228 """Get metric value.
@@ -57,7 +33,7 @@ def get(self, metric: ComponentMetricId) -> float | None:
5733 Returns:
5834 Value of the metric.
5935 """
60- return self ._metrics .get (metric , None )
36+ return self .metrics .get (metric , None )
6137
6238 def __eq__ (self , other : object ) -> bool :
6339 """Compare two objects of this class.
@@ -74,6 +50,4 @@ def __eq__(self, other: object) -> bool:
7450 if not isinstance (other , ComponentMetricsData ):
7551 return False
7652
77- return (
78- self .component_id == other .component_id and self ._metrics == other ._metrics
79- )
53+ return self .component_id == other .component_id and self .metrics == other .metrics
0 commit comments