Skip to content

Commit

Permalink
fix: remove checks for state for lock/unlock
Browse files Browse the repository at this point in the history
Tesla will automatically relock so the lock state may not match the internal known
state and prevent a lock/unlock.
  • Loading branch information
alandtse committed Mar 15, 2020
1 parent 2de7e0f commit bc0dca9
Showing 1 changed file with 24 additions and 28 deletions.
52 changes: 24 additions & 28 deletions teslajsonpy/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,21 @@ async def async_update(self, wake_if_asleep=False) -> None:

async def lock(self):
"""Lock the doors."""
if not self.__lock_state:
data = await self._controller.command(
self._id, "door_lock", wake_if_asleep=True
)
if data and data["response"]["result"]:
self.__lock_state = True
self.__manual_update_time = time.time()
data = await self._controller.command(
self._id, "door_lock", wake_if_asleep=True
)
if data and data["response"]["result"]:
self.__lock_state = True
self.__manual_update_time = time.time()

async def unlock(self):
"""Unlock the doors and extend handles where applicable."""
if self.__lock_state:
data = await self._controller.command(
self._id, "door_unlock", wake_if_asleep=True
)
if data and data["response"]["result"]:
self.__lock_state = False
self.__manual_update_time = time.time()
data = await self._controller.command(
self._id, "door_unlock", wake_if_asleep=True
)
if data and data["response"]["result"]:
self.__lock_state = False
self.__manual_update_time = time.time()

def is_locked(self):
"""Return whether doors are locked."""
Expand Down Expand Up @@ -133,23 +131,21 @@ async def async_update(self, wake_if_asleep=False) -> None:

async def lock(self):
"""Close the charger door."""
if not self.__lock_state:
data = await self._controller.command(
self._id, "charge_port_door_close", wake_if_asleep=True
)
if data and data["response"]["result"]:
self.__lock_state = True
self.__manual_update_time = time.time()
data = await self._controller.command(
self._id, "charge_port_door_close", wake_if_asleep=True
)
if data and data["response"]["result"]:
self.__lock_state = True
self.__manual_update_time = time.time()

async def unlock(self):
"""Open the charger door."""
if self.__lock_state:
data = await self._controller.command(
self._id, "charge_port_door_open", wake_if_asleep=True
)
if data and data["response"]["result"]:
self.__lock_state = False
self.__manual_update_time = time.time()
data = await self._controller.command(
self._id, "charge_port_door_open", wake_if_asleep=True
)
if data and data["response"]["result"]:
self.__lock_state = False
self.__manual_update_time = time.time()

def is_locked(self):
"""Return whether the charger is closed."""
Expand Down

0 comments on commit bc0dca9

Please sign in to comment.