Skip to content

Commit

Permalink
Merge pull request #64 from alandtse/relocking
Browse files Browse the repository at this point in the history
fix: remove checks for state for lock/unlock
  • Loading branch information
alandtse committed Mar 15, 2020
2 parents 167660f + bc0dca9 commit 9c826ad
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 9c826ad

Please sign in to comment.