Skip to content
This repository has been archived by the owner on Jul 12, 2023. It is now read-only.

Commit

Permalink
Merge pull request #37 from mjmeli/fix-account-details-call-failures
Browse files Browse the repository at this point in the history
add primary and related bp number on account-details call
  • Loading branch information
mjmeli authored Sep 7, 2022
2 parents 3c9430c + 57a717d commit 47393f5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = pyduke-energy
version = 1.0.1
version = 1.0.2
author = Michael Meli
author_email = [email protected]
description = Python Wrapper for unofficial Duke Energy REST API
Expand Down
14 changes: 9 additions & 5 deletions src/pyduke_energy/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,23 +105,25 @@ async def get_account_list(self) -> List[Account]:
"GET", CUST_API_BASE_URL, ACCT_ENDPOINT, headers=headers, params=params
)
account_list: List[dict] = resp.get("accounts")
return [Account(acc) for acc in account_list]
return [Account(acc, resp) for acc in account_list]

async def get_account_details(self, account: Account) -> AccountDetails:
"""Get detailed account data for a specific account."""
return await self._get_account_details(
account.src_sys_cd,
account.src_acct_id,
account.src_acct_id_2,
account.bp_number,
account.primary_bp_number,
account.related_bp_number,
)

async def _get_account_details(
self,
src_sys_cd: str,
src_acct_id: str,
src_acct_id_2: Optional[str],
bp_number: Optional[str],
primary_bp_number: Optional[str],
related_bp_number: Optional[str],
) -> AccountDetails:
headers = await self._get_oauth_headers()
params = {
Expand All @@ -131,8 +133,10 @@ async def _get_account_details(
}
if src_acct_id_2:
params["srcAcctId2"] = src_acct_id_2
if bp_number:
params["bpNumber"] = bp_number
if primary_bp_number:
params["primaryBpNumber"] = primary_bp_number
if related_bp_number:
params["relatedBpNumber"] = related_bp_number
resp = await self._async_request(
"GET", CUST_API_BASE_URL, ACCT_DET_ENDPOINT, headers=headers, params=params
)
Expand Down
7 changes: 5 additions & 2 deletions src/pyduke_energy/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,22 @@
class Account:
"""An account as provided by account-list endpoint."""

def __init__(self, data: dict):
def __init__(self, data: dict, common_data: dict):
self.default_account: bool = data.get("defaultAccount")
self.nickname: str = data.get("nickname")
self.account_number: str = data.get("accountNumber")
self.src_acct_id: str = data.get("srcAcctId")
self.src_acct_id_2: str = data.get("srcAcctId2")
self.src_sys_cd: str = data.get("srcSysCd")
self.bp_number: str = data.get("primaryBpNumber")
self.primary_bp_number: str = data.get("primaryBpNumber")
self.status: str = data.get("status")
self.role: str = data.get("role")
self.service_address: str = data.get("serviceAddress")
self.mobile_app_compatible: bool = data.get("mobileAppCompatible")

# Data common to all accounts
self.related_bp_number: str = common_data.get("relatedBpNumber")


@dataclass
class AccountDetails:
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ commands =
[flake8]
max-line-length = 88
select = C,E,F,W,B,B950
extend-ignore = E203, E501
extend-ignore = E203, E501, W503
exclude = .venv,.git,.tox,docs,venv,bin,lib,deps,build
doctests = True

Expand Down

0 comments on commit 47393f5

Please sign in to comment.