Skip to content

Commit

Permalink
fix python3 support for tesla powerwall interfacer
Browse files Browse the repository at this point in the history
  • Loading branch information
TrystanLea committed May 26, 2020
1 parent 41e315b commit da27a4a
Showing 1 changed file with 8 additions and 19 deletions.
27 changes: 8 additions & 19 deletions src/interfacers/EmonHubTeslaPowerWallInterfacer.py
@@ -1,4 +1,4 @@
import time, json, Cargo, urllib2, ssl
import time, json, Cargo, requests
from emonhub_interfacer import EmonHubInterfacer

"""class EmonHubTeslaPowerWallInterfacer
Expand Down Expand Up @@ -41,23 +41,12 @@ def read(self):
if self._settings['url']:
# HTTP Request
try:
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS)
response = urllib2.urlopen(self._settings['url'], context=ctx, timeout=int(self._settings['readinterval']))
except urllib2.HTTPError as e:
self._log.warning("HTTPError: "+str(e.code))
return
except urllib2.URLError as e:
self._log.warning("URLError: "+str(e.reason))
return
except httplib.HTTPException:
self._log.warning("HTTPException")
return
except Exception:
import traceback
self._log.warning("Exception: "+traceback.format_exc())
return

jsonstr = response.read().rstrip()
reply = requests.get(self._settings['url'],timeout=int(self._settings['readinterval']))
reply.raise_for_status() # Raise an exception if status code isn't 200
except requests.exceptions.RequestException as ex:
self._log.warning(self.name + " couldn't send to server: " + str(ex))

jsonstr = reply.text.rstrip()
self._log.debug("Request response: "+str(jsonstr))

# Decode JSON
Expand Down Expand Up @@ -90,7 +79,7 @@ def set(self, **kwargs):
"""

for key, setting in self._template_settings.iteritems():
for key, setting in self._template_settings.items():
# Decide which setting value to use
if key in kwargs.keys():
setting = kwargs[key]
Expand Down

0 comments on commit da27a4a

Please sign in to comment.