Skip to content

Commit

Permalink
fixing slow execution
Browse files Browse the repository at this point in the history
  • Loading branch information
zabuldon committed Sep 18, 2017
1 parent 3130f73 commit 3274d78
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 13 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from setuptools import setup
setup(
name='teslajsonpy',
version='0.0.12',
version='0.0.13',
packages=['teslajsonpy'],
include_package_data=True,
license='WTFPL',
Expand Down
2 changes: 1 addition & 1 deletion teslajsonpy/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def __open(self, url, headers={}, data=None, baseurl=""):
except TypeError:
pass
opener = build_opener()
self.logger.error(req.full_url)
self.logger.debug(req.full_url)
while True:
try:
resp = opener.open(req)
Expand Down
15 changes: 4 additions & 11 deletions teslajsonpy/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ def __init__(self, email, password, update_interval, logger):
self.__last_update_time = {}
self.__logger = logger
cars = self.__connection.get('vehicles')['response']
self.debug_msg('Found cars: {}'.format(dumps(cars)))
for car in cars:
self.__last_update_time[car['id']] = 0
self.debug_msg('Initializing car with ID: {}'.format(car['id']))
self.update(car['id'])
self.__vehicles.append(Climate(car, self))
self.__vehicles.append(Battery(car, self))
Expand All @@ -36,17 +34,12 @@ def __init__(self, email, password, update_interval, logger):
self.__vehicles.append(ParkingSensor(car, self))
self.__vehicles.append(GPS(car, self))

def debug_msg(self, msg):
if self.__logger:
print(msg)
self.__logger.debug(msg)

def post(self, vehicle_id, command, data={}):
self.debug_msg('vehicles/%i/%s' % (vehicle_id, command))
self.__logger.debug('vehicles/%i/%s' % (vehicle_id, command))
return self.__connection.post('vehicles/%i/%s' % (vehicle_id, command), data)

def get(self, vehicle_id, command):
self.debug_msg('vehicles/%i/%s' % (vehicle_id, command))
self.__logger.debug('vehicles/%i/%s' % (vehicle_id, command))
return self.__connection.get('vehicles/%i/%s' % (vehicle_id, command))

def data_request(self, vehicle_id, name):
Expand All @@ -59,7 +52,7 @@ def list_vehicles(self):
return self.__vehicles

def wake_up(self, vehicle_id):
self.debug_msg('{} {}'.format(vehicle_id, 'wake_up'))
self.__logger.debug('{} {}'.format(vehicle_id, 'wake_up'))
self.post(vehicle_id, 'wake_up')

def update(self, car_id):
Expand All @@ -72,7 +65,7 @@ def update(self, car_id):
self.__state[car_id] = data['vehicle_state']
self.__driving[car_id] = data['drive_state']
self.__last_update_time[car_id] = time.time()
self.debug_msg(
self.__logger.debug(
'Update requested:\n\t'
'Cat_ID: {}\n\t'
'TS: \n\t\t'
Expand Down

0 comments on commit 3274d78

Please sign in to comment.