Skip to content

Commit

Permalink
Fix tracking total kWh
Browse files Browse the repository at this point in the history
  • Loading branch information
mdeweerd committed Nov 6, 2023
1 parent 7edf28d commit 5977da1
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions apps/meters_to_ha/meters_to_ha.py
Original file line number Diff line number Diff line change
Expand Up @@ -2537,10 +2537,11 @@ def update_grdf_device(self, json_file):
if isinstance(response, dict) and "state" in response:
entity_data = response
previous_kWh = response["state"]
try:
current_total_kWh = float(previous_kWh)
except ValueError:
pass
if previous_kWh is not None:
try:
previous_kWh = float(previous_kWh)
except ValueError:
pass

attributes = response["attributes"]
if "meter_m3" in attributes:
Expand Down Expand Up @@ -2581,9 +2582,6 @@ def update_grdf_device(self, json_file):
except (ValueError, RuntimeError):
sensor = "None" # For log message just below

state = get_state_file(self.configuration[STATE_FILE])
self.mylog(f"state: {state!r}", "~~")
previous_kWh = None
if previous_kWh is None:
state = get_state_file(self.configuration[STATE_FILE])
if "grdf" in state:
Expand All @@ -2600,6 +2598,9 @@ def update_grdf_device(self, json_file):
f" from {sensor}"
)

if previous_kWh is not None:
current_total_kWh = previous_kWh

# sys.exit() # For debug
date_time = None
for row in data[pce]["releves"]:
Expand Down

0 comments on commit 5977da1

Please sign in to comment.