Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to convert Energy Company Id to name. Bump to 0.1.6 #23

Merged
merged 2 commits into from
Dec 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 39 additions & 3 deletions pycheckwatt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


class CheckwattManager:
"""Checkwatt manager."""
"""CheckWatt manager."""

def __init__(self, username, password) -> None:
"""Initialize the CheckWatt manager."""
Expand Down Expand Up @@ -136,7 +136,7 @@ async def handle_client_error(self, endpoint, headers, error):
return False

async def login(self):
"""Login to Checkwatt."""
"""Login to CheckWatt."""
try:
credentials = f"{self.username}:{self.password}"
encoded_credentials = base64.b64encode(credentials.encode("utf-8")).decode(
Expand Down Expand Up @@ -172,7 +172,7 @@ async def login(self):
return await self.handle_client_error(endpoint, headers, error)

async def get_customer_details(self):
"""Fetch customer details from Checkwatt."""
"""Fetch customer details from CheckWatt."""
try:
endpoint = "/controlpanel/CustomerDetail"

Expand Down Expand Up @@ -565,6 +565,42 @@ async def get_spot_price(self):
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:
endpoint = "/controlpanel/elhandelsbolag"

# Define headers with the JwtToken
headers = {
**self._get_headers(),
}

async with self.session.get(
self.base_url + endpoint, headers=headers
) as response:
response.raise_for_status()
if response.status == 200:
energy_trading_companies = await response.json()
for energy_trading_company in energy_trading_companies:
if energy_trading_company['Id'] == input_id:
return energy_trading_company['DisplayName']


return None

_LOGGER.error(
"Obtaining data from URL %s failed with status code %d",
self.base_url + endpoint,
response.status,
)
return None

except (ClientResponseError, ClientError) as error:
return await self.handle_client_error(endpoint, headers, error)



@property
def inverter_make_and_model(self):
"""Property for inverter make and model. Not used by HA integration.."""
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.1.5"
version = "0.1.6"
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
Loading