Skip to content

Commit

Permalink
Adding charge port door lock.
Browse files Browse the repository at this point in the history
  • Loading branch information
ultratoto14 committed Oct 7, 2018
1 parent 63e6ffd commit 9bc21c6
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
43 changes: 43 additions & 0 deletions teslajsonpy/Lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,46 @@ def is_locked(self):
@staticmethod
def has_battery():
return False


class ChargerLock(VehicleDevice):
def __init__(self, data, controller):
super().__init__(data, controller)
self.__manual_update_time = 0
self.__lock_state = False

self.type = 'charger door lock'
self.hass_type = 'lock'

self.name = self._name()

self.uniq_name = self._uniq_name()
self.bin_type = 0x7
self.update()

def update(self):
self._controller.update(self._id)
data = self._controller.get_charging_params(self._id)
if data and (time.time() - self.__manual_update_time > 60):
self.__lock_state = not data['charge_port_door_open']

def lock(self):
if not self.__lock_state:
data = self._controller.command(self._id, 'charge_port_door_close')
if data['response']['result']:
self.__lock_state = True
self.__manual_update_time = time.time()

def unlock(self):
if self.__lock_state:
data = self._controller.command(self._id, 'charge_port_door_open')
if data['response']['result']:
self.__lock_state = False
self.__manual_update_time = time.time()

def is_locked(self):
return self.__lock_state

@staticmethod
def has_battery():
return False
3 changes: 2 additions & 1 deletion teslajsonpy/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from multiprocessing import RLock
from teslajsonpy.connection import Connection
from teslajsonpy.BatterySensor import Battery, Range
from teslajsonpy.Lock import Lock
from teslajsonpy.Lock import Lock, ChargerLock
from teslajsonpy.Climate import Climate, TempSensor
from teslajsonpy.BinarySensor import ParkingSensor, ChargerConnectionSensor
from teslajsonpy.Charger import ChargerSwitch, RangeSwitch
Expand Down Expand Up @@ -32,6 +32,7 @@ def __init__(self, email, password, update_interval):
self.__vehicles.append(Range(car, self))
self.__vehicles.append(TempSensor(car, self))
self.__vehicles.append(Lock(car, self))
self.__vehicles.append(ChargerLock(car, self))
self.__vehicles.append(ChargerConnectionSensor(car, self))
self.__vehicles.append(ChargerSwitch(car, self))
self.__vehicles.append(RangeSwitch(car, self))
Expand Down

0 comments on commit 9bc21c6

Please sign in to comment.