Skip to content

Commit

Permalink
Merge pull request #146 from kdeyev/main
Browse files Browse the repository at this point in the history
fix for authentication problem
  • Loading branch information
grahamwetzler committed Apr 27, 2024
2 parents 6fab384 + bda56f2 commit 639fecb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
14 changes: 1 addition & 13 deletions smart_meter_texas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
AUTH_ENDPOINT,
BASE_ENDPOINT,
BASE_HOSTNAME,
BASE_URL,
CLIENT_HEADERS,
INTERVAL_SYNCH,
LATEST_OD_READ_ENDPOINT,
Expand Down Expand Up @@ -234,14 +233,6 @@ def _init_ssl_context(self):
)
self.ssl_context = new_ssl_context

async def _init_websession(self):
"""Make an initial GET request to initialize the session otherwise
future POST requests will timeout."""
self._init_ssl_context()
await self.websession.get(
BASE_URL, headers=self._agent_headers(), ssl=self.ssl_context
)

def _agent_headers(self):
"""Build the user agent header."""
if not self.user_agent:
Expand Down Expand Up @@ -286,12 +277,9 @@ async def authenticate(self):
if not self.token_valid:
_LOGGER.debug("Requesting login token")

# Make an initial GET request otherwise subsequent calls will timeout.
await self._init_websession()

resp = await self.websession.request(
"POST",
f"{BASE_ENDPOINT}{AUTH_ENDPOINT}",
AUTH_ENDPOINT,
json={
"username": self.account.username,
"password": self.account.password,
Expand Down
16 changes: 10 additions & 6 deletions smart_meter_texas/const.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import datetime

BASE_HOSTNAME = "smartmetertexas.com"
BASE_HOSTNAME = "www.smartmetertexas.com"
BASE_URL = "https://" + BASE_HOSTNAME + "/"
BASE_ENDPOINT = BASE_URL + "api"
AUTH_ENDPOINT = "/user/authenticate"
DASHBOARD_ENDPOINT = "/dashboard"
AUTH_ENDPOINT = BASE_URL + "/commonapi/user/authenticate"
LATEST_OD_READ_ENDPOINT = "/usage/latestodrread"
METER_ENDPOINT = "/meter"
OD_READ_ENDPOINT = "/ondemandread"
Expand All @@ -13,11 +12,16 @@
USER_AGENT_TEMPLATE = (
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) "
"AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/85.0.{BUILD}.{REV} Safari/537.36"
"Chrome/123.0.{BUILD}.{REV} Safari/537.36"
)
CLIENT_HEADERS = {
"Content-Type": "application/json",
"Accept": "application/json",
"accept": "application/json, text/plain, */*",
"accept-language": "en-US,en;q=0.9",
"cache-control": "no-cache",
"content-type": "application/json",
"origin": "https://www.smartmetertexas.com",
"pragma": "no-cache",
"referer": "https://www.smartmetertexas.com/home",
}

API_ERROR_KEY = "errormessage"
Expand Down

0 comments on commit 639fecb

Please sign in to comment.