diff --git a/pyproject.toml b/pyproject.toml index 78973b9..8e17288 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "opower" -version = "0.0.17" +version = "0.0.18" license = {text = "Apache-2.0"} authors = [ { name="tronikos", email="tronikos@gmail.com" }, diff --git a/src/opower/opower.py b/src/opower/opower.py index 0d3de2d..628d08a 100644 --- a/src/opower/opower.py +++ b/src/opower/opower.py @@ -132,6 +132,8 @@ def __init__( self, session: aiohttp.ClientSession, utility: str, username: str, password: str ) -> None: """Initialize.""" + # Note: Do not modify default headers since Home Assistant that uses this library needs to use + # a default session for all integrations. Instead specify the headers for each request. self.session = session self.utility: type[UtilityBase] = _select_utility(utility) self.username = username diff --git a/src/opower/utilities/exelon.py b/src/opower/utilities/exelon.py index f9fe676..ee2b55a 100644 --- a/src/opower/utilities/exelon.py +++ b/src/opower/utilities/exelon.py @@ -32,7 +32,9 @@ async def async_login( ) -> str: """Login to the utility website and authorize opower.""" async with session.get( - "https://" + cls.login_domain() + "/Pages/Login.aspx?/login" + "https://" + cls.login_domain() + "/Pages/Login.aspx?/login", + headers={"User-Agent": USER_AGENT}, + raise_for_status=True, ) as resp: result = await resp.text() # transId = "StateProperties=..." @@ -90,7 +92,7 @@ async def async_login( headers={"User-Agent": USER_AGENT}, raise_for_status=True, ) as resp: - result = await resp.text(encoding = "utf-8") + result = await resp.text(encoding="utf-8") async with session.post( "https://"