Skip to content

Commit

Permalink
feat: expose car_type and car_version for entities
Browse files Browse the repository at this point in the history
  • Loading branch information
alandtse committed Oct 22, 2019
1 parent 15282e4 commit 7aa48d5
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 1 deletion.
2 changes: 2 additions & 0 deletions teslajsonpy/battery_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def __init__(self, data, controller):
def update(self):
"""Update the battery state."""
self._controller.update(self._id, wake_if_asleep=False)
super().update()
data = self._controller.get_charging_params(self._id)
if data:
self.__battery_level = data['battery_level']
Expand Down Expand Up @@ -94,6 +95,7 @@ def __init__(self, data, controller):
def update(self):
"""Update the battery range state."""
self._controller.update(self._id, wake_if_asleep=False)
super().update()
data = self._controller.get_charging_params(self._id)
if data:
self.__battery_range = data['battery_range']
Expand Down
2 changes: 2 additions & 0 deletions teslajsonpy/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def __init__(self, data, controller):
def update(self):
"""Update the parking brake sensor."""
self._controller.update(self._id, wake_if_asleep=False)
super().update()
data = self._controller.get_drive_params(self._id)
if data:
if not data['shift_state'] or data['shift_state'] == 'P':
Expand Down Expand Up @@ -101,6 +102,7 @@ def __init__(self, data, controller):
def update(self):
"""Update the charger connection sensor."""
self._controller.update(self._id, wake_if_asleep=False)
super().update()
data = self._controller.get_charging_params(self._id)
if data:
if data['charging_state'] in ["Disconnected"]:
Expand Down
2 changes: 2 additions & 0 deletions teslajsonpy/charger.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def __init__(self, data, controller):
def update(self):
"""Update the charging state of the Tesla Vehicle."""
self._controller.update(self._id, wake_if_asleep=False)
super().update()
data = self._controller.get_charging_params(self._id)
if data and (time.time() - self.__manual_update_time > 60):
if data['charging_state'] != "Charging":
Expand Down Expand Up @@ -97,6 +98,7 @@ def __init__(self, data, controller):
def update(self):
"""Update the status of the range setting."""
self._controller.update(self._id, wake_if_asleep=False)
super().update()
data = self._controller.get_charging_params(self._id)
if data and (time.time() - self.__manual_update_time > 60):
self.__maxrange_state = data['charge_to_max_range']
Expand Down
3 changes: 2 additions & 1 deletion teslajsonpy/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def get_fan_status(self):
def update(self):
"""Update the HVAC state."""
self._controller.update(self._id, wake_if_asleep=False)

super().update()
data = self._controller.get_climate_params(self._id)
if data:
if time.time() - self.__manual_update_time > 60:
Expand Down Expand Up @@ -181,6 +181,7 @@ def get_outside_temp(self):
def update(self):
"""Update the temperature."""
self._controller.update(self._id, wake_if_asleep=False)
super().update()
data = self._controller.get_climate_params(self._id)
if data:
self.__inside_temp = (data['inside_temp'] if data['inside_temp']
Expand Down
2 changes: 2 additions & 0 deletions teslajsonpy/gps.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def get_location(self):
def update(self):
"""Update the current GPS location."""
self._controller.update(self._id, wake_if_asleep=False)
super().update()
data = self._controller.get_drive_params(self._id)
if data:
self.__longitude = data['longitude']
Expand Down Expand Up @@ -102,6 +103,7 @@ def __init__(self, data, controller):
def update(self):
"""Update the odometer and the unit of measurement based on GUI."""
self._controller.update(self._id, wake_if_asleep=False)
super().update()
data = self._controller.get_state_params(self._id)
if data:
self.__odometer = data['odometer']
Expand Down
2 changes: 2 additions & 0 deletions teslajsonpy/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def __init__(self, data, controller):
def update(self):
"""Update the lock state."""
self._controller.update(self._id, wake_if_asleep=False)
super().update()
data = self._controller.get_state_params(self._id)
if data and (time.time() - self.__manual_update_time > 60):
self.__lock_state = data['locked']
Expand Down Expand Up @@ -120,6 +121,7 @@ def __init__(self, data, controller):
def update(self):
"""Update state of the charger lock."""
self._controller.update(self._id, wake_if_asleep=False)
super().update()
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']) and
Expand Down
29 changes: 29 additions & 0 deletions teslajsonpy/vehicle.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
For more details about this api, please refer to the documentation at
https://github.com/zabuldon/teslajsonpy
"""
import logging

_LOGGER = logging.getLogger(__name__)

class VehicleDevice:
"""Home-assistant class of Tesla vehicles.
Expand Down Expand Up @@ -36,6 +38,8 @@ def __init__(self, data, controller):
self._display_name = data['display_name']
self._vin = data['vin']
self._state = data['state']
self._car_type = f"Model {str(self._vin[3]).upper()}"
self._car_version = ""
self._controller = controller
self.should_poll = True
self.type = "device"
Expand All @@ -56,6 +60,25 @@ def id(self):
"""Return the id of this Vehicle."""
return self._id

def car_name(self):
"""Return the software version of this Vehicle."""
return (
self._display_name if
self._display_name is not None and
self._display_name != self._vin[-6:]
else f'Tesla Model {str(self._vin[3]).upper()}'
)

@property
def car_version(self):
"""Return the software version of this Vehicle."""
return self._car_version

@property
def car_type(self):
"""Return the type of this Vehicle."""
return self._car_type

def assumed_state(self):
# pylint: disable=protected-access
"""Return whether the data is from an online vehicle."""
Expand All @@ -64,6 +87,12 @@ def assumed_state(self):
self._controller._last_wake_up_time[self.id()] >
self._controller.update_interval))

def update(self):
"""Update the car version."""
state = self._controller.get_state_params(self.id())
if state and 'car_version' in state:
self._car_version = state['car_version']

@staticmethod
def is_armable():
"""Return whether the data is from an online vehicle."""
Expand Down

0 comments on commit 7aa48d5

Please sign in to comment.