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

Commit

Permalink
remove logger override in client
Browse files Browse the repository at this point in the history
  • Loading branch information
mjmeli committed Oct 26, 2021
1 parent 7ba7434 commit 40caca8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 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 = 0.0.8
version = 0.0.9
author = Michael Meli
author_email = [email protected]
description = Python Wrapper for unofficial Duke Energy REST API
Expand Down
33 changes: 14 additions & 19 deletions src/pyduke_energy/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
)
from pyduke_energy.utils import date_to_utc_timestamp

_DEFAULT_LOGGER = logging.getLogger(__name__)
_LOGGER = logging.getLogger(__name__)


class _BaseAuthInfo:
Expand Down Expand Up @@ -84,16 +84,11 @@ class DukeEnergyClient:
"""The Duke Energy API client."""

def __init__(
self,
email: str,
password: str,
session: Optional[ClientSession] = None,
logger: Optional[logging.Logger] = None,
self, email: str, password: str, session: Optional[ClientSession] = None
):
self._email = email
self._password = password
self._session = session
self._logger = logger if logger else _DEFAULT_LOGGER

# Authentication
self._oauth_auth_info = _OAuthAuthInfo()
Expand Down Expand Up @@ -162,7 +157,7 @@ def reset_selected_meter(self) -> None:
async def select_default_meter(self) -> Tuple[MeterInfo, GatewayStatus]:
"""Find the meter that is used for the gateway by iterating through the accounts and meters."""
account_list = await self.get_account_list()
self._logger.debug(
_LOGGER.debug(
"Accounts to check for gateway (%d): %s",
len(account_list),
",".join(["'" + a.src_acct_id + "'" for a in account_list]),
Expand All @@ -185,9 +180,9 @@ async def _check_account_for_default_meter(
self, account: Account
) -> Tuple[Optional[MeterInfo], Optional[GatewayStatus]]:
try:
self._logger.debug("Checking account '%s' for gateway", account.src_acct_id)
_LOGGER.debug("Checking account '%s' for gateway", account.src_acct_id)
account_details = await self.get_account_details(account)
self._logger.debug(
_LOGGER.debug(
"Meters to check for gateway (%d): %s",
len(account_details.meter_infos),
",".join(
Expand All @@ -203,7 +198,7 @@ async def _check_account_for_default_meter(
return found_meter, found_gateway
except Exception as ex:
# Try the next account if anything fails above
self._logger.debug(
_LOGGER.debug(
"Failed to find meter on account '%s': %s",
account.src_acct_id,
ex,
Expand All @@ -215,7 +210,7 @@ async def _check_account_meter_for_default_meter(
self, account: Account, meter: MeterInfo
) -> Tuple[Optional[MeterInfo], Optional[GatewayStatus]]:
try:
self._logger.debug(
_LOGGER.debug(
"Checking meter '%s' for gateway [meter_type=%s, is_certified_smart_meter=%s]",
meter.serial_num,
meter.meter_type,
Expand All @@ -231,17 +226,17 @@ async def _check_account_meter_for_default_meter(

if gw_status is not None:
# Found a meter
self._logger.debug(
_LOGGER.debug(
"Found meter '%s' with gateway '%s'",
meter.serial_num,
gw_status.id,
)
return meter, gw_status

self._logger.debug("No gateway status for meter '%s'", meter.serial_num)
_LOGGER.debug("No gateway status for meter '%s'", meter.serial_num)
except Exception as ex:
# Try the next meter if anything fails above
self._logger.debug(
_LOGGER.debug(
"Failed to check meter '%s' on account '%s': %s",
meter.serial_num,
account.src_acct_id,
Expand Down Expand Up @@ -275,7 +270,7 @@ async def get_gateway_usage(
) # API expects dates to be UTC
end_hour = range_end.astimezone(timezone.utc).strftime(dt_format)
params = {"startHourDt": start_hour, "endHourDt": end_hour}
self._logger.debug(
_LOGGER.debug(
"Requesting usage between %s UTC and %s UTC", start_hour, end_hour
)

Expand Down Expand Up @@ -316,12 +311,12 @@ async def start_smartmeter_fastpoll(self):
)
# Not real accurate since it doesnt care about the response.
tstart = time.perf_counter()
self._logger.debug("Smartmeter fastpoll requested")
_LOGGER.debug("Smartmeter fastpoll requested")
return tstart

async def _oauth_login(self) -> None:
"""Hit the OAuth login endpoint to generate a new access token."""
self._logger.debug("Getting new OAuth auth")
_LOGGER.debug("Getting new OAuth auth")

headers = {"Authorization": BASIC_AUTH}
request = {
Expand Down Expand Up @@ -354,7 +349,7 @@ async def _gateway_login(self) -> None:
"Gateway needs to be selected before calling gateway functions"
)

self._logger.debug("Getting new gateway auth")
_LOGGER.debug("Getting new gateway auth")

headers = await self._get_oauth_headers()
request = {
Expand Down

0 comments on commit 40caca8

Please sign in to comment.