Skip to content

Commit

Permalink
isort . ; black . ; flake8 . ; ruff . --fix
Browse files Browse the repository at this point in the history
  • Loading branch information
tronikos committed Aug 8, 2023
1 parent 71f8015 commit 4f2e7bc
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 12 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ black .
# Run lint
python -m pip install flake8 ruff
flake8 .
ruff .
ruff . --fix

# Run formatter and lint
isort . ; black . ; flake8 . ; ruff . --fix

# Run tests
python -m pip install pytest
Expand Down
2 changes: 1 addition & 1 deletion src/opower/utilities/delmarva.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def primary_subdomain() -> str:
def secondary_subdomain() -> str:
"""Return the opower.com secondary subdomain for this utility."""
return "dpld"

@staticmethod
def login_domain() -> str:
"""Return the domain that hosts the login page."""
Expand Down
28 changes: 19 additions & 9 deletions src/opower/utilities/exelon.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""Base class for Exelon subsidiaries."""

import json
import re
import logging
import re
from typing import Optional

import aiohttp
Expand All @@ -12,6 +12,7 @@

_LOGGER = logging.getLogger(__file__)


class Exelon:
"""Base class for Exelon subsidiaries."""

Expand All @@ -30,7 +31,7 @@ def timezone() -> str:
def login_domain() -> str:
"""Return the domain that hosts the login page."""
raise NotImplementedError

@classmethod
def subdomain(cls) -> str:
"""Return the opower.com subdomain for this utility."""
Expand Down Expand Up @@ -122,29 +123,38 @@ async def async_login(
result = await resp.json()

# If pepco or delmarva, determine if we should use secondary subdomain
if (cls.login_domain() in ["secure.pepco.com", "secure.delmarva.com"]):
if cls.login_domain() in ["secure.pepco.com", "secure.delmarva.com"]:
# Get the account type & state
async with session.get(
"https://" + cls.login_domain() + "/.euapi/mobile/custom/auth/accounts",
headers={"User-Agent": USER_AGENT, "authorization": f"Bearer {result['access_token']}"},
headers={
"User-Agent": USER_AGENT,
"authorization": f"Bearer {result['access_token']}",
},
raise_for_status=True,
) as resp:
# returned mimetype is nonstandard, so this avoids a ContentTypeError
response = await resp.json(content_type=None)

#Only include active accounts (after moving, old accounts have status: "Inactive")
#NOTE: this logic currently assumes 1 active address per account, if multiple accounts found
# Only include active accounts (after moving, old accounts have status: "Inactive")
# NOTE: this logic currently assumes 1 active address per account, if multiple accounts found
# we default to taking the first in the list. Future enhancement is to support
# multiple accounts (which could result in different subdomain for each)
active_accounts = [account for account in response['data'] if account['status'] == 'Active']
active_accounts = [
account
for account in response["data"]
if account["status"] == "Active"
]
isResidential = active_accounts[0]["isResidential"]
state = active_accounts[0]['PremiseInfo'][0]['mainAddress']['townDetail']['stateOrProvince']
state = active_accounts[0]["PremiseInfo"][0]["mainAddress"][
"townDetail"
]["stateOrProvince"]
_LOGGER.debug("found exelon account isResidential: %s", isResidential)
_LOGGER.debug("found exelon account state: %s", state)

# Determine subdomain to use by matching logic found in https://cls.login_domain()/dist/app.js
Exelon._subdomain = cls.primary_subdomain()
if(not isResidential or 'MD' != state):
if not isResidential or state != "MD":
Exelon._subdomain = cls.secondary_subdomain()

_LOGGER.debug("detected exelon subdomain to be: %s", Exelon._subdomain)
Expand Down
2 changes: 1 addition & 1 deletion src/opower/utilities/pepco.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def primary_subdomain() -> str:
def secondary_subdomain() -> str:
"""Return the opower.com secondary subdomain for this utility."""
return "pepd"

@staticmethod
def login_domain() -> str:
"""Return the domain that hosts the login page."""
Expand Down

0 comments on commit 4f2e7bc

Please sign in to comment.