Skip to content

Commit

Permalink
fix(controller): convert old ids for commands
Browse files Browse the repository at this point in the history
  • Loading branch information
alandtse committed Jan 6, 2020
1 parent d8d11ed commit 5aae7c4
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions teslajsonpy/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ async def post(self, car_id, command, data=None, wake_if_asleep=True):
Tesla json object.
"""
car_id = self._update_id(car_id)
data = data or {}
return await self.__connection.post(f"vehicles/{car_id}/{command}", data=data)

Expand Down Expand Up @@ -343,6 +344,7 @@ async def get(self, car_id, command, wake_if_asleep=False):
Tesla json object.
"""
car_id = self._update_id(car_id)
return await self.__connection.get(f"vehicles/{car_id}/{command}")

async def data_request(self, car_id, name, wake_if_asleep=False):
Expand All @@ -368,6 +370,7 @@ async def data_request(self, car_id, name, wake_if_asleep=False):
Tesla json object.
"""
car_id = self._update_id(car_id)
return (
await self.get(
car_id, f"vehicle_data/{name}", wake_if_asleep=wake_if_asleep
Expand Down Expand Up @@ -397,6 +400,7 @@ async def command(self, car_id, name, data=None, wake_if_asleep=True):
Tesla json object.
"""
car_id = self._update_id(car_id)
data = data or {}
return await self.post(
car_id, f"command/{name}", data=data, wake_if_asleep=wake_if_asleep
Expand All @@ -411,6 +415,7 @@ def get_homeassistant_components(self):

async def _wake_up(self, car_id):
car_vin = self._id_to_vin(car_id)
car_id = self._update_id(car_id)
async with self.__wakeup_conds[car_vin]:
cur_time = int(time.time())
if not self.car_online[car_vin] or (
Expand Down Expand Up @@ -466,6 +471,7 @@ async def update(self, car_id=None, wake_if_asleep=False, force=False):
# to update.
update_succeeded = False
car_vin = self._id_to_vin(car_id)
car_id = self._update_id(car_id)
for vin, online in self.car_online.items():
# If specific car_id provided, only update match
if car_vin and car_vin != vin:
Expand All @@ -486,9 +492,7 @@ async def update(self, car_id=None, wake_if_asleep=False, force=False):
)
): # Only update cars with update flag on
try:
data = await self.get(
self.__vin_id_map[vin], "data", wake_if_asleep
)
data = await self.get(car_id, "data", wake_if_asleep)
except TeslaException:
data = None
if data and data["response"]:
Expand Down Expand Up @@ -629,8 +633,10 @@ def update_interval(self, value: int) -> None:
self._update_interval = int(value)

def _id_to_vin(self, car_id: Text) -> Optional[Text]:
if car_id:
result = self.__id_vin_map.get(car_id)
if result:
return result
return None
return self.__id_vin_map.get(car_id)

def _update_id(self, car_id: Text) -> Optional[Text]:
new_car_id = self.__vin_id_map.get(self._id_to_vin(car_id))
if new_car_id:
car_id = new_car_id
return car_id

0 comments on commit 5aae7c4

Please sign in to comment.