Skip to content

Commit deebd53

Browse files
committed
Create dummy-netstrings for all interval-sensors
Also, pop the dummy-result, optimize code
1 parent c21c984 commit deebd53

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

plugwise/helper.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -201,18 +201,17 @@ def power_data_local_format(attrs, key_string, val):
201201

202202
def power_data_energy_diff(measurement, net_string, f_val, direct_data):
203203
"""Calculate differential energy."""
204-
if "electricity" in measurement:
205-
diff = 1
206-
if "produced" in measurement:
207-
diff = -1
208-
if net_string not in direct_data:
209-
direct_data[net_string] = 0
210-
211-
if isinstance(f_val, int):
212-
direct_data[net_string] += f_val * diff
213-
else:
214-
direct_data[net_string] += float(f_val * diff)
215-
direct_data[net_string] = float(f"{round(direct_data[net_string], 3):.3f}")
204+
diff = 1
205+
if "produced" in measurement:
206+
diff = -1
207+
if net_string not in direct_data:
208+
direct_data[net_string] = 0
209+
210+
if isinstance(f_val, int):
211+
direct_data[net_string] += f_val * diff
212+
else:
213+
direct_data[net_string] += float(f_val * diff)
214+
direct_data[net_string] = float(f"{round(direct_data[net_string], 3):.3f}")
216215

217216
return direct_data
218217

@@ -926,7 +925,7 @@ def _heating_valves(self):
926925
def _power_data_peak_value(self, loc):
927926
"""Helper-function for _power_data_from_location()."""
928927
loc.found = True
929-
loc.net_string = None
928+
loc.net_string = "dummy"
930929

931930
# Only once try to find P1 Legacy values
932931
if loc.logs.find(loc.locator) is None and self.smile_type == "power":
@@ -951,7 +950,7 @@ def _power_data_peak_value(self, loc):
951950
loc.key_string = f"{loc.measurement}_{peak}_{log_found}"
952951
if "gas" in loc.measurement:
953952
loc.key_string = f"{loc.measurement}_{log_found}"
954-
# Don't create net_elec_interval sensor!
953+
# Don't create net_elec_interval sensor
955954
if "electricity" in loc.measurement and "interval" not in log_found:
956955
loc.net_string = f"net_electricity_{log_found}"
957956
val = loc.logs.find(loc.locator).text
@@ -1006,6 +1005,7 @@ def _power_data_from_location(self, loc_id):
10061005
direct_data[loc.key_string] = [loc.f_val, loc.log_date]
10071006

10081007
if direct_data != {}:
1008+
direct_data.pop("dummy")
10091009
return direct_data
10101010

10111011
def _preset(self, loc_id):

0 commit comments

Comments
 (0)