Skip to content

Commit

Permalink
Merge pull request #33 from faanskit/dev
Browse files Browse the repository at this point in the history
Added peak battery effect
  • Loading branch information
faanskit authored Feb 7, 2024
2 parents 0c807aa + c97a34e commit 8571c9f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
34 changes: 34 additions & 0 deletions pycheckwatt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>", "Anders Yderborg <[email protected]>", "Daniel Nilsson <[email protected]>"]
license = "MIT License"
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

MIN_PY_VERSION = "3.10"
PACKAGES = find_packages()
VERSION = "0.2.2"
VERSION = "0.2.3"

setup(
name="pycheckwatt",
Expand Down

0 comments on commit 8571c9f

Please sign in to comment.