diff --git a/examples/example.py b/examples/example.py index be79065..36b515a 100644 --- a/examples/example.py +++ b/examples/example.py @@ -3,12 +3,8 @@ import argparse import json -from dotenv import load_dotenv - from pycheckwatt import CheckwattManager -load_dotenv() - async def main(show_details=False): """Fetch username and password from environment variables.""" @@ -22,7 +18,6 @@ async def main(show_details=False): if await check_watt_instance.login(): # Fetch customer detail await check_watt_instance.get_customer_details() - await check_watt_instance.get_battery_peak_data() # Do a sample print("Customer Details\n================") diff --git a/examples/main.py b/examples/main.py deleted file mode 100644 index 3db8ad3..0000000 --- a/examples/main.py +++ /dev/null @@ -1,183 +0,0 @@ -"""Test-module for pyCheckwatt.""" - -import argparse -import json -import os - -from dotenv import load_dotenv - -from pycheckwatt import CheckwattManager - -load_dotenv() - - -async def main(show_details=False): - """Fetch username and password from environment variables.""" - username = os.getenv("CHECKWATT_USERNAME") - password = os.getenv("CHECKWATT_PASSWORD") - - # Create the async class - async with CheckwattManager(username, password) as check_watt_instance: - try: - # Login to EnergyInBalance and check kill switch - if await check_watt_instance.login(): - # Fetch customer detail - await check_watt_instance.get_customer_details() - - # Do a sample - print("Customer Details\n================") - print(check_watt_instance.registered_owner) - - print("\nSystem\n======") - print("Charge peak", check_watt_instance.battery_charge_peak) - print("Discharge peak", check_watt_instance.battery_discharge_peak) - print(check_watt_instance.battery_make_and_model) - print(check_watt_instance.electricity_provider) - - print("\nLogbook Entries\n===============") - for entry in check_watt_instance.logbook_entries: - print(entry) - - await check_watt_instance.get_fcrd_revenue() - await check_watt_instance.get_fcrd_revenueyear() - await check_watt_instance.get_fcrd_revenuemonth() - print("\nFCR-D\n=====") - print(f"FCR-D State: {check_watt_instance.fcrd_state}") - print(f"FCR-D Percentage: {check_watt_instance.fcrd_percentage}") - print(f"FCR-D Date: {check_watt_instance.fcrd_timestamp}") - print("\n") - print( - "{:<24} {:>6} {:>0}".format( - "Daily average:", - int(check_watt_instance.month_revenue[2]), - "kr", - ) - ) - print( - "{:<24} {:>6} {:>0}".format( - "Month estimate:", - int(check_watt_instance.month_revenue[3]), - "kr", - ) - ) - print( - "{:<24} {:>6} {:>0}".format( - "Month compensation:", - int(check_watt_instance.month_revenue[0]), - "kr", - ) - ) - print( - "{:<24} {:>6} {:>0}".format( - "Month fee:", int(check_watt_instance.month_revenue[1]), "kr" - ) - ) - print( - "{:<24} {:>6} {:>0}".format( - "Month revenue:", - int( - check_watt_instance.month_revenue[0] - - check_watt_instance.month_revenue[1] - ), - "kr", - ) - ) - print( - "{:<24} {:>6} {:>0}".format( - "Year compensation:", - int(check_watt_instance.year_revenue[0]), - "kr", - ) - ) - print( - "{:<24} {:>6} {:>0}".format( - "Year fee:", int(check_watt_instance.year_revenue[1]), "kr" - ) - ) - print( - "{:<24} {:>6} {:>0}".format( - "Year revenue:", - int( - check_watt_instance.year_revenue[0] - - check_watt_instance.year_revenue[1] - ), - "kr", - ) - ) - print( - "{:<24} {:>6} {:>0}".format( - "Today compensation:", - int(check_watt_instance.today_revenue[0]), - "kr", - ) - ) - print( - "{:<24} {:>6} {:>0}".format( - "Today fee:", int(check_watt_instance.today_revenue[1]), "kr" - ) - ) - print( - "{:<24} {:>6} {:>0}".format( - "Today revenue:", - int( - check_watt_instance.today_revenue[0] - - check_watt_instance.today_revenue[1] - ), - "kr", - ) - ) - print( - "{:<24} {:>6} {:>0}".format( - "Tomorrow compensation:", - int(check_watt_instance.tomorrow_revenue[0]), - "kr", - ) - ) - print( - "{:<24} {:>6} {:>0}".format( - "Tomorrow fee:", - int(check_watt_instance.tomorrow_revenue[1]), - "kr", - ) - ) - print( - "{:<24} {:>6} {:>0}".format( - "Tomorrow revenue:", - int( - check_watt_instance.tomorrow_revenue[0] - - check_watt_instance.tomorrow_revenue[1] - ), - "kr", - ) - ) - - await check_watt_instance.get_power_data() - print("\nEnergy\n======") - print(f"Solar: {check_watt_instance.total_solar_energy/1000} kWh") - print(f"Charging: {check_watt_instance.total_charging_energy/1000} kWh") - print( - f"Discharging: {check_watt_instance.total_discharging_energy/1000} kWh" # noqa: E501 - ) - print(f"Import: {check_watt_instance.total_import_energy/1000} kWh") - print(f"Export: {check_watt_instance.total_export_energy/1000} kWh") - - if show_details: - print("\nCustomer Details\n===============") - print(json.dumps(check_watt_instance.customer_details, indent=2)) - - except Exception as e: - print(f"An error occurred: {e}") - - -if __name__ == "__main__": - parser = argparse.ArgumentParser(description="Checkwatt Information") - parser.add_argument( - "-d", "--details", action="store_true", help="Show system details" - ) - args = parser.parse_args() - - import asyncio - - loop = asyncio.new_event_loop() - asyncio.set_event_loop(loop) - loop.run_until_complete(main(args.details)) diff --git a/pycheckwatt/__init__.py b/pycheckwatt/__init__.py index 0f30468..dcce5dd 100644 --- a/pycheckwatt/__init__.py +++ b/pycheckwatt/__init__.py @@ -102,6 +102,7 @@ def _get_headers(self): def _extract_content_and_logbook(self, input_string): """Pull the registered information from the logbook.""" + battery_registration = None # Define the pattern to match the content between the tags pattern = re.compile( @@ -258,6 +259,7 @@ async def get_customer_details(self): response.raise_for_status() if response.status == 200: self.customer_details = await response.json() + print(f"{json.dumps(self.customer_details, indent=4)}") meters = self.customer_details.get("Meter", []) if meters: diff --git a/pyproject.toml b/pyproject.toml index e4cc5c8..1029d5c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "pycheckwatt" -version = "0.2.3" +version = "0.2.4" description = "Read data from CheckWatts EnergyInBalance WEB API" authors = ["Marcus Karlsson ", "Anders Yderborg ", "Daniel Nilsson "] license = "MIT License" diff --git a/setup.py b/setup.py index 17c23d1..b02b7ab 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ MIN_PY_VERSION = "3.10" PACKAGES = find_packages() -VERSION = "0.2.3" +VERSION = "0.2.4" setup( name="pycheckwatt",