File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed
src/frequenz/client/electricity_trading Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -100,8 +100,14 @@ def from_pb(cls, price: price_pb2.Price) -> Self:
100100 Returns:
101101 Price object corresponding to the protobuf message.
102102 """
103+ price_value = price .amount .value
104+ try :
105+ amount = Decimal (price_value )
106+ except Exception as e :
107+ _logger .error ("Error converting price amount `%s`: %s" , price_value , e )
108+ amount = Decimal ("NaN" )
103109 return cls (
104- amount = Decimal ( price . amount . value ) ,
110+ amount = amount ,
105111 currency = Currency .from_pb (price .currency ),
106112 )
107113
@@ -140,7 +146,11 @@ def from_pb(cls, power: power_pb2.Power) -> Self:
140146 Returns:
141147 Power object corresponding to the protobuf message.
142148 """
143- return cls (mw = Decimal (power .mw .value ))
149+ try :
150+ return cls (mw = Decimal (power .mw .value ))
151+ except Exception as e :
152+ _logger .error ("Error converting power amount `%s`: %s" , power .mw .value , e )
153+ return cls (mw = Decimal ("NaN" ))
144154
145155 def to_pb (self ) -> power_pb2 .Power :
146156 """Convert a Power object to protobuf Power.
You can’t perform that action at this time.
0 commit comments