Skip to content

Commit

Permalink
Merge pull request #8 from alandtse/updatetoggle
Browse files Browse the repository at this point in the history
Adding update toggle for vehicles
  • Loading branch information
zabuldon committed Aug 12, 2018
2 parents 7d22342 + 4d3b9f8 commit 4404b96
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
14 changes: 13 additions & 1 deletion teslajsonpy/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def __init__(self, email, password, update_interval):
self.__connection = Connection(email, password)
self.__vehicles = []
self.update_interval = update_interval
self.__update = {}
self.__climate = {}
self.__charging = {}
self.__state = {}
Expand All @@ -24,6 +25,7 @@ def __init__(self, email, password, update_interval):
cars = self.__connection.get('vehicles')['response']
for car in cars:
self.__last_update_time[car['id']] = 0
self.__update[car['id']] = True
self.update(car['id'])
self.__vehicles.append(Climate(car, self))
self.__vehicles.append(Battery(car, self))
Expand Down Expand Up @@ -58,7 +60,8 @@ def wake_up(self, vehicle_id):
def update(self, car_id):
cur_time = time.time()
with self.__lock:
if cur_time - self.__last_update_time[car_id] > self.update_interval:
if (self.__update[car_id] and
(cur_time - self.__last_update_time[car_id] > self.update_interval)):
self.wake_up(car_id)
data = self.get(car_id, 'data')
if data and data['response']:
Expand Down Expand Up @@ -89,3 +92,12 @@ def get_drive_params(self, car_id):

def get_gui_params(self, car_id):
return self.__gui[car_id]

def get_updates(self, car_id=None):
if car_id is not None:
return self.__update[car_id]
else:
return self.__update

def set_updates(self, car_id, value):
self.__update[car_id] = value
5 changes: 4 additions & 1 deletion teslajsonpy/vehicle.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ def _uniq_name(self):
return 'Tesla Model {} {} {}'.format(
str(self._vin[3]).upper(), self._vin, self.type)

def id(self):
return self._id

@staticmethod
def is_armable():
return False

@staticmethod
def is_armed():
return False
return False

2 comments on commit 4404b96

@alandtse
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Do we need a version bump for pypi so I can update the PR in HA?

@adamaze
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Do we need a version bump for pypi so I can update the PR in HA?

i would also love to know when this will make it into HA. im currently using a hacky workaround that i would love to stop using

Please sign in to comment.