From 14e47ca8a85d1f2cee3494d44a7f0b81423593e7 Mon Sep 17 00:00:00 2001 From: Johan Isacsson Date: Tue, 7 Sep 2021 21:26:26 +0200 Subject: [PATCH] Changed all energy units to kWh --- pymyenergi/base_device.py | 12 ++++++------ pymyenergi/cli.py | 13 +++++++------ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/pymyenergi/base_device.py b/pymyenergi/base_device.py index 7373893..76545ec 100644 --- a/pymyenergi/base_device.py +++ b/pymyenergi/base_device.py @@ -143,14 +143,14 @@ async def fetch_history_data(self, date_from, how_long, resolution): watt_hours = row.get(key, 0) / 3600 energy_wh[key] = energy_wh[key] + watt_hours return_data = { - "generated": round(energy_wh["gep"]), - "grid_import": round(energy_wh["imp"]), - "grid_export": round(energy_wh["exp"]), + "generated": round(energy_wh["gep"] / 1000, 2), + "grid_import": round(energy_wh["imp"] / 1000, 2), + "grid_export": round(energy_wh["exp"] / 1000, 2), "device_total": round( - energy_wh["h1b"] + energy_wh["h2b"] + energy_wh["h3b"] + (energy_wh["h1b"] + energy_wh["h2b"] + energy_wh["h3b"]) / 1000, 2 ), "device_diverted": round( - energy_wh["h1d"] + energy_wh["h2d"] + energy_wh["h3d"] + (energy_wh["h1d"] + energy_wh["h2d"] + energy_wh["h3d"]) / 1000, 2 ), } for i in range(6): @@ -159,7 +159,7 @@ async def fetch_history_data(self, date_from, how_long, resolution): ct_key = getattr(self, key).name_as_key if ct_key != "ct_none": return_data[ct_key] = round( - return_data.get(ct_key, 0) + energy_wh[f"ct{i+1}"] + (return_data.get(ct_key, 0) + (energy_wh[f"ct{i+1}"] / 1000)), 2 ) return return_data diff --git a/pymyenergi/cli.py b/pymyenergi/cli.py index 1f78933..97e2400 100644 --- a/pymyenergi/cli.py +++ b/pymyenergi/cli.py @@ -42,18 +42,19 @@ async def main(args): out = out + f"Power generation : {client.power_generation}W\n" out = out + f"Power EV charge : {client.power_charging}W\n" out = out + f"Power battery : {client.power_battery}W\n" - out = out + f"Energy imported : {client.energy_imported/1000:.2f}kWh\n" - out = out + f"Energy exported : {client.energy_exported/1000:.2f}kWh\n" - out = out + f"Energy generated : {client.energy_generated/1000:.2f}kWh\n" - out = out + f"Energy diverted : {client.energy_diverted/1000:.2f}kWh\n" + out = out + f"Energy imported : {client.energy_imported}kWh\n" + out = out + f"Energy exported : {client.energy_exported}kWh\n" + out = out + f"Energy generated : {client.energy_generated}kWh\n" + out = out + f"Energy diverted : {client.energy_diverted}kWh\n" out = out + "Devices:\n" for device in devices: out = out + f"\t{device.kind.capitalize()}: {device.name}" if device.kind != HARVI: - out = out + f"\t{device.energy_total}Wh today\n" + out = out + f"\t{device.energy_total}kWh today\n" for key in device.ct_keys: out = ( - out + f"\t{key} {device.history_data.get(key, 0)}Wh today\n" + out + + f"\t{key} {device.history_data.get(key, 0)}kWh today\n" ) out = out + "\n" else: