-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
12 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -163,6 +163,10 @@ def __init__(self, host="", password="", email="[email protected]", | |
else: | ||
# Disable http persistent connections | ||
self.session = requests | ||
# Enforce authmode | ||
if self.authmode not in ['cookie', 'token']: | ||
log.debug("Invalid value for parameter 'authmode' (%s) switching to default" % str(self.authmode)) | ||
self.authmode = 'cookie' | ||
# Load cached auth session | ||
try: | ||
f = open(self.cachefile, "r") | ||
|
@@ -273,7 +277,7 @@ def poll(self, api='/api/site_info/site_name', jsonformat=False, raw=False, recu | |
|
||
if(fetch): | ||
if(api == '/api/devices/vitals'): | ||
# Always want the raw output from the vitals call; protobuf binary payload | ||
# Always want the raw stream output from the vitals call; protobuf binary payload | ||
raw = True | ||
|
||
url = "https://%s%s" % (self.host, api) | ||
|
@@ -282,7 +286,6 @@ def poll(self, api='/api/site_info/site_name', jsonformat=False, raw=False, recu | |
r = self.session.get(url, headers=self.auth, verify=False, timeout=self.timeout, stream=raw) | ||
else: | ||
r = self.session.get(url, cookies=self.auth, verify=False, timeout=self.timeout, stream=raw) | ||
|
||
except requests.exceptions.Timeout: | ||
log.debug('ERROR Timeout waiting for Powerwall API %s' % url) | ||
return None | ||
|
@@ -294,14 +297,15 @@ def poll(self, api='/api/site_info/site_name', jsonformat=False, raw=False, recu | |
return None | ||
if r.status_code >= 400 and r.status_code < 500: | ||
# Session Expired - Try to get a new one unless we already tried | ||
log.debug('Session Expired - Trying to get a new one') | ||
if(not recursive): | ||
if raw: | ||
# Drain the stream | ||
# Drain the stream before retrying | ||
payload = r.raw.data | ||
self._get_session() | ||
return self.poll(api, jsonformat, raw, True) | ||
else: | ||
log.debug('ERROR Unable to establish session with Powerwall at %s - check password' % url) | ||
log.error('Unable to establish session with Powerwall at %s - check password' % url) | ||
return None | ||
if(raw): | ||
payload = r.raw.data | ||
|