@@ -70,3 +70,53 @@ def test_fix_values():
7070 'pv' : {'all' : {'exported' : 3269 }, 'pv1' : {'exported' : 3269 }},
7171 'sh' : {},
7272 'timestamp' : 1709109001 }
73+
74+
75+ def test_fix_values_missing_components ():
76+ # setup
77+ previous_entry = {'bat' : {'all' : {'exported' : 0 , 'imported' : 2281.851 , 'soc' : 96 },
78+ 'bat2' : {'exported' : 0 , 'imported' : 2281.851 , 'soc' : 96 }},
79+ 'counter' : {'counter0' : {'exported' : 21.382 ,
80+ 'grid' : True ,
81+ 'imported' : 17.913 }},
82+ 'cp' : {'all' : {'exported' : 0 , 'imported' : 0 },
83+ 'cp3' : {'exported' : 0 , 'imported' : 0 },
84+ 'cp4' : {'exported' : 0 , 'imported' : 0 },
85+ 'cp5' : {'exported' : 0 , 'imported' : 0 }},
86+ 'date' : '09:25' ,
87+ 'ev' : {'ev0' : {'soc' : 0 }},
88+ 'hc' : {'all' : {'imported' : 108647.2791628165 }},
89+ 'pv' : {'all' : {'exported' : 3269 }},
90+ 'sh' : {},
91+ 'timestamp' : 1709108702 }
92+ new_entry = {'bat' : {'all' : {'exported' : 0 , 'imported' : 2369.658 , 'soc' : 97 },
93+ 'bat2' : {'exported' : 0 , 'imported' : 2369.658 , 'soc' : 97 }},
94+ 'counter' : {'counter0' : {'exported' : 22.167 , 'grid' : True , 'imported' : 18.54 }},
95+ 'cp' : {'all' : {'exported' : 0 , 'imported' : 0 },
96+ 'cp3' : {'exported' : 0 , 'imported' : 0 },
97+ 'cp4' : {'exported' : 0 , 'imported' : 0 },
98+ 'cp5' : {'exported' : 0 , 'imported' : 0 }},
99+ 'date' : '09:30' ,
100+ 'ev' : {'ev0' : {'soc' : 0 }},
101+ 'hc' : {'all' : {'imported' : 108683.21291147666 }},
102+ 'pv' : {'all' : {'exported' : 0 }, 'pv1' : {'exported' : 0 }},
103+ 'sh' : {},
104+ 'timestamp' : 1709109001 }
105+
106+ # execution
107+ fixed_values = write_log .fix_values (new_entry , previous_entry )
108+
109+ # evaluation
110+ assert fixed_values == {'bat' : {'all' : {'exported' : 0 , 'imported' : 2369.658 , 'soc' : 97 },
111+ 'bat2' : {'exported' : 0 , 'imported' : 2369.658 , 'soc' : 97 }},
112+ 'counter' : {'counter0' : {'exported' : 22.167 , 'grid' : True , 'imported' : 18.54 }},
113+ 'cp' : {'all' : {'exported' : 0 , 'imported' : 0 },
114+ 'cp3' : {'exported' : 0 , 'imported' : 0 },
115+ 'cp4' : {'exported' : 0 , 'imported' : 0 },
116+ 'cp5' : {'exported' : 0 , 'imported' : 0 }},
117+ 'date' : '09:30' ,
118+ 'ev' : {'ev0' : {'soc' : 0 }},
119+ 'hc' : {'all' : {'imported' : 108683.21291147666 }},
120+ 'pv' : {'all' : {'exported' : 3269 }, 'pv1' : {'exported' : 0 }},
121+ 'sh' : {},
122+ 'timestamp' : 1709109001 }
0 commit comments