1- """Event object """
1+ """Event object"""
2+
23from datetime import datetime , timedelta , timezone
34import logging
45import re
@@ -26,7 +27,7 @@ class Event:
2627
2728 def __init__ (self , ** event : dict [str , Any ]):
2829 """Initialize."""
29- self ._convert_phases (cast (dict [str , Any ], event .get ("phases" )))
30+ self ._convert_phases (cast (dict [str , Any ], event .get ("phases" , {} )))
3031 params : dict [str , Any ] = event .get ("parameters" ) or {}
3132 devices : list [dict [str , Any ]] = params .get ("devices" , [])
3233 consumption : dict [str , Any ] = event .get ("consumption" , {})
@@ -44,6 +45,7 @@ def __init__(self, **event: dict[str, Any]):
4445 self .allowed_kWh : float = round (allowed_wH / 1000 , 2 )
4546 self .used_kWh : float = round (used_wH / 1000 , 2 )
4647 self .used_percentage : float = 0
48+ self .reward = cast (float , event .get ("reward" , 0.0 ))
4749 self .last_update = datetime .now (timezone .utc ).astimezone ()
4850 if allowed_wH > 0 :
4951 self .used_percentage = round (used_wH / allowed_wH * 100 , 2 )
@@ -63,6 +65,7 @@ def __init__(self, **event: dict[str, Any]):
6365 "used_kWh" ,
6466 "used_percentage" ,
6567 "last_update" ,
68+ "reward" ,
6669 ]
6770
6871 def update_wh (self , used_wH : float ) -> None :
0 commit comments