From 4f2e7bcca0358eec4526ddd40ab8a6a538002e5e Mon Sep 17 00:00:00 2001 From: tronikos Date: Mon, 7 Aug 2023 22:45:48 -0700 Subject: [PATCH] isort . ; black . ; flake8 . ; ruff . --fix --- README.md | 5 ++++- src/opower/utilities/delmarva.py | 2 +- src/opower/utilities/exelon.py | 28 +++++++++++++++++++--------- src/opower/utilities/pepco.py | 2 +- 4 files changed, 25 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 41cbff0..ca05c9a 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/opower/utilities/delmarva.py b/src/opower/utilities/delmarva.py index 546c56a..d07c676 100644 --- a/src/opower/utilities/delmarva.py +++ b/src/opower/utilities/delmarva.py @@ -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.""" diff --git a/src/opower/utilities/exelon.py b/src/opower/utilities/exelon.py index 52a6090..0ac662f 100644 --- a/src/opower/utilities/exelon.py +++ b/src/opower/utilities/exelon.py @@ -1,8 +1,8 @@ """Base class for Exelon subsidiaries.""" import json -import re import logging +import re from typing import Optional import aiohttp @@ -12,6 +12,7 @@ _LOGGER = logging.getLogger(__file__) + class Exelon: """Base class for Exelon subsidiaries.""" @@ -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.""" @@ -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) diff --git a/src/opower/utilities/pepco.py b/src/opower/utilities/pepco.py index 6675e4e..7a39b44 100644 --- a/src/opower/utilities/pepco.py +++ b/src/opower/utilities/pepco.py @@ -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."""