From c97a34e55b15c85f0e049bafab3411588491a84a Mon Sep 17 00:00:00 2001 From: faanskit Date: Tue, 6 Feb 2024 18:11:45 +0100 Subject: [PATCH] Added peak battery effect --- pycheckwatt/__init__.py | 34 ++++++++++++++++++++++++++++++++++ pyproject.toml | 2 +- setup.py | 2 +- 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/pycheckwatt/__init__.py b/pycheckwatt/__init__.py index 0105329..0f30468 100644 --- a/pycheckwatt/__init__.py +++ b/pycheckwatt/__init__.py @@ -71,6 +71,7 @@ def __init__(self, username, password, application="pyCheckwatt") -> None: self.display_name = None self.reseller_id = None self.energy_provider_id = None + self.month_peak_effect = None async def __aenter__(self): """Asynchronous enter.""" @@ -692,6 +693,39 @@ async def get_spot_price(self): except (ClientResponseError, ClientError) as error: return await self.handle_client_error(endpoint, headers, error) + async def get_battery_month_peak_effect(self): + """Fetch Price Zone from CheckWatt.""" + month = datetime.now().strftime("%Y-%m") + + try: + endpoint = f"/ems/PeakBoughtMonth?month={month}" + # Define headers with the JwtToken + headers = { + **self._get_headers(), + "authorization": f"Bearer {self.jwt_token}", + } + + # First fetch the revenue + async with self.session.get( + self.base_url + endpoint, headers=headers + ) as response: + response.raise_for_status() + if response.status == 200: + peak_data = await response.json() + if "HourPeak" in peak_data: + self.month_peak_effect = peak_data["HourPeak"] + return True + + _LOGGER.error( + "Obtaining data from URL %s failed with status code %d", + self.base_url + endpoint, + response.status, + ) + return False + + except (ClientResponseError, ClientError) as error: + return await self.handle_client_error(endpoint, headers, error) + async def get_energy_trading_company(self, input_id): """Translate Energy Company Id to Energy Company Name.""" try: diff --git a/pyproject.toml b/pyproject.toml index 915830a..e4cc5c8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "pycheckwatt" -version = "0.2.2" +version = "0.2.3" 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 8d8860b..17c23d1 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ MIN_PY_VERSION = "3.10" PACKAGES = find_packages() -VERSION = "0.2.2" +VERSION = "0.2.3" setup( name="pycheckwatt",